isp.c revision 1.39.2.6 1 1.39.2.6 bouyer /* $NetBSD: isp.c,v 1.39.2.6 2001/03/12 13:30:25 bouyer Exp $ */
2 1.1 cgd /*
3 1.39.2.2 bouyer * This driver, which is contained in NetBSD in the files:
4 1.39.2.2 bouyer *
5 1.39.2.2 bouyer * sys/dev/ic/isp.c
6 1.39.2.4 bouyer * sys/dev/ic/isp_inline.h
7 1.39.2.4 bouyer * sys/dev/ic/isp_netbsd.c
8 1.39.2.4 bouyer * sys/dev/ic/isp_netbsd.h
9 1.39.2.4 bouyer * sys/dev/ic/isp_target.c
10 1.39.2.4 bouyer * sys/dev/ic/isp_target.h
11 1.39.2.4 bouyer * sys/dev/ic/isp_tpublic.h
12 1.39.2.4 bouyer * sys/dev/ic/ispmbox.h
13 1.39.2.4 bouyer * sys/dev/ic/ispreg.h
14 1.39.2.4 bouyer * sys/dev/ic/ispvar.h
15 1.39.2.2 bouyer * sys/microcode/isp/asm_sbus.h
16 1.39.2.2 bouyer * sys/microcode/isp/asm_1040.h
17 1.39.2.2 bouyer * sys/microcode/isp/asm_1080.h
18 1.39.2.2 bouyer * sys/microcode/isp/asm_12160.h
19 1.39.2.2 bouyer * sys/microcode/isp/asm_2100.h
20 1.39.2.2 bouyer * sys/microcode/isp/asm_2200.h
21 1.39.2.2 bouyer * sys/pci/isp_pci.c
22 1.39.2.2 bouyer * sys/sbus/isp_sbus.c
23 1.39.2.2 bouyer *
24 1.39.2.2 bouyer * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
25 1.39.2.2 bouyer * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
26 1.39.2.2 bouyer * Linux versions. This tends to be an interesting maintenance problem.
27 1.39.2.2 bouyer *
28 1.39.2.2 bouyer * Please coordinate with Matthew Jacob on changes you wish to make here.
29 1.39.2.2 bouyer */
30 1.39.2.2 bouyer /*
31 1.39.2.2 bouyer * Machine and OS Independent (well, as best as possible)
32 1.39.2.2 bouyer * code for the Qlogic ISP SCSI adapters.
33 1.39.2.2 bouyer *
34 1.39.2.2 bouyer * Copyright (c) 1997, 1998, 1999 by Matthew Jacob
35 1.39.2.2 bouyer * NASA/Ames Research Center
36 1.1 cgd * All rights reserved.
37 1.1 cgd *
38 1.1 cgd * Redistribution and use in source and binary forms, with or without
39 1.1 cgd * modification, are permitted provided that the following conditions
40 1.1 cgd * are met:
41 1.1 cgd * 1. Redistributions of source code must retain the above copyright
42 1.39.2.2 bouyer * notice immediately at the beginning of the file, without modification,
43 1.39.2.2 bouyer * this list of conditions, and the following disclaimer.
44 1.39.2.2 bouyer * 2. The name of the author may not be used to endorse or promote products
45 1.39.2.2 bouyer * derived from this software without specific prior written permission.
46 1.1 cgd *
47 1.39.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
48 1.39.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 1.39.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 1.39.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
51 1.39.2.2 bouyer * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 1.39.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 1.39.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 1.39.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 1.39.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 1.39.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 1.39.2.2 bouyer * SUCH DAMAGE.
58 1.1 cgd */
59 1.39.2.6 bouyer
60 1.1 cgd /*
61 1.1 cgd * Inspiration and ideas about this driver are from Erik Moe's Linux driver
62 1.23 mjacob * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
63 1.23 mjacob * ideas dredged from the Solaris driver.
64 1.1 cgd */
65 1.1 cgd
66 1.23 mjacob /*
67 1.23 mjacob * Include header file appropriate for platform we're building on.
68 1.23 mjacob */
69 1.1 cgd
70 1.23 mjacob #ifdef __NetBSD__
71 1.23 mjacob #include <dev/ic/isp_netbsd.h>
72 1.23 mjacob #endif
73 1.23 mjacob #ifdef __FreeBSD__
74 1.23 mjacob #include <dev/isp/isp_freebsd.h>
75 1.23 mjacob #endif
76 1.33 mjacob #ifdef __OpenBSD__
77 1.33 mjacob #include <dev/ic/isp_openbsd.h>
78 1.33 mjacob #endif
79 1.23 mjacob #ifdef __linux__
80 1.29 mjacob #include "isp_linux.h"
81 1.23 mjacob #endif
82 1.39.2.2 bouyer #ifdef __svr4__
83 1.39.2.2 bouyer #include "isp_solaris.h"
84 1.39.2.2 bouyer #endif
85 1.1 cgd
86 1.23 mjacob /*
87 1.23 mjacob * General defines
88 1.23 mjacob */
89 1.1 cgd
90 1.23 mjacob #define MBOX_DELAY_COUNT 1000000 / 100
91 1.1 cgd
92 1.23 mjacob /*
93 1.27 mjacob * Local static data
94 1.27 mjacob */
95 1.39.2.4 bouyer static const char warnlun[] =
96 1.39.2.2 bouyer "WARNING- cannot determine Expanded LUN capability- limiting to one LUN";
97 1.39.2.4 bouyer static const char portshift[] =
98 1.39.2.2 bouyer "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
99 1.39.2.4 bouyer static const char portdup[] =
100 1.39.2.2 bouyer "Target %d duplicates Target %d- killing off both";
101 1.39.2.4 bouyer static const char retained[] =
102 1.39.2.2 bouyer "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
103 1.39.2.4 bouyer static const char lretained[] =
104 1.39.2.2 bouyer "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
105 1.39.2.4 bouyer static const char plogout[] =
106 1.39.2.2 bouyer "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
107 1.39.2.4 bouyer static const char plogierr[] =
108 1.39.2.2 bouyer "Command Error in PLOGI for Port 0x%x (0x%x)";
109 1.39.2.4 bouyer static const char nopdb[] =
110 1.39.2.2 bouyer "Could not get PDB for Device @ Port 0x%x";
111 1.39.2.4 bouyer static const char pdbmfail1[] =
112 1.39.2.2 bouyer "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
113 1.39.2.4 bouyer static const char pdbmfail2[] =
114 1.39.2.2 bouyer "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
115 1.39.2.4 bouyer static const char ldumped[] =
116 1.39.2.2 bouyer "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
117 1.39.2.4 bouyer static const char notresp[] =
118 1.39.2.3 bouyer "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
119 1.39.2.4 bouyer static const char xact1[] =
120 1.39.2.2 bouyer "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
121 1.39.2.4 bouyer static const char xact2[] =
122 1.39.2.2 bouyer "HBA attempted queued transaction to target routine %d on target %d bus %d";
123 1.39.2.4 bouyer static const char xact3[] =
124 1.39.2.2 bouyer "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
125 1.39.2.4 bouyer static const char pskip[] =
126 1.39.2.2 bouyer "SCSI phase skipped for target %d.%d.%d";
127 1.39.2.4 bouyer static const char topology[] =
128 1.39.2.2 bouyer "Loop ID %d, AL_PA 0x%x, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
129 1.39.2.4 bouyer static const char finmsg[] =
130 1.39.2.6 bouyer "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
131 1.27 mjacob /*
132 1.25 mjacob * Local function prototypes.
133 1.23 mjacob */
134 1.28 mjacob static int isp_parse_async __P((struct ispsoftc *, int));
135 1.25 mjacob static int isp_handle_other_response
136 1.39.2.2 bouyer __P((struct ispsoftc *, ispstatusreq_t *, u_int16_t *));
137 1.23 mjacob static void isp_parse_status
138 1.39.2.2 bouyer __P((struct ispsoftc *, ispstatusreq_t *, XS_T *));
139 1.38 mjacob static void isp_fastpost_complete __P((struct ispsoftc *, u_int32_t));
140 1.36 mjacob static void isp_scsi_init __P((struct ispsoftc *));
141 1.36 mjacob static void isp_scsi_channel_init __P((struct ispsoftc *, int));
142 1.10 mjacob static void isp_fibre_init __P((struct ispsoftc *));
143 1.33 mjacob static void isp_mark_getpdb_all __P((struct ispsoftc *));
144 1.39.2.6 bouyer static int isp_getmap __P((struct ispsoftc *, fcpos_map_t *));
145 1.33 mjacob static int isp_getpdb __P((struct ispsoftc *, int, isp_pdb_t *));
146 1.37 mjacob static u_int64_t isp_get_portname __P((struct ispsoftc *, int, int));
147 1.34 mjacob static int isp_fclink_test __P((struct ispsoftc *, int));
148 1.39.2.2 bouyer static char *isp2100_fw_statename __P((int));
149 1.39.2.6 bouyer static int isp_pdb_sync __P((struct ispsoftc *));
150 1.39.2.6 bouyer static int isp_scan_loop __P((struct ispsoftc *));
151 1.37 mjacob static int isp_scan_fabric __P((struct ispsoftc *));
152 1.39.2.5 bouyer static void isp_register_fc4_type __P((struct ispsoftc *));
153 1.10 mjacob static void isp_fw_state __P((struct ispsoftc *));
154 1.39.2.2 bouyer static void isp_mboxcmd __P((struct ispsoftc *, mbreg_t *, int));
155 1.1 cgd
156 1.36 mjacob static void isp_update __P((struct ispsoftc *));
157 1.36 mjacob static void isp_update_bus __P((struct ispsoftc *, int));
158 1.36 mjacob static void isp_setdfltparm __P((struct ispsoftc *, int));
159 1.25 mjacob static int isp_read_nvram __P((struct ispsoftc *));
160 1.25 mjacob static void isp_rdnvram_word __P((struct ispsoftc *, int, u_int16_t *));
161 1.39.2.2 bouyer static void isp_parse_nvram_1020 __P((struct ispsoftc *, u_int8_t *));
162 1.39.2.2 bouyer static void isp_parse_nvram_1080 __P((struct ispsoftc *, int, u_int8_t *));
163 1.39.2.2 bouyer static void isp_parse_nvram_12160 __P((struct ispsoftc *, int, u_int8_t *));
164 1.39.2.2 bouyer static void isp_parse_nvram_2100 __P((struct ispsoftc *, u_int8_t *));
165 1.25 mjacob
166 1.1 cgd /*
167 1.1 cgd * Reset Hardware.
168 1.25 mjacob *
169 1.39.2.2 bouyer * Hit the chip over the head, download new f/w if available and set it running.
170 1.25 mjacob *
171 1.24 mjacob * Locking done elsewhere.
172 1.1 cgd */
173 1.1 cgd void
174 1.1 cgd isp_reset(isp)
175 1.1 cgd struct ispsoftc *isp;
176 1.1 cgd {
177 1.1 cgd mbreg_t mbs;
178 1.39.2.2 bouyer int loops, i, touched, dodnld = 1;
179 1.39.2.5 bouyer char *revname = "????";
180 1.1 cgd
181 1.1 cgd isp->isp_state = ISP_NILSTATE;
182 1.4 mjacob
183 1.39.2.2 bouyer
184 1.4 mjacob /*
185 1.25 mjacob * Basic types (SCSI, FibreChannel and PCI or SBus)
186 1.25 mjacob * have been set in the MD code. We figure out more
187 1.25 mjacob * here.
188 1.39.2.2 bouyer *
189 1.32 mjacob * After we've fired this chip up, zero out the conf1 register
190 1.39.2.2 bouyer * for SCSI adapters and do other settings for the 2100.
191 1.32 mjacob */
192 1.32 mjacob
193 1.32 mjacob /*
194 1.31 mjacob * Get the current running firmware revision out of the
195 1.31 mjacob * chip before we hit it over the head (if this is our
196 1.31 mjacob * first time through). Note that we store this as the
197 1.31 mjacob * 'ROM' firmware revision- which it may not be. In any
198 1.31 mjacob * case, we don't really use this yet, but we may in
199 1.31 mjacob * the future.
200 1.31 mjacob */
201 1.39.2.2 bouyer if ((touched = isp->isp_touched) == 0) {
202 1.35 mjacob /*
203 1.39.2.2 bouyer * First see whether or not we're sitting in the ISP PROM.
204 1.39.2.2 bouyer * If we've just been reset, we'll have the string "ISP "
205 1.39.2.2 bouyer * spread through outgoing mailbox registers 1-3.
206 1.39.2.2 bouyer */
207 1.39.2.2 bouyer if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
208 1.39.2.2 bouyer ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
209 1.39.2.2 bouyer ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
210 1.39.2.2 bouyer /*
211 1.39.2.2 bouyer * Just in case it was paused...
212 1.39.2.2 bouyer */
213 1.39.2.2 bouyer ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
214 1.39.2.2 bouyer mbs.param[0] = MBOX_ABOUT_FIRMWARE;
215 1.39.2.4 bouyer isp_mboxcmd(isp, &mbs, MBOX_COMMAND_ERROR);
216 1.39.2.2 bouyer /*
217 1.39.2.2 bouyer * This *shouldn't* fail.....
218 1.39.2.2 bouyer */
219 1.39.2.2 bouyer if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
220 1.39.2.2 bouyer isp->isp_romfw_rev[0] = mbs.param[1];
221 1.39.2.2 bouyer isp->isp_romfw_rev[1] = mbs.param[2];
222 1.39.2.2 bouyer isp->isp_romfw_rev[2] = mbs.param[3];
223 1.39.2.2 bouyer }
224 1.30 mjacob }
225 1.39.2.2 bouyer isp->isp_touched = 1;
226 1.30 mjacob }
227 1.30 mjacob
228 1.35 mjacob DISABLE_INTS(isp);
229 1.35 mjacob
230 1.31 mjacob /*
231 1.39.2.6 bouyer * Put the board into PAUSE mode (so we can read the SXP registers
232 1.39.2.6 bouyer * or write FPM/FBM registers).
233 1.31 mjacob */
234 1.31 mjacob ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
235 1.31 mjacob
236 1.37 mjacob if (IS_FC(isp)) {
237 1.37 mjacob switch (isp->isp_type) {
238 1.37 mjacob case ISP_HA_FC_2100:
239 1.39.2.4 bouyer revname = "2100";
240 1.37 mjacob break;
241 1.37 mjacob case ISP_HA_FC_2200:
242 1.39.2.4 bouyer revname = "2200";
243 1.37 mjacob break;
244 1.37 mjacob default:
245 1.37 mjacob break;
246 1.37 mjacob }
247 1.39.2.6 bouyer /*
248 1.39.2.6 bouyer * While we're paused, reset the FPM module and FBM fifos.
249 1.39.2.6 bouyer */
250 1.39.2.6 bouyer ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
251 1.39.2.6 bouyer ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
252 1.39.2.6 bouyer ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
253 1.39.2.6 bouyer ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
254 1.39.2.6 bouyer ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
255 1.39.2.2 bouyer } else if (IS_1240(isp)) {
256 1.39.2.2 bouyer sdparam *sdp = isp->isp_param;
257 1.39.2.2 bouyer revname = "1240";
258 1.36 mjacob isp->isp_clock = 60;
259 1.39.2.2 bouyer sdp->isp_ultramode = 1;
260 1.39.2.2 bouyer sdp++;
261 1.39.2.2 bouyer sdp->isp_ultramode = 1;
262 1.39.2.2 bouyer /*
263 1.39.2.2 bouyer * XXX: Should probably do some bus sensing.
264 1.39.2.2 bouyer */
265 1.39.2.2 bouyer } else if (IS_ULTRA2(isp)) {
266 1.39.2.4 bouyer static const char m[] = "bus %d is in %s Mode";
267 1.34 mjacob u_int16_t l;
268 1.33 mjacob sdparam *sdp = isp->isp_param;
269 1.39.2.2 bouyer
270 1.36 mjacob isp->isp_clock = 100;
271 1.39.2.2 bouyer
272 1.39.2.2 bouyer if (IS_1280(isp))
273 1.39.2.2 bouyer revname = "1280";
274 1.39.2.2 bouyer else if (IS_1080(isp))
275 1.39.2.2 bouyer revname = "1080";
276 1.39.2.2 bouyer else if (IS_12160(isp))
277 1.39.2.2 bouyer revname = "12160";
278 1.39.2.2 bouyer else
279 1.39.2.2 bouyer revname = "<UNKLVD>";
280 1.39.2.2 bouyer
281 1.34 mjacob l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
282 1.34 mjacob switch (l) {
283 1.34 mjacob case ISP1080_LVD_MODE:
284 1.34 mjacob sdp->isp_lvdmode = 1;
285 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
286 1.34 mjacob break;
287 1.34 mjacob case ISP1080_HVD_MODE:
288 1.34 mjacob sdp->isp_diffmode = 1;
289 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
290 1.34 mjacob break;
291 1.34 mjacob case ISP1080_SE_MODE:
292 1.34 mjacob sdp->isp_ultramode = 1;
293 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
294 1.34 mjacob break;
295 1.34 mjacob default:
296 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
297 1.39.2.2 bouyer "unknown mode on bus %d (0x%x)", 0, l);
298 1.34 mjacob break;
299 1.34 mjacob }
300 1.39.2.2 bouyer
301 1.39.2.2 bouyer if (IS_DUALBUS(isp)) {
302 1.39.2.2 bouyer sdp++;
303 1.39.2.2 bouyer l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
304 1.39.2.2 bouyer l &= ISP1080_MODE_MASK;
305 1.39.2.2 bouyer switch(l) {
306 1.39.2.2 bouyer case ISP1080_LVD_MODE:
307 1.39.2.2 bouyer sdp->isp_lvdmode = 1;
308 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
309 1.39.2.2 bouyer break;
310 1.39.2.2 bouyer case ISP1080_HVD_MODE:
311 1.39.2.2 bouyer sdp->isp_diffmode = 1;
312 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG,
313 1.39.2.2 bouyer m, 1, "Differential");
314 1.39.2.2 bouyer break;
315 1.39.2.2 bouyer case ISP1080_SE_MODE:
316 1.39.2.2 bouyer sdp->isp_ultramode = 1;
317 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG,
318 1.39.2.2 bouyer m, 1, "Single-Ended");
319 1.39.2.2 bouyer break;
320 1.39.2.2 bouyer default:
321 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
322 1.39.2.2 bouyer "unknown mode on bus %d (0x%x)", 1, l);
323 1.39.2.2 bouyer break;
324 1.39.2.2 bouyer }
325 1.39.2.2 bouyer }
326 1.10 mjacob } else {
327 1.25 mjacob sdparam *sdp = isp->isp_param;
328 1.30 mjacob i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
329 1.30 mjacob switch (i) {
330 1.10 mjacob default:
331 1.39.2.2 bouyer isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
332 1.25 mjacob /* FALLTHROUGH */
333 1.10 mjacob case 1:
334 1.34 mjacob revname = "1020";
335 1.10 mjacob isp->isp_type = ISP_HA_SCSI_1020;
336 1.36 mjacob isp->isp_clock = 40;
337 1.22 mjacob break;
338 1.22 mjacob case 2:
339 1.25 mjacob /*
340 1.25 mjacob * Some 1020A chips are Ultra Capable, but don't
341 1.25 mjacob * run the clock rate up for that unless told to
342 1.25 mjacob * do so by the Ultra Capable bits being set.
343 1.25 mjacob */
344 1.34 mjacob revname = "1020A";
345 1.22 mjacob isp->isp_type = ISP_HA_SCSI_1020A;
346 1.36 mjacob isp->isp_clock = 40;
347 1.10 mjacob break;
348 1.10 mjacob case 3:
349 1.25 mjacob revname = "1040";
350 1.25 mjacob isp->isp_type = ISP_HA_SCSI_1040;
351 1.36 mjacob isp->isp_clock = 60;
352 1.25 mjacob break;
353 1.25 mjacob case 4:
354 1.10 mjacob revname = "1040A";
355 1.10 mjacob isp->isp_type = ISP_HA_SCSI_1040A;
356 1.36 mjacob isp->isp_clock = 60;
357 1.10 mjacob break;
358 1.10 mjacob case 5:
359 1.10 mjacob revname = "1040B";
360 1.10 mjacob isp->isp_type = ISP_HA_SCSI_1040B;
361 1.36 mjacob isp->isp_clock = 60;
362 1.10 mjacob break;
363 1.35 mjacob case 6:
364 1.39.2.2 bouyer revname = "1040C";
365 1.35 mjacob isp->isp_type = ISP_HA_SCSI_1040C;
366 1.36 mjacob isp->isp_clock = 60;
367 1.35 mjacob break;
368 1.8 mjacob }
369 1.25 mjacob /*
370 1.31 mjacob * Now, while we're at it, gather info about ultra
371 1.31 mjacob * and/or differential mode.
372 1.25 mjacob */
373 1.31 mjacob if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
374 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
375 1.31 mjacob sdp->isp_diffmode = 1;
376 1.31 mjacob } else {
377 1.31 mjacob sdp->isp_diffmode = 0;
378 1.31 mjacob }
379 1.31 mjacob i = ISP_READ(isp, RISC_PSR);
380 1.31 mjacob if (isp->isp_bustype == ISP_BT_SBUS) {
381 1.31 mjacob i &= RISC_PSR_SBUS_ULTRA;
382 1.30 mjacob } else {
383 1.31 mjacob i &= RISC_PSR_PCI_ULTRA;
384 1.31 mjacob }
385 1.31 mjacob if (i != 0) {
386 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
387 1.31 mjacob sdp->isp_ultramode = 1;
388 1.33 mjacob /*
389 1.33 mjacob * If we're in Ultra Mode, we have to be 60Mhz clock-
390 1.33 mjacob * even for the SBus version.
391 1.33 mjacob */
392 1.36 mjacob isp->isp_clock = 60;
393 1.34 mjacob } else {
394 1.31 mjacob sdp->isp_ultramode = 0;
395 1.33 mjacob /*
396 1.33 mjacob * Clock is known. Gronk.
397 1.33 mjacob */
398 1.25 mjacob }
399 1.25 mjacob
400 1.25 mjacob /*
401 1.25 mjacob * Machine dependent clock (if set) overrides
402 1.25 mjacob * our generic determinations.
403 1.25 mjacob */
404 1.25 mjacob if (isp->isp_mdvec->dv_clock) {
405 1.36 mjacob if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
406 1.36 mjacob isp->isp_clock = isp->isp_mdvec->dv_clock;
407 1.25 mjacob }
408 1.25 mjacob }
409 1.31 mjacob
410 1.4 mjacob }
411 1.8 mjacob
412 1.1 cgd /*
413 1.39.2.3 bouyer * Clear instrumentation
414 1.39.2.3 bouyer */
415 1.39.2.3 bouyer isp->isp_intcnt = isp->isp_intbogus = 0;
416 1.39.2.3 bouyer
417 1.39.2.3 bouyer /*
418 1.10 mjacob * Do MD specific pre initialization
419 1.1 cgd */
420 1.10 mjacob ISP_RESET0(isp);
421 1.25 mjacob
422 1.31 mjacob again:
423 1.30 mjacob
424 1.1 cgd /*
425 1.10 mjacob * Hit the chip over the head with hammer,
426 1.10 mjacob * and give the ISP a chance to recover.
427 1.1 cgd */
428 1.1 cgd
429 1.33 mjacob if (IS_SCSI(isp)) {
430 1.10 mjacob ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
431 1.10 mjacob /*
432 1.10 mjacob * A slight delay...
433 1.10 mjacob */
434 1.39.2.2 bouyer USEC_DELAY(100);
435 1.33 mjacob
436 1.10 mjacob /*
437 1.10 mjacob * Clear data && control DMA engines.
438 1.10 mjacob */
439 1.10 mjacob ISP_WRITE(isp, CDMA_CONTROL,
440 1.34 mjacob DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
441 1.10 mjacob ISP_WRITE(isp, DDMA_CONTROL,
442 1.34 mjacob DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
443 1.33 mjacob
444 1.33 mjacob
445 1.10 mjacob } else {
446 1.10 mjacob ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
447 1.10 mjacob /*
448 1.10 mjacob * A slight delay...
449 1.10 mjacob */
450 1.39.2.2 bouyer USEC_DELAY(100);
451 1.31 mjacob
452 1.31 mjacob /*
453 1.31 mjacob * Clear data && control DMA engines.
454 1.31 mjacob */
455 1.10 mjacob ISP_WRITE(isp, CDMA2100_CONTROL,
456 1.10 mjacob DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
457 1.10 mjacob ISP_WRITE(isp, TDMA2100_CONTROL,
458 1.10 mjacob DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
459 1.10 mjacob ISP_WRITE(isp, RDMA2100_CONTROL,
460 1.10 mjacob DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
461 1.10 mjacob }
462 1.10 mjacob
463 1.1 cgd /*
464 1.1 cgd * Wait for ISP to be ready to go...
465 1.1 cgd */
466 1.1 cgd loops = MBOX_DELAY_COUNT;
467 1.10 mjacob for (;;) {
468 1.38 mjacob if (IS_SCSI(isp)) {
469 1.10 mjacob if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
470 1.10 mjacob break;
471 1.10 mjacob } else {
472 1.10 mjacob if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
473 1.10 mjacob break;
474 1.10 mjacob }
475 1.39.2.2 bouyer USEC_DELAY(100);
476 1.1 cgd if (--loops < 0) {
477 1.39.2.2 bouyer ISP_DUMPREGS(isp, "chip reset timed out");
478 1.1 cgd return;
479 1.1 cgd }
480 1.1 cgd }
481 1.31 mjacob
482 1.1 cgd /*
483 1.31 mjacob * After we've fired this chip up, zero out the conf1 register
484 1.31 mjacob * for SCSI adapters and other settings for the 2100.
485 1.1 cgd */
486 1.31 mjacob
487 1.33 mjacob if (IS_SCSI(isp)) {
488 1.10 mjacob ISP_WRITE(isp, BIU_CONF1, 0);
489 1.10 mjacob } else {
490 1.10 mjacob ISP_WRITE(isp, BIU2100_CSR, 0);
491 1.10 mjacob }
492 1.1 cgd
493 1.31 mjacob /*
494 1.31 mjacob * Reset RISC Processor
495 1.31 mjacob */
496 1.1 cgd ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
497 1.39.2.2 bouyer USEC_DELAY(100);
498 1.39.2.6 bouyer /* Clear semaphore register (just to be sure) */
499 1.39.2.6 bouyer ISP_WRITE(isp, BIU_SEMA, 0);
500 1.1 cgd
501 1.30 mjacob /*
502 1.31 mjacob * Establish some initial burst rate stuff.
503 1.30 mjacob * (only for the 1XX0 boards). This really should
504 1.30 mjacob * be done later after fetching from NVRAM.
505 1.30 mjacob */
506 1.33 mjacob if (IS_SCSI(isp)) {
507 1.31 mjacob u_int16_t tmp = isp->isp_mdvec->dv_conf1;
508 1.30 mjacob /*
509 1.30 mjacob * Busted FIFO. Turn off all but burst enables.
510 1.30 mjacob */
511 1.30 mjacob if (isp->isp_type == ISP_HA_SCSI_1040A) {
512 1.31 mjacob tmp &= BIU_BURST_ENABLE;
513 1.30 mjacob }
514 1.31 mjacob ISP_SETBITS(isp, BIU_CONF1, tmp);
515 1.31 mjacob if (tmp & BIU_BURST_ENABLE) {
516 1.1 cgd ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
517 1.1 cgd ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
518 1.1 cgd }
519 1.31 mjacob #ifdef PTI_CARDS
520 1.31 mjacob if (((sdparam *) isp->isp_param)->isp_ultramode) {
521 1.34 mjacob while (ISP_READ(isp, RISC_MTR) != 0x1313) {
522 1.31 mjacob ISP_WRITE(isp, RISC_MTR, 0x1313);
523 1.31 mjacob ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
524 1.31 mjacob }
525 1.34 mjacob } else {
526 1.31 mjacob ISP_WRITE(isp, RISC_MTR, 0x1212);
527 1.31 mjacob }
528 1.31 mjacob /*
529 1.31 mjacob * PTI specific register
530 1.31 mjacob */
531 1.31 mjacob ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
532 1.31 mjacob #else
533 1.31 mjacob ISP_WRITE(isp, RISC_MTR, 0x1212);
534 1.31 mjacob #endif
535 1.31 mjacob } else {
536 1.31 mjacob ISP_WRITE(isp, RISC_MTR2100, 0x1212);
537 1.39.2.6 bouyer if (IS_2200(isp)) {
538 1.39.2.6 bouyer ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
539 1.39.2.6 bouyer }
540 1.1 cgd }
541 1.31 mjacob
542 1.1 cgd ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
543 1.1 cgd
544 1.1 cgd /*
545 1.1 cgd * Do MD specific post initialization
546 1.1 cgd */
547 1.1 cgd ISP_RESET1(isp);
548 1.1 cgd
549 1.1 cgd /*
550 1.31 mjacob * Wait for everything to finish firing up...
551 1.31 mjacob */
552 1.31 mjacob loops = MBOX_DELAY_COUNT;
553 1.31 mjacob while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
554 1.39.2.2 bouyer USEC_DELAY(100);
555 1.31 mjacob if (--loops < 0) {
556 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
557 1.39.2.2 bouyer "MBOX_BUSY never cleared on reset");
558 1.31 mjacob return;
559 1.31 mjacob }
560 1.31 mjacob }
561 1.31 mjacob
562 1.31 mjacob /*
563 1.31 mjacob * Up until this point we've done everything by just reading or
564 1.31 mjacob * setting registers. From this point on we rely on at least *some*
565 1.31 mjacob * kind of firmware running in the card.
566 1.31 mjacob */
567 1.31 mjacob
568 1.31 mjacob /*
569 1.1 cgd * Do some sanity checking.
570 1.1 cgd */
571 1.1 cgd mbs.param[0] = MBOX_NO_OP;
572 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
573 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
574 1.1 cgd return;
575 1.1 cgd }
576 1.1 cgd
577 1.37 mjacob if (IS_SCSI(isp)) {
578 1.10 mjacob mbs.param[0] = MBOX_MAILBOX_REG_TEST;
579 1.10 mjacob mbs.param[1] = 0xdead;
580 1.10 mjacob mbs.param[2] = 0xbeef;
581 1.10 mjacob mbs.param[3] = 0xffff;
582 1.10 mjacob mbs.param[4] = 0x1111;
583 1.10 mjacob mbs.param[5] = 0xa5a5;
584 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
585 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
586 1.10 mjacob return;
587 1.10 mjacob }
588 1.10 mjacob if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
589 1.10 mjacob mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
590 1.10 mjacob mbs.param[5] != 0xa5a5) {
591 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
592 1.39.2.2 bouyer "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
593 1.39.2.2 bouyer mbs.param[1], mbs.param[2], mbs.param[3],
594 1.39.2.2 bouyer mbs.param[4], mbs.param[5]);
595 1.1 cgd return;
596 1.1 cgd }
597 1.10 mjacob
598 1.1 cgd }
599 1.1 cgd
600 1.1 cgd /*
601 1.18 mjacob * Download new Firmware, unless requested not to do so.
602 1.18 mjacob * This is made slightly trickier in some cases where the
603 1.18 mjacob * firmware of the ROM revision is newer than the revision
604 1.18 mjacob * compiled into the driver. So, where we used to compare
605 1.18 mjacob * versions of our f/w and the ROM f/w, now we just see
606 1.18 mjacob * whether we have f/w at all and whether a config flag
607 1.18 mjacob * has disabled our download.
608 1.1 cgd */
609 1.39.2.2 bouyer if ((isp->isp_mdvec->dv_ispfw == NULL) ||
610 1.23 mjacob (isp->isp_confopts & ISP_CFG_NORELOAD)) {
611 1.10 mjacob dodnld = 0;
612 1.10 mjacob }
613 1.10 mjacob
614 1.39.2.2 bouyer if (dodnld) {
615 1.39.2.2 bouyer u_int16_t fwlen = isp->isp_mdvec->dv_ispfw[3];
616 1.39.2.2 bouyer for (i = 0; i < fwlen; i++) {
617 1.10 mjacob mbs.param[0] = MBOX_WRITE_RAM_WORD;
618 1.39.2.2 bouyer mbs.param[1] = ISP_CODE_ORG + i;
619 1.10 mjacob mbs.param[2] = isp->isp_mdvec->dv_ispfw[i];
620 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGNONE);
621 1.10 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
622 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
623 1.39.2.2 bouyer "F/W download failed at word %d", i);
624 1.31 mjacob dodnld = 0;
625 1.31 mjacob goto again;
626 1.10 mjacob }
627 1.10 mjacob }
628 1.10 mjacob
629 1.31 mjacob /*
630 1.31 mjacob * Verify that it downloaded correctly.
631 1.31 mjacob */
632 1.31 mjacob mbs.param[0] = MBOX_VERIFY_CHECKSUM;
633 1.39.2.2 bouyer mbs.param[1] = ISP_CODE_ORG;
634 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGNONE);
635 1.31 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
636 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
637 1.31 mjacob return;
638 1.10 mjacob }
639 1.39.2.2 bouyer isp->isp_loaded_fw = 1;
640 1.10 mjacob } else {
641 1.39.2.2 bouyer isp->isp_loaded_fw = 0;
642 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
643 1.1 cgd }
644 1.1 cgd
645 1.1 cgd /*
646 1.10 mjacob * Now start it rolling.
647 1.10 mjacob *
648 1.10 mjacob * If we didn't actually download f/w,
649 1.10 mjacob * we still need to (re)start it.
650 1.1 cgd */
651 1.1 cgd
652 1.1 cgd mbs.param[0] = MBOX_EXEC_FIRMWARE;
653 1.39.2.2 bouyer mbs.param[1] = ISP_CODE_ORG;
654 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGNONE);
655 1.39.2.2 bouyer /* give it a chance to start */
656 1.39.2.3 bouyer USEC_SLEEP(isp, 500);
657 1.4 mjacob
658 1.38 mjacob if (IS_SCSI(isp)) {
659 1.10 mjacob /*
660 1.25 mjacob * Set CLOCK RATE, but only if asked to.
661 1.10 mjacob */
662 1.36 mjacob if (isp->isp_clock) {
663 1.10 mjacob mbs.param[0] = MBOX_SET_CLOCK_RATE;
664 1.36 mjacob mbs.param[1] = isp->isp_clock;
665 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
666 1.39.2.2 bouyer /* we will try not to care if this fails */
667 1.4 mjacob }
668 1.4 mjacob }
669 1.39.2.2 bouyer
670 1.1 cgd mbs.param[0] = MBOX_ABOUT_FIRMWARE;
671 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
672 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
673 1.1 cgd return;
674 1.1 cgd }
675 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG,
676 1.39.2.2 bouyer "Board Revision %s, %s F/W Revision %d.%d.%d", revname,
677 1.39.2.2 bouyer dodnld? "loaded" : "resident", mbs.param[1], mbs.param[2],
678 1.39.2.2 bouyer mbs.param[3]);
679 1.34 mjacob if (IS_FC(isp)) {
680 1.32 mjacob if (ISP_READ(isp, BIU2100_CSR) & BIU2100_PCI64) {
681 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG,
682 1.39.2.2 bouyer "Installed in 64-Bit PCI slot");
683 1.32 mjacob }
684 1.32 mjacob }
685 1.38 mjacob
686 1.35 mjacob isp->isp_fwrev[0] = mbs.param[1];
687 1.35 mjacob isp->isp_fwrev[1] = mbs.param[2];
688 1.35 mjacob isp->isp_fwrev[2] = mbs.param[3];
689 1.35 mjacob if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
690 1.35 mjacob isp->isp_romfw_rev[2]) {
691 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
692 1.35 mjacob isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
693 1.35 mjacob isp->isp_romfw_rev[2]);
694 1.25 mjacob }
695 1.38 mjacob
696 1.38 mjacob mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
697 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
698 1.38 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
699 1.38 mjacob return;
700 1.38 mjacob }
701 1.38 mjacob isp->isp_maxcmds = mbs.param[2];
702 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO,
703 1.39.2.2 bouyer "%d max I/O commands supported", mbs.param[2]);
704 1.10 mjacob isp_fw_state(isp);
705 1.38 mjacob
706 1.36 mjacob /*
707 1.36 mjacob * Set up DMA for the request and result mailboxes.
708 1.36 mjacob */
709 1.36 mjacob if (ISP_MBOXDMASETUP(isp) != 0) {
710 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
711 1.36 mjacob return;
712 1.36 mjacob }
713 1.1 cgd isp->isp_state = ISP_RESETSTATE;
714 1.39.2.2 bouyer
715 1.39.2.2 bouyer /*
716 1.39.2.2 bouyer * Okay- now that we have new firmware running, we now (re)set our
717 1.39.2.2 bouyer * notion of how many luns we support. This is somewhat tricky because
718 1.39.2.2 bouyer * if we haven't loaded firmware, we don't have an easy way of telling
719 1.39.2.2 bouyer * how many luns we support.
720 1.39.2.2 bouyer *
721 1.39.2.2 bouyer * We'll make a simplifying assumption- if we loaded firmware, we
722 1.39.2.2 bouyer * are running with expanded lun firmware, otherwise not.
723 1.39.2.2 bouyer *
724 1.39.2.2 bouyer * Expanded lun firmware gives you 32 luns for SCSI cards and
725 1.39.2.2 bouyer * 65536 luns for Fibre Channel cards.
726 1.39.2.2 bouyer *
727 1.39.2.2 bouyer * Because the lun is in a a different position in the Request Queue
728 1.39.2.2 bouyer * Entry structure for Fibre Channel with expanded lun firmware, we
729 1.39.2.2 bouyer * can only support one lun (lun zero) when we don't know what kind
730 1.39.2.2 bouyer * of firmware we're running.
731 1.39.2.2 bouyer *
732 1.39.2.2 bouyer * Note that we only do this once (the first time thru isp_reset)
733 1.39.2.2 bouyer * because we may be called again after firmware has been loaded once
734 1.39.2.2 bouyer * and released.
735 1.39.2.2 bouyer */
736 1.39.2.2 bouyer if (touched == 0) {
737 1.39.2.2 bouyer if (dodnld) {
738 1.39.2.2 bouyer if (IS_SCSI(isp)) {
739 1.39.2.2 bouyer isp->isp_maxluns = 32;
740 1.39.2.2 bouyer } else {
741 1.39.2.2 bouyer isp->isp_maxluns = 65536;
742 1.39.2.2 bouyer }
743 1.39.2.2 bouyer } else {
744 1.39.2.2 bouyer if (IS_SCSI(isp)) {
745 1.39.2.2 bouyer isp->isp_maxluns = 8;
746 1.39.2.2 bouyer } else {
747 1.39.2.2 bouyer isp_prt(isp, ISP_LOGALL, warnlun);
748 1.39.2.2 bouyer isp->isp_maxluns = 1;
749 1.39.2.2 bouyer }
750 1.39.2.2 bouyer }
751 1.39.2.2 bouyer }
752 1.1 cgd }
753 1.1 cgd
754 1.1 cgd /*
755 1.31 mjacob * Initialize Parameters of Hardware to a known state.
756 1.24 mjacob *
757 1.24 mjacob * Locks are held before coming here.
758 1.1 cgd */
759 1.24 mjacob
760 1.1 cgd void
761 1.1 cgd isp_init(isp)
762 1.1 cgd struct ispsoftc *isp;
763 1.1 cgd {
764 1.36 mjacob /*
765 1.36 mjacob * Must do this first to get defaults established.
766 1.36 mjacob */
767 1.36 mjacob isp_setdfltparm(isp, 0);
768 1.39.2.2 bouyer if (IS_DUALBUS(isp)) {
769 1.36 mjacob isp_setdfltparm(isp, 1);
770 1.36 mjacob }
771 1.39.2.6 bouyer if (IS_FC(isp)) {
772 1.39.2.6 bouyer isp_fibre_init(isp);
773 1.39.2.6 bouyer } else {
774 1.39.2.6 bouyer isp_scsi_init(isp);
775 1.36 mjacob }
776 1.36 mjacob }
777 1.36 mjacob
778 1.36 mjacob static void
779 1.36 mjacob isp_scsi_init(isp)
780 1.36 mjacob struct ispsoftc *isp;
781 1.36 mjacob {
782 1.36 mjacob sdparam *sdp_chan0, *sdp_chan1;
783 1.1 cgd mbreg_t mbs;
784 1.36 mjacob
785 1.36 mjacob sdp_chan0 = isp->isp_param;
786 1.36 mjacob sdp_chan1 = sdp_chan0;
787 1.39.2.2 bouyer if (IS_DUALBUS(isp)) {
788 1.36 mjacob sdp_chan1++;
789 1.36 mjacob }
790 1.36 mjacob
791 1.39.2.6 bouyer /*
792 1.39.2.6 bouyer * If we have no role (neither target nor initiator), return.
793 1.39.2.6 bouyer */
794 1.39.2.6 bouyer if (isp->isp_role == ISP_ROLE_NONE) {
795 1.39.2.6 bouyer return;
796 1.39.2.6 bouyer }
797 1.39.2.6 bouyer
798 1.36 mjacob /* First do overall per-card settings. */
799 1.25 mjacob
800 1.25 mjacob /*
801 1.36 mjacob * If we have fast memory timing enabled, turn it on.
802 1.25 mjacob */
803 1.39.2.2 bouyer if (sdp_chan0->isp_fast_mttr) {
804 1.36 mjacob ISP_WRITE(isp, RISC_MTR, 0x1313);
805 1.36 mjacob }
806 1.25 mjacob
807 1.25 mjacob /*
808 1.36 mjacob * Set Retry Delay and Count.
809 1.36 mjacob * You set both channels at the same time.
810 1.33 mjacob */
811 1.36 mjacob mbs.param[0] = MBOX_SET_RETRY_COUNT;
812 1.36 mjacob mbs.param[1] = sdp_chan0->isp_retry_count;
813 1.36 mjacob mbs.param[2] = sdp_chan0->isp_retry_delay;
814 1.36 mjacob mbs.param[6] = sdp_chan1->isp_retry_count;
815 1.36 mjacob mbs.param[7] = sdp_chan1->isp_retry_delay;
816 1.36 mjacob
817 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
818 1.36 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
819 1.33 mjacob return;
820 1.33 mjacob }
821 1.34 mjacob
822 1.33 mjacob /*
823 1.36 mjacob * Set ASYNC DATA SETUP time. This is very important.
824 1.25 mjacob */
825 1.36 mjacob mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
826 1.36 mjacob mbs.param[1] = sdp_chan0->isp_async_data_setup;
827 1.36 mjacob mbs.param[2] = sdp_chan1->isp_async_data_setup;
828 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
829 1.36 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
830 1.10 mjacob return;
831 1.1 cgd }
832 1.1 cgd
833 1.10 mjacob /*
834 1.36 mjacob * Set ACTIVE Negation State.
835 1.32 mjacob */
836 1.36 mjacob mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
837 1.36 mjacob mbs.param[1] =
838 1.36 mjacob (sdp_chan0->isp_req_ack_active_neg << 4) |
839 1.36 mjacob (sdp_chan0->isp_data_line_active_neg << 5);
840 1.36 mjacob mbs.param[2] =
841 1.36 mjacob (sdp_chan1->isp_req_ack_active_neg << 4) |
842 1.36 mjacob (sdp_chan1->isp_data_line_active_neg << 5);
843 1.36 mjacob
844 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGNONE);
845 1.36 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
846 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
847 1.39.2.2 bouyer "failed to set active negation state (%d,%d), (%d,%d)",
848 1.36 mjacob sdp_chan0->isp_req_ack_active_neg,
849 1.36 mjacob sdp_chan0->isp_data_line_active_neg,
850 1.36 mjacob sdp_chan1->isp_req_ack_active_neg,
851 1.36 mjacob sdp_chan1->isp_data_line_active_neg);
852 1.36 mjacob /*
853 1.36 mjacob * But don't return.
854 1.36 mjacob */
855 1.32 mjacob }
856 1.32 mjacob
857 1.32 mjacob /*
858 1.36 mjacob * Set the Tag Aging limit
859 1.10 mjacob */
860 1.36 mjacob mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
861 1.36 mjacob mbs.param[1] = sdp_chan0->isp_tag_aging;
862 1.36 mjacob mbs.param[2] = sdp_chan1->isp_tag_aging;
863 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
864 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
865 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
866 1.39.2.2 bouyer sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
867 1.1 cgd return;
868 1.1 cgd }
869 1.1 cgd
870 1.25 mjacob /*
871 1.36 mjacob * Set selection timeout.
872 1.25 mjacob */
873 1.36 mjacob mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
874 1.36 mjacob mbs.param[1] = sdp_chan0->isp_selection_timeout;
875 1.36 mjacob mbs.param[2] = sdp_chan1->isp_selection_timeout;
876 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
877 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
878 1.1 cgd return;
879 1.1 cgd }
880 1.1 cgd
881 1.36 mjacob /* now do per-channel settings */
882 1.36 mjacob isp_scsi_channel_init(isp, 0);
883 1.39.2.2 bouyer if (IS_DUALBUS(isp))
884 1.36 mjacob isp_scsi_channel_init(isp, 1);
885 1.36 mjacob
886 1.25 mjacob /*
887 1.36 mjacob * Now enable request/response queues
888 1.25 mjacob */
889 1.36 mjacob
890 1.36 mjacob mbs.param[0] = MBOX_INIT_RES_QUEUE;
891 1.39.2.2 bouyer mbs.param[1] = RESULT_QUEUE_LEN(isp);
892 1.36 mjacob mbs.param[2] = DMA_MSW(isp->isp_result_dma);
893 1.36 mjacob mbs.param[3] = DMA_LSW(isp->isp_result_dma);
894 1.36 mjacob mbs.param[4] = 0;
895 1.36 mjacob mbs.param[5] = 0;
896 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
897 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
898 1.1 cgd return;
899 1.1 cgd }
900 1.39.2.2 bouyer isp->isp_residx = mbs.param[5];
901 1.1 cgd
902 1.36 mjacob mbs.param[0] = MBOX_INIT_REQ_QUEUE;
903 1.39.2.2 bouyer mbs.param[1] = RQUEST_QUEUE_LEN(isp);
904 1.36 mjacob mbs.param[2] = DMA_MSW(isp->isp_rquest_dma);
905 1.36 mjacob mbs.param[3] = DMA_LSW(isp->isp_rquest_dma);
906 1.36 mjacob mbs.param[4] = 0;
907 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
908 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
909 1.1 cgd return;
910 1.1 cgd }
911 1.39.2.2 bouyer isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
912 1.1 cgd
913 1.25 mjacob /*
914 1.39.2.2 bouyer * Turn on Fast Posting, LVD transitions
915 1.39.2.2 bouyer *
916 1.39.2.2 bouyer * Ultra2 F/W always has had fast posting (and LVD transitions)
917 1.39.2.2 bouyer *
918 1.39.2.2 bouyer * Ultra and older (i.e., SBus) cards may not. It's just safer
919 1.39.2.2 bouyer * to assume not for them.
920 1.25 mjacob */
921 1.25 mjacob
922 1.39.2.2 bouyer mbs.param[0] = MBOX_SET_FW_FEATURES;
923 1.39.2.2 bouyer mbs.param[1] = 0;
924 1.39.2.2 bouyer if (IS_ULTRA2(isp))
925 1.39.2.2 bouyer mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
926 1.39.2.2 bouyer if (IS_ULTRA2(isp) || IS_1240(isp))
927 1.36 mjacob mbs.param[1] |= FW_FEATURE_FAST_POST;
928 1.39.2.2 bouyer if (mbs.param[1] != 0) {
929 1.39.2.2 bouyer u_int16_t sfeat = mbs.param[1];
930 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
931 1.39.2.2 bouyer if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
932 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO,
933 1.39.2.2 bouyer "Enabled FW features (0x%x)", sfeat);
934 1.36 mjacob }
935 1.1 cgd }
936 1.1 cgd
937 1.25 mjacob /*
938 1.36 mjacob * Let the outer layers decide whether to issue a SCSI bus reset.
939 1.25 mjacob */
940 1.36 mjacob isp->isp_state = ISP_INITSTATE;
941 1.36 mjacob }
942 1.25 mjacob
943 1.36 mjacob static void
944 1.36 mjacob isp_scsi_channel_init(isp, channel)
945 1.36 mjacob struct ispsoftc *isp;
946 1.36 mjacob int channel;
947 1.36 mjacob {
948 1.36 mjacob sdparam *sdp;
949 1.36 mjacob mbreg_t mbs;
950 1.36 mjacob int tgt;
951 1.36 mjacob
952 1.36 mjacob sdp = isp->isp_param;
953 1.36 mjacob sdp += channel;
954 1.36 mjacob
955 1.36 mjacob /*
956 1.36 mjacob * Set (possibly new) Initiator ID.
957 1.36 mjacob */
958 1.36 mjacob mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
959 1.36 mjacob mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
960 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
961 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
962 1.1 cgd return;
963 1.1 cgd }
964 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d", sdp->isp_initiator_id);
965 1.39.2.2 bouyer
966 1.1 cgd
967 1.25 mjacob /*
968 1.32 mjacob * Set current per-target parameters to a safe minimum.
969 1.25 mjacob */
970 1.25 mjacob for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
971 1.39.2.2 bouyer int lun;
972 1.32 mjacob u_int16_t sdf;
973 1.10 mjacob
974 1.36 mjacob if (sdp->isp_devparam[tgt].dev_enable == 0) {
975 1.1 cgd continue;
976 1.36 mjacob }
977 1.39.2.2 bouyer sdf = DPARM_SAFE_DFLT;
978 1.36 mjacob /*
979 1.39.2.2 bouyer * It is not quite clear when this changed over so that
980 1.39.2.2 bouyer * we could force narrow and async for 1000/1020 cards,
981 1.39.2.2 bouyer * but assume that this is only the case for loaded
982 1.39.2.2 bouyer * firmware.
983 1.36 mjacob */
984 1.39.2.2 bouyer if (isp->isp_loaded_fw) {
985 1.39.2.2 bouyer sdf |= DPARM_NARROW | DPARM_ASYNC;
986 1.20 mjacob }
987 1.32 mjacob mbs.param[0] = MBOX_SET_TARGET_PARAMS;
988 1.36 mjacob mbs.param[1] = (tgt << 8) | (channel << 15);
989 1.32 mjacob mbs.param[2] = sdf;
990 1.39.2.2 bouyer if ((sdf & DPARM_SYNC) == 0) {
991 1.39.2.2 bouyer mbs.param[3] = 0;
992 1.39.2.2 bouyer } else {
993 1.39.2.2 bouyer mbs.param[3] =
994 1.39.2.2 bouyer (sdp->isp_devparam[tgt].sync_offset << 8) |
995 1.39.2.2 bouyer (sdp->isp_devparam[tgt].sync_period);
996 1.39.2.2 bouyer }
997 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
998 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
999 1.32 mjacob sdf = DPARM_SAFE_DFLT;
1000 1.10 mjacob mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1001 1.36 mjacob mbs.param[1] = (tgt << 8) | (channel << 15);
1002 1.32 mjacob mbs.param[2] = sdf;
1003 1.39.2.2 bouyer mbs.param[3] = 0;
1004 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
1005 1.10 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1006 1.25 mjacob continue;
1007 1.10 mjacob }
1008 1.1 cgd }
1009 1.36 mjacob
1010 1.34 mjacob /*
1011 1.39.2.2 bouyer * We don't update any information directly from the f/w
1012 1.39.2.2 bouyer * because we need to run at least one command to cause a
1013 1.39.2.2 bouyer * new state to be latched up. So, we just assume that we
1014 1.39.2.2 bouyer * converge to the values we just had set.
1015 1.39.2.2 bouyer *
1016 1.34 mjacob * Ensure that we don't believe tagged queuing is enabled yet.
1017 1.34 mjacob * It turns out that sometimes the ISP just ignores our
1018 1.34 mjacob * attempts to set parameters for devices that it hasn't
1019 1.34 mjacob * seen yet.
1020 1.34 mjacob */
1021 1.39.2.2 bouyer sdp->isp_devparam[tgt].cur_dflags = sdf & ~DPARM_TQING;
1022 1.39.2.2 bouyer for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1023 1.1 cgd mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1024 1.36 mjacob mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1025 1.10 mjacob mbs.param[2] = sdp->isp_max_queue_depth;
1026 1.25 mjacob mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1027 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
1028 1.1 cgd if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1029 1.25 mjacob break;
1030 1.1 cgd }
1031 1.1 cgd }
1032 1.31 mjacob }
1033 1.39.2.2 bouyer for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1034 1.39.2.2 bouyer if (sdp->isp_devparam[tgt].dev_refresh) {
1035 1.39.2.2 bouyer isp->isp_sendmarker |= (1 << channel);
1036 1.39.2.2 bouyer isp->isp_update |= (1 << channel);
1037 1.39.2.2 bouyer break;
1038 1.39.2.2 bouyer }
1039 1.39.2.2 bouyer }
1040 1.1 cgd }
1041 1.1 cgd
1042 1.24 mjacob /*
1043 1.24 mjacob * Fibre Channel specific initialization.
1044 1.24 mjacob *
1045 1.24 mjacob * Locks are held before coming here.
1046 1.24 mjacob */
1047 1.10 mjacob static void
1048 1.10 mjacob isp_fibre_init(isp)
1049 1.10 mjacob struct ispsoftc *isp;
1050 1.10 mjacob {
1051 1.10 mjacob fcparam *fcp;
1052 1.10 mjacob isp_icb_t *icbp;
1053 1.10 mjacob mbreg_t mbs;
1054 1.37 mjacob int loopid;
1055 1.39.2.2 bouyer u_int64_t nwwn, pwwn;
1056 1.10 mjacob
1057 1.10 mjacob fcp = isp->isp_param;
1058 1.10 mjacob
1059 1.39.2.6 bouyer /*
1060 1.39.2.6 bouyer * Do this *before* initializing the firmware.
1061 1.39.2.6 bouyer */
1062 1.39.2.6 bouyer isp_mark_getpdb_all(isp);
1063 1.39.2.6 bouyer fcp->isp_fwstate = FW_CONFIG_WAIT;
1064 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_NIL;
1065 1.39.2.6 bouyer
1066 1.39.2.6 bouyer /*
1067 1.39.2.6 bouyer * If we have no role (neither target nor initiator), return.
1068 1.39.2.6 bouyer */
1069 1.39.2.6 bouyer if (isp->isp_role == ISP_ROLE_NONE) {
1070 1.39.2.6 bouyer return;
1071 1.39.2.6 bouyer }
1072 1.39.2.6 bouyer
1073 1.37 mjacob loopid = DEFAULT_LOOPID(isp);
1074 1.10 mjacob icbp = (isp_icb_t *) fcp->isp_scratch;
1075 1.30 mjacob MEMZERO(icbp, sizeof (*icbp));
1076 1.25 mjacob
1077 1.25 mjacob icbp->icb_version = ICB_VERSION1;
1078 1.39.2.2 bouyer
1079 1.39.2.2 bouyer /*
1080 1.39.2.2 bouyer * Firmware Options are either retrieved from NVRAM or
1081 1.39.2.2 bouyer * are patched elsewhere. We check them for sanity here
1082 1.39.2.2 bouyer * and make changes based on board revision, but otherwise
1083 1.39.2.2 bouyer * let others decide policy.
1084 1.39.2.2 bouyer */
1085 1.39.2.2 bouyer
1086 1.39.2.2 bouyer /*
1087 1.39.2.2 bouyer * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1088 1.39.2.2 bouyer */
1089 1.39.2.2 bouyer if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1090 1.39.2.2 bouyer fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1091 1.39.2.2 bouyer }
1092 1.39.2.2 bouyer
1093 1.37 mjacob /*
1094 1.38 mjacob * We have to use FULL LOGIN even though it resets the loop too much
1095 1.38 mjacob * because otherwise port database entries don't get updated after
1096 1.39.2.2 bouyer * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1097 1.37 mjacob */
1098 1.38 mjacob if (ISP_FW_REVX(isp->isp_fwrev) < ISP_FW_REV(1, 17, 0)) {
1099 1.38 mjacob fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1100 1.38 mjacob }
1101 1.39.2.2 bouyer
1102 1.39.2.2 bouyer /*
1103 1.39.2.2 bouyer * Insist on Port Database Update Async notifications
1104 1.39.2.2 bouyer */
1105 1.39.2.2 bouyer fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1106 1.37 mjacob
1107 1.39.2.6 bouyer
1108 1.37 mjacob /*
1109 1.39.2.6 bouyer * Make sure that target role reflects into fwoptions.
1110 1.37 mjacob */
1111 1.39.2.6 bouyer if (isp->isp_role & ISP_ROLE_TARGET) {
1112 1.39.2.6 bouyer fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1113 1.39.2.6 bouyer } else {
1114 1.39.2.6 bouyer fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1115 1.39.2.6 bouyer }
1116 1.31 mjacob
1117 1.39.2.6 bouyer /*
1118 1.39.2.6 bouyer * Propagate all of this into the ICB structure.
1119 1.39.2.6 bouyer */
1120 1.27 mjacob icbp->icb_fwoptions = fcp->isp_fwoptions;
1121 1.25 mjacob icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1122 1.25 mjacob if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1123 1.25 mjacob icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1124 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
1125 1.39.2.2 bouyer "bad frame length (%d) from NVRAM- using %d",
1126 1.39.2.2 bouyer fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1127 1.35 mjacob icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1128 1.25 mjacob }
1129 1.25 mjacob icbp->icb_maxalloc = fcp->isp_maxalloc;
1130 1.37 mjacob if (icbp->icb_maxalloc < 1) {
1131 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
1132 1.39.2.2 bouyer "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1133 1.35 mjacob icbp->icb_maxalloc = 16;
1134 1.35 mjacob }
1135 1.25 mjacob icbp->icb_execthrottle = fcp->isp_execthrottle;
1136 1.35 mjacob if (icbp->icb_execthrottle < 1) {
1137 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
1138 1.39.2.2 bouyer "bad execution throttle of %d- using 16",
1139 1.39.2.2 bouyer fcp->isp_execthrottle);
1140 1.37 mjacob icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1141 1.35 mjacob }
1142 1.25 mjacob icbp->icb_retry_delay = fcp->isp_retry_delay;
1143 1.25 mjacob icbp->icb_retry_count = fcp->isp_retry_count;
1144 1.28 mjacob icbp->icb_hardaddr = loopid;
1145 1.39.2.2 bouyer /*
1146 1.39.2.2 bouyer * Right now we just set extended options to prefer point-to-point
1147 1.39.2.2 bouyer * over loop based upon some soft config options.
1148 1.39.2.2 bouyer */
1149 1.39.2.2 bouyer if (IS_2200(isp)) {
1150 1.39.2.2 bouyer icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1151 1.37 mjacob /*
1152 1.39.2.2 bouyer * Prefer or force Point-To-Point instead Loop?
1153 1.37 mjacob */
1154 1.39.2.3 bouyer switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1155 1.39.2.3 bouyer case ISP_CFG_NPORT:
1156 1.39.2.2 bouyer icbp->icb_xfwoptions = ICBXOPT_PTP_2_LOOP;
1157 1.39.2.3 bouyer break;
1158 1.39.2.3 bouyer case ISP_CFG_NPORT_ONLY:
1159 1.39.2.3 bouyer icbp->icb_xfwoptions = ICBXOPT_PTP_ONLY;
1160 1.39.2.3 bouyer break;
1161 1.39.2.3 bouyer case ISP_CFG_LPORT_ONLY:
1162 1.39.2.3 bouyer icbp->icb_xfwoptions = ICBXOPT_LOOP_ONLY;
1163 1.39.2.3 bouyer break;
1164 1.39.2.3 bouyer default:
1165 1.39.2.2 bouyer icbp->icb_xfwoptions = ICBXOPT_LOOP_2_PTP;
1166 1.39.2.3 bouyer break;
1167 1.39.2.3 bouyer }
1168 1.39.2.2 bouyer }
1169 1.39.2.2 bouyer icbp->icb_logintime = 60; /* 60 second login timeout */
1170 1.39.2.2 bouyer
1171 1.39.2.2 bouyer nwwn = ISP_NODEWWN(isp);
1172 1.39.2.2 bouyer pwwn = ISP_PORTWWN(isp);
1173 1.39.2.2 bouyer if (nwwn && pwwn) {
1174 1.39.2.6 bouyer icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1175 1.39.2.2 bouyer MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1176 1.39.2.2 bouyer MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1177 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1,
1178 1.39.2.2 bouyer "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1179 1.39.2.2 bouyer ((u_int32_t) (nwwn >> 32)),
1180 1.39.2.2 bouyer ((u_int32_t) (nwwn & 0xffffffff)),
1181 1.39.2.2 bouyer ((u_int32_t) (pwwn >> 32)),
1182 1.39.2.2 bouyer ((u_int32_t) (pwwn & 0xffffffff)));
1183 1.35 mjacob } else {
1184 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1185 1.39.2.6 bouyer icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1186 1.28 mjacob }
1187 1.39.2.2 bouyer icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1188 1.39.2.2 bouyer icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1189 1.35 mjacob icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_LSW(isp->isp_rquest_dma);
1190 1.35 mjacob icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_MSW(isp->isp_rquest_dma);
1191 1.35 mjacob icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_LSW(isp->isp_result_dma);
1192 1.35 mjacob icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_MSW(isp->isp_result_dma);
1193 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1,
1194 1.39.2.2 bouyer "isp_fibre_init: fwoptions 0x%x", fcp->isp_fwoptions);
1195 1.38 mjacob ISP_SWIZZLE_ICB(isp, icbp);
1196 1.38 mjacob
1197 1.39.2.6 bouyer
1198 1.38 mjacob /*
1199 1.39.2.6 bouyer * Init the firmware
1200 1.38 mjacob */
1201 1.39.2.2 bouyer mbs.param[0] = MBOX_INIT_FIRMWARE;
1202 1.39.2.2 bouyer mbs.param[1] = 0;
1203 1.39.2.2 bouyer mbs.param[2] = DMA_MSW(fcp->isp_scdma);
1204 1.39.2.2 bouyer mbs.param[3] = DMA_LSW(fcp->isp_scdma);
1205 1.39.2.2 bouyer mbs.param[4] = 0;
1206 1.39.2.2 bouyer mbs.param[5] = 0;
1207 1.39.2.2 bouyer mbs.param[6] = 0;
1208 1.39.2.2 bouyer mbs.param[7] = 0;
1209 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
1210 1.39.2.2 bouyer if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1211 1.39.2.2 bouyer return;
1212 1.10 mjacob }
1213 1.25 mjacob isp->isp_reqidx = isp->isp_reqodx = 0;
1214 1.10 mjacob isp->isp_residx = 0;
1215 1.33 mjacob isp->isp_sendmarker = 1;
1216 1.33 mjacob
1217 1.33 mjacob /*
1218 1.33 mjacob * Whatever happens, we're now committed to being here.
1219 1.33 mjacob */
1220 1.33 mjacob isp->isp_state = ISP_INITSTATE;
1221 1.33 mjacob }
1222 1.33 mjacob
1223 1.33 mjacob /*
1224 1.33 mjacob * Fibre Channel Support- get the port database for the id.
1225 1.33 mjacob *
1226 1.33 mjacob * Locks are held before coming here. Return 0 if success,
1227 1.33 mjacob * else failure.
1228 1.33 mjacob */
1229 1.33 mjacob
1230 1.39.2.6 bouyer static int
1231 1.39.2.6 bouyer isp_getmap(isp, map)
1232 1.39.2.6 bouyer struct ispsoftc *isp;
1233 1.39.2.6 bouyer fcpos_map_t *map;
1234 1.39.2.6 bouyer {
1235 1.39.2.6 bouyer fcparam *fcp = (fcparam *) isp->isp_param;
1236 1.39.2.6 bouyer mbreg_t mbs;
1237 1.39.2.6 bouyer
1238 1.39.2.6 bouyer mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1239 1.39.2.6 bouyer mbs.param[1] = 0;
1240 1.39.2.6 bouyer mbs.param[2] = DMA_MSW(fcp->isp_scdma);
1241 1.39.2.6 bouyer mbs.param[3] = DMA_LSW(fcp->isp_scdma);
1242 1.39.2.6 bouyer /*
1243 1.39.2.6 bouyer * Unneeded. For the 2100, except for initializing f/w, registers
1244 1.39.2.6 bouyer * 4/5 have to not be written to.
1245 1.39.2.6 bouyer * mbs.param[4] = 0;
1246 1.39.2.6 bouyer * mbs.param[5] = 0;
1247 1.39.2.6 bouyer *
1248 1.39.2.6 bouyer */
1249 1.39.2.6 bouyer mbs.param[6] = 0;
1250 1.39.2.6 bouyer mbs.param[7] = 0;
1251 1.39.2.6 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1252 1.39.2.6 bouyer if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1253 1.39.2.6 bouyer MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1254 1.39.2.6 bouyer map->fwmap = mbs.param[1] != 0;
1255 1.39.2.6 bouyer return (0);
1256 1.39.2.6 bouyer }
1257 1.39.2.6 bouyer return (-1);
1258 1.39.2.6 bouyer }
1259 1.39.2.6 bouyer
1260 1.33 mjacob static void
1261 1.33 mjacob isp_mark_getpdb_all(isp)
1262 1.33 mjacob struct ispsoftc *isp;
1263 1.33 mjacob {
1264 1.33 mjacob fcparam *fcp = (fcparam *) isp->isp_param;
1265 1.37 mjacob int i;
1266 1.37 mjacob for (i = 0; i < MAX_FC_TARG; i++) {
1267 1.39.2.6 bouyer fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1268 1.33 mjacob }
1269 1.33 mjacob }
1270 1.33 mjacob
1271 1.33 mjacob static int
1272 1.33 mjacob isp_getpdb(isp, id, pdbp)
1273 1.33 mjacob struct ispsoftc *isp;
1274 1.33 mjacob int id;
1275 1.33 mjacob isp_pdb_t *pdbp;
1276 1.33 mjacob {
1277 1.33 mjacob fcparam *fcp = (fcparam *) isp->isp_param;
1278 1.33 mjacob mbreg_t mbs;
1279 1.37 mjacob
1280 1.33 mjacob mbs.param[0] = MBOX_GET_PORT_DB;
1281 1.33 mjacob mbs.param[1] = id << 8;
1282 1.35 mjacob mbs.param[2] = DMA_MSW(fcp->isp_scdma);
1283 1.35 mjacob mbs.param[3] = DMA_LSW(fcp->isp_scdma);
1284 1.34 mjacob /*
1285 1.34 mjacob * Unneeded. For the 2100, except for initializing f/w, registers
1286 1.34 mjacob * 4/5 have to not be written to.
1287 1.34 mjacob * mbs.param[4] = 0;
1288 1.34 mjacob * mbs.param[5] = 0;
1289 1.34 mjacob *
1290 1.34 mjacob */
1291 1.33 mjacob mbs.param[6] = 0;
1292 1.33 mjacob mbs.param[7] = 0;
1293 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1294 1.39.2.2 bouyer if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1295 1.38 mjacob ISP_UNSWIZZLE_AND_COPY_PDBP(isp, pdbp, fcp->isp_scratch);
1296 1.39.2.2 bouyer return (0);
1297 1.33 mjacob }
1298 1.39.2.2 bouyer return (-1);
1299 1.33 mjacob }
1300 1.33 mjacob
1301 1.37 mjacob static u_int64_t
1302 1.37 mjacob isp_get_portname(isp, loopid, nodename)
1303 1.37 mjacob struct ispsoftc *isp;
1304 1.37 mjacob int loopid;
1305 1.37 mjacob int nodename;
1306 1.37 mjacob {
1307 1.37 mjacob u_int64_t wwn = 0;
1308 1.37 mjacob mbreg_t mbs;
1309 1.37 mjacob
1310 1.37 mjacob mbs.param[0] = MBOX_GET_PORT_NAME;
1311 1.37 mjacob mbs.param[1] = loopid << 8;
1312 1.37 mjacob if (nodename)
1313 1.37 mjacob mbs.param[1] |= 1;
1314 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1315 1.37 mjacob if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1316 1.37 mjacob wwn =
1317 1.37 mjacob (((u_int64_t)(mbs.param[2] & 0xff)) << 56) |
1318 1.37 mjacob (((u_int64_t)(mbs.param[2] >> 8)) << 48) |
1319 1.37 mjacob (((u_int64_t)(mbs.param[3] & 0xff)) << 40) |
1320 1.37 mjacob (((u_int64_t)(mbs.param[3] >> 8)) << 32) |
1321 1.37 mjacob (((u_int64_t)(mbs.param[6] & 0xff)) << 24) |
1322 1.37 mjacob (((u_int64_t)(mbs.param[6] >> 8)) << 16) |
1323 1.37 mjacob (((u_int64_t)(mbs.param[7] & 0xff)) << 8) |
1324 1.37 mjacob (((u_int64_t)(mbs.param[7] >> 8)));
1325 1.37 mjacob }
1326 1.37 mjacob return (wwn);
1327 1.37 mjacob }
1328 1.37 mjacob
1329 1.33 mjacob /*
1330 1.33 mjacob * Make sure we have good FC link and know our Loop ID.
1331 1.33 mjacob */
1332 1.33 mjacob
1333 1.33 mjacob static int
1334 1.39.2.2 bouyer isp_fclink_test(isp, usdelay)
1335 1.33 mjacob struct ispsoftc *isp;
1336 1.39.2.2 bouyer int usdelay;
1337 1.33 mjacob {
1338 1.38 mjacob static char *toponames[] = {
1339 1.38 mjacob "Private Loop",
1340 1.38 mjacob "FL Port",
1341 1.38 mjacob "N-Port to N-Port",
1342 1.39.2.2 bouyer "F Port",
1343 1.39.2.2 bouyer "F Port (no FLOGI_ACC response)"
1344 1.38 mjacob };
1345 1.33 mjacob mbreg_t mbs;
1346 1.39.2.6 bouyer int count, check_for_fabric;
1347 1.33 mjacob u_int8_t lwfs;
1348 1.33 mjacob fcparam *fcp;
1349 1.39.2.6 bouyer struct lportdb *lp;
1350 1.37 mjacob isp_pdb_t pdb;
1351 1.39.2.6 bouyer
1352 1.33 mjacob fcp = isp->isp_param;
1353 1.10 mjacob
1354 1.10 mjacob /*
1355 1.39.2.2 bouyer * XXX: Here is where we would start a 'loop dead' timeout
1356 1.39.2.2 bouyer */
1357 1.39.2.2 bouyer
1358 1.39.2.2 bouyer /*
1359 1.33 mjacob * Wait up to N microseconds for F/W to go to a ready state.
1360 1.10 mjacob */
1361 1.23 mjacob lwfs = FW_CONFIG_WAIT;
1362 1.39.2.2 bouyer count = 0;
1363 1.39.2.2 bouyer while (count < usdelay) {
1364 1.39.2.2 bouyer u_int64_t enano;
1365 1.39.2.2 bouyer u_int32_t wrk;
1366 1.39.2.2 bouyer NANOTIME_T hra, hrb;
1367 1.39.2.2 bouyer
1368 1.39.2.2 bouyer GET_NANOTIME(&hra);
1369 1.10 mjacob isp_fw_state(isp);
1370 1.23 mjacob if (lwfs != fcp->isp_fwstate) {
1371 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1372 1.39.2.2 bouyer isp2100_fw_statename((int)lwfs),
1373 1.28 mjacob isp2100_fw_statename((int)fcp->isp_fwstate));
1374 1.23 mjacob lwfs = fcp->isp_fwstate;
1375 1.23 mjacob }
1376 1.23 mjacob if (fcp->isp_fwstate == FW_READY) {
1377 1.10 mjacob break;
1378 1.23 mjacob }
1379 1.39.2.2 bouyer GET_NANOTIME(&hrb);
1380 1.39.2.2 bouyer
1381 1.39.2.2 bouyer /*
1382 1.39.2.2 bouyer * Get the elapsed time in nanoseconds.
1383 1.39.2.2 bouyer * Always guaranteed to be non-zero.
1384 1.39.2.2 bouyer */
1385 1.39.2.2 bouyer enano = NANOTIME_SUB(&hrb, &hra);
1386 1.39.2.2 bouyer
1387 1.39.2.4 bouyer isp_prt(isp, ISP_LOGDEBUG3, "usec%d: 0x%lx->0x%lx enano %lu",
1388 1.39.2.4 bouyer count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1389 1.39.2.4 bouyer (enano > ((u_int64_t)0xffffffff))? 0xffffffff :
1390 1.39.2.4 bouyer (unsigned long) (enano & 0xffffffff));
1391 1.39.2.4 bouyer
1392 1.39.2.2 bouyer /*
1393 1.39.2.2 bouyer * If the elapsed time is less than 1 millisecond,
1394 1.39.2.2 bouyer * delay a period of time up to that millisecond of
1395 1.39.2.2 bouyer * waiting.
1396 1.39.2.4 bouyer *
1397 1.39.2.2 bouyer * This peculiar code is an attempt to try and avoid
1398 1.39.2.2 bouyer * invoking u_int64_t math support functions for some
1399 1.39.2.2 bouyer * platforms where linkage is a problem.
1400 1.39.2.2 bouyer */
1401 1.39.2.2 bouyer if (enano < (1000 * 1000)) {
1402 1.39.2.2 bouyer count += 1000;
1403 1.39.2.2 bouyer enano = (1000 * 1000) - enano;
1404 1.39.2.2 bouyer while (enano > (u_int64_t) 4000000000U) {
1405 1.39.2.3 bouyer USEC_SLEEP(isp, 4000000);
1406 1.39.2.2 bouyer enano -= (u_int64_t) 4000000000U;
1407 1.39.2.2 bouyer }
1408 1.39.2.2 bouyer wrk = enano;
1409 1.39.2.3 bouyer USEC_SLEEP(isp, wrk/1000);
1410 1.39.2.2 bouyer } else {
1411 1.39.2.2 bouyer while (enano > (u_int64_t) 4000000000U) {
1412 1.39.2.2 bouyer count += 4000000;
1413 1.39.2.2 bouyer enano -= (u_int64_t) 4000000000U;
1414 1.39.2.2 bouyer }
1415 1.39.2.2 bouyer wrk = enano;
1416 1.39.2.2 bouyer count += (wrk / 1000);
1417 1.39.2.2 bouyer }
1418 1.10 mjacob }
1419 1.10 mjacob
1420 1.10 mjacob /*
1421 1.33 mjacob * If we haven't gone to 'ready' state, return.
1422 1.33 mjacob */
1423 1.33 mjacob if (fcp->isp_fwstate != FW_READY) {
1424 1.33 mjacob return (-1);
1425 1.33 mjacob }
1426 1.34 mjacob
1427 1.33 mjacob /*
1428 1.33 mjacob * Get our Loop ID (if possible). We really need to have it.
1429 1.10 mjacob */
1430 1.33 mjacob mbs.param[0] = MBOX_GET_LOOP_ID;
1431 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
1432 1.33 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1433 1.33 mjacob return (-1);
1434 1.23 mjacob }
1435 1.33 mjacob fcp->isp_loopid = mbs.param[1];
1436 1.39.2.2 bouyer if (IS_2200(isp)) {
1437 1.39.2.2 bouyer int topo = (int) mbs.param[6];
1438 1.39.2.2 bouyer if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1439 1.39.2.2 bouyer topo = TOPO_PTP_STUB;
1440 1.39.2.2 bouyer fcp->isp_topo = topo;
1441 1.39.2.2 bouyer } else {
1442 1.39.2.2 bouyer fcp->isp_topo = TOPO_NL_PORT;
1443 1.38 mjacob }
1444 1.39.2.6 bouyer fcp->isp_portid = fcp->isp_alpa = mbs.param[2] & 0xff;
1445 1.39.2.2 bouyer
1446 1.39.2.6 bouyer /*
1447 1.39.2.6 bouyer * Check to see if we're on a fabric by trying to see if we
1448 1.39.2.6 bouyer * can talk to the fabric name server. This can be a bit
1449 1.39.2.6 bouyer * tricky because if we're a 2100, we should check always
1450 1.39.2.6 bouyer * (in case we're connected to an server doing aliasing).
1451 1.39.2.6 bouyer */
1452 1.38 mjacob fcp->isp_onfabric = 0;
1453 1.39.2.6 bouyer
1454 1.39.2.6 bouyer if (IS_2100(isp))
1455 1.39.2.6 bouyer check_for_fabric = 1;
1456 1.39.2.6 bouyer else if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_F_PORT)
1457 1.39.2.6 bouyer check_for_fabric = 1;
1458 1.39.2.6 bouyer else
1459 1.39.2.6 bouyer check_for_fabric = 0;
1460 1.39.2.6 bouyer
1461 1.39.2.6 bouyer if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1462 1.39.2.6 bouyer int loopid = FL_PORT_ID;
1463 1.39.2.2 bouyer if (IS_2100(isp)) {
1464 1.39.2.2 bouyer fcp->isp_topo = TOPO_FL_PORT;
1465 1.39.2.2 bouyer }
1466 1.39.2.6 bouyer
1467 1.39.2.6 bouyer if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1468 1.39.2.6 bouyer /*
1469 1.39.2.6 bouyer * Crock.
1470 1.39.2.6 bouyer */
1471 1.39.2.6 bouyer fcp->isp_topo = TOPO_NL_PORT;
1472 1.39.2.6 bouyer goto not_on_fabric;
1473 1.39.2.6 bouyer }
1474 1.39.2.6 bouyer fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1475 1.37 mjacob
1476 1.37 mjacob /*
1477 1.39.2.2 bouyer * Save the Fabric controller's port database entry.
1478 1.37 mjacob */
1479 1.39.2.6 bouyer lp = &fcp->portdb[loopid];
1480 1.39.2.2 bouyer lp->node_wwn =
1481 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1482 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1483 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1484 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1485 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1486 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1487 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1488 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_nodename[7]));
1489 1.39.2.2 bouyer lp->port_wwn =
1490 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1491 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1492 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1493 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1494 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1495 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1496 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1497 1.39.2.2 bouyer (((u_int64_t)pdb.pdb_portname[7]));
1498 1.39.2.2 bouyer lp->roles =
1499 1.39.2.2 bouyer (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1500 1.39.2.2 bouyer lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1501 1.39.2.2 bouyer lp->loopid = pdb.pdb_loopid;
1502 1.39.2.2 bouyer lp->loggedin = lp->valid = 1;
1503 1.39.2.6 bouyer fcp->isp_onfabric = 1;
1504 1.39.2.6 bouyer (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1505 1.39.2.5 bouyer isp_register_fc4_type(isp);
1506 1.39.2.6 bouyer } else {
1507 1.39.2.6 bouyer not_on_fabric:
1508 1.39.2.2 bouyer fcp->isp_onfabric = 0;
1509 1.39.2.2 bouyer fcp->portdb[FL_PORT_ID].valid = 0;
1510 1.39.2.2 bouyer }
1511 1.39.2.2 bouyer
1512 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, topology, fcp->isp_loopid, fcp->isp_alpa,
1513 1.39.2.2 bouyer fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1514 1.39.2.2 bouyer
1515 1.39.2.6 bouyer /*
1516 1.39.2.6 bouyer * Announce ourselves, too. This involves synthesizing an entry.
1517 1.39.2.6 bouyer */
1518 1.39.2.6 bouyer if (fcp->isp_iid_set == 0) {
1519 1.39.2.6 bouyer fcp->isp_iid_set = 1;
1520 1.39.2.6 bouyer fcp->isp_iid = fcp->isp_loopid;
1521 1.39.2.6 bouyer lp = &fcp->portdb[fcp->isp_iid];
1522 1.39.2.6 bouyer } else {
1523 1.39.2.6 bouyer lp = &fcp->portdb[fcp->isp_iid];
1524 1.39.2.6 bouyer if (fcp->isp_portid != lp->portid ||
1525 1.39.2.6 bouyer fcp->isp_loopid != lp->loopid ||
1526 1.39.2.6 bouyer fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1527 1.39.2.6 bouyer fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1528 1.39.2.6 bouyer lp->valid = 0;
1529 1.39.2.6 bouyer count = fcp->isp_iid;
1530 1.39.2.6 bouyer (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1531 1.39.2.6 bouyer }
1532 1.39.2.6 bouyer }
1533 1.39.2.6 bouyer lp->loopid = fcp->isp_loopid;
1534 1.39.2.6 bouyer lp->portid = fcp->isp_portid;
1535 1.39.2.6 bouyer lp->node_wwn = ISP_NODEWWN(isp);
1536 1.39.2.6 bouyer lp->port_wwn = ISP_PORTWWN(isp);
1537 1.39.2.6 bouyer switch (isp->isp_role) {
1538 1.39.2.6 bouyer case ISP_ROLE_NONE:
1539 1.39.2.6 bouyer lp->roles = 0;
1540 1.39.2.6 bouyer break;
1541 1.39.2.6 bouyer case ISP_ROLE_TARGET:
1542 1.39.2.6 bouyer lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1543 1.39.2.6 bouyer break;
1544 1.39.2.6 bouyer case ISP_ROLE_INITIATOR:
1545 1.39.2.6 bouyer lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1546 1.39.2.6 bouyer break;
1547 1.39.2.6 bouyer case ISP_ROLE_BOTH:
1548 1.39.2.6 bouyer lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1549 1.39.2.6 bouyer break;
1550 1.39.2.6 bouyer }
1551 1.39.2.6 bouyer lp->loggedin = lp->valid = 1;
1552 1.39.2.6 bouyer count = fcp->isp_iid;
1553 1.39.2.6 bouyer (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1554 1.33 mjacob return (0);
1555 1.37 mjacob }
1556 1.37 mjacob
1557 1.39.2.2 bouyer static char *
1558 1.39.2.2 bouyer isp2100_fw_statename(state)
1559 1.39.2.2 bouyer int state;
1560 1.39.2.2 bouyer {
1561 1.39.2.2 bouyer switch(state) {
1562 1.39.2.2 bouyer case FW_CONFIG_WAIT: return "Config Wait";
1563 1.39.2.2 bouyer case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1564 1.39.2.2 bouyer case FW_WAIT_LOGIN: return "Wait Login";
1565 1.39.2.2 bouyer case FW_READY: return "Ready";
1566 1.39.2.2 bouyer case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1567 1.39.2.2 bouyer case FW_ERROR: return "Error";
1568 1.39.2.2 bouyer case FW_REINIT: return "Re-Init";
1569 1.39.2.2 bouyer case FW_NON_PART: return "Nonparticipating";
1570 1.39.2.2 bouyer default: return "?????";
1571 1.39.2.2 bouyer }
1572 1.39.2.2 bouyer }
1573 1.39.2.2 bouyer
1574 1.1 cgd /*
1575 1.37 mjacob * Synchronize our soft copy of the port database with what the f/w thinks
1576 1.37 mjacob * (with a view toward possibly for a specific target....)
1577 1.37 mjacob */
1578 1.37 mjacob
1579 1.37 mjacob static int
1580 1.39.2.6 bouyer isp_pdb_sync(isp)
1581 1.37 mjacob struct ispsoftc *isp;
1582 1.37 mjacob {
1583 1.39.2.6 bouyer struct lportdb *lp;
1584 1.37 mjacob fcparam *fcp = isp->isp_param;
1585 1.37 mjacob isp_pdb_t pdb;
1586 1.39.2.6 bouyer int loopid, base, lim;
1587 1.37 mjacob
1588 1.37 mjacob /*
1589 1.39.2.6 bouyer * Make sure we're okay for doing this right now.
1590 1.37 mjacob */
1591 1.39.2.6 bouyer if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1592 1.39.2.6 bouyer fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1593 1.39.2.6 bouyer fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1594 1.39.2.6 bouyer return (-1);
1595 1.39.2.6 bouyer }
1596 1.39.2.6 bouyer
1597 1.39.2.6 bouyer if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1598 1.39.2.6 bouyer fcp->isp_topo == TOPO_N_PORT) {
1599 1.39.2.6 bouyer if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1600 1.39.2.6 bouyer if (isp_scan_loop(isp) != 0) {
1601 1.39.2.6 bouyer return (-1);
1602 1.39.2.6 bouyer }
1603 1.39.2.6 bouyer }
1604 1.39.2.6 bouyer }
1605 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_SYNCING_PDB;
1606 1.39.2.6 bouyer
1607 1.37 mjacob /*
1608 1.39.2.6 bouyer * If we get this far, we've settled our differences with the f/w
1609 1.39.2.6 bouyer * (for local loop device) and we can say that the loop state is ready.
1610 1.37 mjacob */
1611 1.38 mjacob
1612 1.39.2.6 bouyer if (fcp->isp_topo == TOPO_NL_PORT) {
1613 1.39.2.6 bouyer fcp->loop_seen_once = 1;
1614 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_READY;
1615 1.39.2.6 bouyer return (0);
1616 1.39.2.2 bouyer }
1617 1.39.2.2 bouyer
1618 1.37 mjacob /*
1619 1.39.2.6 bouyer * Find all Fabric Entities that didn't make it from one scan to the
1620 1.39.2.6 bouyer * next and let the world know they went away. Scan the whole database.
1621 1.37 mjacob */
1622 1.39.2.6 bouyer for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1623 1.39.2.6 bouyer if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1624 1.39.2.6 bouyer loopid = lp - fcp->portdb;
1625 1.39.2.6 bouyer lp->valid = 0; /* should already be set */
1626 1.39.2.6 bouyer (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1627 1.39.2.6 bouyer MEMZERO((void *) lp, sizeof (*lp));
1628 1.39.2.6 bouyer continue;
1629 1.39.2.6 bouyer }
1630 1.39.2.6 bouyer lp->was_fabric_dev = lp->fabric_dev;
1631 1.39.2.6 bouyer }
1632 1.39.2.6 bouyer
1633 1.39.2.6 bouyer if (fcp->isp_topo == TOPO_FL_PORT)
1634 1.39.2.6 bouyer base = FC_SNS_ID+1;
1635 1.39.2.6 bouyer else
1636 1.39.2.6 bouyer base = 0;
1637 1.39.2.6 bouyer
1638 1.39.2.6 bouyer if (fcp->isp_topo == TOPO_N_PORT)
1639 1.39.2.6 bouyer lim = 1;
1640 1.39.2.6 bouyer else
1641 1.39.2.6 bouyer lim = MAX_FC_TARG;
1642 1.39.2.2 bouyer
1643 1.39.2.2 bouyer /*
1644 1.39.2.6 bouyer * Now log in any fabric devices that the outer layer has
1645 1.39.2.6 bouyer * left for us to see. This seems the most sane policy
1646 1.39.2.6 bouyer * for the moment.
1647 1.39.2.2 bouyer */
1648 1.39.2.6 bouyer for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1649 1.39.2.6 bouyer u_int32_t portid;
1650 1.39.2.6 bouyer mbreg_t mbs;
1651 1.39.2.2 bouyer
1652 1.39.2.6 bouyer loopid = lp - fcp->portdb;
1653 1.39.2.6 bouyer if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1654 1.37 mjacob continue;
1655 1.39.2.6 bouyer }
1656 1.39.2.6 bouyer
1657 1.39.2.6 bouyer /*
1658 1.39.2.6 bouyer * Anything here?
1659 1.39.2.6 bouyer */
1660 1.37 mjacob if (lp->port_wwn == 0) {
1661 1.37 mjacob continue;
1662 1.37 mjacob }
1663 1.38 mjacob
1664 1.37 mjacob /*
1665 1.39.2.6 bouyer * Don't try to log into yourself.
1666 1.37 mjacob */
1667 1.39.2.6 bouyer if ((portid = lp->portid) == fcp->isp_portid) {
1668 1.37 mjacob continue;
1669 1.37 mjacob }
1670 1.38 mjacob
1671 1.39.2.2 bouyer
1672 1.37 mjacob /*
1673 1.39.2.6 bouyer * If we'd been logged in- see if we still are and we haven't
1674 1.39.2.6 bouyer * changed. If so, no need to log ourselves out, etc..
1675 1.39.2.6 bouyer *
1676 1.39.2.6 bouyer * Unfortunately, our charming Qlogic f/w has decided to
1677 1.39.2.6 bouyer * return a valid port database entry for a fabric device
1678 1.39.2.6 bouyer * that has, in fact, gone away. And it hangs trying to
1679 1.39.2.6 bouyer * log it out.
1680 1.37 mjacob */
1681 1.39.2.6 bouyer if (lp->loggedin &&
1682 1.39.2.6 bouyer isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1683 1.39.2.6 bouyer int nrole;
1684 1.39.2.6 bouyer u_int64_t nwwnn, nwwpn;
1685 1.39.2.6 bouyer nwwnn =
1686 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1687 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1688 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1689 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1690 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1691 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1692 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1693 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[7]));
1694 1.39.2.6 bouyer nwwpn =
1695 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1696 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1697 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1698 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1699 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1700 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1701 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1702 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[7]));
1703 1.39.2.6 bouyer nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1704 1.39.2.6 bouyer SVC3_ROLE_SHIFT;
1705 1.39.2.6 bouyer if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1706 1.39.2.6 bouyer (u_int32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1707 1.39.2.6 bouyer nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1708 1.39.2.6 bouyer lp->roles == nrole) {
1709 1.39.2.6 bouyer lp->loggedin = lp->valid = 1;
1710 1.39.2.6 bouyer isp_prt(isp, ISP_LOGINFO, lretained,
1711 1.39.2.6 bouyer (int) (lp - fcp->portdb),
1712 1.39.2.6 bouyer (int) lp->loopid, lp->portid);
1713 1.37 mjacob continue;
1714 1.37 mjacob }
1715 1.37 mjacob }
1716 1.38 mjacob
1717 1.39.2.6 bouyer if (fcp->isp_fwstate != FW_READY ||
1718 1.39.2.6 bouyer fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1719 1.39.2.6 bouyer return (-1);
1720 1.37 mjacob }
1721 1.37 mjacob
1722 1.37 mjacob /*
1723 1.39.2.6 bouyer * Force a logout if we were logged in.
1724 1.37 mjacob */
1725 1.39.2.6 bouyer if (lp->loggedin) {
1726 1.39.2.6 bouyer if (isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1727 1.39.2.6 bouyer mbs.param[0] = MBOX_FABRIC_LOGOUT;
1728 1.39.2.6 bouyer mbs.param[1] = lp->loopid << 8;
1729 1.39.2.6 bouyer mbs.param[2] = 0;
1730 1.39.2.6 bouyer mbs.param[3] = 0;
1731 1.39.2.6 bouyer isp_mboxcmd(isp, &mbs, MBLOGNONE);
1732 1.39.2.6 bouyer lp->loggedin = 0;
1733 1.39.2.6 bouyer isp_prt(isp, ISP_LOGINFO, plogout,
1734 1.39.2.6 bouyer (int) (lp - fcp->portdb), lp->loopid,
1735 1.39.2.6 bouyer lp->portid);
1736 1.39.2.6 bouyer }
1737 1.39.2.6 bouyer lp->loggedin = 0;
1738 1.39.2.6 bouyer if (fcp->isp_fwstate != FW_READY ||
1739 1.39.2.6 bouyer fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1740 1.39.2.6 bouyer return (-1);
1741 1.39.2.6 bouyer }
1742 1.37 mjacob }
1743 1.37 mjacob
1744 1.37 mjacob /*
1745 1.39.2.6 bouyer * And log in....
1746 1.37 mjacob */
1747 1.39.2.6 bouyer loopid = lp - fcp->portdb;
1748 1.39.2.6 bouyer lp->loopid = FL_PORT_ID;
1749 1.39.2.6 bouyer do {
1750 1.39.2.6 bouyer mbs.param[0] = MBOX_FABRIC_LOGIN;
1751 1.39.2.6 bouyer mbs.param[1] = loopid << 8;
1752 1.39.2.6 bouyer mbs.param[2] = portid >> 16;
1753 1.39.2.6 bouyer mbs.param[3] = portid & 0xffff;
1754 1.39.2.6 bouyer if (IS_2200(isp)) {
1755 1.39.2.6 bouyer /* only issue a PLOGI if not logged in */
1756 1.39.2.6 bouyer mbs.param[1] |= 0x1;
1757 1.37 mjacob }
1758 1.39.2.6 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
1759 1.39.2.6 bouyer MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
1760 1.39.2.6 bouyer if (fcp->isp_fwstate != FW_READY ||
1761 1.39.2.6 bouyer fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1762 1.39.2.6 bouyer return (-1);
1763 1.39.2.6 bouyer }
1764 1.39.2.6 bouyer switch (mbs.param[0]) {
1765 1.39.2.6 bouyer case MBOX_LOOP_ID_USED:
1766 1.37 mjacob /*
1767 1.39.2.6 bouyer * Try the next available loop id.
1768 1.37 mjacob */
1769 1.39.2.6 bouyer loopid++;
1770 1.39.2.6 bouyer break;
1771 1.39.2.6 bouyer case MBOX_PORT_ID_USED:
1772 1.39.2.6 bouyer /*
1773 1.39.2.6 bouyer * This port is already logged in.
1774 1.39.2.6 bouyer * Snaffle the loop id it's using if it's
1775 1.39.2.6 bouyer * nonzero, otherwise we're hosed.
1776 1.39.2.6 bouyer */
1777 1.39.2.6 bouyer if (mbs.param[1] != 0) {
1778 1.39.2.6 bouyer loopid = mbs.param[1];
1779 1.39.2.6 bouyer isp_prt(isp, ISP_LOGINFO, retained,
1780 1.39.2.6 bouyer loopid, (int) (lp - fcp->portdb),
1781 1.39.2.6 bouyer lp->portid);
1782 1.39.2.6 bouyer } else {
1783 1.39.2.6 bouyer loopid = MAX_FC_TARG;
1784 1.39.2.6 bouyer break;
1785 1.39.2.6 bouyer }
1786 1.39.2.6 bouyer /* FALLTHROUGH */
1787 1.39.2.6 bouyer case MBOX_COMMAND_COMPLETE:
1788 1.39.2.6 bouyer lp->loggedin = 1;
1789 1.39.2.6 bouyer lp->loopid = loopid;
1790 1.39.2.6 bouyer break;
1791 1.39.2.6 bouyer case MBOX_COMMAND_ERROR:
1792 1.39.2.6 bouyer isp_prt(isp, ISP_LOGINFO, plogierr,
1793 1.39.2.6 bouyer portid, mbs.param[1]);
1794 1.39.2.6 bouyer /* FALLTHROUGH */
1795 1.39.2.6 bouyer case MBOX_ALL_IDS_USED: /* We're outta IDs */
1796 1.39.2.6 bouyer default:
1797 1.39.2.6 bouyer loopid = MAX_FC_TARG;
1798 1.39.2.6 bouyer break;
1799 1.37 mjacob }
1800 1.39.2.6 bouyer } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
1801 1.37 mjacob
1802 1.37 mjacob /*
1803 1.39.2.6 bouyer * If we get here and we haven't set a Loop ID,
1804 1.39.2.6 bouyer * we failed to log into this device.
1805 1.37 mjacob */
1806 1.39.2.6 bouyer
1807 1.39.2.6 bouyer if (lp->loopid == FL_PORT_ID) {
1808 1.39.2.6 bouyer lp->loopid = 0;
1809 1.37 mjacob continue;
1810 1.37 mjacob }
1811 1.37 mjacob
1812 1.37 mjacob /*
1813 1.39.2.6 bouyer * Make sure we can get the approriate port information.
1814 1.37 mjacob */
1815 1.39.2.6 bouyer if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
1816 1.39.2.6 bouyer isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
1817 1.39.2.6 bouyer goto dump_em;
1818 1.37 mjacob }
1819 1.37 mjacob
1820 1.39.2.6 bouyer if (fcp->isp_fwstate != FW_READY ||
1821 1.39.2.6 bouyer fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1822 1.39.2.6 bouyer return (-1);
1823 1.39.2.6 bouyer }
1824 1.37 mjacob
1825 1.39.2.6 bouyer if (pdb.pdb_loopid != lp->loopid) {
1826 1.39.2.6 bouyer isp_prt(isp, ISP_LOGWARN, pdbmfail1,
1827 1.39.2.6 bouyer lp->portid, pdb.pdb_loopid);
1828 1.39.2.6 bouyer goto dump_em;
1829 1.39.2.6 bouyer }
1830 1.39.2.6 bouyer
1831 1.39.2.6 bouyer if (lp->portid != (u_int32_t) BITS2WORD(pdb.pdb_portid_bits)) {
1832 1.39.2.6 bouyer isp_prt(isp, ISP_LOGWARN, pdbmfail2,
1833 1.39.2.6 bouyer lp->portid, BITS2WORD(pdb.pdb_portid_bits));
1834 1.39.2.6 bouyer goto dump_em;
1835 1.39.2.6 bouyer }
1836 1.39.2.6 bouyer
1837 1.39.2.6 bouyer lp->roles =
1838 1.39.2.6 bouyer (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1839 1.39.2.6 bouyer lp->node_wwn =
1840 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1841 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1842 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1843 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1844 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1845 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1846 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1847 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[7]));
1848 1.39.2.6 bouyer lp->port_wwn =
1849 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1850 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1851 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1852 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1853 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1854 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1855 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1856 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[7]));
1857 1.37 mjacob /*
1858 1.39.2.6 bouyer * Check to make sure this all makes sense.
1859 1.37 mjacob */
1860 1.39.2.6 bouyer if (lp->node_wwn && lp->port_wwn) {
1861 1.39.2.6 bouyer lp->valid = 1;
1862 1.39.2.6 bouyer loopid = lp - fcp->portdb;
1863 1.39.2.6 bouyer (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1864 1.39.2.6 bouyer continue;
1865 1.39.2.6 bouyer }
1866 1.39.2.6 bouyer dump_em:
1867 1.39.2.6 bouyer lp->valid = 0;
1868 1.39.2.6 bouyer isp_prt(isp, ISP_LOGINFO,
1869 1.39.2.6 bouyer ldumped, loopid, lp->loopid, lp->portid);
1870 1.39.2.6 bouyer mbs.param[0] = MBOX_FABRIC_LOGOUT;
1871 1.39.2.6 bouyer mbs.param[1] = lp->loopid << 8;
1872 1.39.2.6 bouyer mbs.param[2] = 0;
1873 1.39.2.6 bouyer mbs.param[3] = 0;
1874 1.39.2.6 bouyer isp_mboxcmd(isp, &mbs, MBLOGNONE);
1875 1.39.2.6 bouyer if (fcp->isp_fwstate != FW_READY ||
1876 1.39.2.6 bouyer fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1877 1.39.2.6 bouyer return (-1);
1878 1.39.2.6 bouyer }
1879 1.37 mjacob }
1880 1.37 mjacob /*
1881 1.39.2.6 bouyer * If we get here, we've for sure seen not only a valid loop
1882 1.39.2.6 bouyer * but know what is or isn't on it, so mark this for usage
1883 1.39.2.6 bouyer * in isp_start.
1884 1.37 mjacob */
1885 1.39.2.6 bouyer fcp->loop_seen_once = 1;
1886 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_READY;
1887 1.39.2.6 bouyer return (0);
1888 1.39.2.6 bouyer }
1889 1.37 mjacob
1890 1.39.2.6 bouyer static int
1891 1.39.2.6 bouyer isp_scan_loop(isp)
1892 1.39.2.6 bouyer struct ispsoftc *isp;
1893 1.39.2.6 bouyer {
1894 1.39.2.6 bouyer struct lportdb *lp;
1895 1.39.2.6 bouyer fcparam *fcp = isp->isp_param;
1896 1.39.2.6 bouyer isp_pdb_t pdb;
1897 1.39.2.6 bouyer int loopid, lim, hival;
1898 1.39.2.6 bouyer
1899 1.39.2.6 bouyer switch (fcp->isp_topo) {
1900 1.39.2.6 bouyer case TOPO_NL_PORT:
1901 1.39.2.6 bouyer hival = FL_PORT_ID;
1902 1.39.2.6 bouyer break;
1903 1.39.2.6 bouyer case TOPO_N_PORT:
1904 1.39.2.6 bouyer hival = 2;
1905 1.39.2.6 bouyer break;
1906 1.39.2.6 bouyer case TOPO_FL_PORT:
1907 1.39.2.6 bouyer hival = FC_PORT_ID;
1908 1.39.2.6 bouyer break;
1909 1.39.2.6 bouyer default:
1910 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_LSCAN_DONE;
1911 1.39.2.6 bouyer return (0);
1912 1.37 mjacob }
1913 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_SCANNING_LOOP;
1914 1.37 mjacob
1915 1.37 mjacob /*
1916 1.39.2.6 bouyer * make sure the temp port database is clean...
1917 1.37 mjacob */
1918 1.39.2.6 bouyer MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
1919 1.37 mjacob
1920 1.39.2.6 bouyer /*
1921 1.39.2.6 bouyer * Run through the local loop ports and get port database info
1922 1.39.2.6 bouyer * for each loop ID.
1923 1.39.2.6 bouyer *
1924 1.39.2.6 bouyer * There's a somewhat unexplained situation where the f/w passes back
1925 1.39.2.6 bouyer * the wrong database entity- if that happens, just restart (up to
1926 1.39.2.6 bouyer * FL_PORT_ID times).
1927 1.39.2.6 bouyer */
1928 1.39.2.6 bouyer for (lim = loopid = 0; loopid < hival; loopid++) {
1929 1.39.2.6 bouyer lp = &fcp->tport[loopid];
1930 1.39.2.6 bouyer
1931 1.39.2.6 bouyer /*
1932 1.39.2.6 bouyer * Don't even try for ourselves...
1933 1.39.2.6 bouyer */
1934 1.39.2.6 bouyer if (loopid == fcp->isp_loopid)
1935 1.39.2.6 bouyer continue;
1936 1.39.2.6 bouyer
1937 1.39.2.6 bouyer lp->node_wwn = isp_get_portname(isp, loopid, 1);
1938 1.39.2.6 bouyer if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
1939 1.39.2.6 bouyer return (-1);
1940 1.39.2.6 bouyer if (lp->node_wwn == 0)
1941 1.39.2.6 bouyer continue;
1942 1.39.2.6 bouyer lp->port_wwn = isp_get_portname(isp, loopid, 0);
1943 1.39.2.6 bouyer if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
1944 1.39.2.6 bouyer return (-1);
1945 1.39.2.6 bouyer if (lp->port_wwn == 0) {
1946 1.39.2.6 bouyer lp->node_wwn = 0;
1947 1.39.2.5 bouyer continue;
1948 1.39.2.5 bouyer }
1949 1.39.2.5 bouyer
1950 1.37 mjacob /*
1951 1.39.2.6 bouyer * Get an entry....
1952 1.37 mjacob */
1953 1.39.2.6 bouyer if (isp_getpdb(isp, loopid, &pdb) != 0) {
1954 1.39.2.6 bouyer if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
1955 1.39.2.6 bouyer return (-1);
1956 1.37 mjacob continue;
1957 1.39.2.5 bouyer }
1958 1.39.2.6 bouyer if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
1959 1.39.2.6 bouyer return (-1);
1960 1.39.2.6 bouyer }
1961 1.39.2.2 bouyer
1962 1.37 mjacob /*
1963 1.39.2.6 bouyer * If the returned database element doesn't match what we
1964 1.39.2.6 bouyer * asked for, restart the process entirely (up to a point...).
1965 1.37 mjacob */
1966 1.39.2.6 bouyer if (pdb.pdb_loopid != loopid) {
1967 1.39.2.6 bouyer loopid = 0;
1968 1.39.2.6 bouyer if (lim++ < hival) {
1969 1.39.2.6 bouyer continue;
1970 1.39.2.6 bouyer }
1971 1.39.2.6 bouyer isp_prt(isp, ISP_LOGWARN,
1972 1.39.2.6 bouyer "giving up on synchronizing the port database");
1973 1.39.2.6 bouyer return (-1);
1974 1.39.2.6 bouyer }
1975 1.39.2.6 bouyer
1976 1.39.2.6 bouyer /*
1977 1.39.2.6 bouyer * Save the pertinent info locally.
1978 1.39.2.6 bouyer */
1979 1.39.2.6 bouyer lp->node_wwn =
1980 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1981 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1982 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1983 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1984 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1985 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1986 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1987 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_nodename[7]));
1988 1.39.2.6 bouyer lp->port_wwn =
1989 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1990 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1991 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1992 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1993 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1994 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1995 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1996 1.39.2.6 bouyer (((u_int64_t)pdb.pdb_portname[7]));
1997 1.39.2.6 bouyer lp->roles =
1998 1.39.2.6 bouyer (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1999 1.39.2.6 bouyer lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2000 1.39.2.6 bouyer lp->loopid = pdb.pdb_loopid;
2001 1.39.2.6 bouyer }
2002 1.39.2.6 bouyer
2003 1.39.2.6 bouyer /*
2004 1.39.2.6 bouyer * Mark all of the permanent local loop database entries as invalid
2005 1.39.2.6 bouyer * (except our own entry).
2006 1.39.2.6 bouyer */
2007 1.39.2.6 bouyer for (loopid = 0; loopid < hival; loopid++) {
2008 1.39.2.6 bouyer if (loopid == fcp->isp_iid) {
2009 1.39.2.6 bouyer fcp->portdb[loopid].valid = 1;
2010 1.39.2.6 bouyer fcp->portdb[loopid].loopid = fcp->isp_loopid;
2011 1.37 mjacob continue;
2012 1.39.2.5 bouyer }
2013 1.39.2.6 bouyer fcp->portdb[loopid].valid = 0;
2014 1.39.2.6 bouyer }
2015 1.37 mjacob
2016 1.39.2.6 bouyer /*
2017 1.39.2.6 bouyer * Now merge our local copy of the port database into our saved copy.
2018 1.39.2.6 bouyer * Notify the outer layers of new devices arriving.
2019 1.39.2.6 bouyer */
2020 1.39.2.6 bouyer for (loopid = 0; loopid < hival; loopid++) {
2021 1.39.2.6 bouyer int i;
2022 1.39.2.2 bouyer
2023 1.37 mjacob /*
2024 1.39.2.6 bouyer * If we don't have a non-zero Port WWN, we're not here.
2025 1.37 mjacob */
2026 1.39.2.6 bouyer if (fcp->tport[loopid].port_wwn == 0) {
2027 1.39.2.6 bouyer continue;
2028 1.39.2.2 bouyer }
2029 1.39.2.2 bouyer
2030 1.39.2.2 bouyer /*
2031 1.39.2.6 bouyer * Skip ourselves.
2032 1.39.2.2 bouyer */
2033 1.39.2.6 bouyer if (loopid == fcp->isp_iid) {
2034 1.39.2.6 bouyer continue;
2035 1.39.2.2 bouyer }
2036 1.37 mjacob
2037 1.37 mjacob /*
2038 1.39.2.6 bouyer * For the purposes of deciding whether this is the
2039 1.39.2.6 bouyer * 'same' device or not, we only search for an identical
2040 1.39.2.6 bouyer * Port WWN. Node WWNs may or may not be the same as
2041 1.39.2.6 bouyer * the Port WWN, and there may be multiple different
2042 1.39.2.6 bouyer * Port WWNs with the same Node WWN. It would be chaos
2043 1.39.2.6 bouyer * to have multiple identical Port WWNs, so we don't
2044 1.39.2.6 bouyer * allow that.
2045 1.37 mjacob */
2046 1.39.2.6 bouyer
2047 1.39.2.6 bouyer for (i = 0; i < hival; i++) {
2048 1.39.2.6 bouyer int j;
2049 1.39.2.6 bouyer if (fcp->portdb[i].port_wwn == 0)
2050 1.39.2.6 bouyer continue;
2051 1.39.2.6 bouyer if (fcp->portdb[i].port_wwn !=
2052 1.39.2.6 bouyer fcp->tport[loopid].port_wwn)
2053 1.39.2.6 bouyer continue;
2054 1.39.2.6 bouyer /*
2055 1.39.2.6 bouyer * We found this WWN elsewhere- it's changed
2056 1.39.2.6 bouyer * loopids then. We don't change it's actual
2057 1.39.2.6 bouyer * position in our cached port database- we
2058 1.39.2.6 bouyer * just change the actual loop ID we'd use.
2059 1.39.2.6 bouyer */
2060 1.39.2.6 bouyer if (fcp->portdb[i].loopid != loopid) {
2061 1.39.2.6 bouyer isp_prt(isp, ISP_LOGINFO, portshift, i,
2062 1.39.2.6 bouyer fcp->portdb[i].loopid,
2063 1.39.2.6 bouyer fcp->portdb[i].portid, loopid,
2064 1.39.2.6 bouyer fcp->tport[loopid].portid);
2065 1.39.2.2 bouyer }
2066 1.39.2.6 bouyer fcp->portdb[i].portid = fcp->tport[loopid].portid;
2067 1.39.2.6 bouyer fcp->portdb[i].loopid = loopid;
2068 1.39.2.6 bouyer fcp->portdb[i].valid = 1;
2069 1.39.2.6 bouyer fcp->portdb[i].roles = fcp->tport[loopid].roles;
2070 1.39.2.6 bouyer
2071 1.39.2.6 bouyer /*
2072 1.39.2.6 bouyer * Now make sure this Port WWN doesn't exist elsewhere
2073 1.39.2.6 bouyer * in the port database.
2074 1.39.2.6 bouyer */
2075 1.39.2.6 bouyer for (j = i+1; j < hival; j++) {
2076 1.39.2.6 bouyer if (fcp->portdb[i].port_wwn !=
2077 1.39.2.6 bouyer fcp->portdb[j].port_wwn) {
2078 1.39.2.6 bouyer continue;
2079 1.39.2.6 bouyer }
2080 1.39.2.6 bouyer isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2081 1.39.2.2 bouyer /*
2082 1.39.2.6 bouyer * Invalidate the 'old' *and* 'new' ones.
2083 1.39.2.6 bouyer * This is really harsh and not quite right,
2084 1.39.2.6 bouyer * but if this happens, we really don't know
2085 1.39.2.6 bouyer * who is what at this point.
2086 1.39.2.2 bouyer */
2087 1.39.2.6 bouyer fcp->portdb[i].valid = 0;
2088 1.39.2.6 bouyer fcp->portdb[j].valid = 0;
2089 1.38 mjacob }
2090 1.39.2.6 bouyer break;
2091 1.39.2.6 bouyer }
2092 1.39.2.2 bouyer
2093 1.39.2.2 bouyer /*
2094 1.39.2.6 bouyer * If we didn't traverse the entire port database,
2095 1.39.2.6 bouyer * then we found (and remapped) an existing entry.
2096 1.39.2.6 bouyer * No need to notify anyone- go for the next one.
2097 1.39.2.2 bouyer */
2098 1.39.2.6 bouyer if (i < hival) {
2099 1.39.2.2 bouyer continue;
2100 1.39.2.2 bouyer }
2101 1.39.2.2 bouyer
2102 1.39.2.2 bouyer /*
2103 1.39.2.6 bouyer * We've not found this Port WWN anywhere. It's a new entry.
2104 1.39.2.6 bouyer * See if we can leave it where it is (with target == loopid).
2105 1.39.2.2 bouyer */
2106 1.39.2.6 bouyer if (fcp->portdb[loopid].port_wwn != 0) {
2107 1.39.2.6 bouyer for (lim = 0; lim < hival; lim++) {
2108 1.39.2.6 bouyer if (fcp->portdb[lim].port_wwn == 0)
2109 1.39.2.6 bouyer break;
2110 1.39.2.6 bouyer }
2111 1.39.2.6 bouyer /* "Cannot Happen" */
2112 1.39.2.6 bouyer if (lim == hival) {
2113 1.39.2.6 bouyer isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2114 1.39.2.6 bouyer continue;
2115 1.39.2.6 bouyer }
2116 1.39.2.6 bouyer i = lim;
2117 1.39.2.6 bouyer } else {
2118 1.39.2.6 bouyer i = loopid;
2119 1.39.2.2 bouyer }
2120 1.39.2.2 bouyer
2121 1.39.2.6 bouyer /*
2122 1.39.2.6 bouyer * NB: The actual loopid we use here is loopid- we may
2123 1.39.2.6 bouyer * in fact be at a completely different index (target).
2124 1.39.2.6 bouyer */
2125 1.39.2.6 bouyer fcp->portdb[i].loopid = loopid;
2126 1.39.2.6 bouyer fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2127 1.39.2.6 bouyer fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2128 1.39.2.6 bouyer fcp->portdb[i].roles = fcp->tport[loopid].roles;
2129 1.39.2.6 bouyer fcp->portdb[i].portid = fcp->tport[loopid].portid;
2130 1.39.2.6 bouyer fcp->portdb[i].valid = 1;
2131 1.39.2.2 bouyer
2132 1.39.2.2 bouyer /*
2133 1.39.2.6 bouyer * Tell the outside world we've arrived.
2134 1.39.2.2 bouyer */
2135 1.39.2.6 bouyer (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2136 1.37 mjacob }
2137 1.39.2.6 bouyer
2138 1.39.2.2 bouyer /*
2139 1.39.2.6 bouyer * Now find all previously used targets that are now invalid and
2140 1.39.2.6 bouyer * notify the outer layers that they're gone.
2141 1.39.2.2 bouyer */
2142 1.39.2.6 bouyer for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2143 1.39.2.6 bouyer if (lp->valid || lp->port_wwn == 0) {
2144 1.39.2.6 bouyer continue;
2145 1.39.2.6 bouyer }
2146 1.39.2.6 bouyer
2147 1.39.2.6 bouyer /*
2148 1.39.2.6 bouyer * Tell the outside world we've gone
2149 1.39.2.6 bouyer * away and erase our pdb entry.
2150 1.39.2.6 bouyer *
2151 1.39.2.6 bouyer */
2152 1.39.2.6 bouyer loopid = lp - fcp->portdb;
2153 1.39.2.6 bouyer (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2154 1.39.2.6 bouyer MEMZERO((void *) lp, sizeof (*lp));
2155 1.39.2.6 bouyer }
2156 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_LSCAN_DONE;
2157 1.37 mjacob return (0);
2158 1.37 mjacob }
2159 1.37 mjacob
2160 1.37 mjacob static int
2161 1.37 mjacob isp_scan_fabric(isp)
2162 1.37 mjacob struct ispsoftc *isp;
2163 1.37 mjacob {
2164 1.37 mjacob fcparam *fcp = isp->isp_param;
2165 1.39.2.6 bouyer u_int32_t portid, first_portid;
2166 1.37 mjacob sns_screq_t *reqp;
2167 1.37 mjacob sns_scrsp_t *resp;
2168 1.37 mjacob mbreg_t mbs;
2169 1.39.2.6 bouyer int hicap, first_portid_seen;
2170 1.39.2.6 bouyer
2171 1.39.2.6 bouyer if (fcp->isp_onfabric == 0) {
2172 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_FSCAN_DONE;
2173 1.39.2.6 bouyer return (0);
2174 1.39.2.6 bouyer }
2175 1.37 mjacob
2176 1.37 mjacob reqp = (sns_screq_t *) fcp->isp_scratch;
2177 1.37 mjacob resp = (sns_scrsp_t *) (&((char *)fcp->isp_scratch)[0x100]);
2178 1.39.2.6 bouyer /*
2179 1.39.2.6 bouyer * Since Port IDs are 24 bits, we can check against having seen
2180 1.39.2.6 bouyer * anything yet with this value.
2181 1.39.2.6 bouyer */
2182 1.39.2.6 bouyer first_portid = portid = fcp->isp_portid;
2183 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2184 1.37 mjacob
2185 1.39.2.6 bouyer for (first_portid_seen = hicap = 0; hicap < 65535; hicap++) {
2186 1.37 mjacob MEMZERO((void *) reqp, SNS_GAN_REQ_SIZE);
2187 1.37 mjacob reqp->snscb_rblen = SNS_GAN_RESP_SIZE >> 1;
2188 1.37 mjacob reqp->snscb_addr[RQRSP_ADDR0015] =
2189 1.37 mjacob DMA_LSW(fcp->isp_scdma + 0x100);
2190 1.37 mjacob reqp->snscb_addr[RQRSP_ADDR1631] =
2191 1.37 mjacob DMA_MSW(fcp->isp_scdma + 0x100);
2192 1.37 mjacob reqp->snscb_sblen = 6;
2193 1.37 mjacob reqp->snscb_data[0] = SNS_GAN;
2194 1.37 mjacob reqp->snscb_data[4] = portid & 0xffff;
2195 1.37 mjacob reqp->snscb_data[5] = (portid >> 16) & 0xff;
2196 1.38 mjacob ISP_SWIZZLE_SNS_REQ(isp, reqp);
2197 1.37 mjacob mbs.param[0] = MBOX_SEND_SNS;
2198 1.37 mjacob mbs.param[1] = SNS_GAN_REQ_SIZE >> 1;
2199 1.37 mjacob mbs.param[2] = DMA_MSW(fcp->isp_scdma);
2200 1.37 mjacob mbs.param[3] = DMA_LSW(fcp->isp_scdma);
2201 1.37 mjacob mbs.param[6] = 0;
2202 1.37 mjacob mbs.param[7] = 0;
2203 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
2204 1.37 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2205 1.39.2.6 bouyer if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC) {
2206 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_PDB_RCVD;
2207 1.39.2.6 bouyer }
2208 1.39.2.6 bouyer return (-1);
2209 1.39.2.6 bouyer }
2210 1.39.2.6 bouyer if (fcp->isp_fwstate != FW_READY ||
2211 1.39.2.6 bouyer fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
2212 1.37 mjacob return (-1);
2213 1.37 mjacob }
2214 1.38 mjacob ISP_UNSWIZZLE_SNS_RSP(isp, resp, SNS_GAN_RESP_SIZE >> 1);
2215 1.37 mjacob portid = (((u_int32_t) resp->snscb_port_id[0]) << 16) |
2216 1.37 mjacob (((u_int32_t) resp->snscb_port_id[1]) << 8) |
2217 1.37 mjacob (((u_int32_t) resp->snscb_port_id[2]));
2218 1.39.2.6 bouyer (void) isp_async(isp, ISPASYNC_FABRIC_DEV, resp);
2219 1.39.2.6 bouyer if (first_portid == portid) {
2220 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_FSCAN_DONE;
2221 1.37 mjacob return (0);
2222 1.37 mjacob }
2223 1.37 mjacob }
2224 1.39.2.6 bouyer
2225 1.39.2.6 bouyer isp_prt(isp, ISP_LOGWARN, "broken fabric nameserver...*wheeze*...");
2226 1.39.2.6 bouyer
2227 1.37 mjacob /*
2228 1.37 mjacob * We either have a broken name server or a huge fabric if we get here.
2229 1.37 mjacob */
2230 1.39.2.6 bouyer fcp->isp_loopstate = LOOP_FSCAN_DONE;
2231 1.37 mjacob return (0);
2232 1.37 mjacob }
2233 1.39.2.5 bouyer
2234 1.39.2.5 bouyer static void
2235 1.39.2.5 bouyer isp_register_fc4_type(struct ispsoftc *isp)
2236 1.39.2.5 bouyer {
2237 1.39.2.5 bouyer fcparam *fcp = isp->isp_param;
2238 1.39.2.5 bouyer sns_screq_t *reqp;
2239 1.39.2.5 bouyer mbreg_t mbs;
2240 1.39.2.5 bouyer
2241 1.39.2.5 bouyer reqp = (sns_screq_t *) fcp->isp_scratch;
2242 1.39.2.5 bouyer MEMZERO((void *) reqp, SNS_RFT_REQ_SIZE);
2243 1.39.2.5 bouyer reqp->snscb_rblen = SNS_RFT_RESP_SIZE >> 1;
2244 1.39.2.5 bouyer reqp->snscb_addr[RQRSP_ADDR0015] = DMA_LSW(fcp->isp_scdma + 0x100);
2245 1.39.2.5 bouyer reqp->snscb_addr[RQRSP_ADDR1631] = DMA_MSW(fcp->isp_scdma + 0x100);
2246 1.39.2.5 bouyer reqp->snscb_sblen = 22;
2247 1.39.2.5 bouyer reqp->snscb_data[0] = SNS_RFT;
2248 1.39.2.5 bouyer reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
2249 1.39.2.5 bouyer reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
2250 1.39.2.5 bouyer reqp->snscb_data[6] = 0x100; /* SCS - FCP */
2251 1.39.2.5 bouyer #if 0
2252 1.39.2.5 bouyer reqp->snscb_data[6] |= 20; /* ISO/IEC 8802-2 LLC/SNAP */
2253 1.39.2.5 bouyer #endif
2254 1.39.2.5 bouyer ISP_SWIZZLE_SNS_REQ(isp, reqp);
2255 1.39.2.5 bouyer mbs.param[0] = MBOX_SEND_SNS;
2256 1.39.2.5 bouyer mbs.param[1] = SNS_RFT_REQ_SIZE >> 1;
2257 1.39.2.5 bouyer mbs.param[2] = DMA_MSW(fcp->isp_scdma);
2258 1.39.2.5 bouyer mbs.param[3] = DMA_LSW(fcp->isp_scdma);
2259 1.39.2.5 bouyer mbs.param[6] = 0;
2260 1.39.2.5 bouyer mbs.param[7] = 0;
2261 1.39.2.5 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
2262 1.39.2.5 bouyer if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2263 1.39.2.6 bouyer isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
2264 1.39.2.5 bouyer }
2265 1.39.2.5 bouyer }
2266 1.39.2.6 bouyer
2267 1.37 mjacob /*
2268 1.23 mjacob * Start a command. Locking is assumed done in the caller.
2269 1.1 cgd */
2270 1.23 mjacob
2271 1.39.2.2 bouyer int
2272 1.39.2.2 bouyer isp_start(xs)
2273 1.39.2.2 bouyer XS_T *xs;
2274 1.1 cgd {
2275 1.1 cgd struct ispsoftc *isp;
2276 1.39.2.2 bouyer u_int16_t iptr, optr;
2277 1.10 mjacob union {
2278 1.10 mjacob ispreq_t *_reqp;
2279 1.10 mjacob ispreqt2_t *_t2reqp;
2280 1.10 mjacob } _u;
2281 1.10 mjacob #define reqp _u._reqp
2282 1.10 mjacob #define t2reqp _u._t2reqp
2283 1.16 mjacob #define UZSIZE max(sizeof (ispreq_t), sizeof (ispreqt2_t))
2284 1.38 mjacob int target, i;
2285 1.1 cgd
2286 1.23 mjacob XS_INITERR(xs);
2287 1.23 mjacob isp = XS_ISP(xs);
2288 1.1 cgd
2289 1.39.2.6 bouyer
2290 1.39.2.6 bouyer /*
2291 1.39.2.6 bouyer * Check to make sure we're supporting initiator role.
2292 1.39.2.6 bouyer */
2293 1.39.2.6 bouyer if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
2294 1.39.2.6 bouyer XS_SETERR(xs, HBA_SELTIMEOUT);
2295 1.39.2.6 bouyer return (CMD_COMPLETE);
2296 1.39.2.6 bouyer }
2297 1.39.2.6 bouyer
2298 1.39.2.6 bouyer /*
2299 1.39.2.6 bouyer * Now make sure we're running.
2300 1.39.2.6 bouyer */
2301 1.39.2.6 bouyer
2302 1.24 mjacob if (isp->isp_state != ISP_RUNSTATE) {
2303 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
2304 1.24 mjacob XS_SETERR(xs, HBA_BOTCH);
2305 1.24 mjacob return (CMD_COMPLETE);
2306 1.24 mjacob }
2307 1.24 mjacob
2308 1.25 mjacob /*
2309 1.39.2.2 bouyer * Check command CDB length, etc.. We really are limited to 16 bytes
2310 1.39.2.2 bouyer * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
2311 1.39.2.2 bouyer * but probably only if we're running fairly new firmware (we'll
2312 1.39.2.2 bouyer * let the old f/w choke on an extended command queue entry).
2313 1.25 mjacob */
2314 1.33 mjacob
2315 1.39.2.2 bouyer if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
2316 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
2317 1.39.2.2 bouyer "unsupported cdb length (%d, CDB[0]=0x%x)",
2318 1.39.2.2 bouyer XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
2319 1.25 mjacob XS_SETERR(xs, HBA_BOTCH);
2320 1.25 mjacob return (CMD_COMPLETE);
2321 1.25 mjacob }
2322 1.25 mjacob
2323 1.25 mjacob /*
2324 1.33 mjacob * Check to see whether we have good firmware state still or
2325 1.33 mjacob * need to refresh our port database for this target.
2326 1.33 mjacob */
2327 1.37 mjacob target = XS_TGT(xs);
2328 1.33 mjacob if (IS_FC(isp)) {
2329 1.33 mjacob fcparam *fcp = isp->isp_param;
2330 1.37 mjacob struct lportdb *lp;
2331 1.39.2.6 bouyer /*
2332 1.39.2.6 bouyer * Check for f/w being in ready state. If the f/w
2333 1.39.2.6 bouyer * isn't in ready state, then we don't know our
2334 1.39.2.6 bouyer * loop ID and the f/w hasn't completed logging
2335 1.39.2.6 bouyer * into all targets on the loop. If this is the
2336 1.39.2.6 bouyer * case, then bounce the command. We pretend this is
2337 1.39.2.6 bouyer * a SELECTION TIMEOUT error if we've never gone to
2338 1.39.2.6 bouyer * FW_READY state at all- in this case we may not
2339 1.39.2.6 bouyer * be hooked to a loop at all and we shouldn't hang
2340 1.39.2.6 bouyer * the machine for this. Otherwise, defer this command
2341 1.39.2.6 bouyer * until later.
2342 1.39.2.6 bouyer */
2343 1.39.2.6 bouyer if (fcp->isp_fwstate != FW_READY) {
2344 1.39.2.6 bouyer /*
2345 1.39.2.6 bouyer * Give ourselves at most a 250ms delay.
2346 1.39.2.6 bouyer */
2347 1.39.2.6 bouyer if (isp_fclink_test(isp, 250000)) {
2348 1.39.2.6 bouyer XS_SETERR(xs, HBA_SELTIMEOUT);
2349 1.39.2.6 bouyer if (fcp->loop_seen_once) {
2350 1.39.2.6 bouyer return (CMD_RQLATER);
2351 1.39.2.6 bouyer } else {
2352 1.39.2.6 bouyer return (CMD_COMPLETE);
2353 1.39.2.6 bouyer }
2354 1.39.2.6 bouyer }
2355 1.39.2.6 bouyer }
2356 1.39.2.6 bouyer
2357 1.39.2.2 bouyer /*
2358 1.39.2.2 bouyer * If we're not on a Fabric, we can't have a target
2359 1.39.2.5 bouyer * above FL_PORT_ID-1.
2360 1.39.2.5 bouyer *
2361 1.39.2.5 bouyer * If we're on a fabric and *not* connected as an F-port,
2362 1.39.2.5 bouyer * we can't have a target less than FC_SNS_ID+1. This
2363 1.39.2.5 bouyer * keeps us from having to sort out the difference between
2364 1.39.2.5 bouyer * local public loop devices and those which we might get
2365 1.39.2.5 bouyer * from a switch's database.
2366 1.39.2.2 bouyer */
2367 1.39.2.2 bouyer if (fcp->isp_onfabric == 0) {
2368 1.39.2.2 bouyer if (target >= FL_PORT_ID) {
2369 1.39.2.2 bouyer XS_SETERR(xs, HBA_SELTIMEOUT);
2370 1.39.2.2 bouyer return (CMD_COMPLETE);
2371 1.39.2.2 bouyer }
2372 1.39.2.2 bouyer } else {
2373 1.39.2.2 bouyer if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
2374 1.39.2.2 bouyer XS_SETERR(xs, HBA_SELTIMEOUT);
2375 1.39.2.2 bouyer return (CMD_COMPLETE);
2376 1.39.2.2 bouyer }
2377 1.39.2.5 bouyer if (fcp->isp_topo != TOPO_F_PORT &&
2378 1.39.2.2 bouyer target < FL_PORT_ID) {
2379 1.37 mjacob XS_SETERR(xs, HBA_SELTIMEOUT);
2380 1.37 mjacob return (CMD_COMPLETE);
2381 1.37 mjacob }
2382 1.37 mjacob }
2383 1.37 mjacob
2384 1.37 mjacob /*
2385 1.37 mjacob * If our loop state is such that we haven't yet received
2386 1.37 mjacob * a "Port Database Changed" notification (after a LIP or
2387 1.37 mjacob * a Loop Reset or firmware initialization), then defer
2388 1.39.2.2 bouyer * sending commands for a little while, but only if we've
2389 1.39.2.2 bouyer * seen a valid loop at one point (otherwise we can get
2390 1.39.2.2 bouyer * stuck at initialization time).
2391 1.37 mjacob */
2392 1.37 mjacob if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
2393 1.37 mjacob XS_SETERR(xs, HBA_SELTIMEOUT);
2394 1.39.2.2 bouyer if (fcp->loop_seen_once) {
2395 1.39.2.2 bouyer return (CMD_RQLATER);
2396 1.39.2.2 bouyer } else {
2397 1.39.2.2 bouyer return (CMD_COMPLETE);
2398 1.39.2.2 bouyer }
2399 1.37 mjacob }
2400 1.37 mjacob
2401 1.37 mjacob /*
2402 1.39.2.6 bouyer * If we're in the middle of loop or fabric scanning
2403 1.39.2.6 bouyer * or merging the port databases, retry this command later.
2404 1.39.2.6 bouyer */
2405 1.39.2.6 bouyer if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
2406 1.39.2.6 bouyer fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
2407 1.39.2.6 bouyer fcp->isp_loopstate == LOOP_SYNCING_PDB) {
2408 1.39.2.6 bouyer return (CMD_RQLATER);
2409 1.39.2.6 bouyer }
2410 1.39.2.6 bouyer
2411 1.39.2.6 bouyer /*
2412 1.39.2.6 bouyer * If our loop state is now such that we've just now
2413 1.39.2.6 bouyer * received a Port Database Change notification, then
2414 1.39.2.6 bouyer * we have to go off and (re)scan the fabric. We back
2415 1.39.2.6 bouyer * out and try again later if this doesn't work.
2416 1.39.2.6 bouyer */
2417 1.39.2.6 bouyer if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
2418 1.39.2.6 bouyer if (isp_scan_fabric(isp)) {
2419 1.39.2.6 bouyer return (CMD_RQLATER);
2420 1.39.2.6 bouyer }
2421 1.39.2.6 bouyer if (fcp->isp_fwstate != FW_READY ||
2422 1.39.2.6 bouyer fcp->isp_loopstate < LOOP_PDB_RCVD) {
2423 1.39.2.6 bouyer return (CMD_RQLATER);
2424 1.39.2.6 bouyer }
2425 1.39.2.6 bouyer }
2426 1.39.2.6 bouyer
2427 1.39.2.6 bouyer /*
2428 1.37 mjacob * If our loop state is now such that we've just now
2429 1.37 mjacob * received a Port Database Change notification, then
2430 1.39.2.2 bouyer * we have to go off and (re)synchronize our port
2431 1.39.2.2 bouyer * database.
2432 1.37 mjacob */
2433 1.39.2.6 bouyer if (fcp->isp_loopstate < LOOP_READY) {
2434 1.39.2.6 bouyer if (isp_pdb_sync(isp)) {
2435 1.39.2.6 bouyer return (CMD_RQLATER);
2436 1.39.2.6 bouyer }
2437 1.39.2.6 bouyer if (fcp->isp_fwstate != FW_READY ||
2438 1.39.2.6 bouyer fcp->isp_loopstate != LOOP_READY) {
2439 1.39.2.6 bouyer return (CMD_RQLATER);
2440 1.33 mjacob }
2441 1.33 mjacob }
2442 1.37 mjacob
2443 1.33 mjacob /*
2444 1.39.2.2 bouyer * XXX: Here's were we would cancel any loop_dead flag
2445 1.39.2.2 bouyer * XXX: also cancel in dead_loop timeout that's running
2446 1.39.2.2 bouyer */
2447 1.39.2.2 bouyer
2448 1.39.2.2 bouyer /*
2449 1.37 mjacob * Now check whether we should even think about pursuing this.
2450 1.33 mjacob */
2451 1.37 mjacob lp = &fcp->portdb[target];
2452 1.37 mjacob if (lp->valid == 0) {
2453 1.37 mjacob XS_SETERR(xs, HBA_SELTIMEOUT);
2454 1.37 mjacob return (CMD_COMPLETE);
2455 1.37 mjacob }
2456 1.37 mjacob if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
2457 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG2,
2458 1.39.2.2 bouyer "Target %d does not have target service", target);
2459 1.37 mjacob XS_SETERR(xs, HBA_SELTIMEOUT);
2460 1.37 mjacob return (CMD_COMPLETE);
2461 1.33 mjacob }
2462 1.37 mjacob /*
2463 1.39.2.6 bouyer * Now turn target into what the actual Loop ID is.
2464 1.37 mjacob */
2465 1.37 mjacob target = lp->loopid;
2466 1.33 mjacob }
2467 1.33 mjacob
2468 1.33 mjacob /*
2469 1.33 mjacob * Next check to see if any HBA or Device
2470 1.25 mjacob * parameters need to be updated.
2471 1.25 mjacob */
2472 1.36 mjacob if (isp->isp_update != 0) {
2473 1.25 mjacob isp_update(isp);
2474 1.10 mjacob }
2475 1.25 mjacob
2476 1.39.2.2 bouyer if (isp_getrqentry(isp, &iptr, &optr, (void **) &reqp)) {
2477 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
2478 1.23 mjacob XS_SETERR(xs, HBA_BOTCH);
2479 1.23 mjacob return (CMD_EAGAIN);
2480 1.1 cgd }
2481 1.13 mjacob
2482 1.36 mjacob /*
2483 1.36 mjacob * Now see if we need to synchronize the ISP with respect to anything.
2484 1.36 mjacob * We do dual duty here (cough) for synchronizing for busses other
2485 1.36 mjacob * than which we got here to send a command to.
2486 1.36 mjacob */
2487 1.1 cgd if (isp->isp_sendmarker) {
2488 1.39.2.2 bouyer u_int8_t n = (IS_DUALBUS(isp)? 2: 1);
2489 1.27 mjacob /*
2490 1.36 mjacob * Check ports to send markers for...
2491 1.27 mjacob */
2492 1.36 mjacob for (i = 0; i < n; i++) {
2493 1.36 mjacob if ((isp->isp_sendmarker & (1 << i)) == 0) {
2494 1.36 mjacob continue;
2495 1.36 mjacob }
2496 1.36 mjacob MEMZERO((void *) reqp, sizeof (*reqp));
2497 1.36 mjacob reqp->req_header.rqs_entry_count = 1;
2498 1.36 mjacob reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
2499 1.36 mjacob reqp->req_modifier = SYNC_ALL;
2500 1.38 mjacob reqp->req_target = i << 7; /* insert bus number */
2501 1.38 mjacob ISP_SWIZZLE_REQUEST(isp, reqp);
2502 1.39.2.2 bouyer ISP_ADD_REQUEST(isp, iptr);
2503 1.36 mjacob
2504 1.39.2.2 bouyer if (isp_getrqentry(isp, &iptr, &optr, (void **)&reqp)) {
2505 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG0,
2506 1.39.2.2 bouyer "Request Queue Overflow+");
2507 1.36 mjacob XS_SETERR(xs, HBA_BOTCH);
2508 1.36 mjacob return (CMD_EAGAIN);
2509 1.36 mjacob }
2510 1.1 cgd }
2511 1.1 cgd }
2512 1.1 cgd
2513 1.30 mjacob MEMZERO((void *) reqp, UZSIZE);
2514 1.10 mjacob reqp->req_header.rqs_entry_count = 1;
2515 1.38 mjacob if (IS_FC(isp)) {
2516 1.10 mjacob reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
2517 1.10 mjacob } else {
2518 1.39.2.2 bouyer if (XS_CDBLEN(xs) > 12)
2519 1.39.2.2 bouyer reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
2520 1.39.2.2 bouyer else
2521 1.39.2.2 bouyer reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
2522 1.10 mjacob }
2523 1.10 mjacob reqp->req_header.rqs_flags = 0;
2524 1.38 mjacob reqp->req_header.rqs_seqno = 0;
2525 1.38 mjacob if (IS_FC(isp)) {
2526 1.10 mjacob /*
2527 1.10 mjacob * See comment in isp_intr
2528 1.10 mjacob */
2529 1.23 mjacob XS_RESID(xs) = 0;
2530 1.34 mjacob
2531 1.10 mjacob /*
2532 1.39.2.2 bouyer * Fibre Channel always requires some kind of tag.
2533 1.39.2.2 bouyer * The Qlogic drivers seem be happy not to use a tag,
2534 1.39.2.2 bouyer * but this breaks for some devices (IBM drives).
2535 1.10 mjacob */
2536 1.39.2.2 bouyer if (XS_TAG_P(xs)) {
2537 1.39.2.2 bouyer t2reqp->req_flags = XS_TAG_TYPE(xs);
2538 1.39.2.2 bouyer } else {
2539 1.39.2.2 bouyer /*
2540 1.39.2.2 bouyer * If we don't know what tag to use, use HEAD OF QUEUE
2541 1.39.2.2 bouyer * for Request Sense or Ordered (for safety's sake).
2542 1.39.2.2 bouyer */
2543 1.39.2.2 bouyer if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
2544 1.39.2.2 bouyer t2reqp->req_flags = REQFLAG_HTAG;
2545 1.39.2.2 bouyer else
2546 1.39.2.2 bouyer t2reqp->req_flags = REQFLAG_OTAG;
2547 1.10 mjacob }
2548 1.10 mjacob } else {
2549 1.23 mjacob sdparam *sdp = (sdparam *)isp->isp_param;
2550 1.37 mjacob if ((sdp->isp_devparam[target].cur_dflags & DPARM_TQING) &&
2551 1.39.2.2 bouyer XS_TAG_P(xs)) {
2552 1.39.2.2 bouyer reqp->req_flags = XS_TAG_TYPE(xs);
2553 1.10 mjacob }
2554 1.10 mjacob }
2555 1.37 mjacob reqp->req_target = target | (XS_CHANNEL(xs) << 7);
2556 1.38 mjacob if (IS_SCSI(isp)) {
2557 1.28 mjacob reqp->req_lun_trn = XS_LUN(xs);
2558 1.23 mjacob reqp->req_cdblen = XS_CDBLEN(xs);
2559 1.28 mjacob } else {
2560 1.39.2.2 bouyer if (isp->isp_maxluns > 16)
2561 1.39.2.2 bouyer t2reqp->req_scclun = XS_LUN(xs);
2562 1.39.2.2 bouyer else
2563 1.39.2.2 bouyer t2reqp->req_lun_trn = XS_LUN(xs);
2564 1.10 mjacob }
2565 1.31 mjacob MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
2566 1.1 cgd
2567 1.23 mjacob reqp->req_time = XS_TIME(xs) / 1000;
2568 1.23 mjacob if (reqp->req_time == 0 && XS_TIME(xs))
2569 1.10 mjacob reqp->req_time = 1;
2570 1.33 mjacob
2571 1.33 mjacob /*
2572 1.33 mjacob * Always give a bit more leeway to commands after a bus reset.
2573 1.36 mjacob * XXX: DOES NOT DISTINGUISH WHICH PORT MAY HAVE BEEN SYNCED
2574 1.33 mjacob */
2575 1.38 mjacob if (isp->isp_sendmarker && reqp->req_time < 5) {
2576 1.33 mjacob reqp->req_time = 5;
2577 1.38 mjacob }
2578 1.38 mjacob if (isp_save_xs(isp, xs, &reqp->req_handle)) {
2579 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1, "out of xflist pointers");
2580 1.38 mjacob XS_SETERR(xs, HBA_BOTCH);
2581 1.38 mjacob return (CMD_EAGAIN);
2582 1.38 mjacob }
2583 1.38 mjacob /*
2584 1.38 mjacob * Set up DMA and/or do any bus swizzling of the request entry
2585 1.38 mjacob * so that the Qlogic F/W understands what is being asked of it.
2586 1.38 mjacob */
2587 1.27 mjacob i = ISP_DMASETUP(isp, xs, reqp, &iptr, optr);
2588 1.27 mjacob if (i != CMD_QUEUED) {
2589 1.38 mjacob isp_destroy_handle(isp, reqp->req_handle);
2590 1.27 mjacob /*
2591 1.27 mjacob * dmasetup sets actual error in packet, and
2592 1.27 mjacob * return what we were given to return.
2593 1.27 mjacob */
2594 1.27 mjacob return (i);
2595 1.1 cgd }
2596 1.23 mjacob XS_SETERR(xs, HBA_NOERROR);
2597 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG2,
2598 1.39.2.6 bouyer "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
2599 1.39.2.6 bouyer XS_CHANNEL(xs), target, XS_LUN(xs), XS_CDBP(xs)[0],
2600 1.39.2.6 bouyer (long) XS_XFRLEN(xs));
2601 1.39.2.2 bouyer ISP_ADD_REQUEST(isp, iptr);
2602 1.23 mjacob isp->isp_nactive++;
2603 1.33 mjacob if (isp->isp_sendmarker)
2604 1.33 mjacob isp->isp_sendmarker = 0;
2605 1.23 mjacob return (CMD_QUEUED);
2606 1.10 mjacob #undef reqp
2607 1.10 mjacob #undef t2reqp
2608 1.1 cgd }
2609 1.1 cgd
2610 1.1 cgd /*
2611 1.23 mjacob * isp control
2612 1.23 mjacob * Locks (ints blocked) assumed held.
2613 1.1 cgd */
2614 1.1 cgd
2615 1.1 cgd int
2616 1.23 mjacob isp_control(isp, ctl, arg)
2617 1.1 cgd struct ispsoftc *isp;
2618 1.23 mjacob ispctl_t ctl;
2619 1.23 mjacob void *arg;
2620 1.1 cgd {
2621 1.39.2.2 bouyer XS_T *xs;
2622 1.23 mjacob mbreg_t mbs;
2623 1.38 mjacob int bus, tgt;
2624 1.38 mjacob u_int32_t handle;
2625 1.3 cgd
2626 1.23 mjacob switch (ctl) {
2627 1.23 mjacob default:
2628 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
2629 1.23 mjacob break;
2630 1.3 cgd
2631 1.23 mjacob case ISPCTL_RESET_BUS:
2632 1.33 mjacob /*
2633 1.33 mjacob * Issue a bus reset.
2634 1.33 mjacob */
2635 1.23 mjacob mbs.param[0] = MBOX_BUS_RESET;
2636 1.39.2.2 bouyer mbs.param[2] = 0;
2637 1.38 mjacob if (IS_SCSI(isp)) {
2638 1.32 mjacob mbs.param[1] =
2639 1.32 mjacob ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
2640 1.33 mjacob if (mbs.param[1] < 2)
2641 1.33 mjacob mbs.param[1] = 2;
2642 1.38 mjacob bus = *((int *) arg);
2643 1.39.2.2 bouyer if (IS_DUALBUS(isp))
2644 1.39.2.2 bouyer mbs.param[2] = bus;
2645 1.32 mjacob } else {
2646 1.38 mjacob mbs.param[1] = 10;
2647 1.38 mjacob bus = 0;
2648 1.32 mjacob }
2649 1.39.2.2 bouyer isp->isp_sendmarker |= (1 << bus);
2650 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
2651 1.23 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2652 1.23 mjacob break;
2653 1.23 mjacob }
2654 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO,
2655 1.39.2.2 bouyer "driver initiated bus reset of bus %d", bus);
2656 1.23 mjacob return (0);
2657 1.23 mjacob
2658 1.34 mjacob case ISPCTL_RESET_DEV:
2659 1.36 mjacob tgt = (*((int *) arg)) & 0xffff;
2660 1.36 mjacob bus = (*((int *) arg)) >> 16;
2661 1.23 mjacob mbs.param[0] = MBOX_ABORT_TARGET;
2662 1.36 mjacob mbs.param[1] = (tgt << 8) | (bus << 15);
2663 1.32 mjacob mbs.param[2] = 3; /* 'delay', in seconds */
2664 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
2665 1.23 mjacob if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2666 1.23 mjacob break;
2667 1.23 mjacob }
2668 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO,
2669 1.39.2.2 bouyer "Target %d on Bus %d Reset Succeeded", tgt, bus);
2670 1.39.2.2 bouyer isp->isp_sendmarker |= (1 << bus);
2671 1.23 mjacob return (0);
2672 1.23 mjacob
2673 1.34 mjacob case ISPCTL_ABORT_CMD:
2674 1.39.2.2 bouyer xs = (XS_T *) arg;
2675 1.39.2.2 bouyer tgt = XS_TGT(xs);
2676 1.38 mjacob handle = isp_find_handle(isp, xs);
2677 1.38 mjacob if (handle == 0) {
2678 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
2679 1.39.2.2 bouyer "cannot find handle for command to abort");
2680 1.23 mjacob break;
2681 1.23 mjacob }
2682 1.38 mjacob bus = XS_CHANNEL(xs);
2683 1.23 mjacob mbs.param[0] = MBOX_ABORT;
2684 1.38 mjacob if (IS_FC(isp)) {
2685 1.39.2.2 bouyer if (isp->isp_maxluns > 16) {
2686 1.39.2.2 bouyer mbs.param[1] = tgt << 8;
2687 1.39.2.2 bouyer mbs.param[4] = 0;
2688 1.39.2.2 bouyer mbs.param[5] = 0;
2689 1.39.2.2 bouyer mbs.param[6] = XS_LUN(xs);
2690 1.39.2.2 bouyer } else {
2691 1.39.2.2 bouyer mbs.param[1] = tgt << 8 | XS_LUN(xs);
2692 1.39.2.2 bouyer }
2693 1.28 mjacob } else {
2694 1.38 mjacob mbs.param[1] =
2695 1.38 mjacob (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
2696 1.28 mjacob }
2697 1.39.2.2 bouyer mbs.param[3] = handle >> 16;
2698 1.39.2.2 bouyer mbs.param[2] = handle & 0xffff;
2699 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
2700 1.39.2.2 bouyer if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2701 1.39.2.2 bouyer return (0);
2702 1.23 mjacob }
2703 1.39.2.2 bouyer /*
2704 1.39.2.2 bouyer * XXX: Look for command in the REQUEST QUEUE. That is,
2705 1.39.2.2 bouyer * XXX: It hasen't been picked up by firmware yet.
2706 1.39.2.2 bouyer */
2707 1.39.2.2 bouyer break;
2708 1.26 mjacob
2709 1.26 mjacob case ISPCTL_UPDATE_PARAMS:
2710 1.39.2.6 bouyer
2711 1.26 mjacob isp_update(isp);
2712 1.34 mjacob return (0);
2713 1.33 mjacob
2714 1.33 mjacob case ISPCTL_FCLINK_TEST:
2715 1.39.2.6 bouyer
2716 1.39.2.2 bouyer if (IS_FC(isp)) {
2717 1.39.2.2 bouyer int usdelay = (arg)? *((int *) arg) : 250000;
2718 1.39.2.2 bouyer return (isp_fclink_test(isp, usdelay));
2719 1.39.2.2 bouyer }
2720 1.39.2.2 bouyer break;
2721 1.39.2.2 bouyer
2722 1.39.2.6 bouyer case ISPCTL_SCAN_FABRIC:
2723 1.39.2.6 bouyer
2724 1.39.2.6 bouyer if (IS_FC(isp)) {
2725 1.39.2.6 bouyer return (isp_scan_fabric(isp));
2726 1.39.2.6 bouyer }
2727 1.39.2.6 bouyer break;
2728 1.39.2.6 bouyer
2729 1.39.2.6 bouyer case ISPCTL_SCAN_LOOP:
2730 1.39.2.6 bouyer
2731 1.39.2.6 bouyer if (IS_FC(isp)) {
2732 1.39.2.6 bouyer return (isp_scan_loop(isp));
2733 1.39.2.6 bouyer }
2734 1.39.2.6 bouyer break;
2735 1.39.2.6 bouyer
2736 1.39.2.2 bouyer case ISPCTL_PDB_SYNC:
2737 1.39.2.6 bouyer
2738 1.39.2.6 bouyer if (IS_FC(isp)) {
2739 1.39.2.6 bouyer return (isp_pdb_sync(isp));
2740 1.39.2.6 bouyer }
2741 1.39.2.6 bouyer break;
2742 1.39.2.6 bouyer
2743 1.39.2.6 bouyer case ISPCTL_SEND_LIP:
2744 1.39.2.6 bouyer
2745 1.39.2.2 bouyer if (IS_FC(isp)) {
2746 1.39.2.6 bouyer mbs.param[0] = MBOX_INIT_LIP;
2747 1.39.2.6 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
2748 1.39.2.6 bouyer if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2749 1.39.2.6 bouyer return (0);
2750 1.39.2.6 bouyer }
2751 1.39.2.6 bouyer }
2752 1.39.2.6 bouyer break;
2753 1.39.2.6 bouyer
2754 1.39.2.6 bouyer case ISPCTL_GET_POSMAP:
2755 1.39.2.6 bouyer
2756 1.39.2.6 bouyer if (IS_FC(isp) && arg) {
2757 1.39.2.6 bouyer return (isp_getmap(isp, arg));
2758 1.39.2.2 bouyer }
2759 1.39.2.2 bouyer break;
2760 1.39.2.6 bouyer
2761 1.39.2.6 bouyer case ISPCTL_RUN_MBOXCMD:
2762 1.39.2.6 bouyer
2763 1.39.2.6 bouyer isp_mboxcmd(isp, arg, MBLOGALL);
2764 1.39.2.6 bouyer return(0);
2765 1.39.2.6 bouyer
2766 1.39.2.2 bouyer #ifdef ISP_TARGET_MODE
2767 1.39.2.2 bouyer case ISPCTL_TOGGLE_TMODE:
2768 1.39.2.2 bouyer {
2769 1.39.2.2 bouyer int ena = *(int *)arg;
2770 1.39.2.6 bouyer
2771 1.39.2.6 bouyer /*
2772 1.39.2.6 bouyer * We don't check/set against role here- that's the
2773 1.39.2.6 bouyer * responsibility for the outer layer to coordinate.
2774 1.39.2.6 bouyer */
2775 1.39.2.2 bouyer if (IS_SCSI(isp)) {
2776 1.39.2.2 bouyer mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
2777 1.39.2.2 bouyer mbs.param[1] = (ena)? ENABLE_TARGET_FLAG : 0;
2778 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
2779 1.39.2.2 bouyer if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2780 1.39.2.2 bouyer break;
2781 1.39.2.2 bouyer }
2782 1.39.2.2 bouyer }
2783 1.39.2.2 bouyer return (0);
2784 1.39.2.2 bouyer }
2785 1.39.2.2 bouyer #endif
2786 1.1 cgd }
2787 1.23 mjacob return (-1);
2788 1.1 cgd }
2789 1.1 cgd
2790 1.23 mjacob /*
2791 1.23 mjacob * Interrupt Service Routine(s).
2792 1.23 mjacob *
2793 1.23 mjacob * External (OS) framework has done the appropriate locking,
2794 1.23 mjacob * and the locking will be held throughout this function.
2795 1.23 mjacob */
2796 1.23 mjacob
2797 1.39.2.2 bouyer /*
2798 1.39.2.2 bouyer * Limit our stack depth by sticking with the max likely number
2799 1.39.2.2 bouyer * of completions on a request queue at any one time.
2800 1.39.2.2 bouyer */
2801 1.39.2.2 bouyer #define MAX_REQUESTQ_COMPLETIONS 32
2802 1.39.2.2 bouyer
2803 1.1 cgd int
2804 1.1 cgd isp_intr(arg)
2805 1.1 cgd void *arg;
2806 1.1 cgd {
2807 1.1 cgd struct ispsoftc *isp = arg;
2808 1.39.2.2 bouyer XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
2809 1.39.2.2 bouyer u_int16_t iptr, optr, isr, sema, junk;
2810 1.32 mjacob int i, nlooked = 0, ndone = 0;
2811 1.1 cgd
2812 1.39.2.2 bouyer if (IS_2100(isp)) {
2813 1.39.2.2 bouyer i = 0;
2814 1.39.2.2 bouyer do {
2815 1.39.2.2 bouyer isr = ISP_READ(isp, BIU_ISR);
2816 1.39.2.2 bouyer junk = ISP_READ(isp, BIU_ISR);
2817 1.39.2.2 bouyer } while (isr != junk && ++i < 1000);
2818 1.39.2.2 bouyer if (isr != junk) {
2819 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
2820 1.39.2.2 bouyer "isr unsteady (%x, %x)", isr, junk);
2821 1.39.2.2 bouyer }
2822 1.39.2.2 bouyer i = 0;
2823 1.39.2.2 bouyer do {
2824 1.39.2.2 bouyer sema = ISP_READ(isp, BIU_SEMA);
2825 1.39.2.2 bouyer junk = ISP_READ(isp, BIU_SEMA);
2826 1.39.2.2 bouyer } while (sema != junk && ++i < 1000);
2827 1.39.2.2 bouyer if (sema != junk) {
2828 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
2829 1.39.2.2 bouyer "sema unsteady (%x, %x)", sema, junk);
2830 1.39.2.2 bouyer }
2831 1.39.2.2 bouyer } else {
2832 1.38 mjacob isr = ISP_READ(isp, BIU_ISR);
2833 1.39.2.2 bouyer sema = ISP_READ(isp, BIU_SEMA);
2834 1.39 mjacob }
2835 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG3, "isp_intr isr %x sem %x", isr, sema);
2836 1.39.2.2 bouyer isr &= INT_PENDING_MASK(isp);
2837 1.39.2.2 bouyer sema &= BIU_SEMA_LOCK;
2838 1.39.2.3 bouyer isp->isp_intcnt++;
2839 1.39.2.2 bouyer if (isr == 0 && sema == 0) {
2840 1.39.2.3 bouyer isp->isp_intbogus++;
2841 1.39 mjacob return (0);
2842 1.1 cgd }
2843 1.1 cgd
2844 1.36 mjacob if (sema) {
2845 1.39.2.2 bouyer u_int16_t mbox;
2846 1.39.2.2 bouyer
2847 1.39.2.2 bouyer if (IS_2100(isp)) {
2848 1.39.2.2 bouyer i = 0;
2849 1.39.2.2 bouyer do {
2850 1.39.2.2 bouyer mbox = ISP_READ(isp, OUTMAILBOX0);
2851 1.39.2.2 bouyer junk = ISP_READ(isp, OUTMAILBOX0);;
2852 1.39.2.2 bouyer } while (junk != mbox && ++i < 1000);
2853 1.39.2.2 bouyer if (mbox != junk) {
2854 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
2855 1.39.2.2 bouyer "mailbox0 unsteady (%x, %x)", mbox, junk);
2856 1.39.2.2 bouyer ISP_WRITE(isp, BIU_SEMA, 0);
2857 1.39.2.2 bouyer ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
2858 1.39.2.2 bouyer return (1);
2859 1.39.2.2 bouyer }
2860 1.39.2.2 bouyer } else {
2861 1.39.2.2 bouyer mbox = ISP_READ(isp, OUTMAILBOX0);
2862 1.39.2.2 bouyer }
2863 1.33 mjacob if (mbox & 0x4000) {
2864 1.39.2.2 bouyer int obits, i = 0;
2865 1.39.2.2 bouyer if ((obits = isp->isp_mboxbsy) != 0) {
2866 1.39.2.2 bouyer isp->isp_mboxtmp[i++] = mbox;
2867 1.39.2.4 bouyer for (i = 1; i < MAX_MAILBOX; i++) {
2868 1.39.2.2 bouyer if ((obits & (1 << i)) == 0) {
2869 1.39.2.2 bouyer continue;
2870 1.39.2.2 bouyer }
2871 1.39.2.2 bouyer isp->isp_mboxtmp[i] =
2872 1.39.2.2 bouyer ISP_READ(isp, MBOX_OFF(i));
2873 1.39.2.2 bouyer }
2874 1.39.2.2 bouyer MBOX_NOTIFY_COMPLETE(isp);
2875 1.39.2.2 bouyer } else {
2876 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
2877 1.39.2.2 bouyer "Mbox Command Async (0x%x) with no waiters",
2878 1.39.2.2 bouyer mbox);
2879 1.39.2.2 bouyer }
2880 1.33 mjacob } else {
2881 1.33 mjacob u_int32_t fhandle = isp_parse_async(isp, (int) mbox);
2882 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
2883 1.35 mjacob if (fhandle > 0) {
2884 1.38 mjacob isp_fastpost_complete(isp, fhandle);
2885 1.33 mjacob }
2886 1.31 mjacob }
2887 1.39.2.2 bouyer if (IS_FC(isp) || isp->isp_state != ISP_RUNSTATE) {
2888 1.39.2.2 bouyer ISP_WRITE(isp, BIU_SEMA, 0);
2889 1.39.2.2 bouyer ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
2890 1.39.2.2 bouyer return (1);
2891 1.39.2.2 bouyer }
2892 1.39.2.2 bouyer }
2893 1.39.2.2 bouyer
2894 1.39.2.2 bouyer /*
2895 1.39.2.2 bouyer * We can't be getting this now.
2896 1.39.2.2 bouyer */
2897 1.39.2.2 bouyer if (isp->isp_state != ISP_RUNSTATE) {
2898 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
2899 1.39.2.2 bouyer "interrupt (isr=%x, sema=%x) when not ready", isr, sema);
2900 1.39.2.2 bouyer ISP_WRITE(isp, INMAILBOX5, ISP_READ(isp, OUTMAILBOX5));
2901 1.35 mjacob ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
2902 1.39.2.2 bouyer ISP_WRITE(isp, BIU_SEMA, 0);
2903 1.35 mjacob return (1);
2904 1.1 cgd }
2905 1.25 mjacob
2906 1.35 mjacob /*
2907 1.35 mjacob * You *must* read OUTMAILBOX5 prior to clearing the RISC interrupt.
2908 1.35 mjacob */
2909 1.24 mjacob optr = isp->isp_residx;
2910 1.39.2.2 bouyer
2911 1.39.2.2 bouyer if (IS_2100(isp)) {
2912 1.39.2.2 bouyer i = 0;
2913 1.39.2.2 bouyer do {
2914 1.39.2.2 bouyer iptr = ISP_READ(isp, OUTMAILBOX5);
2915 1.39.2.2 bouyer junk = ISP_READ(isp, OUTMAILBOX5);
2916 1.39.2.2 bouyer } while (junk != iptr && ++i < 1000);
2917 1.39.2.2 bouyer
2918 1.39.2.2 bouyer if (iptr != junk) {
2919 1.39.2.2 bouyer ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
2920 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
2921 1.39.2.2 bouyer "mailbox5 unsteady (%x, %x)", iptr, junk);
2922 1.39.2.2 bouyer return (1);
2923 1.39.2.2 bouyer }
2924 1.39.2.2 bouyer } else {
2925 1.39.2.2 bouyer iptr = ISP_READ(isp, OUTMAILBOX5);
2926 1.39.2.2 bouyer }
2927 1.39.2.2 bouyer
2928 1.39.2.2 bouyer if (sema) {
2929 1.39.2.2 bouyer ISP_WRITE(isp, BIU_SEMA, 0);
2930 1.39.2.2 bouyer }
2931 1.35 mjacob ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
2932 1.39.2.2 bouyer
2933 1.39.2.2 bouyer if (optr == iptr && sema == 0) {
2934 1.39.2.2 bouyer /*
2935 1.39.2.2 bouyer * There are a lot of these- reasons unknown- mostly on
2936 1.39.2.2 bouyer * faster Alpha machines.
2937 1.39.2.2 bouyer *
2938 1.39.2.2 bouyer * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
2939 1.39.2.2 bouyer * make sure the old interrupt went away (to avoid 'ringing'
2940 1.39.2.2 bouyer * effects), but that didn't stop this from occurring.
2941 1.39.2.2 bouyer */
2942 1.39.2.2 bouyer junk = ISP_READ(isp, BIU_ISR);
2943 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG2,
2944 1.39.2.2 bouyer "bogus intr- isr %x (%x) iptr %x optr %x",
2945 1.39.2.2 bouyer isr, junk, iptr, optr);
2946 1.10 mjacob }
2947 1.10 mjacob
2948 1.1 cgd while (optr != iptr) {
2949 1.1 cgd ispstatusreq_t *sp;
2950 1.39.2.2 bouyer u_int16_t oop;
2951 1.1 cgd int buddaboom = 0;
2952 1.1 cgd
2953 1.7 thorpej sp = (ispstatusreq_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
2954 1.25 mjacob oop = optr;
2955 1.39.2.2 bouyer optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
2956 1.32 mjacob nlooked++;
2957 1.38 mjacob /*
2958 1.38 mjacob * Do any appropriate unswizzling of what the Qlogic f/w has
2959 1.39.2.2 bouyer * written into memory so it makes sense to us. This is a
2960 1.39.2.2 bouyer * per-platform thing. Also includes any memory barriers.
2961 1.38 mjacob */
2962 1.39.2.2 bouyer ISP_UNSWIZZLE_RESPONSE(isp, sp, oop);
2963 1.1 cgd if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
2964 1.25 mjacob if (isp_handle_other_response(isp, sp, &optr) == 0) {
2965 1.39.2.2 bouyer MEMZERO(sp, sizeof (isphdr_t));
2966 1.25 mjacob continue;
2967 1.25 mjacob }
2968 1.25 mjacob /*
2969 1.25 mjacob * It really has to be a bounced request just copied
2970 1.36 mjacob * from the request queue to the response queue. If
2971 1.36 mjacob * not, something bad has happened.
2972 1.25 mjacob */
2973 1.1 cgd if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
2974 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, notresp,
2975 1.39.2.3 bouyer sp->req_header.rqs_entry_type, oop, optr,
2976 1.39.2.3 bouyer nlooked);
2977 1.39.2.3 bouyer if (isp->isp_dblev & ISP_LOGDEBUG0) {
2978 1.39.2.3 bouyer isp_print_bytes(isp, "Queue Entry",
2979 1.39.2.3 bouyer QENTRY_LEN, sp);
2980 1.39.2.3 bouyer }
2981 1.39.2.2 bouyer MEMZERO(sp, sizeof (isphdr_t));
2982 1.1 cgd continue;
2983 1.1 cgd }
2984 1.1 cgd buddaboom = 1;
2985 1.1 cgd }
2986 1.1 cgd
2987 1.1 cgd if (sp->req_header.rqs_flags & 0xf) {
2988 1.36 mjacob #define _RQS_OFLAGS \
2989 1.36 mjacob ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
2990 1.1 cgd if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
2991 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
2992 1.39.2.2 bouyer "continuation segment");
2993 1.1 cgd ISP_WRITE(isp, INMAILBOX5, optr);
2994 1.1 cgd continue;
2995 1.1 cgd }
2996 1.23 mjacob if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
2997 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1,
2998 1.39.2.2 bouyer "internal queues full");
2999 1.36 mjacob /*
3000 1.39.2.2 bouyer * We'll synthesize a QUEUE FULL message below.
3001 1.36 mjacob */
3002 1.23 mjacob }
3003 1.23 mjacob if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3004 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "bad header flag");
3005 1.23 mjacob buddaboom++;
3006 1.23 mjacob }
3007 1.23 mjacob if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3008 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "bad request packet");
3009 1.23 mjacob buddaboom++;
3010 1.23 mjacob }
3011 1.36 mjacob if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3012 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3013 1.39.2.2 bouyer "unknown flags (0x%x) in response",
3014 1.39.2.2 bouyer sp->req_header.rqs_flags);
3015 1.36 mjacob buddaboom++;
3016 1.36 mjacob }
3017 1.36 mjacob #undef _RQS_OFLAGS
3018 1.1 cgd }
3019 1.38 mjacob if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3020 1.39.2.2 bouyer MEMZERO(sp, sizeof (isphdr_t));
3021 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3022 1.39.2.6 bouyer "bad request handle %d (type 0x%x, flags 0x%x)",
3023 1.39.2.6 bouyer sp->req_handle, sp->req_header.rqs_entry_type,
3024 1.39.2.6 bouyer sp->req_header.rqs_flags);
3025 1.1 cgd ISP_WRITE(isp, INMAILBOX5, optr);
3026 1.1 cgd continue;
3027 1.1 cgd }
3028 1.38 mjacob xs = isp_find_xs(isp, sp->req_handle);
3029 1.1 cgd if (xs == NULL) {
3030 1.39.2.2 bouyer MEMZERO(sp, sizeof (isphdr_t));
3031 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3032 1.39.2.2 bouyer "cannot find handle 0x%x in xflist",
3033 1.39.2.2 bouyer sp->req_handle);
3034 1.1 cgd ISP_WRITE(isp, INMAILBOX5, optr);
3035 1.1 cgd continue;
3036 1.1 cgd }
3037 1.38 mjacob isp_destroy_handle(isp, sp->req_handle);
3038 1.1 cgd if (sp->req_status_flags & RQSTF_BUS_RESET) {
3039 1.36 mjacob isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3040 1.1 cgd }
3041 1.1 cgd if (buddaboom) {
3042 1.23 mjacob XS_SETERR(xs, HBA_BOTCH);
3043 1.1 cgd }
3044 1.39.2.2 bouyer
3045 1.39.2.2 bouyer if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3046 1.31 mjacob /*
3047 1.39.2.2 bouyer * Fibre Channel F/W doesn't say we got status
3048 1.39.2.2 bouyer * if there's Sense Data instead. I guess they
3049 1.39.2.2 bouyer * think it goes w/o saying.
3050 1.31 mjacob */
3051 1.39.2.2 bouyer sp->req_state_flags |= RQSF_GOT_STATUS;
3052 1.39.2.2 bouyer }
3053 1.39.2.2 bouyer if (sp->req_state_flags & RQSF_GOT_STATUS) {
3054 1.39.2.2 bouyer *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3055 1.1 cgd }
3056 1.39.2.1 thorpej
3057 1.39.2.2 bouyer switch (sp->req_header.rqs_entry_type) {
3058 1.39.2.2 bouyer case RQSTYPE_RESPONSE:
3059 1.39.2.2 bouyer XS_SET_STATE_STAT(isp, xs, sp);
3060 1.39.2.2 bouyer isp_parse_status(isp, sp, xs);
3061 1.39.2.2 bouyer if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3062 1.39.2.2 bouyer (*XS_STSP(xs) == SCSI_BUSY)) {
3063 1.39.2.1 thorpej XS_SETERR(xs, HBA_TGTBSY);
3064 1.39.2.1 thorpej }
3065 1.39.2.2 bouyer if (IS_SCSI(isp)) {
3066 1.39.2.2 bouyer XS_RESID(xs) = sp->req_resid;
3067 1.39.2.2 bouyer if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3068 1.39.2.2 bouyer (*XS_STSP(xs) == SCSI_CHECK) &&
3069 1.39.2.2 bouyer (sp->req_state_flags & RQSF_GOT_SENSE)) {
3070 1.39.2.2 bouyer XS_SAVE_SENSE(xs, sp);
3071 1.39.2.2 bouyer }
3072 1.39.2.2 bouyer /*
3073 1.39.2.2 bouyer * A new synchronous rate was negotiated for
3074 1.39.2.2 bouyer * this target. Mark state such that we'll go
3075 1.39.2.2 bouyer * look up that which has changed later.
3076 1.39.2.2 bouyer */
3077 1.39.2.2 bouyer if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3078 1.39.2.2 bouyer int t = XS_TGT(xs);
3079 1.39.2.2 bouyer sdparam *sdp = isp->isp_param;
3080 1.39.2.2 bouyer sdp += XS_CHANNEL(xs);
3081 1.39.2.2 bouyer sdp->isp_devparam[t].dev_refresh = 1;
3082 1.39.2.2 bouyer isp->isp_update |=
3083 1.39.2.2 bouyer (1 << XS_CHANNEL(xs));
3084 1.39.2.2 bouyer }
3085 1.39.2.2 bouyer } else {
3086 1.39.2.2 bouyer if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3087 1.39.2.2 bouyer XS_RESID(xs) = 0;
3088 1.39.2.2 bouyer } else if (sp->req_scsi_status & RQCS_RESID) {
3089 1.39.2.2 bouyer XS_RESID(xs) = sp->req_resid;
3090 1.39.2.2 bouyer } else {
3091 1.39.2.2 bouyer XS_RESID(xs) = 0;
3092 1.39.2.2 bouyer }
3093 1.39.2.2 bouyer if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3094 1.39.2.2 bouyer (*XS_STSP(xs) == SCSI_CHECK) &&
3095 1.39.2.2 bouyer (sp->req_scsi_status & RQCS_SV)) {
3096 1.39.2.2 bouyer XS_SAVE_SENSE(xs, sp);
3097 1.39.2.6 bouyer /* solely for the benefit of debug */
3098 1.39.2.6 bouyer sp->req_state_flags |= RQSF_GOT_SENSE;
3099 1.39.2.2 bouyer }
3100 1.25 mjacob }
3101 1.39.2.6 bouyer isp_prt(isp, ISP_LOGDEBUG2,
3102 1.39.2.6 bouyer "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3103 1.39.2.6 bouyer (long) sp->req_resid);
3104 1.39.2.2 bouyer break;
3105 1.39.2.2 bouyer case RQSTYPE_REQUEST:
3106 1.36 mjacob if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3107 1.36 mjacob /*
3108 1.39.2.2 bouyer * Force Queue Full status.
3109 1.36 mjacob */
3110 1.39.2.2 bouyer *XS_STSP(xs) = SCSI_QFULL;
3111 1.39.2.2 bouyer XS_SETERR(xs, HBA_NOERROR);
3112 1.36 mjacob } else if (XS_NOERR(xs)) {
3113 1.36 mjacob XS_SETERR(xs, HBA_BOTCH);
3114 1.36 mjacob }
3115 1.39.2.2 bouyer XS_RESID(xs) = XS_XFRLEN(xs);
3116 1.39.2.2 bouyer break;
3117 1.39.2.2 bouyer default:
3118 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3119 1.39.2.6 bouyer "unhandled response queue type 0x%x",
3120 1.39.2.2 bouyer sp->req_header.rqs_entry_type);
3121 1.30 mjacob if (XS_NOERR(xs)) {
3122 1.23 mjacob XS_SETERR(xs, HBA_BOTCH);
3123 1.30 mjacob }
3124 1.39.2.2 bouyer break;
3125 1.1 cgd }
3126 1.39.2.2 bouyer
3127 1.39.2.2 bouyer /*
3128 1.39.2.2 bouyer * Free any dma resources. As a side effect, this may
3129 1.39.2.2 bouyer * also do any cache flushing necessary for data coherence. */
3130 1.23 mjacob if (XS_XFRLEN(xs)) {
3131 1.38 mjacob ISP_DMAFREE(isp, xs, sp->req_handle);
3132 1.1 cgd }
3133 1.39.2.2 bouyer
3134 1.39.2.2 bouyer if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
3135 1.39.2.6 bouyer ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
3136 1.39.2.6 bouyer (*XS_STSP(xs) != SCSI_GOOD)))) {
3137 1.39.2.2 bouyer char skey;
3138 1.10 mjacob if (sp->req_state_flags & RQSF_GOT_SENSE) {
3139 1.39.2.2 bouyer skey = XS_SNSKEY(xs) & 0xf;
3140 1.39.2.2 bouyer if (skey < 10)
3141 1.39.2.2 bouyer skey += '0';
3142 1.39.2.2 bouyer else
3143 1.39.2.6 bouyer skey += 'a' - 10;
3144 1.39.2.2 bouyer } else if (*XS_STSP(xs) == SCSI_CHECK) {
3145 1.39.2.2 bouyer skey = '?';
3146 1.39.2.2 bouyer } else {
3147 1.39.2.2 bouyer skey = '.';
3148 1.1 cgd }
3149 1.39.2.2 bouyer isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
3150 1.39.2.2 bouyer XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
3151 1.39.2.2 bouyer *XS_STSP(xs), skey, XS_ERR(xs));
3152 1.1 cgd }
3153 1.23 mjacob
3154 1.28 mjacob if (isp->isp_nactive > 0)
3155 1.28 mjacob isp->isp_nactive--;
3156 1.25 mjacob complist[ndone++] = xs; /* defer completion call until later */
3157 1.39.2.2 bouyer MEMZERO(sp, sizeof (isphdr_t));
3158 1.39.2.2 bouyer if (ndone == MAX_REQUESTQ_COMPLETIONS) {
3159 1.39.2.2 bouyer break;
3160 1.39.2.2 bouyer }
3161 1.1 cgd }
3162 1.32 mjacob
3163 1.27 mjacob /*
3164 1.32 mjacob * If we looked at any commands, then it's valid to find out
3165 1.32 mjacob * what the outpointer is. It also is a trigger to update the
3166 1.32 mjacob * ISP's notion of what we've seen so far.
3167 1.27 mjacob */
3168 1.33 mjacob if (nlooked) {
3169 1.32 mjacob ISP_WRITE(isp, INMAILBOX5, optr);
3170 1.34 mjacob isp->isp_reqodx = ISP_READ(isp, OUTMAILBOX4);
3171 1.27 mjacob }
3172 1.39.2.2 bouyer
3173 1.1 cgd isp->isp_residx = optr;
3174 1.25 mjacob for (i = 0; i < ndone; i++) {
3175 1.25 mjacob xs = complist[i];
3176 1.25 mjacob if (xs) {
3177 1.39.2.2 bouyer isp_done(xs);
3178 1.25 mjacob }
3179 1.25 mjacob }
3180 1.1 cgd return (1);
3181 1.1 cgd }
3182 1.1 cgd
3183 1.1 cgd /*
3184 1.1 cgd * Support routines.
3185 1.1 cgd */
3186 1.1 cgd
3187 1.25 mjacob static int
3188 1.25 mjacob isp_parse_async(isp, mbox)
3189 1.25 mjacob struct ispsoftc *isp;
3190 1.28 mjacob int mbox;
3191 1.25 mjacob {
3192 1.39.2.2 bouyer int bus;
3193 1.31 mjacob u_int32_t fast_post_handle = 0;
3194 1.31 mjacob
3195 1.39.2.2 bouyer if (IS_DUALBUS(isp)) {
3196 1.39.2.2 bouyer bus = ISP_READ(isp, OUTMAILBOX6);
3197 1.39.2.2 bouyer } else {
3198 1.39.2.2 bouyer bus = 0;
3199 1.39.2.2 bouyer }
3200 1.39.2.2 bouyer
3201 1.25 mjacob switch (mbox) {
3202 1.25 mjacob case ASYNC_BUS_RESET:
3203 1.39.2.2 bouyer isp->isp_sendmarker |= (1 << bus);
3204 1.29 mjacob #ifdef ISP_TARGET_MODE
3205 1.39.2.2 bouyer isp_target_async(isp, bus, mbox);
3206 1.29 mjacob #endif
3207 1.39.2.2 bouyer isp_async(isp, ISPASYNC_BUS_RESET, &bus);
3208 1.25 mjacob break;
3209 1.25 mjacob case ASYNC_SYSTEM_ERROR:
3210 1.25 mjacob mbox = ISP_READ(isp, OUTMAILBOX1);
3211 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3212 1.39.2.6 bouyer "Internal Firmware Error @ RISC Addr 0x%x", mbox);
3213 1.39.2.6 bouyer ISP_DUMPREGS(isp, "Firmware Error");
3214 1.39.2.2 bouyer isp_reinit(isp);
3215 1.39.2.3 bouyer #ifdef ISP_TARGET_MODE
3216 1.39.2.6 bouyer isp_target_async(isp, bus, ASYNC_SYSTEM_ERROR);
3217 1.39.2.3 bouyer #endif
3218 1.25 mjacob /* no point continuing after this */
3219 1.31 mjacob return (-1);
3220 1.25 mjacob
3221 1.25 mjacob case ASYNC_RQS_XFER_ERR:
3222 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
3223 1.25 mjacob break;
3224 1.25 mjacob
3225 1.25 mjacob case ASYNC_RSP_XFER_ERR:
3226 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
3227 1.25 mjacob break;
3228 1.25 mjacob
3229 1.25 mjacob case ASYNC_QWAKEUP:
3230 1.39.2.2 bouyer /*
3231 1.39.2.2 bouyer * We've just been notified that the Queue has woken up.
3232 1.39.2.2 bouyer * We don't need to be chatty about this- just unlatch things
3233 1.39.2.2 bouyer * and move on.
3234 1.39.2.2 bouyer */
3235 1.25 mjacob mbox = ISP_READ(isp, OUTMAILBOX4);
3236 1.25 mjacob break;
3237 1.25 mjacob
3238 1.25 mjacob case ASYNC_TIMEOUT_RESET:
3239 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3240 1.39.2.2 bouyer "timeout initiated SCSI bus reset of bus %d\n", bus);
3241 1.39.2.2 bouyer isp->isp_sendmarker |= (1 << bus);
3242 1.29 mjacob #ifdef ISP_TARGET_MODE
3243 1.39.2.2 bouyer isp_target_async(isp, bus, mbox);
3244 1.29 mjacob #endif
3245 1.25 mjacob break;
3246 1.25 mjacob
3247 1.28 mjacob case ASYNC_DEVICE_RESET:
3248 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
3249 1.39.2.2 bouyer isp->isp_sendmarker |= (1 << bus);
3250 1.29 mjacob #ifdef ISP_TARGET_MODE
3251 1.39.2.2 bouyer isp_target_async(isp, bus, mbox);
3252 1.29 mjacob #endif
3253 1.25 mjacob break;
3254 1.25 mjacob
3255 1.25 mjacob case ASYNC_EXTMSG_UNDERRUN:
3256 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN, "extended message underrun");
3257 1.25 mjacob break;
3258 1.25 mjacob
3259 1.25 mjacob case ASYNC_SCAM_INT:
3260 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
3261 1.25 mjacob break;
3262 1.25 mjacob
3263 1.25 mjacob case ASYNC_HUNG_SCSI:
3264 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3265 1.39.2.2 bouyer "stalled SCSI Bus after DATA Overrun");
3266 1.25 mjacob /* XXX: Need to issue SCSI reset at this point */
3267 1.25 mjacob break;
3268 1.25 mjacob
3269 1.25 mjacob case ASYNC_KILLED_BUS:
3270 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
3271 1.25 mjacob break;
3272 1.25 mjacob
3273 1.25 mjacob case ASYNC_BUS_TRANSIT:
3274 1.34 mjacob mbox = ISP_READ(isp, OUTMAILBOX2);
3275 1.34 mjacob switch (mbox & 0x1c00) {
3276 1.34 mjacob case SXP_PINS_LVD_MODE:
3277 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
3278 1.39.2.2 bouyer SDPARAM(isp)->isp_diffmode = 0;
3279 1.39.2.2 bouyer SDPARAM(isp)->isp_ultramode = 0;
3280 1.39.2.2 bouyer SDPARAM(isp)->isp_lvdmode = 1;
3281 1.34 mjacob break;
3282 1.34 mjacob case SXP_PINS_HVD_MODE:
3283 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO,
3284 1.39.2.2 bouyer "Transition to Differential mode");
3285 1.39.2.2 bouyer SDPARAM(isp)->isp_diffmode = 1;
3286 1.39.2.2 bouyer SDPARAM(isp)->isp_ultramode = 0;
3287 1.39.2.2 bouyer SDPARAM(isp)->isp_lvdmode = 0;
3288 1.34 mjacob break;
3289 1.34 mjacob case SXP_PINS_SE_MODE:
3290 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO,
3291 1.39.2.2 bouyer "Transition to Single Ended mode");
3292 1.39.2.2 bouyer SDPARAM(isp)->isp_diffmode = 0;
3293 1.39.2.2 bouyer SDPARAM(isp)->isp_ultramode = 1;
3294 1.39.2.2 bouyer SDPARAM(isp)->isp_lvdmode = 0;
3295 1.34 mjacob break;
3296 1.34 mjacob default:
3297 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3298 1.39.2.2 bouyer "Transition to Unknown Mode 0x%x", mbox);
3299 1.34 mjacob break;
3300 1.34 mjacob }
3301 1.34 mjacob /*
3302 1.34 mjacob * XXX: Set up to renegotiate again!
3303 1.34 mjacob */
3304 1.36 mjacob /* Can only be for a 1080... */
3305 1.39.2.2 bouyer isp->isp_sendmarker |= (1 << bus);
3306 1.25 mjacob break;
3307 1.25 mjacob
3308 1.25 mjacob case ASYNC_CMD_CMPLT:
3309 1.31 mjacob fast_post_handle = (ISP_READ(isp, OUTMAILBOX2) << 16) |
3310 1.31 mjacob ISP_READ(isp, OUTMAILBOX1);
3311 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG3, "fast post completion of %u",
3312 1.39.2.2 bouyer fast_post_handle);
3313 1.25 mjacob break;
3314 1.25 mjacob
3315 1.25 mjacob case ASYNC_CTIO_DONE:
3316 1.39.2.2 bouyer #ifdef ISP_TARGET_MODE
3317 1.39.2.2 bouyer /*
3318 1.39.2.2 bouyer * Bus gets overloaded with the handle. Dual bus
3319 1.39.2.2 bouyer * cards don't put bus# into the handle.
3320 1.39.2.2 bouyer */
3321 1.39.2.2 bouyer bus = (ISP_READ(isp, OUTMAILBOX2) << 16) |
3322 1.39.2.2 bouyer ISP_READ(isp, OUTMAILBOX1);
3323 1.39.2.2 bouyer isp_target_async(isp, bus, mbox);
3324 1.39.2.2 bouyer #else
3325 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
3326 1.39.2.2 bouyer #endif
3327 1.25 mjacob break;
3328 1.25 mjacob
3329 1.25 mjacob case ASYNC_LIP_OCCURRED:
3330 1.39.2.2 bouyer FCPARAM(isp)->isp_lipseq =
3331 1.39 mjacob ISP_READ(isp, OUTMAILBOX1);
3332 1.39.2.2 bouyer FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
3333 1.39.2.2 bouyer FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
3334 1.33 mjacob isp->isp_sendmarker = 1;
3335 1.35 mjacob isp_mark_getpdb_all(isp);
3336 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "LIP occurred");
3337 1.39.2.2 bouyer #ifdef ISP_TARGET_MODE
3338 1.39.2.2 bouyer isp_target_async(isp, bus, mbox);
3339 1.39.2.2 bouyer #endif
3340 1.25 mjacob break;
3341 1.25 mjacob
3342 1.25 mjacob case ASYNC_LOOP_UP:
3343 1.37 mjacob isp->isp_sendmarker = 1;
3344 1.39.2.2 bouyer FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
3345 1.39.2.2 bouyer FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
3346 1.35 mjacob isp_mark_getpdb_all(isp);
3347 1.32 mjacob isp_async(isp, ISPASYNC_LOOP_UP, NULL);
3348 1.39.2.2 bouyer #ifdef ISP_TARGET_MODE
3349 1.39.2.2 bouyer isp_target_async(isp, bus, mbox);
3350 1.39.2.2 bouyer #endif
3351 1.25 mjacob break;
3352 1.25 mjacob
3353 1.25 mjacob case ASYNC_LOOP_DOWN:
3354 1.37 mjacob isp->isp_sendmarker = 1;
3355 1.39.2.2 bouyer FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
3356 1.39.2.2 bouyer FCPARAM(isp)->isp_loopstate = LOOP_NIL;
3357 1.35 mjacob isp_mark_getpdb_all(isp);
3358 1.32 mjacob isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
3359 1.39.2.2 bouyer #ifdef ISP_TARGET_MODE
3360 1.39.2.2 bouyer isp_target_async(isp, bus, mbox);
3361 1.39.2.2 bouyer #endif
3362 1.25 mjacob break;
3363 1.25 mjacob
3364 1.25 mjacob case ASYNC_LOOP_RESET:
3365 1.37 mjacob isp->isp_sendmarker = 1;
3366 1.39.2.2 bouyer FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
3367 1.39.2.2 bouyer FCPARAM(isp)->isp_loopstate = LOOP_NIL;
3368 1.35 mjacob isp_mark_getpdb_all(isp);
3369 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "Loop RESET");
3370 1.29 mjacob #ifdef ISP_TARGET_MODE
3371 1.39.2.2 bouyer isp_target_async(isp, bus, mbox);
3372 1.29 mjacob #endif
3373 1.25 mjacob break;
3374 1.25 mjacob
3375 1.25 mjacob case ASYNC_PDB_CHANGED:
3376 1.33 mjacob isp->isp_sendmarker = 1;
3377 1.39.2.2 bouyer FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
3378 1.33 mjacob isp_mark_getpdb_all(isp);
3379 1.39.2.6 bouyer isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
3380 1.25 mjacob break;
3381 1.25 mjacob
3382 1.25 mjacob case ASYNC_CHANGE_NOTIFY:
3383 1.38 mjacob /*
3384 1.38 mjacob * Not correct, but it will force us to rescan the loop.
3385 1.38 mjacob */
3386 1.39.2.2 bouyer FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
3387 1.39.2.5 bouyer isp_mark_getpdb_all(isp);
3388 1.39.2.6 bouyer isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
3389 1.25 mjacob break;
3390 1.25 mjacob
3391 1.39.2.2 bouyer case ASYNC_PTPMODE:
3392 1.39.2.2 bouyer if (FCPARAM(isp)->isp_onfabric)
3393 1.39.2.2 bouyer FCPARAM(isp)->isp_topo = TOPO_F_PORT;
3394 1.39.2.6 bouyer else
3395 1.39.2.6 bouyer FCPARAM(isp)->isp_topo = TOPO_N_PORT;
3396 1.39.2.2 bouyer isp_mark_getpdb_all(isp);
3397 1.39.2.2 bouyer isp->isp_sendmarker = 1;
3398 1.39.2.2 bouyer FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
3399 1.39.2.2 bouyer FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
3400 1.39.2.6 bouyer isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
3401 1.39.2.2 bouyer #ifdef ISP_TARGET_MODE
3402 1.39.2.2 bouyer isp_target_async(isp, bus, mbox);
3403 1.39.2.2 bouyer #endif
3404 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
3405 1.39.2.2 bouyer break;
3406 1.39.2.2 bouyer
3407 1.39.2.2 bouyer case ASYNC_CONNMODE:
3408 1.39.2.2 bouyer mbox = ISP_READ(isp, OUTMAILBOX1);
3409 1.39.2.6 bouyer isp_mark_getpdb_all(isp);
3410 1.39.2.2 bouyer switch (mbox) {
3411 1.39.2.2 bouyer case ISP_CONN_LOOP:
3412 1.39.2.6 bouyer isp_prt(isp, ISP_LOGINFO,
3413 1.39.2.6 bouyer "Point-to-Point -> Loop mode");
3414 1.39.2.2 bouyer break;
3415 1.39.2.2 bouyer case ISP_CONN_PTP:
3416 1.39.2.6 bouyer isp_prt(isp, ISP_LOGINFO,
3417 1.39.2.6 bouyer "Loop -> Point-to-Point mode");
3418 1.39.2.2 bouyer break;
3419 1.39.2.2 bouyer case ISP_CONN_BADLIP:
3420 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3421 1.39.2.6 bouyer "Point-to-Point -> Loop mode (BAD LIP)");
3422 1.39.2.2 bouyer break;
3423 1.39.2.2 bouyer case ISP_CONN_FATAL:
3424 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
3425 1.39.2.2 bouyer isp_reinit(isp);
3426 1.39.2.3 bouyer #ifdef ISP_TARGET_MODE
3427 1.39.2.3 bouyer isp_target_async(isp, bus, ASYNC_SYSTEM_ERROR);
3428 1.39.2.3 bouyer #endif
3429 1.39.2.2 bouyer /* no point continuing after this */
3430 1.39.2.2 bouyer return (-1);
3431 1.39.2.2 bouyer case ISP_CONN_LOOPBACK:
3432 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3433 1.39.2.2 bouyer "Looped Back in Point-to-Point mode");
3434 1.39.2.6 bouyer break;
3435 1.39.2.6 bouyer default:
3436 1.39.2.6 bouyer isp_prt(isp, ISP_LOGWARN,
3437 1.39.2.6 bouyer "Unknown connection mode (0x%x)", mbox);
3438 1.39.2.6 bouyer break;
3439 1.39.2.2 bouyer }
3440 1.39.2.6 bouyer isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
3441 1.39.2.6 bouyer isp->isp_sendmarker = 1;
3442 1.39.2.6 bouyer FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
3443 1.39.2.6 bouyer FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
3444 1.39.2.2 bouyer break;
3445 1.39.2.2 bouyer
3446 1.25 mjacob default:
3447 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
3448 1.25 mjacob break;
3449 1.25 mjacob }
3450 1.31 mjacob return (fast_post_handle);
3451 1.25 mjacob }
3452 1.25 mjacob
3453 1.39.2.2 bouyer /*
3454 1.39.2.2 bouyer * Handle other response entries. A pointer to the request queue output
3455 1.39.2.2 bouyer * index is here in case we want to eat several entries at once, although
3456 1.39.2.2 bouyer * this is not used currently.
3457 1.39.2.2 bouyer */
3458 1.39.2.2 bouyer
3459 1.25 mjacob static int
3460 1.25 mjacob isp_handle_other_response(isp, sp, optrp)
3461 1.25 mjacob struct ispsoftc *isp;
3462 1.25 mjacob ispstatusreq_t *sp;
3463 1.39.2.2 bouyer u_int16_t *optrp;
3464 1.25 mjacob {
3465 1.25 mjacob switch (sp->req_header.rqs_entry_type) {
3466 1.39.2.2 bouyer case RQSTYPE_STATUS_CONT:
3467 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
3468 1.39.2.2 bouyer return (0);
3469 1.38 mjacob case RQSTYPE_ATIO:
3470 1.39.2.2 bouyer case RQSTYPE_CTIO:
3471 1.29 mjacob case RQSTYPE_ENABLE_LUN:
3472 1.29 mjacob case RQSTYPE_MODIFY_LUN:
3473 1.38 mjacob case RQSTYPE_NOTIFY:
3474 1.38 mjacob case RQSTYPE_NOTIFY_ACK:
3475 1.38 mjacob case RQSTYPE_CTIO1:
3476 1.29 mjacob case RQSTYPE_ATIO2:
3477 1.38 mjacob case RQSTYPE_CTIO2:
3478 1.38 mjacob case RQSTYPE_CTIO3:
3479 1.38 mjacob #ifdef ISP_TARGET_MODE
3480 1.39.2.2 bouyer return (isp_target_notify(isp, sp, optrp));
3481 1.29 mjacob #else
3482 1.39.2.2 bouyer optrp = optrp;
3483 1.38 mjacob /* FALLTHROUGH */
3484 1.29 mjacob #endif
3485 1.38 mjacob case RQSTYPE_REQUEST:
3486 1.25 mjacob default:
3487 1.39.2.6 bouyer if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, sp)) {
3488 1.39.2.6 bouyer return (0);
3489 1.39.2.6 bouyer }
3490 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
3491 1.39.2.2 bouyer sp->req_header.rqs_entry_type);
3492 1.29 mjacob return (-1);
3493 1.29 mjacob }
3494 1.29 mjacob }
3495 1.29 mjacob
3496 1.23 mjacob static void
3497 1.10 mjacob isp_parse_status(isp, sp, xs)
3498 1.1 cgd struct ispsoftc *isp;
3499 1.1 cgd ispstatusreq_t *sp;
3500 1.39.2.2 bouyer XS_T *xs;
3501 1.1 cgd {
3502 1.39.2.2 bouyer switch (sp->req_completion_status & 0xff) {
3503 1.1 cgd case RQCS_COMPLETE:
3504 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3505 1.39.2.2 bouyer XS_SETERR(xs, HBA_NOERROR);
3506 1.39.2.2 bouyer }
3507 1.23 mjacob return;
3508 1.10 mjacob
3509 1.1 cgd case RQCS_INCOMPLETE:
3510 1.1 cgd if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
3511 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1,
3512 1.39.2.2 bouyer "Selection Timeout for %d.%d.%d",
3513 1.39.2.3 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3514 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3515 1.39.2.2 bouyer XS_SETERR(xs, HBA_SELTIMEOUT);
3516 1.39.2.2 bouyer }
3517 1.23 mjacob return;
3518 1.1 cgd }
3519 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3520 1.39.2.2 bouyer "command incomplete for %d.%d.%d, state 0x%x",
3521 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
3522 1.25 mjacob sp->req_state_flags);
3523 1.25 mjacob break;
3524 1.25 mjacob
3525 1.25 mjacob case RQCS_DMA_ERROR:
3526 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
3527 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3528 1.1 cgd break;
3529 1.15 mjacob
3530 1.15 mjacob case RQCS_TRANSPORT_ERROR:
3531 1.39.2.2 bouyer {
3532 1.39.2.2 bouyer char buf[172];
3533 1.39.2.2 bouyer buf[0] = 0;
3534 1.39.2.2 bouyer STRNCAT(buf, "states=>", sizeof buf);
3535 1.39.2.2 bouyer if (sp->req_state_flags & RQSF_GOT_BUS) {
3536 1.39.2.2 bouyer STRNCAT(buf, " GOT_BUS", sizeof buf);
3537 1.39.2.2 bouyer }
3538 1.39.2.2 bouyer if (sp->req_state_flags & RQSF_GOT_TARGET) {
3539 1.39.2.2 bouyer STRNCAT(buf, " GOT_TGT", sizeof buf);
3540 1.39.2.2 bouyer }
3541 1.39.2.2 bouyer if (sp->req_state_flags & RQSF_SENT_CDB) {
3542 1.39.2.2 bouyer STRNCAT(buf, " SENT_CDB", sizeof buf);
3543 1.39.2.2 bouyer }
3544 1.39.2.2 bouyer if (sp->req_state_flags & RQSF_XFRD_DATA) {
3545 1.39.2.2 bouyer STRNCAT(buf, " XFRD_DATA", sizeof buf);
3546 1.39.2.2 bouyer }
3547 1.39.2.2 bouyer if (sp->req_state_flags & RQSF_GOT_STATUS) {
3548 1.39.2.2 bouyer STRNCAT(buf, " GOT_STS", sizeof buf);
3549 1.39.2.2 bouyer }
3550 1.39.2.2 bouyer if (sp->req_state_flags & RQSF_GOT_SENSE) {
3551 1.39.2.2 bouyer STRNCAT(buf, " GOT_SNS", sizeof buf);
3552 1.39.2.2 bouyer }
3553 1.39.2.2 bouyer if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
3554 1.39.2.2 bouyer STRNCAT(buf, " XFR_CMPLT", sizeof buf);
3555 1.39.2.2 bouyer }
3556 1.39.2.2 bouyer STRNCAT(buf, "\nstatus=>", sizeof buf);
3557 1.39.2.2 bouyer if (sp->req_status_flags & RQSTF_DISCONNECT) {
3558 1.39.2.2 bouyer STRNCAT(buf, " Disconnect", sizeof buf);
3559 1.39.2.2 bouyer }
3560 1.39.2.2 bouyer if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
3561 1.39.2.2 bouyer STRNCAT(buf, " Sync_xfr", sizeof buf);
3562 1.39.2.2 bouyer }
3563 1.39.2.2 bouyer if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
3564 1.39.2.2 bouyer STRNCAT(buf, " Parity", sizeof buf);
3565 1.39.2.2 bouyer }
3566 1.39.2.2 bouyer if (sp->req_status_flags & RQSTF_BUS_RESET) {
3567 1.39.2.2 bouyer STRNCAT(buf, " Bus_Reset", sizeof buf);
3568 1.39.2.2 bouyer }
3569 1.39.2.2 bouyer if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
3570 1.39.2.2 bouyer STRNCAT(buf, " Device_Reset", sizeof buf);
3571 1.39.2.2 bouyer }
3572 1.39.2.2 bouyer if (sp->req_status_flags & RQSTF_ABORTED) {
3573 1.39.2.2 bouyer STRNCAT(buf, " Aborted", sizeof buf);
3574 1.39.2.2 bouyer }
3575 1.39.2.2 bouyer if (sp->req_status_flags & RQSTF_TIMEOUT) {
3576 1.39.2.2 bouyer STRNCAT(buf, " Timeout", sizeof buf);
3577 1.39.2.2 bouyer }
3578 1.39.2.2 bouyer if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3579 1.39.2.2 bouyer STRNCAT(buf, " Negotiation", sizeof buf);
3580 1.39.2.2 bouyer }
3581 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "%s", buf);
3582 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
3583 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
3584 1.15 mjacob break;
3585 1.39.2.2 bouyer }
3586 1.25 mjacob case RQCS_RESET_OCCURRED:
3587 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3588 1.39.2.2 bouyer "bus reset destroyed command for %d.%d.%d",
3589 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3590 1.39.2.2 bouyer isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3591 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3592 1.39.2.2 bouyer XS_SETERR(xs, HBA_BUSRESET);
3593 1.39.2.2 bouyer }
3594 1.25 mjacob return;
3595 1.25 mjacob
3596 1.25 mjacob case RQCS_ABORTED:
3597 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
3598 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3599 1.39.2.2 bouyer isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3600 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3601 1.39.2.2 bouyer XS_SETERR(xs, HBA_ABORTED);
3602 1.39.2.2 bouyer }
3603 1.25 mjacob return;
3604 1.25 mjacob
3605 1.25 mjacob case RQCS_TIMEOUT:
3606 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
3607 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3608 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3609 1.39.2.2 bouyer XS_SETERR(xs, HBA_CMDTIMEOUT);
3610 1.39.2.2 bouyer }
3611 1.25 mjacob return;
3612 1.25 mjacob
3613 1.10 mjacob case RQCS_DATA_OVERRUN:
3614 1.39.2.2 bouyer XS_RESID(xs) = sp->req_resid;
3615 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
3616 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3617 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3618 1.39.2.2 bouyer XS_SETERR(xs, HBA_DATAOVR);
3619 1.10 mjacob }
3620 1.23 mjacob return;
3621 1.10 mjacob
3622 1.25 mjacob case RQCS_COMMAND_OVERRUN:
3623 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3624 1.39.2.2 bouyer "command overrun for command on %d.%d.%d",
3625 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3626 1.25 mjacob break;
3627 1.25 mjacob
3628 1.25 mjacob case RQCS_STATUS_OVERRUN:
3629 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3630 1.39.2.2 bouyer "status overrun for command on %d.%d.%d",
3631 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3632 1.25 mjacob break;
3633 1.25 mjacob
3634 1.25 mjacob case RQCS_BAD_MESSAGE:
3635 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3636 1.39.2.2 bouyer "msg not COMMAND COMPLETE after status %d.%d.%d",
3637 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3638 1.25 mjacob break;
3639 1.25 mjacob
3640 1.25 mjacob case RQCS_NO_MESSAGE_OUT:
3641 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3642 1.39.2.2 bouyer "No MESSAGE OUT phase after selection on %d.%d.%d",
3643 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3644 1.25 mjacob break;
3645 1.25 mjacob
3646 1.25 mjacob case RQCS_EXT_ID_FAILED:
3647 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
3648 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3649 1.25 mjacob break;
3650 1.25 mjacob
3651 1.25 mjacob case RQCS_IDE_MSG_FAILED:
3652 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3653 1.39.2.2 bouyer "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
3654 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3655 1.25 mjacob break;
3656 1.25 mjacob
3657 1.25 mjacob case RQCS_ABORT_MSG_FAILED:
3658 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
3659 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3660 1.25 mjacob break;
3661 1.25 mjacob
3662 1.25 mjacob case RQCS_REJECT_MSG_FAILED:
3663 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
3664 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3665 1.25 mjacob break;
3666 1.25 mjacob
3667 1.25 mjacob case RQCS_NOP_MSG_FAILED:
3668 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
3669 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3670 1.25 mjacob break;
3671 1.25 mjacob
3672 1.25 mjacob case RQCS_PARITY_ERROR_MSG_FAILED:
3673 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3674 1.39.2.2 bouyer "MESSAGE PARITY ERROR rejected by %d.%d.%d",
3675 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3676 1.25 mjacob break;
3677 1.25 mjacob
3678 1.25 mjacob case RQCS_DEVICE_RESET_MSG_FAILED:
3679 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3680 1.39.2.2 bouyer "BUS DEVICE RESET rejected by %d.%d.%d",
3681 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3682 1.25 mjacob break;
3683 1.25 mjacob
3684 1.25 mjacob case RQCS_ID_MSG_FAILED:
3685 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
3686 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3687 1.25 mjacob break;
3688 1.25 mjacob
3689 1.25 mjacob case RQCS_UNEXP_BUS_FREE:
3690 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
3691 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3692 1.25 mjacob break;
3693 1.25 mjacob
3694 1.1 cgd case RQCS_DATA_UNDERRUN:
3695 1.39.2.2 bouyer XS_RESID(xs) = sp->req_resid;
3696 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3697 1.39.2.2 bouyer XS_SETERR(xs, HBA_NOERROR);
3698 1.10 mjacob }
3699 1.23 mjacob return;
3700 1.10 mjacob
3701 1.25 mjacob case RQCS_XACT_ERR1:
3702 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
3703 1.39.2.2 bouyer XS_TGT(xs), XS_LUN(xs));
3704 1.25 mjacob break;
3705 1.25 mjacob
3706 1.25 mjacob case RQCS_XACT_ERR2:
3707 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, xact2,
3708 1.39.2.2 bouyer XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
3709 1.25 mjacob break;
3710 1.25 mjacob
3711 1.25 mjacob case RQCS_XACT_ERR3:
3712 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, xact3, XS_TGT(xs),
3713 1.39.2.2 bouyer XS_LUN(xs), XS_CHANNEL(xs));
3714 1.25 mjacob break;
3715 1.25 mjacob
3716 1.25 mjacob case RQCS_BAD_ENTRY:
3717 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
3718 1.25 mjacob break;
3719 1.25 mjacob
3720 1.25 mjacob case RQCS_QUEUE_FULL:
3721 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1,
3722 1.39.2.2 bouyer "internal queues full for %d.%d.%d status 0x%x", XS_TGT(xs),
3723 1.39.2.2 bouyer XS_LUN(xs), XS_CHANNEL(xs), *XS_STSP(xs));
3724 1.39.2.2 bouyer /*
3725 1.39.2.2 bouyer * If QFULL or some other status byte is set, then this
3726 1.39.2.2 bouyer * isn't an error, per se.
3727 1.39.2.2 bouyer */
3728 1.39.2.2 bouyer if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
3729 1.39.2.2 bouyer XS_SETERR(xs, HBA_NOERROR);
3730 1.39.2.2 bouyer return;
3731 1.39.2.2 bouyer }
3732 1.39.2.2 bouyer break;
3733 1.25 mjacob
3734 1.25 mjacob case RQCS_PHASE_SKIPPED:
3735 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, pskip,
3736 1.39.2.2 bouyer XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
3737 1.25 mjacob break;
3738 1.25 mjacob
3739 1.25 mjacob case RQCS_ARQS_FAILED:
3740 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3741 1.39.2.2 bouyer "Auto Request Sense failed for %d.%d.%d",
3742 1.39.2.2 bouyer XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3743 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3744 1.39.2.2 bouyer XS_SETERR(xs, HBA_ARQFAIL);
3745 1.39.2.2 bouyer }
3746 1.23 mjacob return;
3747 1.10 mjacob
3748 1.25 mjacob case RQCS_WIDE_FAILED:
3749 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3750 1.39.2.2 bouyer "Wide Negotiation failed for %d.%d.%d",
3751 1.39.2.2 bouyer XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
3752 1.36 mjacob if (IS_SCSI(isp)) {
3753 1.25 mjacob sdparam *sdp = isp->isp_param;
3754 1.36 mjacob sdp += XS_CHANNEL(xs);
3755 1.31 mjacob sdp->isp_devparam[XS_TGT(xs)].dev_flags &= ~DPARM_WIDE;
3756 1.25 mjacob sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
3757 1.39.2.2 bouyer isp->isp_update |= (1 << XS_CHANNEL(xs));
3758 1.39.2.2 bouyer }
3759 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3760 1.39.2.2 bouyer XS_SETERR(xs, HBA_NOERROR);
3761 1.25 mjacob }
3762 1.23 mjacob return;
3763 1.10 mjacob
3764 1.25 mjacob case RQCS_SYNCXFER_FAILED:
3765 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3766 1.39.2.2 bouyer "SDTR Message failed for target %d.%d.%d",
3767 1.39.2.2 bouyer XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
3768 1.36 mjacob if (IS_SCSI(isp)) {
3769 1.25 mjacob sdparam *sdp = isp->isp_param;
3770 1.36 mjacob sdp += XS_CHANNEL(xs);
3771 1.31 mjacob sdp->isp_devparam[XS_TGT(xs)].dev_flags &= ~DPARM_SYNC;
3772 1.25 mjacob sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
3773 1.39.2.2 bouyer isp->isp_update |= (1 << XS_CHANNEL(xs));
3774 1.25 mjacob }
3775 1.25 mjacob break;
3776 1.25 mjacob
3777 1.25 mjacob case RQCS_LVD_BUSERR:
3778 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR,
3779 1.39.2.2 bouyer "Bad LVD condition while talking to %d.%d.%d",
3780 1.39.2.2 bouyer XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
3781 1.25 mjacob break;
3782 1.10 mjacob
3783 1.10 mjacob case RQCS_PORT_UNAVAILABLE:
3784 1.10 mjacob /*
3785 1.10 mjacob * No such port on the loop. Moral equivalent of SELTIMEO
3786 1.10 mjacob */
3787 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO,
3788 1.39.2.2 bouyer "Port Unavailable for target %d", XS_TGT(xs));
3789 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3790 1.39.2.2 bouyer XS_SETERR(xs, HBA_SELTIMEOUT);
3791 1.39.2.2 bouyer }
3792 1.23 mjacob return;
3793 1.10 mjacob
3794 1.10 mjacob case RQCS_PORT_LOGGED_OUT:
3795 1.27 mjacob /*
3796 1.27 mjacob * It was there (maybe)- treat as a selection timeout.
3797 1.27 mjacob */
3798 1.39.2.2 bouyer isp_prt(isp, ISP_LOGINFO,
3799 1.39.2.2 bouyer "port logout for target %d", XS_TGT(xs));
3800 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3801 1.39.2.2 bouyer XS_SETERR(xs, HBA_SELTIMEOUT);
3802 1.39.2.2 bouyer }
3803 1.27 mjacob return;
3804 1.10 mjacob
3805 1.10 mjacob case RQCS_PORT_CHANGED:
3806 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3807 1.39.2.2 bouyer "port changed for target %d", XS_TGT(xs));
3808 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3809 1.39.2.2 bouyer XS_SETERR(xs, HBA_SELTIMEOUT);
3810 1.39.2.2 bouyer }
3811 1.39.2.2 bouyer return;
3812 1.10 mjacob
3813 1.10 mjacob case RQCS_PORT_BUSY:
3814 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3815 1.39.2.2 bouyer "port busy for target %d", XS_TGT(xs));
3816 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3817 1.39.2.2 bouyer XS_SETERR(xs, HBA_TGTBSY);
3818 1.39.2.2 bouyer }
3819 1.23 mjacob return;
3820 1.10 mjacob
3821 1.1 cgd default:
3822 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
3823 1.34 mjacob sp->req_completion_status);
3824 1.1 cgd break;
3825 1.1 cgd }
3826 1.39.2.2 bouyer if (XS_NOERR(xs)) {
3827 1.39.2.2 bouyer XS_SETERR(xs, HBA_BOTCH);
3828 1.39.2.2 bouyer }
3829 1.1 cgd }
3830 1.1 cgd
3831 1.33 mjacob static void
3832 1.33 mjacob isp_fastpost_complete(isp, fph)
3833 1.33 mjacob struct ispsoftc *isp;
3834 1.38 mjacob u_int32_t fph;
3835 1.33 mjacob {
3836 1.39.2.2 bouyer XS_T *xs;
3837 1.33 mjacob
3838 1.38 mjacob if (fph < 1) {
3839 1.33 mjacob return;
3840 1.38 mjacob }
3841 1.38 mjacob xs = isp_find_xs(isp, fph);
3842 1.33 mjacob if (xs == NULL) {
3843 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN,
3844 1.39.2.2 bouyer "Command for fast post handle 0x%x not found", fph);
3845 1.33 mjacob return;
3846 1.33 mjacob }
3847 1.38 mjacob isp_destroy_handle(isp, fph);
3848 1.38 mjacob
3849 1.33 mjacob /*
3850 1.33 mjacob * Since we don't have a result queue entry item,
3851 1.33 mjacob * we must believe that SCSI status is zero and
3852 1.33 mjacob * that all data transferred.
3853 1.33 mjacob */
3854 1.39.2.2 bouyer XS_SET_STATE_STAT(isp, xs, NULL);
3855 1.33 mjacob XS_RESID(xs) = 0;
3856 1.39.2.2 bouyer *XS_STSP(xs) = SCSI_GOOD;
3857 1.33 mjacob if (XS_XFRLEN(xs)) {
3858 1.38 mjacob ISP_DMAFREE(isp, xs, fph);
3859 1.33 mjacob }
3860 1.38 mjacob if (isp->isp_nactive)
3861 1.38 mjacob isp->isp_nactive--;
3862 1.39.2.2 bouyer isp_done(xs);
3863 1.33 mjacob }
3864 1.33 mjacob
3865 1.39.2.2 bouyer #define HIBYT(x) ((x) >> 0x8)
3866 1.39.2.2 bouyer #define LOBYT(x) ((x) & 0xff)
3867 1.39.2.2 bouyer #define ISPOPMAP(a, b) (((a) << 8) | (b))
3868 1.39.2.2 bouyer static u_int16_t mbpscsi[] = {
3869 1.39.2.2 bouyer ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
3870 1.39.2.2 bouyer ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
3871 1.39.2.2 bouyer ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
3872 1.39.2.2 bouyer ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
3873 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
3874 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
3875 1.39.2.2 bouyer ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
3876 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
3877 1.39.2.2 bouyer ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
3878 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x09: */
3879 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x0a: */
3880 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x0b: */
3881 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x0c: */
3882 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x0d: */
3883 1.39.2.2 bouyer ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
3884 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x0f: */
3885 1.39.2.2 bouyer ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
3886 1.39.2.2 bouyer ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
3887 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
3888 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
3889 1.39.2.2 bouyer ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
3890 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
3891 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
3892 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
3893 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
3894 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
3895 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
3896 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
3897 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
3898 1.39.2.2 bouyer ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
3899 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x1e: */
3900 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
3901 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
3902 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
3903 1.39.2.2 bouyer ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
3904 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
3905 1.39.2.2 bouyer ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
3906 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
3907 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
3908 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
3909 1.39.2.2 bouyer ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
3910 1.39.2.2 bouyer ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
3911 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
3912 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2b: */
3913 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2c: */
3914 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2d: */
3915 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2e: */
3916 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2f: */
3917 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
3918 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
3919 1.39.2.2 bouyer ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
3920 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
3921 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
3922 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
3923 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
3924 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
3925 1.39.2.2 bouyer ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
3926 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
3927 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
3928 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3b: */
3929 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3c: */
3930 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3d: */
3931 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3e: */
3932 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3f: */
3933 1.39.2.2 bouyer ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
3934 1.39.2.2 bouyer ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
3935 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
3936 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x43: */
3937 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x44: */
3938 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
3939 1.39.2.2 bouyer ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
3940 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x47: */
3941 1.39.2.2 bouyer ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
3942 1.39.2.2 bouyer ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
3943 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
3944 1.39.2.2 bouyer ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
3945 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4c: */
3946 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4d: */
3947 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4e: */
3948 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4f: */
3949 1.39.2.2 bouyer ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
3950 1.39.2.2 bouyer ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
3951 1.39.2.2 bouyer ISPOPMAP(0xdf, 0xdf), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
3952 1.39.2.2 bouyer ISPOPMAP(0xff, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
3953 1.39.2.2 bouyer ISPOPMAP(0xcf, 0xff), /* 0x54: EXECUTE IOCB A64 */
3954 1.39.2.2 bouyer ISPOPMAP(0x03, 0x01), /* 0x55: ENABLE TARGET MODE */
3955 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x56: */
3956 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x57: */
3957 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x58: */
3958 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x59: */
3959 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
3960 1.39.2.2 bouyer ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
3961 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
3962 1.39.2.2 bouyer ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
3963 1.1 cgd };
3964 1.39.2.2 bouyer
3965 1.39.2.2 bouyer #ifndef ISP_STRIPEED
3966 1.39.2.2 bouyer static char *scsi_mbcmd_names[] = {
3967 1.39.2.2 bouyer "NO-OP",
3968 1.39.2.2 bouyer "LOAD RAM",
3969 1.39.2.2 bouyer "EXEC FIRMWARE",
3970 1.39.2.2 bouyer "DUMP RAM",
3971 1.39.2.2 bouyer "WRITE RAM WORD",
3972 1.39.2.2 bouyer "READ RAM WORD",
3973 1.39.2.2 bouyer "MAILBOX REG TEST",
3974 1.39.2.2 bouyer "VERIFY CHECKSUM",
3975 1.39.2.2 bouyer "ABOUT FIRMWARE",
3976 1.39.2.2 bouyer NULL,
3977 1.39.2.2 bouyer NULL,
3978 1.39.2.2 bouyer NULL,
3979 1.39.2.2 bouyer NULL,
3980 1.39.2.2 bouyer NULL,
3981 1.39.2.2 bouyer "CHECK FIRMWARE",
3982 1.39.2.2 bouyer NULL,
3983 1.39.2.2 bouyer "INIT REQUEST QUEUE",
3984 1.39.2.2 bouyer "INIT RESULT QUEUE",
3985 1.39.2.2 bouyer "EXECUTE IOCB",
3986 1.39.2.2 bouyer "WAKE UP",
3987 1.39.2.2 bouyer "STOP FIRMWARE",
3988 1.39.2.2 bouyer "ABORT",
3989 1.39.2.2 bouyer "ABORT DEVICE",
3990 1.39.2.2 bouyer "ABORT TARGET",
3991 1.39.2.2 bouyer "BUS RESET",
3992 1.39.2.2 bouyer "STOP QUEUE",
3993 1.39.2.2 bouyer "START QUEUE",
3994 1.39.2.2 bouyer "SINGLE STEP QUEUE",
3995 1.39.2.2 bouyer "ABORT QUEUE",
3996 1.39.2.2 bouyer "GET DEV QUEUE STATUS",
3997 1.39.2.2 bouyer NULL,
3998 1.39.2.2 bouyer "GET FIRMWARE STATUS",
3999 1.39.2.2 bouyer "GET INIT SCSI ID",
4000 1.39.2.2 bouyer "GET SELECT TIMEOUT",
4001 1.39.2.2 bouyer "GET RETRY COUNT",
4002 1.39.2.2 bouyer "GET TAG AGE LIMIT",
4003 1.39.2.2 bouyer "GET CLOCK RATE",
4004 1.39.2.2 bouyer "GET ACT NEG STATE",
4005 1.39.2.2 bouyer "GET ASYNC DATA SETUP TIME",
4006 1.39.2.2 bouyer "GET PCI PARAMS",
4007 1.39.2.2 bouyer "GET TARGET PARAMS",
4008 1.39.2.2 bouyer "GET DEV QUEUE PARAMS",
4009 1.39.2.2 bouyer "GET RESET DELAY PARAMS",
4010 1.39.2.2 bouyer NULL,
4011 1.39.2.2 bouyer NULL,
4012 1.39.2.2 bouyer NULL,
4013 1.39.2.2 bouyer NULL,
4014 1.39.2.2 bouyer NULL,
4015 1.39.2.2 bouyer "SET INIT SCSI ID",
4016 1.39.2.2 bouyer "SET SELECT TIMEOUT",
4017 1.39.2.2 bouyer "SET RETRY COUNT",
4018 1.39.2.2 bouyer "SET TAG AGE LIMIT",
4019 1.39.2.2 bouyer "SET CLOCK RATE",
4020 1.39.2.2 bouyer "SET ACT NEG STATE",
4021 1.39.2.2 bouyer "SET ASYNC DATA SETUP TIME",
4022 1.39.2.2 bouyer "SET PCI CONTROL PARAMS",
4023 1.39.2.2 bouyer "SET TARGET PARAMS",
4024 1.39.2.2 bouyer "SET DEV QUEUE PARAMS",
4025 1.39.2.2 bouyer "SET RESET DELAY PARAMS",
4026 1.39.2.2 bouyer NULL,
4027 1.39.2.2 bouyer NULL,
4028 1.39.2.2 bouyer NULL,
4029 1.39.2.2 bouyer NULL,
4030 1.39.2.2 bouyer NULL,
4031 1.39.2.2 bouyer "RETURN BIOS BLOCK ADDR",
4032 1.39.2.2 bouyer "WRITE FOUR RAM WORDS",
4033 1.39.2.2 bouyer "EXEC BIOS IOCB",
4034 1.39.2.2 bouyer NULL,
4035 1.39.2.2 bouyer NULL,
4036 1.39.2.2 bouyer "SET SYSTEM PARAMETER",
4037 1.39.2.2 bouyer "GET SYSTEM PARAMETER",
4038 1.39.2.2 bouyer NULL,
4039 1.39.2.2 bouyer "GET SCAM CONFIGURATION",
4040 1.39.2.2 bouyer "SET SCAM CONFIGURATION",
4041 1.39.2.2 bouyer "SET FIRMWARE FEATURES",
4042 1.39.2.2 bouyer "GET FIRMWARE FEATURES",
4043 1.39.2.2 bouyer NULL,
4044 1.39.2.2 bouyer NULL,
4045 1.39.2.2 bouyer NULL,
4046 1.39.2.2 bouyer NULL,
4047 1.39.2.2 bouyer "LOAD RAM A64",
4048 1.39.2.2 bouyer "DUMP RAM A64",
4049 1.39.2.2 bouyer "INITIALIZE REQUEST QUEUE A64",
4050 1.39.2.2 bouyer "INITIALIZE RESPONSE QUEUE A64",
4051 1.39.2.2 bouyer "EXECUTE IOCB A64",
4052 1.39.2.2 bouyer "ENABLE TARGET MODE",
4053 1.39.2.2 bouyer NULL,
4054 1.39.2.2 bouyer NULL,
4055 1.39.2.2 bouyer NULL,
4056 1.39.2.2 bouyer NULL,
4057 1.39.2.2 bouyer "SET DATA OVERRUN RECOVERY MODE",
4058 1.39.2.2 bouyer "GET DATA OVERRUN RECOVERY MODE",
4059 1.39.2.2 bouyer "SET HOST DATA",
4060 1.39.2.2 bouyer "GET NOST DATA",
4061 1.39.2.2 bouyer };
4062 1.39.2.2 bouyer #endif
4063 1.39.2.2 bouyer
4064 1.39.2.2 bouyer static u_int16_t mbpfc[] = {
4065 1.39.2.2 bouyer ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4066 1.39.2.2 bouyer ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4067 1.39.2.2 bouyer ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4068 1.39.2.6 bouyer ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
4069 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4070 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4071 1.39.2.2 bouyer ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
4072 1.39.2.2 bouyer ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
4073 1.39.2.2 bouyer ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4074 1.39.2.2 bouyer ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
4075 1.39.2.2 bouyer ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
4076 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x0b: */
4077 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x0c: */
4078 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x0d: */
4079 1.39.2.2 bouyer ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4080 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x0f: */
4081 1.39.2.2 bouyer ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
4082 1.39.2.2 bouyer ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
4083 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
4084 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4085 1.39.2.2 bouyer ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
4086 1.39.2.2 bouyer ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
4087 1.39.2.2 bouyer ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
4088 1.39.2.2 bouyer ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
4089 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
4090 1.39.2.2 bouyer ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
4091 1.39.2.2 bouyer ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
4092 1.39.2.2 bouyer ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4093 1.39.2.2 bouyer ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
4094 1.39.2.2 bouyer ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4095 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x1e: */
4096 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4097 1.39.2.2 bouyer ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
4098 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x21: */
4099 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
4100 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x23: */
4101 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x24: */
4102 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x25: */
4103 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x26: */
4104 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x27: */
4105 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x1), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
4106 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
4107 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2a: */
4108 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2b: */
4109 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2c: */
4110 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2d: */
4111 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2e: */
4112 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x2f: */
4113 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x30: */
4114 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x31: */
4115 1.39.2.2 bouyer ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
4116 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x33: */
4117 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x34: */
4118 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x35: */
4119 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x36: */
4120 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x37: */
4121 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
4122 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
4123 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3a: */
4124 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3b: */
4125 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3c: */
4126 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3d: */
4127 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3e: */
4128 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x3f: */
4129 1.39.2.2 bouyer ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
4130 1.39.2.2 bouyer ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
4131 1.39.2.2 bouyer ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
4132 1.39.2.2 bouyer ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
4133 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x44: */
4134 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x45: */
4135 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x46: */
4136 1.39.2.2 bouyer ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
4137 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x48: */
4138 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x49: */
4139 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4a: */
4140 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4b: */
4141 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4c: */
4142 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4d: */
4143 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4e: */
4144 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x4f: */
4145 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x50: */
4146 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x51: */
4147 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x52: */
4148 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x53: */
4149 1.39.2.2 bouyer ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
4150 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x55: */
4151 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x56: */
4152 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x57: */
4153 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x58: */
4154 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x59: */
4155 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x5a: */
4156 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x5b: */
4157 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x5c: */
4158 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x5d: */
4159 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x5e: */
4160 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x5f: */
4161 1.39.2.2 bouyer ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
4162 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x61: */
4163 1.39.2.2 bouyer ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
4164 1.39.2.2 bouyer ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
4165 1.39.2.2 bouyer ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
4166 1.39.2.2 bouyer ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
4167 1.39.2.2 bouyer ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
4168 1.39.2.2 bouyer ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
4169 1.39.2.2 bouyer ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
4170 1.39.2.2 bouyer ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
4171 1.39.2.2 bouyer ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
4172 1.39.2.2 bouyer ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
4173 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
4174 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x6d: */
4175 1.39.2.2 bouyer ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
4176 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
4177 1.39.2.2 bouyer ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
4178 1.39.2.2 bouyer ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
4179 1.39.2.2 bouyer ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
4180 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x73: */
4181 1.39.2.2 bouyer ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
4182 1.39.2.2 bouyer ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
4183 1.39.2.2 bouyer ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
4184 1.39.2.2 bouyer ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
4185 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x78: */
4186 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x79: */
4187 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x7a: */
4188 1.39.2.2 bouyer ISPOPMAP(0x00, 0x00), /* 0x7b: */
4189 1.39.2.2 bouyer ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
4190 1.39.2.2 bouyer ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
4191 1.39.2.2 bouyer ISPOPMAP(0x07, 0x01) /* 0x7e: Lun RESET */
4192 1.39.2.2 bouyer };
4193 1.39.2.2 bouyer
4194 1.39.2.2 bouyer #ifndef ISP_STRIPPED
4195 1.39.2.2 bouyer static char *fc_mbcmd_names[] = {
4196 1.39.2.2 bouyer "NO-OP",
4197 1.39.2.2 bouyer "LOAD RAM",
4198 1.39.2.2 bouyer "EXEC FIRMWARE",
4199 1.39.2.2 bouyer "DUMP RAM",
4200 1.39.2.2 bouyer "WRITE RAM WORD",
4201 1.39.2.2 bouyer "READ RAM WORD",
4202 1.39.2.2 bouyer "MAILBOX REG TEST",
4203 1.39.2.2 bouyer "VERIFY CHECKSUM",
4204 1.39.2.2 bouyer "ABOUT FIRMWARE",
4205 1.39.2.2 bouyer "LOAD RAM",
4206 1.39.2.2 bouyer "DUMP RAM",
4207 1.39.2.2 bouyer NULL,
4208 1.39.2.2 bouyer NULL,
4209 1.39.2.2 bouyer NULL,
4210 1.39.2.2 bouyer "CHECK FIRMWARE",
4211 1.39.2.2 bouyer NULL,
4212 1.39.2.2 bouyer "INIT REQUEST QUEUE",
4213 1.39.2.2 bouyer "INIT RESULT QUEUE",
4214 1.39.2.2 bouyer "EXECUTE IOCB",
4215 1.39.2.2 bouyer "WAKE UP",
4216 1.39.2.2 bouyer "STOP FIRMWARE",
4217 1.39.2.2 bouyer "ABORT",
4218 1.39.2.2 bouyer "ABORT DEVICE",
4219 1.39.2.2 bouyer "ABORT TARGET",
4220 1.39.2.2 bouyer "BUS RESET",
4221 1.39.2.2 bouyer "STOP QUEUE",
4222 1.39.2.2 bouyer "START QUEUE",
4223 1.39.2.2 bouyer "SINGLE STEP QUEUE",
4224 1.39.2.2 bouyer "ABORT QUEUE",
4225 1.39.2.2 bouyer "GET DEV QUEUE STATUS",
4226 1.39.2.2 bouyer NULL,
4227 1.39.2.2 bouyer "GET FIRMWARE STATUS",
4228 1.39.2.2 bouyer "GET LOOP ID",
4229 1.39.2.2 bouyer NULL,
4230 1.39.2.2 bouyer "GET RETRY COUNT",
4231 1.39.2.2 bouyer NULL,
4232 1.39.2.2 bouyer NULL,
4233 1.39.2.2 bouyer NULL,
4234 1.39.2.2 bouyer NULL,
4235 1.39.2.2 bouyer NULL,
4236 1.39.2.2 bouyer "GET FIRMWARE OPTIONS",
4237 1.39.2.2 bouyer "GET PORT QUEUE PARAMS",
4238 1.39.2.2 bouyer NULL,
4239 1.39.2.2 bouyer NULL,
4240 1.39.2.2 bouyer NULL,
4241 1.39.2.2 bouyer NULL,
4242 1.39.2.2 bouyer NULL,
4243 1.39.2.2 bouyer NULL,
4244 1.39.2.2 bouyer NULL,
4245 1.39.2.2 bouyer NULL,
4246 1.39.2.2 bouyer "SET RETRY COUNT",
4247 1.39.2.2 bouyer NULL,
4248 1.39.2.2 bouyer NULL,
4249 1.39.2.2 bouyer NULL,
4250 1.39.2.2 bouyer NULL,
4251 1.39.2.2 bouyer NULL,
4252 1.39.2.2 bouyer "SET FIRMWARE OPTIONS",
4253 1.39.2.2 bouyer "SET PORT QUEUE PARAMS",
4254 1.39.2.2 bouyer NULL,
4255 1.39.2.2 bouyer NULL,
4256 1.39.2.2 bouyer NULL,
4257 1.39.2.2 bouyer NULL,
4258 1.39.2.2 bouyer NULL,
4259 1.39.2.2 bouyer NULL,
4260 1.39.2.2 bouyer "LOOP PORT BYPASS",
4261 1.39.2.2 bouyer "LOOP PORT ENABLE",
4262 1.39.2.2 bouyer "GET RESOURCE COUNTS",
4263 1.39.2.2 bouyer "REQUEST NON PARTICIPATING MODE",
4264 1.39.2.2 bouyer NULL,
4265 1.39.2.2 bouyer NULL,
4266 1.39.2.2 bouyer NULL,
4267 1.39.2.2 bouyer "GET PORT DATABASE,, ENHANCED",
4268 1.39.2.2 bouyer NULL,
4269 1.39.2.2 bouyer NULL,
4270 1.39.2.2 bouyer NULL,
4271 1.39.2.2 bouyer NULL,
4272 1.39.2.2 bouyer NULL,
4273 1.39.2.2 bouyer NULL,
4274 1.39.2.2 bouyer NULL,
4275 1.39.2.2 bouyer NULL,
4276 1.39.2.2 bouyer NULL,
4277 1.39.2.2 bouyer NULL,
4278 1.39.2.2 bouyer NULL,
4279 1.39.2.2 bouyer NULL,
4280 1.39.2.2 bouyer "EXECUTE IOCB A64",
4281 1.39.2.2 bouyer NULL,
4282 1.39.2.2 bouyer NULL,
4283 1.39.2.2 bouyer NULL,
4284 1.39.2.2 bouyer NULL,
4285 1.39.2.2 bouyer NULL,
4286 1.39.2.2 bouyer NULL,
4287 1.39.2.2 bouyer NULL,
4288 1.39.2.2 bouyer NULL,
4289 1.39.2.2 bouyer NULL,
4290 1.39.2.2 bouyer NULL,
4291 1.39.2.2 bouyer NULL,
4292 1.39.2.2 bouyer "INIT FIRMWARE",
4293 1.39.2.2 bouyer NULL,
4294 1.39.2.2 bouyer "INIT LIP",
4295 1.39.2.2 bouyer "GET FC-AL POSITION MAP",
4296 1.39.2.2 bouyer "GET PORT DATABASE",
4297 1.39.2.2 bouyer "CLEAR ACA",
4298 1.39.2.2 bouyer "TARGET RESET",
4299 1.39.2.2 bouyer "CLEAR TASK SET",
4300 1.39.2.2 bouyer "ABORT TASK SET",
4301 1.39.2.2 bouyer "GET FW STATE",
4302 1.39.2.2 bouyer "GET PORT NAME",
4303 1.39.2.2 bouyer "GET LINK STATUS",
4304 1.39.2.2 bouyer "INIT LIP RESET",
4305 1.39.2.2 bouyer NULL,
4306 1.39.2.2 bouyer "SEND SNS",
4307 1.39.2.2 bouyer "FABRIC LOGIN",
4308 1.39.2.2 bouyer "SEND CHANGE REQUEST",
4309 1.39.2.2 bouyer "FABRIC LOGOUT",
4310 1.39.2.2 bouyer "INIT LIP LOGIN",
4311 1.39.2.2 bouyer NULL,
4312 1.39.2.2 bouyer "LOGIN LOOP PORT",
4313 1.39.2.2 bouyer "GET PORT/NODE NAME LIST",
4314 1.39.2.2 bouyer "SET VENDOR ID",
4315 1.39.2.2 bouyer "INITIALIZE IP MAILBOX",
4316 1.39.2.2 bouyer NULL,
4317 1.39.2.2 bouyer NULL,
4318 1.39.2.2 bouyer NULL,
4319 1.39.2.2 bouyer NULL,
4320 1.39.2.2 bouyer "Get ID List",
4321 1.39.2.2 bouyer "SEND LFA",
4322 1.39.2.2 bouyer "Lun RESET"
4323 1.39.2.2 bouyer };
4324 1.39.2.2 bouyer #endif
4325 1.1 cgd
4326 1.10 mjacob static void
4327 1.39.2.2 bouyer isp_mboxcmd(isp, mbp, logmask)
4328 1.1 cgd struct ispsoftc *isp;
4329 1.1 cgd mbreg_t *mbp;
4330 1.39.2.2 bouyer int logmask;
4331 1.1 cgd {
4332 1.39.2.2 bouyer char *cname, *xname, tname[16], mname[16];
4333 1.39.2.2 bouyer unsigned int lim, ibits, obits, box, opcode;
4334 1.39.2.2 bouyer u_int16_t *mcp;
4335 1.39.2.2 bouyer
4336 1.39.2.2 bouyer if (IS_FC(isp)) {
4337 1.39.2.2 bouyer mcp = mbpfc;
4338 1.39.2.2 bouyer lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
4339 1.39.2.2 bouyer } else {
4340 1.39.2.2 bouyer mcp = mbpscsi;
4341 1.39.2.2 bouyer lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
4342 1.1 cgd }
4343 1.1 cgd
4344 1.39.2.2 bouyer if ((opcode = mbp->param[0]) >= lim) {
4345 1.39.2.2 bouyer mbp->param[0] = MBOX_INVALID_COMMAND;
4346 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
4347 1.10 mjacob return;
4348 1.1 cgd }
4349 1.1 cgd
4350 1.39.2.2 bouyer ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
4351 1.39.2.2 bouyer obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
4352 1.10 mjacob
4353 1.39.2.2 bouyer if (ibits == 0 && obits == 0) {
4354 1.39.2.2 bouyer mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
4355 1.39.2.2 bouyer isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
4356 1.39.2.2 bouyer return;
4357 1.28 mjacob }
4358 1.24 mjacob
4359 1.33 mjacob /*
4360 1.39.2.2 bouyer * Get exclusive usage of mailbox registers.
4361 1.33 mjacob */
4362 1.39.2.2 bouyer MBOX_ACQUIRE(isp);
4363 1.33 mjacob
4364 1.39.2.2 bouyer for (box = 0; box < MAX_MAILBOX; box++) {
4365 1.39.2.2 bouyer if (ibits & (1 << box)) {
4366 1.39.2.2 bouyer ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
4367 1.34 mjacob }
4368 1.39.2.2 bouyer isp->isp_mboxtmp[box] = mbp->param[box] = 0;
4369 1.1 cgd }
4370 1.1 cgd
4371 1.39.2.6 bouyer isp->isp_lastmbxcmd = opcode;
4372 1.39.2.6 bouyer
4373 1.1 cgd /*
4374 1.39.2.2 bouyer * We assume that we can't overwrite a previous command.
4375 1.1 cgd */
4376 1.39.2.2 bouyer isp->isp_mboxbsy = obits;
4377 1.1 cgd
4378 1.1 cgd /*
4379 1.1 cgd * Set Host Interrupt condition so that RISC will pick up mailbox regs.
4380 1.1 cgd */
4381 1.1 cgd ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
4382 1.1 cgd
4383 1.33 mjacob /*
4384 1.39.2.2 bouyer * While we haven't finished the command, spin our wheels here.
4385 1.33 mjacob */
4386 1.39.2.2 bouyer MBOX_WAIT_COMPLETE(isp);
4387 1.1 cgd
4388 1.1 cgd /*
4389 1.39.2.2 bouyer * Copy back output registers.
4390 1.1 cgd */
4391 1.39.2.2 bouyer for (box = 0; box < MAX_MAILBOX; box++) {
4392 1.39.2.2 bouyer if (obits & (1 << box)) {
4393 1.39.2.2 bouyer mbp->param[box] = isp->isp_mboxtmp[box];
4394 1.36 mjacob }
4395 1.36 mjacob }
4396 1.36 mjacob
4397 1.39.2.2 bouyer MBOX_RELEASE(isp);
4398 1.1 cgd
4399 1.39.2.2 bouyer if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
4400 1.39.2.2 bouyer return;
4401 1.39.2.2 bouyer }
4402 1.39.2.2 bouyer #ifdef ISP_STRIPPED
4403 1.39.2.2 bouyer cname = NULL;
4404 1.39.2.2 bouyer #else
4405 1.39.2.2 bouyer cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
4406 1.39.2.2 bouyer #endif
4407 1.39.2.2 bouyer if (cname == NULL) {
4408 1.39.2.2 bouyer SNPRINTF(cname, sizeof tname, "opcode %x", opcode);
4409 1.39.2.2 bouyer }
4410 1.10 mjacob
4411 1.10 mjacob /*
4412 1.10 mjacob * Just to be chatty here...
4413 1.10 mjacob */
4414 1.39.2.2 bouyer xname = NULL;
4415 1.34 mjacob switch (mbp->param[0]) {
4416 1.10 mjacob case MBOX_COMMAND_COMPLETE:
4417 1.10 mjacob break;
4418 1.10 mjacob case MBOX_INVALID_COMMAND:
4419 1.39.2.2 bouyer if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
4420 1.39.2.2 bouyer xname = "INVALID COMMAND";
4421 1.10 mjacob break;
4422 1.10 mjacob case MBOX_HOST_INTERFACE_ERROR:
4423 1.39.2.2 bouyer if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
4424 1.39.2.2 bouyer xname = "HOST INTERFACE ERROR";
4425 1.10 mjacob break;
4426 1.10 mjacob case MBOX_TEST_FAILED:
4427 1.39.2.2 bouyer if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
4428 1.39.2.2 bouyer xname = "TEST FAILED";
4429 1.10 mjacob break;
4430 1.10 mjacob case MBOX_COMMAND_ERROR:
4431 1.39.2.2 bouyer if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
4432 1.39.2.2 bouyer xname = "COMMAND ERROR";
4433 1.10 mjacob break;
4434 1.10 mjacob case MBOX_COMMAND_PARAM_ERROR:
4435 1.39.2.2 bouyer if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
4436 1.39.2.2 bouyer xname = "COMMAND PARAMETER ERROR";
4437 1.10 mjacob break;
4438 1.39.2.2 bouyer case MBOX_LOOP_ID_USED:
4439 1.39.2.2 bouyer if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
4440 1.39.2.2 bouyer xname = "LOOP ID ALREADY IN USE";
4441 1.39.2.2 bouyer break;
4442 1.39.2.2 bouyer case MBOX_PORT_ID_USED:
4443 1.39.2.2 bouyer if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
4444 1.39.2.2 bouyer xname = "PORT ID ALREADY IN USE";
4445 1.39.2.2 bouyer break;
4446 1.39.2.2 bouyer case MBOX_ALL_IDS_USED:
4447 1.39.2.2 bouyer if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
4448 1.39.2.2 bouyer xname = "ALL LOOP IDS IN USE";
4449 1.37 mjacob break;
4450 1.39.2.2 bouyer case 0: /* special case */
4451 1.39.2.2 bouyer xname = "TIMEOUT";
4452 1.37 mjacob break;
4453 1.39.2.2 bouyer default:
4454 1.39.2.2 bouyer SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
4455 1.39.2.2 bouyer xname = mname;
4456 1.33 mjacob break;
4457 1.39.2.2 bouyer }
4458 1.39.2.2 bouyer if (xname)
4459 1.39.2.2 bouyer isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
4460 1.39.2.2 bouyer cname, xname);
4461 1.39.2.2 bouyer }
4462 1.10 mjacob
4463 1.10 mjacob static void
4464 1.25 mjacob isp_fw_state(isp)
4465 1.25 mjacob struct ispsoftc *isp;
4466 1.10 mjacob {
4467 1.38 mjacob if (IS_FC(isp)) {
4468 1.39.2.2 bouyer mbreg_t mbs;
4469 1.10 mjacob fcparam *fcp = isp->isp_param;
4470 1.39.2.2 bouyer
4471 1.10 mjacob mbs.param[0] = MBOX_GET_FW_STATE;
4472 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
4473 1.39.2.6 bouyer if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4474 1.39.2.2 bouyer fcp->isp_fwstate = mbs.param[1];
4475 1.39.2.6 bouyer }
4476 1.10 mjacob }
4477 1.10 mjacob }
4478 1.10 mjacob
4479 1.10 mjacob static void
4480 1.25 mjacob isp_update(isp)
4481 1.25 mjacob struct ispsoftc *isp;
4482 1.10 mjacob {
4483 1.39.2.2 bouyer int bus, upmask;
4484 1.36 mjacob
4485 1.39.2.2 bouyer for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
4486 1.39.2.2 bouyer if (upmask & (1 << bus)) {
4487 1.36 mjacob isp_update_bus(isp, bus);
4488 1.36 mjacob }
4489 1.39.2.2 bouyer upmask &= ~(1 << bus);
4490 1.36 mjacob }
4491 1.36 mjacob }
4492 1.36 mjacob
4493 1.36 mjacob static void
4494 1.36 mjacob isp_update_bus(isp, bus)
4495 1.36 mjacob struct ispsoftc *isp;
4496 1.36 mjacob int bus;
4497 1.36 mjacob {
4498 1.25 mjacob int tgt;
4499 1.10 mjacob mbreg_t mbs;
4500 1.10 mjacob sdparam *sdp;
4501 1.10 mjacob
4502 1.39.2.2 bouyer isp->isp_update &= ~(1 << bus);
4503 1.38 mjacob if (IS_FC(isp)) {
4504 1.39.2.2 bouyer /*
4505 1.39.2.2 bouyer * There are no 'per-bus' settings for Fibre Channel.
4506 1.39.2.2 bouyer */
4507 1.4 mjacob return;
4508 1.4 mjacob }
4509 1.25 mjacob sdp = isp->isp_param;
4510 1.36 mjacob sdp += bus;
4511 1.36 mjacob
4512 1.25 mjacob for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
4513 1.36 mjacob u_int16_t flags, period, offset;
4514 1.31 mjacob int get;
4515 1.31 mjacob
4516 1.25 mjacob if (sdp->isp_devparam[tgt].dev_enable == 0) {
4517 1.39.2.2 bouyer sdp->isp_devparam[tgt].dev_update = 0;
4518 1.39.2.2 bouyer sdp->isp_devparam[tgt].dev_refresh = 0;
4519 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1,
4520 1.39.2.2 bouyer "skipping target %d bus %d update", tgt, bus);
4521 1.25 mjacob continue;
4522 1.25 mjacob }
4523 1.34 mjacob /*
4524 1.34 mjacob * If the goal is to update the status of the device,
4525 1.34 mjacob * take what's in dev_flags and try and set the device
4526 1.34 mjacob * toward that. Otherwise, if we're just refreshing the
4527 1.34 mjacob * current device state, get the current parameters.
4528 1.34 mjacob */
4529 1.39.2.2 bouyer
4530 1.39.2.2 bouyer /*
4531 1.39.2.2 bouyer * Refresh overrides set
4532 1.39.2.2 bouyer */
4533 1.39.2.2 bouyer if (sdp->isp_devparam[tgt].dev_refresh) {
4534 1.39.2.2 bouyer mbs.param[0] = MBOX_GET_TARGET_PARAMS;
4535 1.39.2.2 bouyer sdp->isp_devparam[tgt].dev_refresh = 0;
4536 1.39.2.2 bouyer get = 1;
4537 1.39.2.2 bouyer } else if (sdp->isp_devparam[tgt].dev_update) {
4538 1.31 mjacob mbs.param[0] = MBOX_SET_TARGET_PARAMS;
4539 1.39.2.2 bouyer /*
4540 1.39.2.2 bouyer * Make sure dev_flags has "Renegotiate on Error"
4541 1.39.2.2 bouyer * on and "Freeze Queue on Error" off.
4542 1.39.2.2 bouyer */
4543 1.39.2.2 bouyer sdp->isp_devparam[tgt].dev_flags |= DPARM_RENEG;
4544 1.39.2.2 bouyer sdp->isp_devparam[tgt].dev_flags &= ~DPARM_QFRZ;
4545 1.39.2.2 bouyer
4546 1.31 mjacob mbs.param[2] = sdp->isp_devparam[tgt].dev_flags;
4547 1.39.2.2 bouyer
4548 1.36 mjacob /*
4549 1.39.2.2 bouyer * Insist that PARITY must be enabled
4550 1.39.2.2 bouyer * if SYNC or WIDE is enabled.
4551 1.36 mjacob */
4552 1.39.2.2 bouyer if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
4553 1.36 mjacob mbs.param[2] |= DPARM_PARITY;
4554 1.36 mjacob }
4555 1.39.2.2 bouyer
4556 1.39.2.2 bouyer if ((mbs.param[2] & DPARM_SYNC) == 0) {
4557 1.39.2.2 bouyer mbs.param[3] = 0;
4558 1.39.2.2 bouyer } else {
4559 1.39.2.2 bouyer mbs.param[3] =
4560 1.39.2.2 bouyer (sdp->isp_devparam[tgt].sync_offset << 8) |
4561 1.39.2.2 bouyer (sdp->isp_devparam[tgt].sync_period);
4562 1.39.2.2 bouyer }
4563 1.34 mjacob /*
4564 1.34 mjacob * A command completion later that has
4565 1.39.2.2 bouyer * RQSTF_NEGOTIATION set canl cause
4566 1.39.2.2 bouyer * the dev_refresh/announce cycle also.
4567 1.39.2.2 bouyer &
4568 1.34 mjacob *
4569 1.34 mjacob * Note: It is really important to update our current
4570 1.34 mjacob * flags with at least the state of TAG capabilities-
4571 1.34 mjacob * otherwise we might try and send a tagged command
4572 1.34 mjacob * when we have it all turned off. So change it here
4573 1.34 mjacob * to say that current already matches goal.
4574 1.34 mjacob */
4575 1.34 mjacob sdp->isp_devparam[tgt].cur_dflags &= ~DPARM_TQING;
4576 1.34 mjacob sdp->isp_devparam[tgt].cur_dflags |=
4577 1.34 mjacob (sdp->isp_devparam[tgt].dev_flags & DPARM_TQING);
4578 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG2,
4579 1.39.2.2 bouyer "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
4580 1.39.2.2 bouyer bus, tgt, mbs.param[2], mbs.param[3] >> 8,
4581 1.39.2.2 bouyer mbs.param[3] & 0xff);
4582 1.39.2.2 bouyer sdp->isp_devparam[tgt].dev_update = 0;
4583 1.36 mjacob sdp->isp_devparam[tgt].dev_refresh = 1;
4584 1.31 mjacob get = 0;
4585 1.31 mjacob } else {
4586 1.25 mjacob continue;
4587 1.25 mjacob }
4588 1.36 mjacob mbs.param[1] = (bus << 15) | (tgt << 8) ;
4589 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
4590 1.31 mjacob if (get == 0) {
4591 1.36 mjacob isp->isp_sendmarker |= (1 << bus);
4592 1.31 mjacob continue;
4593 1.31 mjacob }
4594 1.31 mjacob flags = mbs.param[2];
4595 1.31 mjacob period = mbs.param[3] & 0xff;
4596 1.31 mjacob offset = mbs.param[3] >> 8;
4597 1.31 mjacob sdp->isp_devparam[tgt].cur_dflags = flags;
4598 1.34 mjacob sdp->isp_devparam[tgt].cur_period = period;
4599 1.34 mjacob sdp->isp_devparam[tgt].cur_offset = offset;
4600 1.36 mjacob get = (bus << 16) | tgt;
4601 1.36 mjacob (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
4602 1.10 mjacob }
4603 1.39.2.2 bouyer
4604 1.39.2.2 bouyer for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
4605 1.39.2.2 bouyer if (sdp->isp_devparam[tgt].dev_update ||
4606 1.39.2.2 bouyer sdp->isp_devparam[tgt].dev_refresh) {
4607 1.39.2.2 bouyer isp->isp_update |= (1 << bus);
4608 1.39.2.2 bouyer break;
4609 1.39.2.2 bouyer }
4610 1.39.2.2 bouyer }
4611 1.25 mjacob }
4612 1.10 mjacob
4613 1.25 mjacob static void
4614 1.36 mjacob isp_setdfltparm(isp, channel)
4615 1.25 mjacob struct ispsoftc *isp;
4616 1.36 mjacob int channel;
4617 1.25 mjacob {
4618 1.34 mjacob int tgt;
4619 1.25 mjacob mbreg_t mbs;
4620 1.39.2.2 bouyer sdparam *sdp;
4621 1.36 mjacob
4622 1.36 mjacob if (IS_FC(isp)) {
4623 1.36 mjacob fcparam *fcp = (fcparam *) isp->isp_param;
4624 1.39.2.5 bouyer int nvfail;
4625 1.39.2.5 bouyer
4626 1.36 mjacob fcp += channel;
4627 1.36 mjacob if (fcp->isp_gotdparms) {
4628 1.36 mjacob return;
4629 1.36 mjacob }
4630 1.36 mjacob fcp->isp_gotdparms = 1;
4631 1.37 mjacob fcp->isp_maxfrmlen = ICB_DFLT_FRMLEN;
4632 1.37 mjacob fcp->isp_maxalloc = ICB_DFLT_ALLOC;
4633 1.39.2.2 bouyer fcp->isp_execthrottle = ISP_EXEC_THROTTLE;
4634 1.37 mjacob fcp->isp_retry_delay = ICB_DFLT_RDELAY;
4635 1.37 mjacob fcp->isp_retry_count = ICB_DFLT_RCOUNT;
4636 1.37 mjacob /* Platform specific.... */
4637 1.37 mjacob fcp->isp_loopid = DEFAULT_LOOPID(isp);
4638 1.39.2.2 bouyer fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
4639 1.39.2.2 bouyer fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
4640 1.39.2.2 bouyer fcp->isp_fwoptions = 0;
4641 1.39.2.2 bouyer fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
4642 1.39.2.2 bouyer fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
4643 1.39.2.2 bouyer fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
4644 1.39.2.2 bouyer #ifndef ISP_NO_FASTPOST_FC
4645 1.39.2.2 bouyer fcp->isp_fwoptions |= ICBOPT_FAST_POST;
4646 1.39.2.2 bouyer #endif
4647 1.39.2.2 bouyer if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
4648 1.39.2.2 bouyer fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
4649 1.39.2.2 bouyer
4650 1.39.2.2 bouyer /*
4651 1.39.2.2 bouyer * Make sure this is turned off now until we get
4652 1.39.2.2 bouyer * extended options from NVRAM
4653 1.39.2.2 bouyer */
4654 1.39.2.2 bouyer fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
4655 1.39.2.2 bouyer
4656 1.37 mjacob /*
4657 1.39.2.5 bouyer * Now try and read NVRAM unless told to not do so.
4658 1.39.2.5 bouyer * This will set fcparam's isp_nodewwn && isp_portwwn.
4659 1.37 mjacob */
4660 1.39.2.5 bouyer if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
4661 1.39.2.5 bouyer nvfail = isp_read_nvram(isp);
4662 1.39.2.5 bouyer if (nvfail)
4663 1.39.2.5 bouyer isp->isp_confopts |= ISP_CFG_NONVRAM;
4664 1.39.2.5 bouyer } else {
4665 1.39.2.5 bouyer nvfail = 1;
4666 1.39.2.5 bouyer }
4667 1.39.2.5 bouyer /*
4668 1.39.2.5 bouyer * Set node && port to override platform set defaults
4669 1.39.2.5 bouyer * unless the nvram read failed (or none was done),
4670 1.39.2.5 bouyer * or the platform code wants to use what had been
4671 1.39.2.5 bouyer * set in the defaults.
4672 1.39.2.5 bouyer */
4673 1.39.2.5 bouyer if (nvfail || (isp->isp_confopts & ISP_CFG_OWNWWN)) {
4674 1.39.2.5 bouyer isp_prt(isp, ISP_LOGCONFIG,
4675 1.39.2.5 bouyer "Using Node WWN 0x%08x%08x, Port WWN 0x%08x%08x",
4676 1.39.2.5 bouyer (u_int32_t) (DEFAULT_NODEWWN(isp) >> 32),
4677 1.39.2.5 bouyer (u_int32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff),
4678 1.39.2.5 bouyer (u_int32_t) (DEFAULT_PORTWWN(isp) >> 32),
4679 1.39.2.5 bouyer (u_int32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
4680 1.39.2.5 bouyer isp->isp_confopts |= ISP_CFG_OWNWWN;
4681 1.39.2.5 bouyer ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
4682 1.39.2.5 bouyer ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
4683 1.39.2.5 bouyer } else {
4684 1.39.2.5 bouyer /*
4685 1.39.2.5 bouyer * We always start out with values derived
4686 1.39.2.5 bouyer * from NVRAM or our platform default.
4687 1.39.2.5 bouyer */
4688 1.39.2.5 bouyer ISP_NODEWWN(isp) = fcp->isp_nodewwn;
4689 1.39.2.5 bouyer ISP_PORTWWN(isp) = fcp->isp_portwwn;
4690 1.36 mjacob }
4691 1.36 mjacob return;
4692 1.36 mjacob }
4693 1.36 mjacob
4694 1.39.2.2 bouyer sdp = (sdparam *) isp->isp_param;
4695 1.39.2.2 bouyer sdp += channel;
4696 1.10 mjacob
4697 1.10 mjacob /*
4698 1.25 mjacob * Been there, done that, got the T-shirt...
4699 1.10 mjacob */
4700 1.36 mjacob if (sdp->isp_gotdparms) {
4701 1.25 mjacob return;
4702 1.25 mjacob }
4703 1.36 mjacob sdp->isp_gotdparms = 1;
4704 1.25 mjacob
4705 1.34 mjacob /*
4706 1.34 mjacob * If we've not been told to avoid reading NVRAM, try and read it.
4707 1.34 mjacob * If we're successful reading it, we can return since NVRAM will
4708 1.34 mjacob * tell us the right thing to do. Otherwise, establish some reasonable
4709 1.34 mjacob * defaults.
4710 1.34 mjacob */
4711 1.34 mjacob if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
4712 1.34 mjacob if (isp_read_nvram(isp) == 0) {
4713 1.34 mjacob return;
4714 1.34 mjacob }
4715 1.25 mjacob }
4716 1.10 mjacob
4717 1.36 mjacob /*
4718 1.36 mjacob * Now try and see whether we have specific values for them.
4719 1.36 mjacob */
4720 1.39.2.2 bouyer if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
4721 1.39.2.2 bouyer mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
4722 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
4723 1.39.2.2 bouyer if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4724 1.39.2.2 bouyer sdp->isp_req_ack_active_neg = 1;
4725 1.39.2.2 bouyer sdp->isp_data_line_active_neg = 1;
4726 1.39.2.2 bouyer } else {
4727 1.39.2.2 bouyer sdp->isp_req_ack_active_neg =
4728 1.39.2.2 bouyer (mbs.param[1+channel] >> 4) & 0x1;
4729 1.39.2.2 bouyer sdp->isp_data_line_active_neg =
4730 1.39.2.2 bouyer (mbs.param[1+channel] >> 5) & 0x1;
4731 1.36 mjacob }
4732 1.10 mjacob } else {
4733 1.39.2.2 bouyer sdp->isp_req_ack_active_neg = 1;
4734 1.39.2.2 bouyer sdp->isp_data_line_active_neg = 1;
4735 1.10 mjacob }
4736 1.32 mjacob
4737 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1,
4738 1.39.2.2 bouyer "defaulting bus %d REQ/ACK Active Negation is %d",
4739 1.39.2.2 bouyer channel, sdp->isp_req_ack_active_neg);
4740 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1,
4741 1.39.2.2 bouyer "defaulting bus %d DATA Active Negation is %d",
4742 1.39.2.2 bouyer channel, sdp->isp_data_line_active_neg);
4743 1.39.2.2 bouyer
4744 1.34 mjacob /*
4745 1.34 mjacob * The trick here is to establish a default for the default (honk!)
4746 1.34 mjacob * state (dev_flags). Then try and get the current status from
4747 1.34 mjacob * the card to fill in the current state. We don't, in fact, set
4748 1.34 mjacob * the default to the SAFE default state- that's not the goal state.
4749 1.34 mjacob */
4750 1.34 mjacob for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
4751 1.34 mjacob sdp->isp_devparam[tgt].cur_offset = 0;
4752 1.34 mjacob sdp->isp_devparam[tgt].cur_period = 0;
4753 1.34 mjacob sdp->isp_devparam[tgt].dev_flags = DPARM_DEFAULT;
4754 1.34 mjacob sdp->isp_devparam[tgt].cur_dflags = 0;
4755 1.39.2.2 bouyer /*
4756 1.39.2.2 bouyer * We default to Wide/Fast for versions less than a 1040
4757 1.39.2.2 bouyer * (unless it's SBus).
4758 1.39.2.2 bouyer */
4759 1.39.2.2 bouyer if ((isp->isp_bustype == ISP_BT_SBUS &&
4760 1.39.2.2 bouyer isp->isp_type < ISP_HA_SCSI_1020A) ||
4761 1.39.2.2 bouyer (isp->isp_bustype == ISP_BT_PCI &&
4762 1.39.2.2 bouyer isp->isp_type < ISP_HA_SCSI_1040) ||
4763 1.39.2.2 bouyer (isp->isp_clock && isp->isp_clock < 60) ||
4764 1.39.2.2 bouyer (sdp->isp_ultramode == 0)) {
4765 1.34 mjacob sdp->isp_devparam[tgt].sync_offset =
4766 1.32 mjacob ISP_10M_SYNCPARMS >> 8;
4767 1.34 mjacob sdp->isp_devparam[tgt].sync_period =
4768 1.32 mjacob ISP_10M_SYNCPARMS & 0xff;
4769 1.39.2.2 bouyer } else if (IS_ULTRA3(isp)) {
4770 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_offset =
4771 1.39.2.2 bouyer ISP_80M_SYNCPARMS >> 8;
4772 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_period =
4773 1.39.2.2 bouyer ISP_80M_SYNCPARMS & 0xff;
4774 1.39.2.2 bouyer } else if (IS_ULTRA2(isp)) {
4775 1.34 mjacob sdp->isp_devparam[tgt].sync_offset =
4776 1.34 mjacob ISP_40M_SYNCPARMS >> 8;
4777 1.34 mjacob sdp->isp_devparam[tgt].sync_period =
4778 1.34 mjacob ISP_40M_SYNCPARMS & 0xff;
4779 1.39.2.2 bouyer } else if (IS_1240(isp)) {
4780 1.34 mjacob sdp->isp_devparam[tgt].sync_offset =
4781 1.32 mjacob ISP_20M_SYNCPARMS >> 8;
4782 1.34 mjacob sdp->isp_devparam[tgt].sync_period =
4783 1.32 mjacob ISP_20M_SYNCPARMS & 0xff;
4784 1.39.2.2 bouyer } else {
4785 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_offset =
4786 1.39.2.2 bouyer ISP_20M_SYNCPARMS_1040 >> 8;
4787 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_period =
4788 1.39.2.2 bouyer ISP_20M_SYNCPARMS_1040 & 0xff;
4789 1.32 mjacob }
4790 1.32 mjacob
4791 1.32 mjacob /*
4792 1.32 mjacob * Don't get current target parameters if we've been
4793 1.32 mjacob * told not to use NVRAM- it's really the same thing.
4794 1.32 mjacob */
4795 1.39.2.2 bouyer if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
4796 1.25 mjacob
4797 1.39.2.2 bouyer mbs.param[0] = MBOX_GET_TARGET_PARAMS;
4798 1.39.2.2 bouyer mbs.param[1] = tgt << 8;
4799 1.39.2.2 bouyer isp_mboxcmd(isp, &mbs, MBLOGALL);
4800 1.39.2.2 bouyer if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4801 1.39.2.2 bouyer continue;
4802 1.39.2.2 bouyer }
4803 1.39.2.2 bouyer sdp->isp_devparam[tgt].cur_dflags = mbs.param[2];
4804 1.39.2.2 bouyer sdp->isp_devparam[tgt].dev_flags = mbs.param[2];
4805 1.39.2.2 bouyer sdp->isp_devparam[tgt].cur_period = mbs.param[3] & 0xff;
4806 1.39.2.2 bouyer sdp->isp_devparam[tgt].cur_offset = mbs.param[3] >> 8;
4807 1.34 mjacob
4808 1.39.2.2 bouyer /*
4809 1.39.2.2 bouyer * The maximum period we can really see
4810 1.39.2.2 bouyer * here is 100 (decimal), or 400 ns.
4811 1.39.2.2 bouyer * For some unknown reason we sometimes
4812 1.39.2.2 bouyer * get back wildass numbers from the
4813 1.39.2.2 bouyer * boot device's parameters (alpha only).
4814 1.39.2.2 bouyer */
4815 1.39.2.2 bouyer if ((mbs.param[3] & 0xff) <= 0x64) {
4816 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_period =
4817 1.39.2.2 bouyer mbs.param[3] & 0xff;
4818 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_offset =
4819 1.39.2.2 bouyer mbs.param[3] >> 8;
4820 1.39.2.2 bouyer }
4821 1.25 mjacob
4822 1.39.2.2 bouyer /*
4823 1.39.2.2 bouyer * It is not safe to run Ultra Mode with a clock < 60.
4824 1.39.2.2 bouyer */
4825 1.39.2.2 bouyer if (((isp->isp_clock && isp->isp_clock < 60) ||
4826 1.39.2.2 bouyer (isp->isp_type < ISP_HA_SCSI_1020A)) &&
4827 1.39.2.2 bouyer (sdp->isp_devparam[tgt].sync_period <=
4828 1.39.2.2 bouyer (ISP_20M_SYNCPARMS & 0xff))) {
4829 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_offset =
4830 1.39.2.2 bouyer ISP_10M_SYNCPARMS >> 8;
4831 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_period =
4832 1.39.2.2 bouyer ISP_10M_SYNCPARMS & 0xff;
4833 1.39.2.2 bouyer }
4834 1.10 mjacob }
4835 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG1,
4836 1.39.2.2 bouyer "Initial bus %d tgt %d flags %x offset %x period %x",
4837 1.39.2.2 bouyer channel, tgt, sdp->isp_devparam[tgt].dev_flags,
4838 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_offset,
4839 1.39.2.2 bouyer sdp->isp_devparam[tgt].sync_period);
4840 1.10 mjacob }
4841 1.10 mjacob
4842 1.10 mjacob /*
4843 1.36 mjacob * Establish default some more default parameters.
4844 1.10 mjacob */
4845 1.10 mjacob sdp->isp_cmd_dma_burst_enable = 1;
4846 1.10 mjacob sdp->isp_data_dma_burst_enabl = 1;
4847 1.25 mjacob sdp->isp_fifo_threshold = 0;
4848 1.39.2.2 bouyer sdp->isp_initiator_id = DEFAULT_IID(isp);
4849 1.25 mjacob if (isp->isp_type >= ISP_HA_SCSI_1040) {
4850 1.25 mjacob sdp->isp_async_data_setup = 9;
4851 1.25 mjacob } else {
4852 1.25 mjacob sdp->isp_async_data_setup = 6;
4853 1.25 mjacob }
4854 1.10 mjacob sdp->isp_selection_timeout = 250;
4855 1.39.2.2 bouyer sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
4856 1.10 mjacob sdp->isp_tag_aging = 8;
4857 1.10 mjacob sdp->isp_bus_reset_delay = 3;
4858 1.36 mjacob sdp->isp_retry_count = 2;
4859 1.36 mjacob sdp->isp_retry_delay = 2;
4860 1.10 mjacob
4861 1.34 mjacob for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
4862 1.39.2.2 bouyer sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
4863 1.34 mjacob sdp->isp_devparam[tgt].dev_enable = 1;
4864 1.10 mjacob }
4865 1.10 mjacob }
4866 1.10 mjacob
4867 1.34 mjacob /*
4868 1.24 mjacob * Re-initialize the ISP and complete all orphaned commands
4869 1.38 mjacob * with a 'botched' notice. The reset/init routines should
4870 1.38 mjacob * not disturb an already active list of commands.
4871 1.24 mjacob *
4872 1.24 mjacob * Locks held prior to coming here.
4873 1.24 mjacob */
4874 1.24 mjacob
4875 1.24 mjacob void
4876 1.39.2.2 bouyer isp_reinit(isp)
4877 1.25 mjacob struct ispsoftc *isp;
4878 1.10 mjacob {
4879 1.39.2.2 bouyer XS_T *xs;
4880 1.38 mjacob u_int32_t handle;
4881 1.10 mjacob
4882 1.10 mjacob isp_reset(isp);
4883 1.39.2.6 bouyer if (isp->isp_state != ISP_RESETSTATE) {
4884 1.39.2.6 bouyer isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
4885 1.39.2.6 bouyer goto skip;
4886 1.39.2.6 bouyer }
4887 1.39.2.6 bouyer isp_init(isp);
4888 1.39.2.6 bouyer if (isp->isp_role == ISP_ROLE_NONE) {
4889 1.39.2.6 bouyer goto skip;
4890 1.39.2.6 bouyer }
4891 1.39.2.6 bouyer if (isp->isp_state == ISP_INITSTATE) {
4892 1.39.2.6 bouyer isp->isp_state = ISP_RUNSTATE;
4893 1.24 mjacob }
4894 1.24 mjacob if (isp->isp_state != ISP_RUNSTATE) {
4895 1.39.2.6 bouyer isp_prt(isp, ISP_LOGERR, "isp_reinit cannot restart card");
4896 1.24 mjacob }
4897 1.39.2.6 bouyer skip:
4898 1.38 mjacob isp->isp_nactive = 0;
4899 1.10 mjacob
4900 1.39.2.2 bouyer for (handle = 1; (int) handle <= isp->isp_maxcmds; handle++) {
4901 1.38 mjacob xs = isp_find_xs(isp, handle);
4902 1.38 mjacob if (xs == NULL) {
4903 1.10 mjacob continue;
4904 1.27 mjacob }
4905 1.38 mjacob isp_destroy_handle(isp, handle);
4906 1.38 mjacob if (XS_XFRLEN(xs)) {
4907 1.38 mjacob ISP_DMAFREE(isp, xs, handle);
4908 1.38 mjacob XS_RESID(xs) = XS_XFRLEN(xs);
4909 1.38 mjacob } else {
4910 1.38 mjacob XS_RESID(xs) = 0;
4911 1.38 mjacob }
4912 1.27 mjacob XS_SETERR(xs, HBA_BUSRESET);
4913 1.39.2.2 bouyer isp_done(xs);
4914 1.10 mjacob }
4915 1.15 mjacob }
4916 1.15 mjacob
4917 1.28 mjacob /*
4918 1.25 mjacob * NVRAM Routines
4919 1.25 mjacob */
4920 1.25 mjacob static int
4921 1.25 mjacob isp_read_nvram(isp)
4922 1.25 mjacob struct ispsoftc *isp;
4923 1.25 mjacob {
4924 1.25 mjacob int i, amt;
4925 1.25 mjacob u_int8_t csum, minversion;
4926 1.25 mjacob union {
4927 1.25 mjacob u_int8_t _x[ISP2100_NVRAM_SIZE];
4928 1.25 mjacob u_int16_t _s[ISP2100_NVRAM_SIZE>>1];
4929 1.25 mjacob } _n;
4930 1.25 mjacob #define nvram_data _n._x
4931 1.25 mjacob #define nvram_words _n._s
4932 1.25 mjacob
4933 1.33 mjacob if (IS_FC(isp)) {
4934 1.25 mjacob amt = ISP2100_NVRAM_SIZE;
4935 1.25 mjacob minversion = 1;
4936 1.39.2.2 bouyer } else if (IS_ULTRA2(isp)) {
4937 1.36 mjacob amt = ISP1080_NVRAM_SIZE;
4938 1.36 mjacob minversion = 0;
4939 1.25 mjacob } else {
4940 1.25 mjacob amt = ISP_NVRAM_SIZE;
4941 1.25 mjacob minversion = 2;
4942 1.25 mjacob }
4943 1.25 mjacob
4944 1.25 mjacob /*
4945 1.25 mjacob * Just read the first two words first to see if we have a valid
4946 1.25 mjacob * NVRAM to continue reading the rest with.
4947 1.25 mjacob */
4948 1.25 mjacob for (i = 0; i < 2; i++) {
4949 1.25 mjacob isp_rdnvram_word(isp, i, &nvram_words[i]);
4950 1.25 mjacob }
4951 1.25 mjacob if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
4952 1.25 mjacob nvram_data[2] != 'P') {
4953 1.25 mjacob if (isp->isp_bustype != ISP_BT_SBUS) {
4954 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
4955 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
4956 1.39.2.2 bouyer nvram_data[0], nvram_data[1], nvram_data[2]);
4957 1.25 mjacob }
4958 1.25 mjacob return (-1);
4959 1.25 mjacob }
4960 1.25 mjacob for (i = 2; i < amt>>1; i++) {
4961 1.25 mjacob isp_rdnvram_word(isp, i, &nvram_words[i]);
4962 1.25 mjacob }
4963 1.25 mjacob for (csum = 0, i = 0; i < amt; i++) {
4964 1.25 mjacob csum += nvram_data[i];
4965 1.25 mjacob }
4966 1.25 mjacob if (csum != 0) {
4967 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
4968 1.25 mjacob return (-1);
4969 1.25 mjacob }
4970 1.25 mjacob if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
4971 1.39.2.2 bouyer isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
4972 1.25 mjacob ISP_NVRAM_VERSION(nvram_data));
4973 1.25 mjacob return (-1);
4974 1.25 mjacob }
4975 1.25 mjacob
4976 1.39.2.2 bouyer if (IS_ULTRA3(isp)) {
4977 1.39.2.2 bouyer isp_parse_nvram_12160(isp, 0, nvram_data);
4978 1.39.2.2 bouyer isp_parse_nvram_12160(isp, 1, nvram_data);
4979 1.39.2.2 bouyer } else if (IS_1080(isp)) {
4980 1.39.2.2 bouyer isp_parse_nvram_1080(isp, 0, nvram_data);
4981 1.39.2.2 bouyer } else if (IS_1280(isp) || IS_1240(isp)) {
4982 1.39.2.2 bouyer isp_parse_nvram_1080(isp, 0, nvram_data);
4983 1.39.2.2 bouyer isp_parse_nvram_1080(isp, 1, nvram_data);
4984 1.36 mjacob } else if (IS_SCSI(isp)) {
4985 1.39.2.2 bouyer isp_parse_nvram_1020(isp, nvram_data);
4986 1.25 mjacob } else {
4987 1.39.2.2 bouyer isp_parse_nvram_2100(isp, nvram_data);
4988 1.25 mjacob }
4989 1.25 mjacob return (0);
4990 1.39.2.2 bouyer #undef nvram_data
4991 1.39.2.2 bouyer #undef nvram_words
4992 1.25 mjacob }
4993 1.25 mjacob
4994 1.25 mjacob static void
4995 1.25 mjacob isp_rdnvram_word(isp, wo, rp)
4996 1.25 mjacob struct ispsoftc *isp;
4997 1.25 mjacob int wo;
4998 1.25 mjacob u_int16_t *rp;
4999 1.25 mjacob {
5000 1.25 mjacob int i, cbits;
5001 1.25 mjacob u_int16_t bit, rqst;
5002 1.25 mjacob
5003 1.25 mjacob ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5004 1.39.2.2 bouyer USEC_DELAY(2);
5005 1.25 mjacob ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5006 1.39.2.2 bouyer USEC_DELAY(2);
5007 1.25 mjacob
5008 1.36 mjacob if (IS_FC(isp)) {
5009 1.25 mjacob wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
5010 1.36 mjacob rqst = (ISP_NVRAM_READ << 8) | wo;
5011 1.36 mjacob cbits = 10;
5012 1.39.2.2 bouyer } else if (IS_ULTRA2(isp)) {
5013 1.36 mjacob wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
5014 1.25 mjacob rqst = (ISP_NVRAM_READ << 8) | wo;
5015 1.25 mjacob cbits = 10;
5016 1.25 mjacob } else {
5017 1.25 mjacob wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
5018 1.25 mjacob rqst = (ISP_NVRAM_READ << 6) | wo;
5019 1.25 mjacob cbits = 8;
5020 1.25 mjacob }
5021 1.25 mjacob
5022 1.25 mjacob /*
5023 1.25 mjacob * Clock the word select request out...
5024 1.25 mjacob */
5025 1.25 mjacob for (i = cbits; i >= 0; i--) {
5026 1.25 mjacob if ((rqst >> i) & 1) {
5027 1.25 mjacob bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
5028 1.25 mjacob } else {
5029 1.25 mjacob bit = BIU_NVRAM_SELECT;
5030 1.25 mjacob }
5031 1.25 mjacob ISP_WRITE(isp, BIU_NVRAM, bit);
5032 1.39.2.2 bouyer USEC_DELAY(2);
5033 1.25 mjacob ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
5034 1.39.2.2 bouyer USEC_DELAY(2);
5035 1.25 mjacob ISP_WRITE(isp, BIU_NVRAM, bit);
5036 1.39.2.2 bouyer USEC_DELAY(2);
5037 1.25 mjacob }
5038 1.25 mjacob /*
5039 1.25 mjacob * Now read the result back in (bits come back in MSB format).
5040 1.25 mjacob */
5041 1.25 mjacob *rp = 0;
5042 1.25 mjacob for (i = 0; i < 16; i++) {
5043 1.25 mjacob u_int16_t rv;
5044 1.25 mjacob *rp <<= 1;
5045 1.25 mjacob ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5046 1.39.2.2 bouyer USEC_DELAY(2);
5047 1.25 mjacob rv = ISP_READ(isp, BIU_NVRAM);
5048 1.25 mjacob if (rv & BIU_NVRAM_DATAIN) {
5049 1.25 mjacob *rp |= 1;
5050 1.25 mjacob }
5051 1.39.2.2 bouyer USEC_DELAY(2);
5052 1.25 mjacob ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5053 1.39.2.2 bouyer USEC_DELAY(2);
5054 1.25 mjacob }
5055 1.25 mjacob ISP_WRITE(isp, BIU_NVRAM, 0);
5056 1.39.2.2 bouyer USEC_DELAY(2);
5057 1.39.2.2 bouyer ISP_SWIZZLE_NVRAM_WORD(isp, rp);
5058 1.39.2.2 bouyer }
5059 1.39.2.2 bouyer
5060 1.39.2.2 bouyer static void
5061 1.39.2.2 bouyer isp_parse_nvram_1020(isp, nvram_data)
5062 1.39.2.2 bouyer struct ispsoftc *isp;
5063 1.39.2.2 bouyer u_int8_t *nvram_data;
5064 1.39.2.2 bouyer {
5065 1.39.2.2 bouyer int i;
5066 1.39.2.2 bouyer sdparam *sdp = (sdparam *) isp->isp_param;
5067 1.39.2.2 bouyer
5068 1.39.2.2 bouyer sdp->isp_fifo_threshold =
5069 1.39.2.2 bouyer ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
5070 1.39.2.2 bouyer (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
5071 1.39.2.2 bouyer
5072 1.39.2.2 bouyer sdp->isp_initiator_id =
5073 1.39.2.2 bouyer ISP_NVRAM_INITIATOR_ID(nvram_data);
5074 1.39.2.2 bouyer
5075 1.39.2.2 bouyer sdp->isp_bus_reset_delay =
5076 1.39.2.2 bouyer ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
5077 1.39.2.2 bouyer
5078 1.39.2.2 bouyer sdp->isp_retry_count =
5079 1.39.2.2 bouyer ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
5080 1.39.2.2 bouyer
5081 1.39.2.2 bouyer sdp->isp_retry_delay =
5082 1.39.2.2 bouyer ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
5083 1.39.2.2 bouyer
5084 1.39.2.2 bouyer sdp->isp_async_data_setup =
5085 1.39.2.2 bouyer ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
5086 1.39.2.2 bouyer
5087 1.39.2.2 bouyer if (isp->isp_type >= ISP_HA_SCSI_1040) {
5088 1.39.2.2 bouyer if (sdp->isp_async_data_setup < 9) {
5089 1.39.2.2 bouyer sdp->isp_async_data_setup = 9;
5090 1.39.2.2 bouyer }
5091 1.39.2.2 bouyer } else {
5092 1.39.2.2 bouyer if (sdp->isp_async_data_setup != 6) {
5093 1.39.2.2 bouyer sdp->isp_async_data_setup = 6;
5094 1.39.2.2 bouyer }
5095 1.39.2.2 bouyer }
5096 1.39.2.2 bouyer
5097 1.39.2.2 bouyer sdp->isp_req_ack_active_neg =
5098 1.39.2.2 bouyer ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
5099 1.39.2.2 bouyer
5100 1.39.2.2 bouyer sdp->isp_data_line_active_neg =
5101 1.39.2.2 bouyer ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
5102 1.39.2.2 bouyer
5103 1.39.2.2 bouyer sdp->isp_data_dma_burst_enabl =
5104 1.39.2.2 bouyer ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
5105 1.39.2.2 bouyer
5106 1.39.2.2 bouyer sdp->isp_cmd_dma_burst_enable =
5107 1.39.2.2 bouyer ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
5108 1.39.2.2 bouyer
5109 1.39.2.2 bouyer sdp->isp_tag_aging =
5110 1.39.2.2 bouyer ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
5111 1.39.2.2 bouyer
5112 1.39.2.2 bouyer sdp->isp_selection_timeout =
5113 1.39.2.2 bouyer ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
5114 1.39.2.2 bouyer
5115 1.39.2.2 bouyer sdp->isp_max_queue_depth =
5116 1.39.2.2 bouyer ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
5117 1.39.2.2 bouyer
5118 1.39.2.2 bouyer sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
5119 1.39.2.2 bouyer for (i = 0; i < MAX_TARGETS; i++) {
5120 1.39.2.2 bouyer sdp->isp_devparam[i].dev_enable =
5121 1.39.2.2 bouyer ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, i);
5122 1.39.2.2 bouyer sdp->isp_devparam[i].exc_throttle =
5123 1.39.2.2 bouyer ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, i);
5124 1.39.2.2 bouyer sdp->isp_devparam[i].sync_offset =
5125 1.39.2.2 bouyer ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, i);
5126 1.39.2.2 bouyer sdp->isp_devparam[i].sync_period =
5127 1.39.2.2 bouyer ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, i);
5128 1.39.2.2 bouyer
5129 1.39.2.2 bouyer if (isp->isp_type < ISP_HA_SCSI_1040) {
5130 1.39.2.2 bouyer /*
5131 1.39.2.2 bouyer * If we're not ultra, we can't possibly
5132 1.39.2.2 bouyer * be a shorter period than this.
5133 1.39.2.2 bouyer */
5134 1.39.2.2 bouyer if (sdp->isp_devparam[i].sync_period < 0x19) {
5135 1.39.2.2 bouyer sdp->isp_devparam[i].sync_period = 0x19;
5136 1.39.2.2 bouyer }
5137 1.39.2.2 bouyer if (sdp->isp_devparam[i].sync_offset > 0xc) {
5138 1.39.2.2 bouyer sdp->isp_devparam[i].sync_offset = 0x0c;
5139 1.39.2.2 bouyer }
5140 1.39.2.2 bouyer } else {
5141 1.39.2.2 bouyer if (sdp->isp_devparam[i].sync_offset > 0x8) {
5142 1.39.2.2 bouyer sdp->isp_devparam[i].sync_offset = 0x8;
5143 1.39.2.2 bouyer }
5144 1.39.2.2 bouyer }
5145 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags = 0;
5146 1.39.2.2 bouyer if (ISP_NVRAM_TGT_RENEG(nvram_data, i))
5147 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_RENEG;
5148 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_ARQ;
5149 1.39.2.2 bouyer if (ISP_NVRAM_TGT_TQING(nvram_data, i))
5150 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_TQING;
5151 1.39.2.2 bouyer if (ISP_NVRAM_TGT_SYNC(nvram_data, i))
5152 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_SYNC;
5153 1.39.2.2 bouyer if (ISP_NVRAM_TGT_WIDE(nvram_data, i))
5154 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_WIDE;
5155 1.39.2.2 bouyer if (ISP_NVRAM_TGT_PARITY(nvram_data, i))
5156 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_PARITY;
5157 1.39.2.2 bouyer if (ISP_NVRAM_TGT_DISC(nvram_data, i))
5158 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_DISC;
5159 1.39.2.2 bouyer sdp->isp_devparam[i].cur_dflags = 0; /* we don't know */
5160 1.39.2.2 bouyer }
5161 1.39.2.2 bouyer }
5162 1.39.2.2 bouyer
5163 1.39.2.2 bouyer static void
5164 1.39.2.2 bouyer isp_parse_nvram_1080(isp, bus, nvram_data)
5165 1.39.2.2 bouyer struct ispsoftc *isp;
5166 1.39.2.2 bouyer int bus;
5167 1.39.2.2 bouyer u_int8_t *nvram_data;
5168 1.39.2.2 bouyer {
5169 1.39.2.2 bouyer int i;
5170 1.39.2.2 bouyer sdparam *sdp = (sdparam *) isp->isp_param;
5171 1.39.2.2 bouyer sdp += bus;
5172 1.39.2.2 bouyer
5173 1.39.2.2 bouyer sdp->isp_fifo_threshold =
5174 1.39.2.2 bouyer ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
5175 1.39.2.2 bouyer
5176 1.39.2.2 bouyer sdp->isp_initiator_id =
5177 1.39.2.2 bouyer ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
5178 1.39.2.2 bouyer
5179 1.39.2.2 bouyer sdp->isp_bus_reset_delay =
5180 1.39.2.2 bouyer ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
5181 1.39.2.2 bouyer
5182 1.39.2.2 bouyer sdp->isp_retry_count =
5183 1.39.2.2 bouyer ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
5184 1.39.2.2 bouyer
5185 1.39.2.2 bouyer sdp->isp_retry_delay =
5186 1.39.2.2 bouyer ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
5187 1.39.2.2 bouyer
5188 1.39.2.2 bouyer sdp->isp_async_data_setup =
5189 1.39.2.2 bouyer ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data,
5190 1.39.2.2 bouyer bus);
5191 1.39.2.2 bouyer
5192 1.39.2.2 bouyer sdp->isp_req_ack_active_neg =
5193 1.39.2.2 bouyer ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data,
5194 1.39.2.2 bouyer bus);
5195 1.39.2.2 bouyer
5196 1.39.2.2 bouyer sdp->isp_data_line_active_neg =
5197 1.39.2.2 bouyer ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data,
5198 1.39.2.2 bouyer bus);
5199 1.39.2.2 bouyer
5200 1.39.2.2 bouyer sdp->isp_data_dma_burst_enabl =
5201 1.39.2.2 bouyer ISP1080_NVRAM_BURST_ENABLE(nvram_data);
5202 1.39.2.2 bouyer
5203 1.39.2.2 bouyer sdp->isp_cmd_dma_burst_enable =
5204 1.39.2.2 bouyer ISP1080_NVRAM_BURST_ENABLE(nvram_data);
5205 1.39.2.2 bouyer
5206 1.39.2.2 bouyer sdp->isp_selection_timeout =
5207 1.39.2.2 bouyer ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
5208 1.39.2.2 bouyer
5209 1.39.2.2 bouyer sdp->isp_max_queue_depth =
5210 1.39.2.2 bouyer ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
5211 1.39.2.2 bouyer
5212 1.39.2.2 bouyer for (i = 0; i < MAX_TARGETS; i++) {
5213 1.39.2.2 bouyer sdp->isp_devparam[i].dev_enable =
5214 1.39.2.2 bouyer ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, i, bus);
5215 1.39.2.2 bouyer sdp->isp_devparam[i].exc_throttle =
5216 1.39.2.2 bouyer ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, i, bus);
5217 1.39.2.2 bouyer sdp->isp_devparam[i].sync_offset =
5218 1.39.2.2 bouyer ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, i, bus);
5219 1.39.2.2 bouyer sdp->isp_devparam[i].sync_period =
5220 1.39.2.2 bouyer ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, i, bus);
5221 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags = 0;
5222 1.39.2.2 bouyer if (ISP1080_NVRAM_TGT_RENEG(nvram_data, i, bus))
5223 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_RENEG;
5224 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_ARQ;
5225 1.39.2.2 bouyer if (ISP1080_NVRAM_TGT_TQING(nvram_data, i, bus))
5226 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_TQING;
5227 1.39.2.2 bouyer if (ISP1080_NVRAM_TGT_SYNC(nvram_data, i, bus))
5228 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_SYNC;
5229 1.39.2.2 bouyer if (ISP1080_NVRAM_TGT_WIDE(nvram_data, i, bus))
5230 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_WIDE;
5231 1.39.2.2 bouyer if (ISP1080_NVRAM_TGT_PARITY(nvram_data, i, bus))
5232 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_PARITY;
5233 1.39.2.2 bouyer if (ISP1080_NVRAM_TGT_DISC(nvram_data, i, bus))
5234 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_DISC;
5235 1.39.2.2 bouyer sdp->isp_devparam[i].cur_dflags = 0;
5236 1.39.2.2 bouyer }
5237 1.39.2.2 bouyer }
5238 1.39.2.2 bouyer
5239 1.39.2.2 bouyer static void
5240 1.39.2.2 bouyer isp_parse_nvram_12160(isp, bus, nvram_data)
5241 1.39.2.2 bouyer struct ispsoftc *isp;
5242 1.39.2.2 bouyer int bus;
5243 1.39.2.2 bouyer u_int8_t *nvram_data;
5244 1.39.2.2 bouyer {
5245 1.39.2.2 bouyer sdparam *sdp = (sdparam *) isp->isp_param;
5246 1.39.2.2 bouyer int i;
5247 1.39.2.2 bouyer
5248 1.39.2.2 bouyer sdp += bus;
5249 1.39.2.2 bouyer
5250 1.39.2.2 bouyer sdp->isp_fifo_threshold =
5251 1.39.2.2 bouyer ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
5252 1.39.2.2 bouyer
5253 1.39.2.2 bouyer sdp->isp_initiator_id =
5254 1.39.2.2 bouyer ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
5255 1.39.2.2 bouyer
5256 1.39.2.2 bouyer sdp->isp_bus_reset_delay =
5257 1.39.2.2 bouyer ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
5258 1.39.2.2 bouyer
5259 1.39.2.2 bouyer sdp->isp_retry_count =
5260 1.39.2.2 bouyer ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
5261 1.39.2.2 bouyer
5262 1.39.2.2 bouyer sdp->isp_retry_delay =
5263 1.39.2.2 bouyer ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
5264 1.39.2.2 bouyer
5265 1.39.2.2 bouyer sdp->isp_async_data_setup =
5266 1.39.2.2 bouyer ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data,
5267 1.39.2.2 bouyer bus);
5268 1.39.2.2 bouyer
5269 1.39.2.2 bouyer sdp->isp_req_ack_active_neg =
5270 1.39.2.2 bouyer ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data,
5271 1.39.2.2 bouyer bus);
5272 1.39.2.2 bouyer
5273 1.39.2.2 bouyer sdp->isp_data_line_active_neg =
5274 1.39.2.2 bouyer ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data,
5275 1.39.2.2 bouyer bus);
5276 1.39.2.2 bouyer
5277 1.39.2.2 bouyer sdp->isp_data_dma_burst_enabl =
5278 1.39.2.2 bouyer ISP12160_NVRAM_BURST_ENABLE(nvram_data);
5279 1.39.2.2 bouyer
5280 1.39.2.2 bouyer sdp->isp_cmd_dma_burst_enable =
5281 1.39.2.2 bouyer ISP12160_NVRAM_BURST_ENABLE(nvram_data);
5282 1.39.2.2 bouyer
5283 1.39.2.2 bouyer sdp->isp_selection_timeout =
5284 1.39.2.2 bouyer ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
5285 1.39.2.2 bouyer
5286 1.39.2.2 bouyer sdp->isp_max_queue_depth =
5287 1.39.2.2 bouyer ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
5288 1.39.2.2 bouyer
5289 1.39.2.2 bouyer for (i = 0; i < MAX_TARGETS; i++) {
5290 1.39.2.2 bouyer sdp->isp_devparam[i].dev_enable =
5291 1.39.2.2 bouyer ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, i, bus);
5292 1.39.2.2 bouyer sdp->isp_devparam[i].exc_throttle =
5293 1.39.2.2 bouyer ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, i, bus);
5294 1.39.2.2 bouyer sdp->isp_devparam[i].sync_offset =
5295 1.39.2.2 bouyer ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, i, bus);
5296 1.39.2.2 bouyer sdp->isp_devparam[i].sync_period =
5297 1.39.2.2 bouyer ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, i, bus);
5298 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags = 0;
5299 1.39.2.2 bouyer if (ISP12160_NVRAM_TGT_RENEG(nvram_data, i, bus))
5300 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_RENEG;
5301 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_ARQ;
5302 1.39.2.2 bouyer if (ISP12160_NVRAM_TGT_TQING(nvram_data, i, bus))
5303 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_TQING;
5304 1.39.2.2 bouyer if (ISP12160_NVRAM_TGT_SYNC(nvram_data, i, bus))
5305 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_SYNC;
5306 1.39.2.2 bouyer if (ISP12160_NVRAM_TGT_WIDE(nvram_data, i, bus))
5307 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_WIDE;
5308 1.39.2.2 bouyer if (ISP12160_NVRAM_TGT_PARITY(nvram_data, i, bus))
5309 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_PARITY;
5310 1.39.2.2 bouyer if (ISP12160_NVRAM_TGT_DISC(nvram_data, i, bus))
5311 1.39.2.2 bouyer sdp->isp_devparam[i].dev_flags |= DPARM_DISC;
5312 1.39.2.2 bouyer sdp->isp_devparam[i].cur_dflags = 0;
5313 1.39.2.2 bouyer }
5314 1.39.2.2 bouyer }
5315 1.39.2.2 bouyer
5316 1.39.2.2 bouyer static void
5317 1.39.2.2 bouyer isp_parse_nvram_2100(isp, nvram_data)
5318 1.39.2.2 bouyer struct ispsoftc *isp;
5319 1.39.2.2 bouyer u_int8_t *nvram_data;
5320 1.39.2.2 bouyer {
5321 1.39.2.2 bouyer fcparam *fcp = (fcparam *) isp->isp_param;
5322 1.39.2.2 bouyer u_int64_t wwn;
5323 1.39.2.2 bouyer
5324 1.39.2.2 bouyer /*
5325 1.39.2.2 bouyer * There is NVRAM storage for both Port and Node entities-
5326 1.39.2.2 bouyer * but the Node entity appears to be unused on all the cards
5327 1.39.2.2 bouyer * I can find. However, we should account for this being set
5328 1.39.2.2 bouyer * at some point in the future.
5329 1.39.2.2 bouyer *
5330 1.39.2.2 bouyer * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
5331 1.39.2.2 bouyer * bits 48..60. In the case of the 2202, it appears that they do
5332 1.39.2.2 bouyer * use bit 48 to distinguish between the two instances on the card.
5333 1.39.2.2 bouyer * The 2204, which I've never seen, *probably* extends this method.
5334 1.39.2.2 bouyer */
5335 1.39.2.2 bouyer wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
5336 1.39.2.2 bouyer if (wwn) {
5337 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
5338 1.39.2.2 bouyer (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
5339 1.39.2.2 bouyer if ((wwn >> 60) == 0) {
5340 1.39.2.2 bouyer wwn |= (((u_int64_t) 2)<< 60);
5341 1.39.2.2 bouyer }
5342 1.39.2.2 bouyer }
5343 1.39.2.2 bouyer fcp->isp_portwwn = wwn;
5344 1.39.2.2 bouyer wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
5345 1.39.2.2 bouyer if (wwn) {
5346 1.39.2.2 bouyer isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
5347 1.39.2.2 bouyer (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
5348 1.39.2.2 bouyer if ((wwn >> 60) == 0) {
5349 1.39.2.2 bouyer wwn |= (((u_int64_t) 2)<< 60);
5350 1.39.2.2 bouyer }
5351 1.39.2.2 bouyer }
5352 1.39.2.2 bouyer fcp->isp_nodewwn = wwn;
5353 1.39.2.2 bouyer
5354 1.39.2.2 bouyer /*
5355 1.39.2.2 bouyer * Make sure we have both Node and Port as non-zero values.
5356 1.39.2.2 bouyer */
5357 1.39.2.2 bouyer if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
5358 1.39.2.2 bouyer fcp->isp_portwwn = fcp->isp_nodewwn;
5359 1.39.2.2 bouyer } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
5360 1.39.2.2 bouyer fcp->isp_nodewwn = fcp->isp_portwwn;
5361 1.39.2.2 bouyer }
5362 1.39.2.2 bouyer
5363 1.39.2.2 bouyer /*
5364 1.39.2.2 bouyer * Make the Node and Port values sane if they're NAA == 2.
5365 1.39.2.2 bouyer * This means to clear bits 48..56 for the Node WWN and
5366 1.39.2.2 bouyer * make sure that there's some non-zero value in 48..56
5367 1.39.2.2 bouyer * for the Port WWN.
5368 1.39.2.2 bouyer */
5369 1.39.2.2 bouyer if (fcp->isp_nodewwn && fcp->isp_portwwn) {
5370 1.39.2.2 bouyer if ((fcp->isp_nodewwn & (((u_int64_t) 0xfff) << 48)) != 0 &&
5371 1.39.2.2 bouyer (fcp->isp_nodewwn >> 60) == 2) {
5372 1.39.2.2 bouyer fcp->isp_nodewwn &= ~((u_int64_t) 0xfff << 48);
5373 1.39.2.2 bouyer }
5374 1.39.2.2 bouyer if ((fcp->isp_portwwn & (((u_int64_t) 0xfff) << 48)) == 0 &&
5375 1.39.2.2 bouyer (fcp->isp_portwwn >> 60) == 2) {
5376 1.39.2.2 bouyer fcp->isp_portwwn |= ((u_int64_t) 1 << 56);
5377 1.39.2.2 bouyer }
5378 1.39.2.2 bouyer }
5379 1.39.2.2 bouyer
5380 1.39.2.2 bouyer fcp->isp_maxalloc =
5381 1.39.2.2 bouyer ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
5382 1.39.2.2 bouyer fcp->isp_maxfrmlen =
5383 1.39.2.2 bouyer ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
5384 1.39.2.2 bouyer fcp->isp_retry_delay =
5385 1.39.2.2 bouyer ISP2100_NVRAM_RETRY_DELAY(nvram_data);
5386 1.39.2.2 bouyer fcp->isp_retry_count =
5387 1.39.2.2 bouyer ISP2100_NVRAM_RETRY_COUNT(nvram_data);
5388 1.39.2.2 bouyer fcp->isp_loopid =
5389 1.39.2.2 bouyer ISP2100_NVRAM_HARDLOOPID(nvram_data);
5390 1.39.2.2 bouyer fcp->isp_execthrottle =
5391 1.39.2.2 bouyer ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
5392 1.39.2.2 bouyer fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
5393 1.39.2.2 bouyer isp_prt(isp, ISP_LOGDEBUG0,
5394 1.39.2.2 bouyer "fwoptions from nvram are 0x%x", fcp->isp_fwoptions);
5395 1.1 cgd }
5396