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