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