Deleted Added
full compact
isp.c (115630) isp.c (119418)
1/* $FreeBSD: head/sys/dev/isp/isp.c 115630 2003-06-01 19:01:01Z mjacob $ */
2/*
3 * Machine and OS Independent (well, as best as possible)
4 * code for the Qlogic ISP SCSI adapters.
5 *
6 * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob
7 * Feral Software
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32/*
33 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
34 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
35 * ideas dredged from the Solaris driver.
36 */
37
1/*
2 * Machine and OS Independent (well, as best as possible)
3 * code for the Qlogic ISP SCSI adapters.
4 *
5 * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob
6 * Feral Software
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice immediately at the beginning of the file, without modification,
14 * this list of conditions, and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31/*
32 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
33 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
34 * ideas dredged from the Solaris driver.
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/dev/isp/isp.c 119418 2003-08-24 17:55:58Z obrien $");
39
38/*
39 * Include header file appropriate for platform we're building on.
40 */
41
42#ifdef __NetBSD__
43#include <dev/ic/isp_netbsd.h>
44#endif
45#ifdef __FreeBSD__
46#include <dev/isp/isp_freebsd.h>
47#endif
48#ifdef __OpenBSD__
49#include <dev/ic/isp_openbsd.h>
50#endif
51#ifdef __linux__
52#include "isp_linux.h"
53#endif
54#ifdef __svr4__
55#include "isp_solaris.h"
56#endif
57
58/*
59 * General defines
60 */
61
62#define MBOX_DELAY_COUNT 1000000 / 100
63
64/*
65 * Local static data
66 */
67static const char portshift[] =
68 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
69static const char portdup[] =
70 "Target %d duplicates Target %d- killing off both";
71static const char retained[] =
72 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
73static const char lretained[] =
74 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
75static const char plogout[] =
76 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
77static const char plogierr[] =
78 "Command Error in PLOGI for Port 0x%x (0x%x)";
79static const char nopdb[] =
80 "Could not get PDB for Device @ Port 0x%x";
81static const char pdbmfail1[] =
82 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
83static const char pdbmfail2[] =
84 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
85static const char ldumped[] =
86 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
87static const char notresp[] =
88 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
89static const char xact1[] =
90 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
91static const char xact2[] =
92 "HBA attempted queued transaction to target routine %d on target %d bus %d";
93static const char xact3[] =
94 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
95static const char pskip[] =
96 "SCSI phase skipped for target %d.%d.%d";
97static const char topology[] =
98 "Loop ID %d, AL_PA 0x%x, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
99static const char swrej[] =
100 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
101static const char finmsg[] =
102 "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
103static const char sc0[] =
104 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
105static const char sc1[] =
106 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
107static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
108static const char sc3[] = "Generated";
109static const char sc4[] = "NVRAM";
110static const char bun[] =
111 "bad underrun for %d.%d (count %d, resid %d, status %s)";
112
113/*
114 * Local function prototypes.
115 */
116static int isp_parse_async(struct ispsoftc *, u_int16_t);
117static int isp_handle_other_response(struct ispsoftc *, int, isphdr_t *,
118 u_int16_t *);
119static void
120isp_parse_status(struct ispsoftc *, ispstatusreq_t *, XS_T *);
121static void isp_fastpost_complete(struct ispsoftc *, u_int16_t);
122static int isp_mbox_continue(struct ispsoftc *);
123static void isp_scsi_init(struct ispsoftc *);
124static void isp_scsi_channel_init(struct ispsoftc *, int);
125static void isp_fibre_init(struct ispsoftc *);
126static void isp_mark_getpdb_all(struct ispsoftc *);
127static int isp_getmap(struct ispsoftc *, fcpos_map_t *);
128static int isp_getpdb(struct ispsoftc *, int, isp_pdb_t *);
129static u_int64_t isp_get_portname(struct ispsoftc *, int, int);
130static int isp_fclink_test(struct ispsoftc *, int);
131static char *isp2100_fw_statename(int);
132static int isp_pdb_sync(struct ispsoftc *);
133static int isp_scan_loop(struct ispsoftc *);
134static int isp_fabric_mbox_cmd(struct ispsoftc *, mbreg_t *);
135static int isp_scan_fabric(struct ispsoftc *, int);
136static void isp_register_fc4_type(struct ispsoftc *);
137static void isp_fw_state(struct ispsoftc *);
138static void isp_mboxcmd_qnw(struct ispsoftc *, mbreg_t *, int);
139static void isp_mboxcmd(struct ispsoftc *, mbreg_t *, int);
140
141static void isp_update(struct ispsoftc *);
142static void isp_update_bus(struct ispsoftc *, int);
143static void isp_setdfltparm(struct ispsoftc *, int);
144static int isp_read_nvram(struct ispsoftc *);
145static void isp_rdnvram_word(struct ispsoftc *, int, u_int16_t *);
146static void isp_parse_nvram_1020(struct ispsoftc *, u_int8_t *);
147static void isp_parse_nvram_1080(struct ispsoftc *, int, u_int8_t *);
148static void isp_parse_nvram_12160(struct ispsoftc *, int, u_int8_t *);
149static void isp_parse_nvram_2100(struct ispsoftc *, u_int8_t *);
150
151/*
152 * Reset Hardware.
153 *
154 * Hit the chip over the head, download new f/w if available and set it running.
155 *
156 * Locking done elsewhere.
157 */
158
159void
160isp_reset(struct ispsoftc *isp)
161{
162 mbreg_t mbs;
163 u_int16_t code_org;
164 int loops, i, dodnld = 1;
165 char *btype = "????";
166
167 isp->isp_state = ISP_NILSTATE;
168
169 /*
170 * Basic types (SCSI, FibreChannel and PCI or SBus)
171 * have been set in the MD code. We figure out more
172 * here. Possibly more refined types based upon PCI
173 * identification. Chip revision has been gathered.
174 *
175 * After we've fired this chip up, zero out the conf1 register
176 * for SCSI adapters and do other settings for the 2100.
177 */
178
179 /*
180 * Get the current running firmware revision out of the
181 * chip before we hit it over the head (if this is our
182 * first time through). Note that we store this as the
183 * 'ROM' firmware revision- which it may not be. In any
184 * case, we don't really use this yet, but we may in
185 * the future.
186 */
187 if (isp->isp_touched == 0) {
188 /*
189 * First see whether or not we're sitting in the ISP PROM.
190 * If we've just been reset, we'll have the string "ISP "
191 * spread through outgoing mailbox registers 1-3. We do
192 * this for PCI cards because otherwise we really don't
193 * know what state the card is in and we could hang if
194 * we try this command otherwise.
195 *
196 * For SBus cards, we just do this because they almost
197 * certainly will be running firmware by now.
198 */
199 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
200 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
201 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
202 /*
203 * Just in case it was paused...
204 */
205 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
206 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
207 isp_mboxcmd(isp, &mbs, MBLOGNONE);
208 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
209 isp->isp_romfw_rev[0] = mbs.param[1];
210 isp->isp_romfw_rev[1] = mbs.param[2];
211 isp->isp_romfw_rev[2] = mbs.param[3];
212 }
213 }
214 isp->isp_touched = 1;
215 }
216
217 DISABLE_INTS(isp);
218
219 /*
220 * Set up default request/response queue in-pointer/out-pointer
221 * register indices.
222 */
223 if (IS_23XX(isp)) {
224 isp->isp_rqstinrp = BIU_REQINP;
225 isp->isp_rqstoutrp = BIU_REQOUTP;
226 isp->isp_respinrp = BIU_RSPINP;
227 isp->isp_respoutrp = BIU_RSPOUTP;
228 } else {
229 isp->isp_rqstinrp = INMAILBOX4;
230 isp->isp_rqstoutrp = OUTMAILBOX4;
231 isp->isp_respinrp = OUTMAILBOX5;
232 isp->isp_respoutrp = INMAILBOX5;
233 }
234
235 /*
236 * Put the board into PAUSE mode (so we can read the SXP registers
237 * or write FPM/FBM registers).
238 */
239 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
240
241 if (IS_FC(isp)) {
242 switch (isp->isp_type) {
243 case ISP_HA_FC_2100:
244 btype = "2100";
245 break;
246 case ISP_HA_FC_2200:
247 btype = "2200";
248 break;
249 case ISP_HA_FC_2300:
250 btype = "2300";
251 break;
252 case ISP_HA_FC_2312:
253 btype = "2312";
254 break;
255 default:
256 break;
257 }
258 /*
259 * While we're paused, reset the FPM module and FBM fifos.
260 */
261 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
262 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
263 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
264 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
265 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
266 } else if (IS_1240(isp)) {
267 sdparam *sdp = isp->isp_param;
268 btype = "1240";
269 isp->isp_clock = 60;
270 sdp->isp_ultramode = 1;
271 sdp++;
272 sdp->isp_ultramode = 1;
273 /*
274 * XXX: Should probably do some bus sensing.
275 */
276 } else if (IS_ULTRA2(isp)) {
277 static const char m[] = "bus %d is in %s Mode";
278 u_int16_t l;
279 sdparam *sdp = isp->isp_param;
280
281 isp->isp_clock = 100;
282
283 if (IS_1280(isp))
284 btype = "1280";
285 else if (IS_1080(isp))
286 btype = "1080";
287 else if (IS_10160(isp))
288 btype = "10160";
289 else if (IS_12160(isp))
290 btype = "12160";
291 else
292 btype = "<UNKLVD>";
293
294 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
295 switch (l) {
296 case ISP1080_LVD_MODE:
297 sdp->isp_lvdmode = 1;
298 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
299 break;
300 case ISP1080_HVD_MODE:
301 sdp->isp_diffmode = 1;
302 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
303 break;
304 case ISP1080_SE_MODE:
305 sdp->isp_ultramode = 1;
306 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
307 break;
308 default:
309 isp_prt(isp, ISP_LOGERR,
310 "unknown mode on bus %d (0x%x)", 0, l);
311 break;
312 }
313
314 if (IS_DUALBUS(isp)) {
315 sdp++;
316 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
317 l &= ISP1080_MODE_MASK;
318 switch(l) {
319 case ISP1080_LVD_MODE:
320 sdp->isp_lvdmode = 1;
321 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
322 break;
323 case ISP1080_HVD_MODE:
324 sdp->isp_diffmode = 1;
325 isp_prt(isp, ISP_LOGCONFIG,
326 m, 1, "Differential");
327 break;
328 case ISP1080_SE_MODE:
329 sdp->isp_ultramode = 1;
330 isp_prt(isp, ISP_LOGCONFIG,
331 m, 1, "Single-Ended");
332 break;
333 default:
334 isp_prt(isp, ISP_LOGERR,
335 "unknown mode on bus %d (0x%x)", 1, l);
336 break;
337 }
338 }
339 } else {
340 sdparam *sdp = isp->isp_param;
341 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
342 switch (i) {
343 default:
344 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
345 /* FALLTHROUGH */
346 case 1:
347 btype = "1020";
348 isp->isp_type = ISP_HA_SCSI_1020;
349 isp->isp_clock = 40;
350 break;
351 case 2:
352 /*
353 * Some 1020A chips are Ultra Capable, but don't
354 * run the clock rate up for that unless told to
355 * do so by the Ultra Capable bits being set.
356 */
357 btype = "1020A";
358 isp->isp_type = ISP_HA_SCSI_1020A;
359 isp->isp_clock = 40;
360 break;
361 case 3:
362 btype = "1040";
363 isp->isp_type = ISP_HA_SCSI_1040;
364 isp->isp_clock = 60;
365 break;
366 case 4:
367 btype = "1040A";
368 isp->isp_type = ISP_HA_SCSI_1040A;
369 isp->isp_clock = 60;
370 break;
371 case 5:
372 btype = "1040B";
373 isp->isp_type = ISP_HA_SCSI_1040B;
374 isp->isp_clock = 60;
375 break;
376 case 6:
377 btype = "1040C";
378 isp->isp_type = ISP_HA_SCSI_1040C;
379 isp->isp_clock = 60;
380 break;
381 }
382 /*
383 * Now, while we're at it, gather info about ultra
384 * and/or differential mode.
385 */
386 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
387 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
388 sdp->isp_diffmode = 1;
389 } else {
390 sdp->isp_diffmode = 0;
391 }
392 i = ISP_READ(isp, RISC_PSR);
393 if (isp->isp_bustype == ISP_BT_SBUS) {
394 i &= RISC_PSR_SBUS_ULTRA;
395 } else {
396 i &= RISC_PSR_PCI_ULTRA;
397 }
398 if (i != 0) {
399 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
400 sdp->isp_ultramode = 1;
401 /*
402 * If we're in Ultra Mode, we have to be 60Mhz clock-
403 * even for the SBus version.
404 */
405 isp->isp_clock = 60;
406 } else {
407 sdp->isp_ultramode = 0;
408 /*
409 * Clock is known. Gronk.
410 */
411 }
412
413 /*
414 * Machine dependent clock (if set) overrides
415 * our generic determinations.
416 */
417 if (isp->isp_mdvec->dv_clock) {
418 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
419 isp->isp_clock = isp->isp_mdvec->dv_clock;
420 }
421 }
422
423 }
424
425 /*
426 * Clear instrumentation
427 */
428 isp->isp_intcnt = isp->isp_intbogus = 0;
429
430 /*
431 * Do MD specific pre initialization
432 */
433 ISP_RESET0(isp);
434
435again:
436
437 /*
438 * Hit the chip over the head with hammer,
439 * and give the ISP a chance to recover.
440 */
441
442 if (IS_SCSI(isp)) {
443 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
444 /*
445 * A slight delay...
446 */
447 USEC_DELAY(100);
448
449 /*
450 * Clear data && control DMA engines.
451 */
452 ISP_WRITE(isp, CDMA_CONTROL,
453 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
454 ISP_WRITE(isp, DDMA_CONTROL,
455 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
456
457
458 } else {
459 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
460 /*
461 * A slight delay...
462 */
463 USEC_DELAY(100);
464
465 /*
466 * Clear data && control DMA engines.
467 */
468 ISP_WRITE(isp, CDMA2100_CONTROL,
469 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
470 ISP_WRITE(isp, TDMA2100_CONTROL,
471 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
472 ISP_WRITE(isp, RDMA2100_CONTROL,
473 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
474 }
475
476 /*
477 * Wait for ISP to be ready to go...
478 */
479 loops = MBOX_DELAY_COUNT;
480 for (;;) {
481 if (IS_SCSI(isp)) {
482 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
483 break;
484 } else {
485 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
486 break;
487 }
488 USEC_DELAY(100);
489 if (--loops < 0) {
490 ISP_DUMPREGS(isp, "chip reset timed out");
491 return;
492 }
493 }
494
495 /*
496 * After we've fired this chip up, zero out the conf1 register
497 * for SCSI adapters and other settings for the 2100.
498 */
499
500 if (IS_SCSI(isp)) {
501 ISP_WRITE(isp, BIU_CONF1, 0);
502 } else {
503 ISP_WRITE(isp, BIU2100_CSR, 0);
504 }
505
506 /*
507 * Reset RISC Processor
508 */
509 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
510 USEC_DELAY(100);
511 /* Clear semaphore register (just to be sure) */
512 ISP_WRITE(isp, BIU_SEMA, 0);
513
514 /*
515 * Establish some initial burst rate stuff.
516 * (only for the 1XX0 boards). This really should
517 * be done later after fetching from NVRAM.
518 */
519 if (IS_SCSI(isp)) {
520 u_int16_t tmp = isp->isp_mdvec->dv_conf1;
521 /*
522 * Busted FIFO. Turn off all but burst enables.
523 */
524 if (isp->isp_type == ISP_HA_SCSI_1040A) {
525 tmp &= BIU_BURST_ENABLE;
526 }
527 ISP_SETBITS(isp, BIU_CONF1, tmp);
528 if (tmp & BIU_BURST_ENABLE) {
529 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
530 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
531 }
532#ifdef PTI_CARDS
533 if (((sdparam *) isp->isp_param)->isp_ultramode) {
534 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
535 ISP_WRITE(isp, RISC_MTR, 0x1313);
536 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
537 }
538 } else {
539 ISP_WRITE(isp, RISC_MTR, 0x1212);
540 }
541 /*
542 * PTI specific register
543 */
544 ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
545#else
546 ISP_WRITE(isp, RISC_MTR, 0x1212);
547#endif
548 } else {
549 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
550 if (IS_2200(isp) || IS_23XX(isp)) {
551 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
552 }
553 }
554
555 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
556
557 /*
558 * Do MD specific post initialization
559 */
560 ISP_RESET1(isp);
561
562 /*
563 * Wait for everything to finish firing up.
564 *
565 * Avoid doing this on the 2312 because you can generate a PCI
566 * parity error (chip breakage).
567 */
568 if (IS_23XX(isp)) {
569 USEC_DELAY(5);
570 } else {
571 loops = MBOX_DELAY_COUNT;
572 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
573 USEC_DELAY(100);
574 if (--loops < 0) {
575 isp_prt(isp, ISP_LOGERR,
576 "MBOX_BUSY never cleared on reset");
577 return;
578 }
579 }
580 }
581
582 /*
583 * Up until this point we've done everything by just reading or
584 * setting registers. From this point on we rely on at least *some*
585 * kind of firmware running in the card.
586 */
587
588 /*
589 * Do some sanity checking.
590 */
591 mbs.param[0] = MBOX_NO_OP;
592 isp_mboxcmd(isp, &mbs, MBLOGALL);
593 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
594 return;
595 }
596
597 if (IS_SCSI(isp)) {
598 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
599 mbs.param[1] = 0xdead;
600 mbs.param[2] = 0xbeef;
601 mbs.param[3] = 0xffff;
602 mbs.param[4] = 0x1111;
603 mbs.param[5] = 0xa5a5;
604 isp_mboxcmd(isp, &mbs, MBLOGALL);
605 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
606 return;
607 }
608 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
609 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
610 mbs.param[5] != 0xa5a5) {
611 isp_prt(isp, ISP_LOGERR,
612 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
613 mbs.param[1], mbs.param[2], mbs.param[3],
614 mbs.param[4], mbs.param[5]);
615 return;
616 }
617
618 }
619
620 /*
621 * Download new Firmware, unless requested not to do so.
622 * This is made slightly trickier in some cases where the
623 * firmware of the ROM revision is newer than the revision
624 * compiled into the driver. So, where we used to compare
625 * versions of our f/w and the ROM f/w, now we just see
626 * whether we have f/w at all and whether a config flag
627 * has disabled our download.
628 */
629 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
630 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
631 dodnld = 0;
632 }
633
634 if (IS_23XX(isp))
635 code_org = ISP_CODE_ORG_2300;
636 else
637 code_org = ISP_CODE_ORG;
638
639 if (dodnld) {
640 isp->isp_mbxworkp = (void *) &isp->isp_mdvec->dv_ispfw[1];
641 isp->isp_mbxwrk0 = isp->isp_mdvec->dv_ispfw[3] - 1;
642 isp->isp_mbxwrk1 = code_org + 1;
643 mbs.param[0] = MBOX_WRITE_RAM_WORD;
644 mbs.param[1] = code_org;
645 mbs.param[2] = isp->isp_mdvec->dv_ispfw[0];
646 isp_mboxcmd(isp, &mbs, MBLOGNONE);
647 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
648 isp_prt(isp, ISP_LOGERR,
649 "F/W download failed at word %d",
650 isp->isp_mbxwrk1 - code_org);
651 dodnld = 0;
652 goto again;
653 }
654 /*
655 * Verify that it downloaded correctly.
656 */
657 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
658 mbs.param[1] = code_org;
659 isp_mboxcmd(isp, &mbs, MBLOGNONE);
660 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
661 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
662 return;
663 }
664 isp->isp_loaded_fw = 1;
665 } else {
666 isp->isp_loaded_fw = 0;
667 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
668 }
669
670 /*
671 * Now start it rolling.
672 *
673 * If we didn't actually download f/w,
674 * we still need to (re)start it.
675 */
676
677
678 mbs.param[0] = MBOX_EXEC_FIRMWARE;
679 mbs.param[1] = code_org;
680 isp_mboxcmd(isp, &mbs, MBLOGNONE);
681 /*
682 * Give it a chance to start.
683 */
684 USEC_DELAY(500);
685
686 if (IS_SCSI(isp)) {
687 /*
688 * Set CLOCK RATE, but only if asked to.
689 */
690 if (isp->isp_clock) {
691 mbs.param[0] = MBOX_SET_CLOCK_RATE;
692 mbs.param[1] = isp->isp_clock;
693 isp_mboxcmd(isp, &mbs, MBLOGALL);
694 /* we will try not to care if this fails */
695 }
696 }
697
698 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
699 isp_mboxcmd(isp, &mbs, MBLOGALL);
700 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
701 return;
702 }
703
704 /*
705 * The SBus firmware that we are using apparently does not return
706 * major, minor, micro revisions in the mailbox registers, which
707 * is really, really, annoying.
708 */
709 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
710 if (dodnld) {
711#ifdef ISP_TARGET_MODE
712 isp->isp_fwrev[0] = 7;
713 isp->isp_fwrev[1] = 55;
714#else
715 isp->isp_fwrev[0] = 1;
716 isp->isp_fwrev[1] = 37;
717#endif
718 isp->isp_fwrev[2] = 0;
719 }
720 } else {
721 isp->isp_fwrev[0] = mbs.param[1];
722 isp->isp_fwrev[1] = mbs.param[2];
723 isp->isp_fwrev[2] = mbs.param[3];
724 }
725 isp_prt(isp, ISP_LOGCONFIG,
726 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
727 btype, isp->isp_revision, dodnld? "loaded" : "resident",
728 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
729
730 if (IS_FC(isp)) {
731 /*
732 * We do not believe firmware attributes for 2100 code less
733 * than 1.17.0, unless it's the firmware we specifically
734 * are loading.
735 *
736 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
737 */
738 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
739#ifdef USE_SMALLER_2100_FIRMWARE
740 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
741#else
742 FCPARAM(isp)->isp_fwattr = 0;
743#endif
744 } else {
745 FCPARAM(isp)->isp_fwattr = mbs.param[6];
746 isp_prt(isp, ISP_LOGDEBUG0,
747 "Firmware Attributes = 0x%x", mbs.param[6]);
748 }
749 if (ISP_READ(isp, BIU2100_CSR) & BIU2100_PCI64) {
750 isp_prt(isp, ISP_LOGCONFIG,
751 "Installed in 64-Bit PCI slot");
752 }
753 }
754
755 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
756 isp->isp_romfw_rev[2]) {
757 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
758 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
759 isp->isp_romfw_rev[2]);
760 }
761
762 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
763 isp_mboxcmd(isp, &mbs, MBLOGALL);
764 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
765 return;
766 }
767 isp->isp_maxcmds = mbs.param[2];
768 isp_prt(isp, ISP_LOGINFO,
769 "%d max I/O commands supported", mbs.param[2]);
770 isp_fw_state(isp);
771
772 /*
773 * Set up DMA for the request and result mailboxes.
774 */
775 if (ISP_MBOXDMASETUP(isp) != 0) {
776 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
777 return;
778 }
779 isp->isp_state = ISP_RESETSTATE;
780
781 /*
782 * Okay- now that we have new firmware running, we now (re)set our
783 * notion of how many luns we support. This is somewhat tricky because
784 * if we haven't loaded firmware, we sometimes do not have an easy way
785 * of knowing how many luns we support.
786 *
787 * Expanded lun firmware gives you 32 luns for SCSI cards and
788 * 16384 luns for Fibre Channel cards.
789 *
790 * It turns out that even for QLogic 2100s with ROM 1.10 and above
791 * we do get a firmware attributes word returned in mailbox register 6.
792 *
793 * Because the lun is in a different position in the Request Queue
794 * Entry structure for Fibre Channel with expanded lun firmware, we
795 * can only support one lun (lun zero) when we don't know what kind
796 * of firmware we're running.
797 */
798 if (IS_SCSI(isp)) {
799 if (dodnld) {
800 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
801 isp->isp_maxluns = 32;
802 } else {
803 isp->isp_maxluns = 8;
804 }
805 } else {
806 isp->isp_maxluns = 8;
807 }
808 } else {
809 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
810 isp->isp_maxluns = 16384;
811 } else {
812 isp->isp_maxluns = 16;
813 }
814 }
815}
816
817/*
818 * Initialize Parameters of Hardware to a known state.
819 *
820 * Locks are held before coming here.
821 */
822
823void
824isp_init(struct ispsoftc *isp)
825{
826 /*
827 * Must do this first to get defaults established.
828 */
829 isp_setdfltparm(isp, 0);
830 if (IS_DUALBUS(isp)) {
831 isp_setdfltparm(isp, 1);
832 }
833 if (IS_FC(isp)) {
834 isp_fibre_init(isp);
835 } else {
836 isp_scsi_init(isp);
837 }
838}
839
840static void
841isp_scsi_init(struct ispsoftc *isp)
842{
843 sdparam *sdp_chan0, *sdp_chan1;
844 mbreg_t mbs;
845
846 sdp_chan0 = isp->isp_param;
847 sdp_chan1 = sdp_chan0;
848 if (IS_DUALBUS(isp)) {
849 sdp_chan1++;
850 }
851
852 /*
853 * If we have no role (neither target nor initiator), return.
854 */
855 if (isp->isp_role == ISP_ROLE_NONE) {
856 return;
857 }
858
859 /* First do overall per-card settings. */
860
861 /*
862 * If we have fast memory timing enabled, turn it on.
863 */
864 if (sdp_chan0->isp_fast_mttr) {
865 ISP_WRITE(isp, RISC_MTR, 0x1313);
866 }
867
868 /*
869 * Set Retry Delay and Count.
870 * You set both channels at the same time.
871 */
872 mbs.param[0] = MBOX_SET_RETRY_COUNT;
873 mbs.param[1] = sdp_chan0->isp_retry_count;
874 mbs.param[2] = sdp_chan0->isp_retry_delay;
875 mbs.param[6] = sdp_chan1->isp_retry_count;
876 mbs.param[7] = sdp_chan1->isp_retry_delay;
877
878 isp_mboxcmd(isp, &mbs, MBLOGALL);
879 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
880 return;
881 }
882
883 /*
884 * Set ASYNC DATA SETUP time. This is very important.
885 */
886 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
887 mbs.param[1] = sdp_chan0->isp_async_data_setup;
888 mbs.param[2] = sdp_chan1->isp_async_data_setup;
889 isp_mboxcmd(isp, &mbs, MBLOGALL);
890 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
891 return;
892 }
893
894 /*
895 * Set ACTIVE Negation State.
896 */
897 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
898 mbs.param[1] =
899 (sdp_chan0->isp_req_ack_active_neg << 4) |
900 (sdp_chan0->isp_data_line_active_neg << 5);
901 mbs.param[2] =
902 (sdp_chan1->isp_req_ack_active_neg << 4) |
903 (sdp_chan1->isp_data_line_active_neg << 5);
904
905 isp_mboxcmd(isp, &mbs, MBLOGNONE);
906 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
907 isp_prt(isp, ISP_LOGERR,
908 "failed to set active negation state (%d,%d), (%d,%d)",
909 sdp_chan0->isp_req_ack_active_neg,
910 sdp_chan0->isp_data_line_active_neg,
911 sdp_chan1->isp_req_ack_active_neg,
912 sdp_chan1->isp_data_line_active_neg);
913 /*
914 * But don't return.
915 */
916 }
917
918 /*
919 * Set the Tag Aging limit
920 */
921 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
922 mbs.param[1] = sdp_chan0->isp_tag_aging;
923 mbs.param[2] = sdp_chan1->isp_tag_aging;
924 isp_mboxcmd(isp, &mbs, MBLOGALL);
925 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
926 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
927 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
928 return;
929 }
930
931 /*
932 * Set selection timeout.
933 */
934 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
935 mbs.param[1] = sdp_chan0->isp_selection_timeout;
936 mbs.param[2] = sdp_chan1->isp_selection_timeout;
937 isp_mboxcmd(isp, &mbs, MBLOGALL);
938 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
939 return;
940 }
941
942 /* now do per-channel settings */
943 isp_scsi_channel_init(isp, 0);
944 if (IS_DUALBUS(isp))
945 isp_scsi_channel_init(isp, 1);
946
947 /*
948 * Now enable request/response queues
949 */
950
951 if (IS_ULTRA2(isp) || IS_1240(isp)) {
952 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
953 mbs.param[1] = RESULT_QUEUE_LEN(isp);
954 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
955 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
956 mbs.param[4] = 0;
957 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
958 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
959 isp_mboxcmd(isp, &mbs, MBLOGALL);
960 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
961 return;
962 }
963 isp->isp_residx = mbs.param[5];
964
965 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
966 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
967 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
968 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
969 mbs.param[5] = 0;
970 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
971 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
972 isp_mboxcmd(isp, &mbs, MBLOGALL);
973 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
974 return;
975 }
976 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
977 } else {
978 mbs.param[0] = MBOX_INIT_RES_QUEUE;
979 mbs.param[1] = RESULT_QUEUE_LEN(isp);
980 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
981 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
982 mbs.param[4] = 0;
983 isp_mboxcmd(isp, &mbs, MBLOGALL);
984 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
985 return;
986 }
987 isp->isp_residx = mbs.param[5];
988
989 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
990 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
991 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
992 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
993 mbs.param[5] = 0;
994 isp_mboxcmd(isp, &mbs, MBLOGALL);
995 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
996 return;
997 }
998 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
999 }
1000
1001 /*
1002 * Turn on Fast Posting, LVD transitions
1003 *
1004 * Ultra2 F/W always has had fast posting (and LVD transitions)
1005 *
1006 * Ultra and older (i.e., SBus) cards may not. It's just safer
1007 * to assume not for them.
1008 */
1009
1010 mbs.param[0] = MBOX_SET_FW_FEATURES;
1011 mbs.param[1] = 0;
1012 if (IS_ULTRA2(isp))
1013 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1014#ifndef ISP_NO_RIO
1015 if (IS_ULTRA2(isp) || IS_1240(isp))
1016 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1017#else
1018#ifndef ISP_NO_FASTPOST
1019 if (IS_ULTRA2(isp) || IS_1240(isp))
1020 mbs.param[1] |= FW_FEATURE_FAST_POST;
1021#endif
1022#endif
1023 if (mbs.param[1] != 0) {
1024 u_int16_t sfeat = mbs.param[1];
1025 isp_mboxcmd(isp, &mbs, MBLOGALL);
1026 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1027 isp_prt(isp, ISP_LOGINFO,
1028 "Enabled FW features (0x%x)", sfeat);
1029 }
1030 }
1031
1032 /*
1033 * Let the outer layers decide whether to issue a SCSI bus reset.
1034 */
1035 isp->isp_state = ISP_INITSTATE;
1036}
1037
1038static void
1039isp_scsi_channel_init(struct ispsoftc *isp, int channel)
1040{
1041 sdparam *sdp;
1042 mbreg_t mbs;
1043 int tgt;
1044
1045 sdp = isp->isp_param;
1046 sdp += channel;
1047
1048 /*
1049 * Set (possibly new) Initiator ID.
1050 */
1051 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1052 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1053 isp_mboxcmd(isp, &mbs, MBLOGALL);
1054 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1055 return;
1056 }
1057 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1058 sdp->isp_initiator_id, channel);
1059
1060
1061 /*
1062 * Set current per-target parameters to an initial safe minimum.
1063 */
1064 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1065 int lun;
1066 u_int16_t sdf;
1067
1068 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1069 continue;
1070 }
1071#ifndef ISP_TARGET_MODE
1072 sdf = sdp->isp_devparam[tgt].goal_flags;
1073 sdf &= DPARM_SAFE_DFLT;
1074 /*
1075 * It is not quite clear when this changed over so that
1076 * we could force narrow and async for 1000/1020 cards,
1077 * but assume that this is only the case for loaded
1078 * firmware.
1079 */
1080 if (isp->isp_loaded_fw) {
1081 sdf |= DPARM_NARROW | DPARM_ASYNC;
1082 }
1083#else
1084 /*
1085 * The !$*!)$!$)* f/w uses the same index into some
1086 * internal table to decide how to respond to negotiations,
1087 * so if we've said "let's be safe" for ID X, and ID X
1088 * selects *us*, the negotiations will back to 'safe'
1089 * (as in narrow/async). What the f/w *should* do is
1090 * use the initiator id settings to decide how to respond.
1091 */
1092 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1093#endif
1094 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1095 mbs.param[1] = (channel << 15) | (tgt << 8);
1096 mbs.param[2] = sdf;
1097 if ((sdf & DPARM_SYNC) == 0) {
1098 mbs.param[3] = 0;
1099 } else {
1100 mbs.param[3] =
1101 (sdp->isp_devparam[tgt].goal_offset << 8) |
1102 (sdp->isp_devparam[tgt].goal_period);
1103 }
1104 isp_prt(isp, ISP_LOGDEBUG0,
1105 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1106 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1107 mbs.param[3] & 0xff);
1108 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1109 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1110 sdf = DPARM_SAFE_DFLT;
1111 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1112 mbs.param[1] = (tgt << 8) | (channel << 15);
1113 mbs.param[2] = sdf;
1114 mbs.param[3] = 0;
1115 isp_mboxcmd(isp, &mbs, MBLOGALL);
1116 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1117 continue;
1118 }
1119 }
1120
1121 /*
1122 * We don't update any information directly from the f/w
1123 * because we need to run at least one command to cause a
1124 * new state to be latched up. So, we just assume that we
1125 * converge to the values we just had set.
1126 *
1127 * Ensure that we don't believe tagged queuing is enabled yet.
1128 * It turns out that sometimes the ISP just ignores our
1129 * attempts to set parameters for devices that it hasn't
1130 * seen yet.
1131 */
1132 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1133 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1134 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1135 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1136 mbs.param[2] = sdp->isp_max_queue_depth;
1137 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1138 isp_mboxcmd(isp, &mbs, MBLOGALL);
1139 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1140 break;
1141 }
1142 }
1143 }
1144 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1145 if (sdp->isp_devparam[tgt].dev_refresh) {
1146 isp->isp_sendmarker |= (1 << channel);
1147 isp->isp_update |= (1 << channel);
1148 break;
1149 }
1150 }
1151}
1152
1153/*
1154 * Fibre Channel specific initialization.
1155 *
1156 * Locks are held before coming here.
1157 */
1158static void
1159isp_fibre_init(struct ispsoftc *isp)
1160{
1161 fcparam *fcp;
1162 isp_icb_t local, *icbp = &local;
1163 mbreg_t mbs;
1164 int loopid;
1165 u_int64_t nwwn, pwwn;
1166
1167 fcp = isp->isp_param;
1168
1169 /*
1170 * Do this *before* initializing the firmware.
1171 */
1172 isp_mark_getpdb_all(isp);
1173 fcp->isp_fwstate = FW_CONFIG_WAIT;
1174 fcp->isp_loopstate = LOOP_NIL;
1175
1176 /*
1177 * If we have no role (neither target nor initiator), return.
1178 */
1179 if (isp->isp_role == ISP_ROLE_NONE) {
1180 return;
1181 }
1182
1183 loopid = fcp->isp_loopid;
1184 MEMZERO(icbp, sizeof (*icbp));
1185 icbp->icb_version = ICB_VERSION1;
1186
1187 /*
1188 * Firmware Options are either retrieved from NVRAM or
1189 * are patched elsewhere. We check them for sanity here
1190 * and make changes based on board revision, but otherwise
1191 * let others decide policy.
1192 */
1193
1194 /*
1195 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1196 */
1197 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1198 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1199 }
1200
1201 /*
1202 * We have to use FULL LOGIN even though it resets the loop too much
1203 * because otherwise port database entries don't get updated after
1204 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1205 */
1206 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1207 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1208 }
1209
1210 /*
1211 * Insist on Port Database Update Async notifications
1212 */
1213 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1214
1215 /*
1216 * Make sure that target role reflects into fwoptions.
1217 */
1218 if (isp->isp_role & ISP_ROLE_TARGET) {
1219 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1220 } else {
1221 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1222 }
1223
1224 /*
1225 * Propagate all of this into the ICB structure.
1226 */
1227 icbp->icb_fwoptions = fcp->isp_fwoptions;
1228 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1229 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1230 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1231 isp_prt(isp, ISP_LOGERR,
1232 "bad frame length (%d) from NVRAM- using %d",
1233 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1234 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1235 }
1236 icbp->icb_maxalloc = fcp->isp_maxalloc;
1237 if (icbp->icb_maxalloc < 1) {
1238 isp_prt(isp, ISP_LOGERR,
1239 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1240 icbp->icb_maxalloc = 16;
1241 }
1242 icbp->icb_execthrottle = fcp->isp_execthrottle;
1243 if (icbp->icb_execthrottle < 1) {
1244 isp_prt(isp, ISP_LOGERR,
1245 "bad execution throttle of %d- using 16",
1246 fcp->isp_execthrottle);
1247 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1248 }
1249 icbp->icb_retry_delay = fcp->isp_retry_delay;
1250 icbp->icb_retry_count = fcp->isp_retry_count;
1251 icbp->icb_hardaddr = loopid;
1252 /*
1253 * Right now we just set extended options to prefer point-to-point
1254 * over loop based upon some soft config options.
1255 *
1256 * NB: for the 2300, ICBOPT_EXTENDED is required.
1257 */
1258 if (IS_2200(isp) || IS_23XX(isp)) {
1259 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1260 /*
1261 * Prefer or force Point-To-Point instead Loop?
1262 */
1263 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1264 case ISP_CFG_NPORT:
1265 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1266 break;
1267 case ISP_CFG_NPORT_ONLY:
1268 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1269 break;
1270 case ISP_CFG_LPORT_ONLY:
1271 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1272 break;
1273 default:
1274 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1275 break;
1276 }
1277 if (IS_23XX(isp)) {
1278 /*
1279 * QLogic recommends that FAST Posting be turned
1280 * off for 23XX cards and instead allow the HBA
1281 * to write response queue entries and interrupt
1282 * after a delay (ZIO).
1283 *
1284 * If we set ZIO, it will disable fast posting,
1285 * so we don't need to clear it in fwoptions.
1286 */
1287 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1288
1289 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1290 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1291 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1292 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1293 } else {
1294 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1295 }
1296 }
1297 }
1298
1299#ifndef ISP_NO_RIO_FC
1300 /*
1301 * RIO seems to be enabled in 2100s for fw >= 1.17.0.
1302 *
1303 * I've had some questionable problems with RIO on 2200.
1304 * More specifically, on a 2204 I had problems with RIO
1305 * on a Linux system where I was dropping commands right
1306 * and left. It's not clear to me what the actual problem
1307 * was.
1308 *
1309 * 23XX Cards do not support RIO. Instead they support ZIO.
1310 */
1311#if 0
1312 if (!IS_23XX(isp) && ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1313 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1314 icbp->icb_racctimer = 4;
1315 icbp->icb_idelaytimer = 8;
1316 }
1317#endif
1318#endif
1319
1320 /*
1321 * For 22XX > 2.1.26 && 23XX, set someoptions.
1322 * XXX: Probably okay for newer 2100 f/w too.
1323 */
1324 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1325 /*
1326 * Turn on LIP F8 async event (1)
1327 * Turn on generate AE 8013 on all LIP Resets (2)
1328 * Disable LIP F7 switching (8)
1329 */
1330 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1331 mbs.param[1] = 0xb;
1332 mbs.param[2] = 0;
1333 mbs.param[3] = 0;
1334 isp_mboxcmd(isp, &mbs, MBLOGALL);
1335 }
1336 icbp->icb_logintime = 30; /* 30 second login timeout */
1337
1338 if (IS_23XX(isp)) {
1339 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
1340 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
1341 ISP_WRITE(isp, isp->isp_respinrp, 0);
1342 ISP_WRITE(isp, isp->isp_respoutrp, 0);
1343 }
1344
1345 nwwn = ISP_NODEWWN(isp);
1346 pwwn = ISP_PORTWWN(isp);
1347 if (nwwn && pwwn) {
1348 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1349 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1350 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1351 isp_prt(isp, ISP_LOGDEBUG1,
1352 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1353 ((u_int32_t) (nwwn >> 32)),
1354 ((u_int32_t) (nwwn & 0xffffffff)),
1355 ((u_int32_t) (pwwn >> 32)),
1356 ((u_int32_t) (pwwn & 0xffffffff)));
1357 } else {
1358 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1359 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1360 }
1361 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1362 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1363 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1364 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1365 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1366 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1367 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1368 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1369 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1370 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1371 isp_prt(isp, ISP_LOGDEBUG0,
1372 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1373 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1374
1375 FC_SCRATCH_ACQUIRE(isp);
1376 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1377
1378 /*
1379 * Init the firmware
1380 */
1381 mbs.param[0] = MBOX_INIT_FIRMWARE;
1382 mbs.param[1] = 0;
1383 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1384 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1385 mbs.param[4] = 0;
1386 mbs.param[5] = 0;
1387 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1388 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1389 isp_mboxcmd(isp, &mbs, MBLOGALL);
1390 FC_SCRATCH_RELEASE(isp);
1391 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1392 return;
1393 }
1394 isp->isp_reqidx = isp->isp_reqodx = 0;
1395 isp->isp_residx = 0;
1396 isp->isp_sendmarker = 1;
1397
1398 /*
1399 * Whatever happens, we're now committed to being here.
1400 */
1401 isp->isp_state = ISP_INITSTATE;
1402}
1403
1404/*
1405 * Fibre Channel Support- get the port database for the id.
1406 *
1407 * Locks are held before coming here. Return 0 if success,
1408 * else failure.
1409 */
1410
1411static int
1412isp_getmap(struct ispsoftc *isp, fcpos_map_t *map)
1413{
1414 fcparam *fcp = (fcparam *) isp->isp_param;
1415 mbreg_t mbs;
1416
1417 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1418 mbs.param[1] = 0;
1419 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1420 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1421 /*
1422 * Unneeded. For the 2100, except for initializing f/w, registers
1423 * 4/5 have to not be written to.
1424 * mbs.param[4] = 0;
1425 * mbs.param[5] = 0;
1426 *
1427 */
1428 mbs.param[6] = 0;
1429 mbs.param[7] = 0;
1430 FC_SCRATCH_ACQUIRE(isp);
1431 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1432 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1433 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1434 map->fwmap = mbs.param[1] != 0;
1435 FC_SCRATCH_RELEASE(isp);
1436 return (0);
1437 }
1438 FC_SCRATCH_RELEASE(isp);
1439 return (-1);
1440}
1441
1442static void
1443isp_mark_getpdb_all(struct ispsoftc *isp)
1444{
1445 fcparam *fcp = (fcparam *) isp->isp_param;
1446 int i;
1447 for (i = 0; i < MAX_FC_TARG; i++) {
1448 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1449 }
1450}
1451
1452static int
1453isp_getpdb(struct ispsoftc *isp, int id, isp_pdb_t *pdbp)
1454{
1455 fcparam *fcp = (fcparam *) isp->isp_param;
1456 mbreg_t mbs;
1457
1458 mbs.param[0] = MBOX_GET_PORT_DB;
1459 mbs.param[1] = id << 8;
1460 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1461 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1462 /*
1463 * Unneeded. For the 2100, except for initializing f/w, registers
1464 * 4/5 have to not be written to.
1465 * mbs.param[4] = 0;
1466 * mbs.param[5] = 0;
1467 *
1468 */
1469 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1470 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1471 FC_SCRATCH_ACQUIRE(isp);
1472 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1473 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1474 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1475 FC_SCRATCH_RELEASE(isp);
1476 return (0);
1477 }
1478 FC_SCRATCH_RELEASE(isp);
1479 return (-1);
1480}
1481
1482static u_int64_t
1483isp_get_portname(struct ispsoftc *isp, int loopid, int nodename)
1484{
1485 u_int64_t wwn = 0;
1486 mbreg_t mbs;
1487
1488 mbs.param[0] = MBOX_GET_PORT_NAME;
1489 mbs.param[1] = loopid << 8;
1490 if (nodename)
1491 mbs.param[1] |= 1;
1492 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1493 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1494 wwn =
1495 (((u_int64_t)(mbs.param[2] & 0xff)) << 56) |
1496 (((u_int64_t)(mbs.param[2] >> 8)) << 48) |
1497 (((u_int64_t)(mbs.param[3] & 0xff)) << 40) |
1498 (((u_int64_t)(mbs.param[3] >> 8)) << 32) |
1499 (((u_int64_t)(mbs.param[6] & 0xff)) << 24) |
1500 (((u_int64_t)(mbs.param[6] >> 8)) << 16) |
1501 (((u_int64_t)(mbs.param[7] & 0xff)) << 8) |
1502 (((u_int64_t)(mbs.param[7] >> 8)));
1503 }
1504 return (wwn);
1505}
1506
1507/*
1508 * Make sure we have good FC link and know our Loop ID.
1509 */
1510
1511static int
1512isp_fclink_test(struct ispsoftc *isp, int usdelay)
1513{
1514 static char *toponames[] = {
1515 "Private Loop",
1516 "FL Port",
1517 "N-Port to N-Port",
1518 "F Port",
1519 "F Port (no FLOGI_ACC response)"
1520 };
1521 mbreg_t mbs;
1522 int count, check_for_fabric;
1523 u_int8_t lwfs;
1524 fcparam *fcp;
1525 struct lportdb *lp;
1526 isp_pdb_t pdb;
1527
1528 fcp = isp->isp_param;
1529
1530 /*
1531 * XXX: Here is where we would start a 'loop dead' timeout
1532 */
1533
1534 /*
1535 * Wait up to N microseconds for F/W to go to a ready state.
1536 */
1537 lwfs = FW_CONFIG_WAIT;
1538 count = 0;
1539 while (count < usdelay) {
1540 u_int64_t enano;
1541 u_int32_t wrk;
1542 NANOTIME_T hra, hrb;
1543
1544 GET_NANOTIME(&hra);
1545 isp_fw_state(isp);
1546 if (lwfs != fcp->isp_fwstate) {
1547 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1548 isp2100_fw_statename((int)lwfs),
1549 isp2100_fw_statename((int)fcp->isp_fwstate));
1550 lwfs = fcp->isp_fwstate;
1551 }
1552 if (fcp->isp_fwstate == FW_READY) {
1553 break;
1554 }
1555 GET_NANOTIME(&hrb);
1556
1557 /*
1558 * Get the elapsed time in nanoseconds.
1559 * Always guaranteed to be non-zero.
1560 */
1561 enano = NANOTIME_SUB(&hrb, &hra);
1562
1563 isp_prt(isp, ISP_LOGDEBUG1,
1564 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1565 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1566 (u_int32_t)(enano >> 32), (u_int32_t)(enano & 0xffffffff));
1567
1568 /*
1569 * If the elapsed time is less than 1 millisecond,
1570 * delay a period of time up to that millisecond of
1571 * waiting.
1572 *
1573 * This peculiar code is an attempt to try and avoid
1574 * invoking u_int64_t math support functions for some
1575 * platforms where linkage is a problem.
1576 */
1577 if (enano < (1000 * 1000)) {
1578 count += 1000;
1579 enano = (1000 * 1000) - enano;
1580 while (enano > (u_int64_t) 4000000000U) {
1581 USEC_SLEEP(isp, 4000000);
1582 enano -= (u_int64_t) 4000000000U;
1583 }
1584 wrk = enano;
1585 wrk /= 1000;
1586 USEC_SLEEP(isp, wrk);
1587 } else {
1588 while (enano > (u_int64_t) 4000000000U) {
1589 count += 4000000;
1590 enano -= (u_int64_t) 4000000000U;
1591 }
1592 wrk = enano;
1593 count += (wrk / 1000);
1594 }
1595 }
1596
1597 /*
1598 * If we haven't gone to 'ready' state, return.
1599 */
1600 if (fcp->isp_fwstate != FW_READY) {
1601 return (-1);
1602 }
1603
1604 /*
1605 * Get our Loop ID (if possible). We really need to have it.
1606 */
1607 mbs.param[0] = MBOX_GET_LOOP_ID;
1608 isp_mboxcmd(isp, &mbs, MBLOGALL);
1609 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1610 return (-1);
1611 }
1612 fcp->isp_loopid = mbs.param[1];
1613 if (IS_2200(isp) || IS_23XX(isp)) {
1614 int topo = (int) mbs.param[6];
1615 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1616 topo = TOPO_PTP_STUB;
1617 fcp->isp_topo = topo;
1618 } else {
1619 fcp->isp_topo = TOPO_NL_PORT;
1620 }
1621 fcp->isp_portid = fcp->isp_alpa = mbs.param[2] & 0xff;
1622
1623 /*
1624 * Check to see if we're on a fabric by trying to see if we
1625 * can talk to the fabric name server. This can be a bit
1626 * tricky because if we're a 2100, we should check always
1627 * (in case we're connected to a server doing aliasing).
1628 */
1629 fcp->isp_onfabric = 0;
1630
1631 if (IS_2100(isp)) {
1632 /*
1633 * Don't bother with fabric if we are using really old
1634 * 2100 firmware. It's just not worth it.
1635 */
1636 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1637 check_for_fabric = 1;
1638 } else {
1639 check_for_fabric = 0;
1640 }
1641 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1642 fcp->isp_topo == TOPO_F_PORT) {
1643 check_for_fabric = 1;
1644 } else
1645 check_for_fabric = 0;
1646
1647 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1648 int loopid = FL_PORT_ID;
1649 if (IS_2100(isp)) {
1650 fcp->isp_topo = TOPO_FL_PORT;
1651 }
1652
1653 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1654 /*
1655 * Crock.
1656 */
1657 fcp->isp_topo = TOPO_NL_PORT;
1658 goto not_on_fabric;
1659 }
1660 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1661
1662 /*
1663 * Save the Fabric controller's port database entry.
1664 */
1665 lp = &fcp->portdb[loopid];
1666 lp->node_wwn =
1667 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1668 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1669 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1670 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1671 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1672 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1673 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1674 (((u_int64_t)pdb.pdb_nodename[7]));
1675 lp->port_wwn =
1676 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1677 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1678 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1679 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1680 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1681 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1682 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1683 (((u_int64_t)pdb.pdb_portname[7]));
1684 lp->roles =
1685 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1686 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1687 lp->loopid = pdb.pdb_loopid;
1688 lp->loggedin = lp->valid = 1;
1689 fcp->isp_onfabric = 1;
1690 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1691 isp_register_fc4_type(isp);
1692 } else {
1693not_on_fabric:
1694 fcp->isp_onfabric = 0;
1695 fcp->portdb[FL_PORT_ID].valid = 0;
1696 }
1697
1698 fcp->isp_gbspeed = 1;
1699 if (IS_23XX(isp)) {
1700 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1701 mbs.param[1] = MBGSD_GET_RATE;
1702 /* mbs.param[2] undefined if we're just getting rate */
1703 isp_mboxcmd(isp, &mbs, MBLOGALL);
1704 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1705 if (mbs.param[1] == MBGSD_TWOGB) {
1706 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1707 fcp->isp_gbspeed = 2;
1708 }
1709 }
1710 }
1711
1712 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid, fcp->isp_alpa,
1713 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1714
1715 /*
1716 * Announce ourselves, too. This involves synthesizing an entry.
1717 */
1718 if (fcp->isp_iid_set == 0) {
1719 fcp->isp_iid_set = 1;
1720 fcp->isp_iid = fcp->isp_loopid;
1721 lp = &fcp->portdb[fcp->isp_iid];
1722 } else {
1723 lp = &fcp->portdb[fcp->isp_iid];
1724 if (fcp->isp_portid != lp->portid ||
1725 fcp->isp_loopid != lp->loopid ||
1726 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1727 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1728 lp->valid = 0;
1729 count = fcp->isp_iid;
1730 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1731 }
1732 }
1733 lp->loopid = fcp->isp_loopid;
1734 lp->portid = fcp->isp_portid;
1735 lp->node_wwn = ISP_NODEWWN(isp);
1736 lp->port_wwn = ISP_PORTWWN(isp);
1737 switch (isp->isp_role) {
1738 case ISP_ROLE_NONE:
1739 lp->roles = 0;
1740 break;
1741 case ISP_ROLE_TARGET:
1742 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1743 break;
1744 case ISP_ROLE_INITIATOR:
1745 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1746 break;
1747 case ISP_ROLE_BOTH:
1748 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1749 break;
1750 }
1751 lp->loggedin = lp->valid = 1;
1752 count = fcp->isp_iid;
1753 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1754 return (0);
1755}
1756
1757static char *
1758isp2100_fw_statename(int state)
1759{
1760 switch(state) {
1761 case FW_CONFIG_WAIT: return "Config Wait";
1762 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1763 case FW_WAIT_LOGIN: return "Wait Login";
1764 case FW_READY: return "Ready";
1765 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1766 case FW_ERROR: return "Error";
1767 case FW_REINIT: return "Re-Init";
1768 case FW_NON_PART: return "Nonparticipating";
1769 default: return "?????";
1770 }
1771}
1772
1773/*
1774 * Synchronize our soft copy of the port database with what the f/w thinks
1775 * (with a view toward possibly for a specific target....)
1776 */
1777
1778static int
1779isp_pdb_sync(struct ispsoftc *isp)
1780{
1781 struct lportdb *lp;
1782 fcparam *fcp = isp->isp_param;
1783 isp_pdb_t pdb;
1784 int loopid, base, lim;
1785
1786 /*
1787 * Make sure we're okay for doing this right now.
1788 */
1789 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1790 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1791 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1792 return (-1);
1793 }
1794
1795 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1796 fcp->isp_topo == TOPO_N_PORT) {
1797 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1798 if (isp_scan_loop(isp) != 0) {
1799 return (-1);
1800 }
1801 }
1802 }
1803 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1804
1805 /*
1806 * If we get this far, we've settled our differences with the f/w
1807 * (for local loop device) and we can say that the loop state is ready.
1808 */
1809
1810 if (fcp->isp_topo == TOPO_NL_PORT) {
1811 fcp->loop_seen_once = 1;
1812 fcp->isp_loopstate = LOOP_READY;
1813 return (0);
1814 }
1815
1816 /*
1817 * Find all Fabric Entities that didn't make it from one scan to the
1818 * next and let the world know they went away. Scan the whole database.
1819 */
1820 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1821 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1822 loopid = lp - fcp->portdb;
1823 lp->valid = 0; /* should already be set */
1824 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1825 MEMZERO((void *) lp, sizeof (*lp));
1826 continue;
1827 }
1828 lp->was_fabric_dev = lp->fabric_dev;
1829 }
1830
1831 if (fcp->isp_topo == TOPO_FL_PORT)
1832 base = FC_SNS_ID+1;
1833 else
1834 base = 0;
1835
1836 if (fcp->isp_topo == TOPO_N_PORT)
1837 lim = 1;
1838 else
1839 lim = MAX_FC_TARG;
1840
1841 /*
1842 * Now log in any fabric devices that the outer layer has
1843 * left for us to see. This seems the most sane policy
1844 * for the moment.
1845 */
1846 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1847 u_int32_t portid;
1848 mbreg_t mbs;
1849
1850 loopid = lp - fcp->portdb;
1851 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1852 continue;
1853 }
1854
1855 /*
1856 * Anything here?
1857 */
1858 if (lp->port_wwn == 0) {
1859 continue;
1860 }
1861
1862 /*
1863 * Don't try to log into yourself.
1864 */
1865 if ((portid = lp->portid) == fcp->isp_portid) {
1866 continue;
1867 }
1868
1869
1870 /*
1871 * If we'd been logged in- see if we still are and we haven't
1872 * changed. If so, no need to log ourselves out, etc..
1873 *
1874 * Unfortunately, our charming Qlogic f/w has decided to
1875 * return a valid port database entry for a fabric device
1876 * that has, in fact, gone away. And it hangs trying to
1877 * log it out.
1878 */
1879 if (lp->loggedin && lp->force_logout == 0 &&
1880 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1881 int nrole;
1882 u_int64_t nwwnn, nwwpn;
1883 nwwnn =
1884 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1885 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1886 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1887 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1888 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1889 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1890 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1891 (((u_int64_t)pdb.pdb_nodename[7]));
1892 nwwpn =
1893 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1894 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1895 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1896 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1897 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1898 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1899 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1900 (((u_int64_t)pdb.pdb_portname[7]));
1901 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1902 SVC3_ROLE_SHIFT;
1903 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1904 (u_int32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1905 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1906 lp->roles == nrole && lp->force_logout == 0) {
1907 lp->loggedin = lp->valid = 1;
1908 isp_prt(isp, ISP_LOGCONFIG, lretained,
1909 (int) (lp - fcp->portdb),
1910 (int) lp->loopid, lp->portid);
1911 continue;
1912 }
1913 }
1914
1915 if (fcp->isp_fwstate != FW_READY ||
1916 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1917 return (-1);
1918 }
1919
1920 /*
1921 * Force a logout if we were logged in.
1922 */
1923 if (lp->loggedin) {
1924 if (lp->force_logout ||
1925 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1926 mbs.param[0] = MBOX_FABRIC_LOGOUT;
1927 mbs.param[1] = lp->loopid << 8;
1928 mbs.param[2] = 0;
1929 mbs.param[3] = 0;
1930 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1931 isp_prt(isp, ISP_LOGINFO, plogout,
1932 (int) (lp - fcp->portdb), lp->loopid,
1933 lp->portid);
1934 }
1935 lp->force_logout = lp->loggedin = 0;
1936 if (fcp->isp_fwstate != FW_READY ||
1937 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1938 return (-1);
1939 }
1940 }
1941
1942 /*
1943 * And log in....
1944 */
1945 loopid = lp - fcp->portdb;
1946 lp->loopid = FL_PORT_ID;
1947 do {
1948 mbs.param[0] = MBOX_FABRIC_LOGIN;
1949 mbs.param[1] = loopid << 8;
1950 mbs.param[2] = portid >> 16;
1951 mbs.param[3] = portid & 0xffff;
1952 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
1953 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
1954 if (fcp->isp_fwstate != FW_READY ||
1955 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1956 return (-1);
1957 }
1958 switch (mbs.param[0]) {
1959 case MBOX_LOOP_ID_USED:
1960 /*
1961 * Try the next available loop id.
1962 */
1963 loopid++;
1964 break;
1965 case MBOX_PORT_ID_USED:
1966 /*
1967 * This port is already logged in.
1968 * Snaffle the loop id it's using if it's
1969 * nonzero, otherwise we're hosed.
1970 */
1971 if (mbs.param[1] != 0) {
1972 loopid = mbs.param[1];
1973 isp_prt(isp, ISP_LOGINFO, retained,
1974 loopid, (int) (lp - fcp->portdb),
1975 lp->portid);
1976 } else {
1977 loopid = MAX_FC_TARG;
1978 break;
1979 }
1980 /* FALLTHROUGH */
1981 case MBOX_COMMAND_COMPLETE:
1982 lp->loggedin = 1;
1983 lp->loopid = loopid;
1984 break;
1985 case MBOX_COMMAND_ERROR:
1986 isp_prt(isp, ISP_LOGINFO, plogierr,
1987 portid, mbs.param[1]);
1988 /* FALLTHROUGH */
1989 case MBOX_ALL_IDS_USED: /* We're outta IDs */
1990 default:
1991 loopid = MAX_FC_TARG;
1992 break;
1993 }
1994 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
1995
1996 /*
1997 * If we get here and we haven't set a Loop ID,
1998 * we failed to log into this device.
1999 */
2000
2001 if (lp->loopid == FL_PORT_ID) {
2002 lp->loopid = 0;
2003 continue;
2004 }
2005
2006 /*
2007 * Make sure we can get the approriate port information.
2008 */
2009 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2010 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2011 goto dump_em;
2012 }
2013
2014 if (fcp->isp_fwstate != FW_READY ||
2015 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2016 return (-1);
2017 }
2018
2019 if (pdb.pdb_loopid != lp->loopid) {
2020 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2021 lp->portid, pdb.pdb_loopid);
2022 goto dump_em;
2023 }
2024
2025 if (lp->portid != (u_int32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2026 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2027 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2028 goto dump_em;
2029 }
2030
2031 lp->roles =
2032 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2033 lp->node_wwn =
2034 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2035 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2036 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2037 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2038 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2039 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2040 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2041 (((u_int64_t)pdb.pdb_nodename[7]));
2042 lp->port_wwn =
2043 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2044 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2045 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2046 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2047 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2048 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2049 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2050 (((u_int64_t)pdb.pdb_portname[7]));
2051 /*
2052 * Check to make sure this all makes sense.
2053 */
2054 if (lp->node_wwn && lp->port_wwn) {
2055 lp->valid = 1;
2056 loopid = lp - fcp->portdb;
2057 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2058 continue;
2059 }
2060dump_em:
2061 lp->valid = 0;
2062 isp_prt(isp, ISP_LOGINFO,
2063 ldumped, loopid, lp->loopid, lp->portid);
2064 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2065 mbs.param[1] = lp->loopid << 8;
2066 mbs.param[2] = 0;
2067 mbs.param[3] = 0;
2068 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2069 if (fcp->isp_fwstate != FW_READY ||
2070 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2071 return (-1);
2072 }
2073 }
2074 /*
2075 * If we get here, we've for sure seen not only a valid loop
2076 * but know what is or isn't on it, so mark this for usage
2077 * in isp_start.
2078 */
2079 fcp->loop_seen_once = 1;
2080 fcp->isp_loopstate = LOOP_READY;
2081 return (0);
2082}
2083
2084static int
2085isp_scan_loop(struct ispsoftc *isp)
2086{
2087 struct lportdb *lp;
2088 fcparam *fcp = isp->isp_param;
2089 isp_pdb_t pdb;
2090 int loopid, lim, hival;
2091
2092 switch (fcp->isp_topo) {
2093 case TOPO_NL_PORT:
2094 hival = FL_PORT_ID;
2095 break;
2096 case TOPO_N_PORT:
2097 hival = 2;
2098 break;
2099 case TOPO_FL_PORT:
2100 hival = FC_PORT_ID;
2101 break;
2102 default:
2103 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2104 return (0);
2105 }
2106 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2107
2108 /*
2109 * make sure the temp port database is clean...
2110 */
2111 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2112
2113 /*
2114 * Run through the local loop ports and get port database info
2115 * for each loop ID.
2116 *
2117 * There's a somewhat unexplained situation where the f/w passes back
2118 * the wrong database entity- if that happens, just restart (up to
2119 * FL_PORT_ID times).
2120 */
2121 for (lim = loopid = 0; loopid < hival; loopid++) {
2122 lp = &fcp->tport[loopid];
2123
2124 /*
2125 * Don't even try for ourselves...
2126 */
2127 if (loopid == fcp->isp_loopid)
2128 continue;
2129
2130 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2131 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2132 return (-1);
2133 if (lp->node_wwn == 0)
2134 continue;
2135 lp->port_wwn = isp_get_portname(isp, loopid, 0);
2136 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2137 return (-1);
2138 if (lp->port_wwn == 0) {
2139 lp->node_wwn = 0;
2140 continue;
2141 }
2142
2143 /*
2144 * Get an entry....
2145 */
2146 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2147 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2148 return (-1);
2149 continue;
2150 }
2151 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2152 return (-1);
2153 }
2154
2155 /*
2156 * If the returned database element doesn't match what we
2157 * asked for, restart the process entirely (up to a point...).
2158 */
2159 if (pdb.pdb_loopid != loopid) {
2160 loopid = 0;
2161 if (lim++ < hival) {
2162 continue;
2163 }
2164 isp_prt(isp, ISP_LOGWARN,
2165 "giving up on synchronizing the port database");
2166 return (-1);
2167 }
2168
2169 /*
2170 * Save the pertinent info locally.
2171 */
2172 lp->node_wwn =
2173 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2174 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2175 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2176 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2177 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2178 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2179 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2180 (((u_int64_t)pdb.pdb_nodename[7]));
2181 lp->port_wwn =
2182 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2183 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2184 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2185 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2186 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2187 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2188 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2189 (((u_int64_t)pdb.pdb_portname[7]));
2190 lp->roles =
2191 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2192 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2193 lp->loopid = pdb.pdb_loopid;
2194 }
2195
2196 /*
2197 * Mark all of the permanent local loop database entries as invalid
2198 * (except our own entry).
2199 */
2200 for (loopid = 0; loopid < hival; loopid++) {
2201 if (loopid == fcp->isp_iid) {
2202 fcp->portdb[loopid].valid = 1;
2203 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2204 continue;
2205 }
2206 fcp->portdb[loopid].valid = 0;
2207 }
2208
2209 /*
2210 * Now merge our local copy of the port database into our saved copy.
2211 * Notify the outer layers of new devices arriving.
2212 */
2213 for (loopid = 0; loopid < hival; loopid++) {
2214 int i;
2215
2216 /*
2217 * If we don't have a non-zero Port WWN, we're not here.
2218 */
2219 if (fcp->tport[loopid].port_wwn == 0) {
2220 continue;
2221 }
2222
2223 /*
2224 * Skip ourselves.
2225 */
2226 if (loopid == fcp->isp_iid) {
2227 continue;
2228 }
2229
2230 /*
2231 * For the purposes of deciding whether this is the
2232 * 'same' device or not, we only search for an identical
2233 * Port WWN. Node WWNs may or may not be the same as
2234 * the Port WWN, and there may be multiple different
2235 * Port WWNs with the same Node WWN. It would be chaos
2236 * to have multiple identical Port WWNs, so we don't
2237 * allow that.
2238 */
2239
2240 for (i = 0; i < hival; i++) {
2241 int j;
2242 if (fcp->portdb[i].port_wwn == 0)
2243 continue;
2244 if (fcp->portdb[i].port_wwn !=
2245 fcp->tport[loopid].port_wwn)
2246 continue;
2247 /*
2248 * We found this WWN elsewhere- it's changed
2249 * loopids then. We don't change it's actual
2250 * position in our cached port database- we
2251 * just change the actual loop ID we'd use.
2252 */
2253 if (fcp->portdb[i].loopid != loopid) {
2254 isp_prt(isp, ISP_LOGINFO, portshift, i,
2255 fcp->portdb[i].loopid,
2256 fcp->portdb[i].portid, loopid,
2257 fcp->tport[loopid].portid);
2258 }
2259 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2260 fcp->portdb[i].loopid = loopid;
2261 fcp->portdb[i].valid = 1;
2262 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2263
2264 /*
2265 * Now make sure this Port WWN doesn't exist elsewhere
2266 * in the port database.
2267 */
2268 for (j = i+1; j < hival; j++) {
2269 if (fcp->portdb[i].port_wwn !=
2270 fcp->portdb[j].port_wwn) {
2271 continue;
2272 }
2273 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2274 /*
2275 * Invalidate the 'old' *and* 'new' ones.
2276 * This is really harsh and not quite right,
2277 * but if this happens, we really don't know
2278 * who is what at this point.
2279 */
2280 fcp->portdb[i].valid = 0;
2281 fcp->portdb[j].valid = 0;
2282 }
2283 break;
2284 }
2285
2286 /*
2287 * If we didn't traverse the entire port database,
2288 * then we found (and remapped) an existing entry.
2289 * No need to notify anyone- go for the next one.
2290 */
2291 if (i < hival) {
2292 isp_prt(isp, ISP_LOGINFO, retained,
2293 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2294 continue;
2295 }
2296
2297 /*
2298 * We've not found this Port WWN anywhere. It's a new entry.
2299 * See if we can leave it where it is (with target == loopid).
2300 */
2301 if (fcp->portdb[loopid].port_wwn != 0) {
2302 for (lim = 0; lim < hival; lim++) {
2303 if (fcp->portdb[lim].port_wwn == 0)
2304 break;
2305 }
2306 /* "Cannot Happen" */
2307 if (lim == hival) {
2308 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2309 continue;
2310 }
2311 i = lim;
2312 } else {
2313 i = loopid;
2314 }
2315
2316 /*
2317 * NB: The actual loopid we use here is loopid- we may
2318 * in fact be at a completely different index (target).
2319 */
2320 fcp->portdb[i].loopid = loopid;
2321 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2322 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2323 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2324 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2325 fcp->portdb[i].valid = 1;
2326
2327 /*
2328 * Tell the outside world we've arrived.
2329 */
2330 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2331 }
2332
2333 /*
2334 * Now find all previously used targets that are now invalid and
2335 * notify the outer layers that they're gone.
2336 */
2337 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2338 if (lp->valid || lp->port_wwn == 0) {
2339 continue;
2340 }
2341
2342 /*
2343 * Tell the outside world we've gone
2344 * away and erase our pdb entry.
2345 *
2346 */
2347 loopid = lp - fcp->portdb;
2348 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2349 MEMZERO((void *) lp, sizeof (*lp));
2350 }
2351 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2352 return (0);
2353}
2354
2355
2356static int
2357isp_fabric_mbox_cmd(struct ispsoftc *isp, mbreg_t *mbp)
2358{
2359 isp_mboxcmd(isp, mbp, MBLOGNONE);
2360 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2361 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2362 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2363 }
2364 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2365 char tbuf[16];
2366 char *m;
2367 switch (mbp->param[1]) {
2368 case 1:
2369 m = "No Loop";
2370 break;
2371 case 2:
2372 m = "Failed to allocate IOCB buffer";
2373 break;
2374 case 3:
2375 m = "Failed to allocate XCB buffer";
2376 break;
2377 case 4:
2378 m = "timeout or transmit failed";
2379 break;
2380 case 5:
2381 m = "no fabric loop";
2382 break;
2383 case 6:
2384 m = "remote device not a target";
2385 break;
2386 default:
2387 SNPRINTF(tbuf, sizeof tbuf, "%x",
2388 mbp->param[1]);
2389 m = tbuf;
2390 break;
2391 }
2392 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2393 }
2394 return (-1);
2395 }
2396
2397 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2398 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2399 return (-1);
2400 }
2401 return(0);
2402}
2403
2404#ifdef ISP_USE_GA_NXT
2405static int
2406isp_scan_fabric(struct ispsoftc *isp, int ftype)
2407{
2408 fcparam *fcp = isp->isp_param;
2409 u_int32_t portid, first_portid, last_portid;
2410 int hicap, last_port_same;
2411
2412 if (fcp->isp_onfabric == 0) {
2413 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2414 return (0);
2415 }
2416
2417 FC_SCRATCH_ACQUIRE(isp);
2418
2419 /*
2420 * Since Port IDs are 24 bits, we can check against having seen
2421 * anything yet with this value.
2422 */
2423 last_port_same = 0;
2424 last_portid = 0xffffffff; /* not a port */
2425 first_portid = portid = fcp->isp_portid;
2426 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2427
2428 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2429 mbreg_t mbs;
2430 sns_screq_t *rq;
2431 sns_ga_nxt_rsp_t *rs0, *rs1;
2432 struct lportdb lcl;
2433 u_int8_t sc[SNS_GA_NXT_RESP_SIZE];
2434
2435 rq = (sns_screq_t *)sc;
2436 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2437 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2438 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2439 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2440 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2441 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2442 rq->snscb_sblen = 6;
2443 rq->snscb_data[0] = SNS_GA_NXT;
2444 rq->snscb_data[4] = portid & 0xffff;
2445 rq->snscb_data[5] = (portid >> 16) & 0xff;
2446 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2447 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2448 mbs.param[0] = MBOX_SEND_SNS;
2449 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2450 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2451 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2452 /*
2453 * Leave 4 and 5 alone
2454 */
2455 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2456 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2457 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2458 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2459 fcp->isp_loopstate = LOOP_PDB_RCVD;
2460 }
2461 FC_SCRATCH_RELEASE(isp);
2462 return (-1);
2463 }
2464 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2465 rs1 = (sns_ga_nxt_rsp_t *) sc;
2466 rs0 = (sns_ga_nxt_rsp_t *) ((u_int8_t *)fcp->isp_scratch+0x100);
2467 isp_get_ga_nxt_response(isp, rs0, rs1);
2468 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2469 int level;
2470 if (rs1->snscb_cthdr.ct_reason == 9 &&
2471 rs1->snscb_cthdr.ct_explanation == 7)
2472 level = ISP_LOGDEBUG0;
2473 else
2474 level = ISP_LOGWARN;
2475 isp_prt(isp, level, swrej, "GA_NXT",
2476 rs1->snscb_cthdr.ct_reason,
2477 rs1->snscb_cthdr.ct_explanation, portid);
2478 FC_SCRATCH_RELEASE(isp);
2479 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2480 return (0);
2481 }
2482 portid =
2483 (((u_int32_t) rs1->snscb_port_id[0]) << 16) |
2484 (((u_int32_t) rs1->snscb_port_id[1]) << 8) |
2485 (((u_int32_t) rs1->snscb_port_id[2]));
2486
2487 /*
2488 * XXX: We should check to make sure that this entry
2489 * XXX: supports the type(s) we are interested in.
2490 */
2491 /*
2492 * Okay, we now have information about a fabric object.
2493 * If it is the type we're interested in, tell the outer layers
2494 * about it. The outer layer needs to know: Port ID, WWNN,
2495 * WWPN, FC4 type, and port type.
2496 *
2497 * The lportdb structure is adequate for this.
2498 */
2499 MEMZERO(&lcl, sizeof (lcl));
2500 lcl.port_type = rs1->snscb_port_type;
2501 lcl.fc4_type = ftype;
2502 lcl.portid = portid;
2503 lcl.node_wwn =
2504 (((u_int64_t)rs1->snscb_nodename[0]) << 56) |
2505 (((u_int64_t)rs1->snscb_nodename[1]) << 48) |
2506 (((u_int64_t)rs1->snscb_nodename[2]) << 40) |
2507 (((u_int64_t)rs1->snscb_nodename[3]) << 32) |
2508 (((u_int64_t)rs1->snscb_nodename[4]) << 24) |
2509 (((u_int64_t)rs1->snscb_nodename[5]) << 16) |
2510 (((u_int64_t)rs1->snscb_nodename[6]) << 8) |
2511 (((u_int64_t)rs1->snscb_nodename[7]));
2512 lcl.port_wwn =
2513 (((u_int64_t)rs1->snscb_portname[0]) << 56) |
2514 (((u_int64_t)rs1->snscb_portname[1]) << 48) |
2515 (((u_int64_t)rs1->snscb_portname[2]) << 40) |
2516 (((u_int64_t)rs1->snscb_portname[3]) << 32) |
2517 (((u_int64_t)rs1->snscb_portname[4]) << 24) |
2518 (((u_int64_t)rs1->snscb_portname[5]) << 16) |
2519 (((u_int64_t)rs1->snscb_portname[6]) << 8) |
2520 (((u_int64_t)rs1->snscb_portname[7]));
2521
2522 /*
2523 * Does this fabric object support the type we want?
2524 * If not, skip it.
2525 */
2526 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2527 if (first_portid == portid) {
2528 lcl.last_fabric_dev = 1;
2529 } else {
2530 lcl.last_fabric_dev = 0;
2531 }
2532 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2533 } else {
2534 isp_prt(isp, ISP_LOGDEBUG0,
2535 "PortID 0x%x doesn't support FC4 type 0x%x",
2536 portid, ftype);
2537 }
2538 if (first_portid == portid) {
2539 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2540 FC_SCRATCH_RELEASE(isp);
2541 return (0);
2542 }
2543 if (portid == last_portid) {
2544 if (last_port_same++ > 20) {
2545 isp_prt(isp, ISP_LOGWARN,
2546 "tangled fabric database detected");
2547 break;
2548 }
2549 } else {
2550 last_port_same = 0 ;
2551 last_portid = portid;
2552 }
2553 }
2554 FC_SCRATCH_RELEASE(isp);
2555 if (hicap >= GA_NXT_MAX) {
2556 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2557 }
2558 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2559 return (0);
2560}
2561#else
2562#define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2563#define NGENT ((GIDLEN - 16) >> 2)
2564
2565#define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2566#define GXOFF (256)
2567
2568static int
2569isp_scan_fabric(struct ispsoftc *isp, int ftype)
2570{
2571 fcparam *fcp = FCPARAM(isp);
2572 mbreg_t mbs;
2573 int i;
2574 sns_gid_ft_req_t *rq;
2575 sns_gid_ft_rsp_t *rs0, *rs1;
2576
2577 if (fcp->isp_onfabric == 0) {
2578 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2579 return (0);
2580 }
2581
2582 FC_SCRATCH_ACQUIRE(isp);
2583 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2584
2585 rq = (sns_gid_ft_req_t *)fcp->tport;
2586 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2587 rq->snscb_rblen = GIDLEN >> 1;
2588 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2589 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2590 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2591 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2592 rq->snscb_sblen = 6;
2593 rq->snscb_cmd = SNS_GID_FT;
2594 rq->snscb_mword_div_2 = NGENT;
2595 rq->snscb_fc4_type = ftype;
2596 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2597 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2598 mbs.param[0] = MBOX_SEND_SNS;
2599 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2600 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2601 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2602
2603 /*
2604 * Leave 4 and 5 alone
2605 */
2606 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2607 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2608 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2609 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2610 fcp->isp_loopstate = LOOP_PDB_RCVD;
2611 }
2612 FC_SCRATCH_RELEASE(isp);
2613 return (-1);
2614 }
2615 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2616 FC_SCRATCH_RELEASE(isp);
2617 return (-1);
2618 }
2619 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2620 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2621 rs0 = (sns_gid_ft_rsp_t *) ((u_int8_t *)fcp->isp_scratch+IGPOFF);
2622 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2623 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2624 int level;
2625 if (rs1->snscb_cthdr.ct_reason == 9 &&
2626 rs1->snscb_cthdr.ct_explanation == 7)
2627 level = ISP_LOGDEBUG0;
2628 else
2629 level = ISP_LOGWARN;
2630 isp_prt(isp, level, swrej, "GID_FT",
2631 rs1->snscb_cthdr.ct_reason,
2632 rs1->snscb_cthdr.ct_explanation, 0);
2633 FC_SCRATCH_RELEASE(isp);
2634 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2635 return (0);
2636 }
2637
2638 /*
2639 * Okay, we now have a list of Port IDs for this class of device.
2640 * Go through the list and for each one get the WWPN/WWNN for it
2641 * and tell the outer layers about it. The outer layer needs to
2642 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2643 *
2644 * The lportdb structure is adequate for this.
2645 */
2646 i = -1;
2647 do {
2648 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2649 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2650 struct lportdb lcl;
2651#if 0
2652 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2653#endif
2654
2655 i++;
2656 MEMZERO(&lcl, sizeof (lcl));
2657 lcl.fc4_type = ftype;
2658 lcl.portid =
2659 (((u_int32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2660 (((u_int32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2661 (((u_int32_t) rs1->snscb_ports[i].portid[2]));
2662
2663 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2664 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2665 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2666 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2667 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2668 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2669 gq->snscb_sblen = 6;
2670 gq->snscb_cmd = SNS_GPN_ID;
2671 gq->snscb_portid = lcl.portid;
2672 isp_put_gxn_id_request(isp, gq,
2673 (sns_gxn_id_req_t *) fcp->isp_scratch);
2674 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2675 mbs.param[0] = MBOX_SEND_SNS;
2676 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2677 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2678 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2679 /*
2680 * Leave 4 and 5 alone
2681 */
2682 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2683 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2684 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2685 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2686 fcp->isp_loopstate = LOOP_PDB_RCVD;
2687 }
2688 FC_SCRATCH_RELEASE(isp);
2689 return (-1);
2690 }
2691 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2692 FC_SCRATCH_RELEASE(isp);
2693 return (-1);
2694 }
2695 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2696 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2697 isp_get_gxn_id_response(isp, gs0, gs1);
2698 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2699 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2700 gs1->snscb_cthdr.ct_reason,
2701 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2702 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2703 FC_SCRATCH_RELEASE(isp);
2704 return (-1);
2705 }
2706 continue;
2707 }
2708 lcl.port_wwn =
2709 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2710 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2711 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2712 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2713 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2714 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2715 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2716 (((u_int64_t)gs1->snscb_wwn[7]));
2717
2718 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2719 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2720 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2721 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2722 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2723 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2724 gq->snscb_sblen = 6;
2725 gq->snscb_cmd = SNS_GNN_ID;
2726 gq->snscb_portid = lcl.portid;
2727 isp_put_gxn_id_request(isp, gq,
2728 (sns_gxn_id_req_t *) fcp->isp_scratch);
2729 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2730 mbs.param[0] = MBOX_SEND_SNS;
2731 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2732 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2733 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2734 /*
2735 * Leave 4 and 5 alone
2736 */
2737 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2738 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2739 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2740 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2741 fcp->isp_loopstate = LOOP_PDB_RCVD;
2742 }
2743 FC_SCRATCH_RELEASE(isp);
2744 return (-1);
2745 }
2746 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2747 FC_SCRATCH_RELEASE(isp);
2748 return (-1);
2749 }
2750 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2751 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2752 isp_get_gxn_id_response(isp, gs0, gs1);
2753 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2754 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2755 gs1->snscb_cthdr.ct_reason,
2756 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2757 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2758 FC_SCRATCH_RELEASE(isp);
2759 return (-1);
2760 }
2761 continue;
2762 }
2763 lcl.node_wwn =
2764 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2765 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2766 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2767 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2768 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2769 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2770 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2771 (((u_int64_t)gs1->snscb_wwn[7]));
2772
2773 /*
2774 * The QLogic f/w is bouncing this with a parameter error.
2775 */
2776#if 0
2777 /*
2778 * Try and get FC4 Features (FC-GS-3 only).
2779 * We can use the sns_gxn_id_req_t for this request.
2780 */
2781 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2782 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2783 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2784 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2785 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2786 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2787 gq->snscb_sblen = 6;
2788 gq->snscb_cmd = SNS_GFF_ID;
2789 gq->snscb_portid = lcl.portid;
2790 isp_put_gxn_id_request(isp, gq,
2791 (sns_gxn_id_req_t *) fcp->isp_scratch);
2792 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2793 mbs.param[0] = MBOX_SEND_SNS;
2794 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2795 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2796 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2797 /*
2798 * Leave 4 and 5 alone
2799 */
2800 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2801 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2802 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2803 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2804 fcp->isp_loopstate = LOOP_PDB_RCVD;
2805 }
2806 FC_SCRATCH_RELEASE(isp);
2807 return (-1);
2808 }
2809 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2810 FC_SCRATCH_RELEASE(isp);
2811 return (-1);
2812 }
2813 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2814 fs0 = (sns_gff_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2815 isp_get_gff_id_response(isp, fs0, fs1);
2816 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2817 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2818 swrej, "GFF_ID",
2819 fs1->snscb_cthdr.ct_reason,
2820 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2821 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2822 FC_SCRATCH_RELEASE(isp);
2823 return (-1);
2824 }
2825 } else {
2826 int index = (ftype >> 3);
2827 int bshft = (ftype & 0x7) * 4;
2828 int fc4_fval =
2829 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2830 if (fc4_fval & 0x1) {
2831 lcl.roles |=
2832 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2833 }
2834 if (fc4_fval & 0x2) {
2835 lcl.roles |=
2836 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
2837 }
2838 }
2839#endif
2840
2841 /*
2842 * If we really want to know what kind of port type this is,
2843 * we have to run another CT command. Otherwise, we'll leave
2844 * it as undefined.
2845 *
2846 lcl.port_type = 0;
2847 */
2848 if (rs1->snscb_ports[i].control & 0x80) {
2849 lcl.last_fabric_dev = 1;
2850 } else {
2851 lcl.last_fabric_dev = 0;
2852 }
2853 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2854
2855 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
2856
2857 /*
2858 * If we're not at the last entry, our list isn't big enough.
2859 */
2860 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
2861 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
2862 }
2863
2864 FC_SCRATCH_RELEASE(isp);
2865 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2866 return (0);
2867}
2868#endif
2869
2870static void
2871isp_register_fc4_type(struct ispsoftc *isp)
2872{
2873 fcparam *fcp = isp->isp_param;
2874 u_int8_t local[SNS_RFT_ID_REQ_SIZE];
2875 sns_screq_t *reqp = (sns_screq_t *) local;
2876 mbreg_t mbs;
2877
2878 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
2879 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
2880 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
2881 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
2882 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
2883 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
2884 reqp->snscb_sblen = 22;
2885 reqp->snscb_data[0] = SNS_RFT_ID;
2886 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
2887 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
2888 reqp->snscb_data[6] = (1 << FC4_SCSI);
2889#if 0
2890 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
2891#endif
2892 FC_SCRATCH_ACQUIRE(isp);
2893 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
2894 mbs.param[0] = MBOX_SEND_SNS;
2895 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
2896 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2897 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2898 /*
2899 * Leave 4 and 5 alone
2900 */
2901 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2902 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2903 isp_mboxcmd(isp, &mbs, MBLOGALL);
2904 FC_SCRATCH_RELEASE(isp);
2905 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2906 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
2907 }
2908}
2909
2910/*
2911 * Start a command. Locking is assumed done in the caller.
2912 */
2913
2914int
2915isp_start(XS_T *xs)
2916{
2917 struct ispsoftc *isp;
2918 u_int16_t nxti, optr, handle;
2919 u_int8_t local[QENTRY_LEN];
2920 ispreq_t *reqp, *qep;
2921 int target, i;
2922
2923 XS_INITERR(xs);
2924 isp = XS_ISP(xs);
2925
2926 /*
2927 * Check to make sure we're supporting initiator role.
2928 */
2929 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
2930 XS_SETERR(xs, HBA_SELTIMEOUT);
2931 return (CMD_COMPLETE);
2932 }
2933
2934 /*
2935 * Now make sure we're running.
2936 */
2937
2938 if (isp->isp_state != ISP_RUNSTATE) {
2939 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
2940 XS_SETERR(xs, HBA_BOTCH);
2941 return (CMD_COMPLETE);
2942 }
2943
2944 /*
2945 * Check command CDB length, etc.. We really are limited to 16 bytes
2946 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
2947 * but probably only if we're running fairly new firmware (we'll
2948 * let the old f/w choke on an extended command queue entry).
2949 */
2950
2951 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
2952 isp_prt(isp, ISP_LOGERR,
2953 "unsupported cdb length (%d, CDB[0]=0x%x)",
2954 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
2955 XS_SETERR(xs, HBA_BOTCH);
2956 return (CMD_COMPLETE);
2957 }
2958
2959 /*
2960 * Check to see whether we have good firmware state still or
2961 * need to refresh our port database for this target.
2962 */
2963 target = XS_TGT(xs);
2964 if (IS_FC(isp)) {
2965 fcparam *fcp = isp->isp_param;
2966 struct lportdb *lp;
2967#ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
2968 if (fcp->isp_fwstate != FW_READY ||
2969 fcp->isp_loopstate != LOOP_READY) {
2970 return (CMD_RQLATER);
2971 }
2972
2973 /*
2974 * If we're not on a Fabric, we can't have a target
2975 * above FL_PORT_ID-1.
2976 *
2977 * If we're on a fabric and *not* connected as an F-port,
2978 * we can't have a target less than FC_SNS_ID+1. This
2979 * keeps us from having to sort out the difference between
2980 * local public loop devices and those which we might get
2981 * from a switch's database.
2982 */
2983 if (fcp->isp_onfabric == 0) {
2984 if (target >= FL_PORT_ID) {
2985 XS_SETERR(xs, HBA_SELTIMEOUT);
2986 return (CMD_COMPLETE);
2987 }
2988 } else {
2989 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
2990 XS_SETERR(xs, HBA_SELTIMEOUT);
2991 return (CMD_COMPLETE);
2992 }
2993 /*
2994 * We used to exclude having local loop ports
2995 * at the same time that we have fabric ports.
2996 * That is, we used to exclude having ports
2997 * at < FL_PORT_ID if we're FL-port.
2998 *
2999 * That's wrong. The only thing that could be
3000 * dicey is if the switch you're connected to
3001 * has these local loop ports appear on the
3002 * fabric and we somehow attach them twice.
3003 */
3004 }
3005#else
3006 /*
3007 * Check for f/w being in ready state. If the f/w
3008 * isn't in ready state, then we don't know our
3009 * loop ID and the f/w hasn't completed logging
3010 * into all targets on the loop. If this is the
3011 * case, then bounce the command. We pretend this is
3012 * a SELECTION TIMEOUT error if we've never gone to
3013 * FW_READY state at all- in this case we may not
3014 * be hooked to a loop at all and we shouldn't hang
3015 * the machine for this. Otherwise, defer this command
3016 * until later.
3017 */
3018 if (fcp->isp_fwstate != FW_READY) {
3019 /*
3020 * Give ourselves at most a 250ms delay.
3021 */
3022 if (isp_fclink_test(isp, 250000)) {
3023 XS_SETERR(xs, HBA_SELTIMEOUT);
3024 if (fcp->loop_seen_once) {
3025 return (CMD_RQLATER);
3026 } else {
3027 return (CMD_COMPLETE);
3028 }
3029 }
3030 }
3031
3032 /*
3033 * If we're not on a Fabric, we can't have a target
3034 * above FL_PORT_ID-1.
3035 *
3036 * If we're on a fabric and *not* connected as an F-port,
3037 * we can't have a target less than FC_SNS_ID+1. This
3038 * keeps us from having to sort out the difference between
3039 * local public loop devices and those which we might get
3040 * from a switch's database.
3041 */
3042 if (fcp->isp_onfabric == 0) {
3043 if (target >= FL_PORT_ID) {
3044 XS_SETERR(xs, HBA_SELTIMEOUT);
3045 return (CMD_COMPLETE);
3046 }
3047 } else {
3048 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3049 XS_SETERR(xs, HBA_SELTIMEOUT);
3050 return (CMD_COMPLETE);
3051 }
3052 if (fcp->isp_topo != TOPO_F_PORT &&
3053 target < FL_PORT_ID) {
3054 XS_SETERR(xs, HBA_SELTIMEOUT);
3055 return (CMD_COMPLETE);
3056 }
3057 }
3058
3059 /*
3060 * If our loop state is such that we haven't yet received
3061 * a "Port Database Changed" notification (after a LIP or
3062 * a Loop Reset or firmware initialization), then defer
3063 * sending commands for a little while, but only if we've
3064 * seen a valid loop at one point (otherwise we can get
3065 * stuck at initialization time).
3066 */
3067 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3068 XS_SETERR(xs, HBA_SELTIMEOUT);
3069 if (fcp->loop_seen_once) {
3070 return (CMD_RQLATER);
3071 } else {
3072 return (CMD_COMPLETE);
3073 }
3074 }
3075
3076 /*
3077 * If we're in the middle of loop or fabric scanning
3078 * or merging the port databases, retry this command later.
3079 */
3080 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3081 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3082 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3083 return (CMD_RQLATER);
3084 }
3085
3086 /*
3087 * If our loop state is now such that we've just now
3088 * received a Port Database Change notification, then
3089 * we have to go off and (re)scan the fabric. We back
3090 * out and try again later if this doesn't work.
3091 */
3092 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3093 if (isp_scan_fabric(isp, FC4_SCSI)) {
3094 return (CMD_RQLATER);
3095 }
3096 if (fcp->isp_fwstate != FW_READY ||
3097 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3098 return (CMD_RQLATER);
3099 }
3100 }
3101
3102 /*
3103 * If our loop state is now such that we've just now
3104 * received a Port Database Change notification, then
3105 * we have to go off and (re)synchronize our port
3106 * database.
3107 */
3108 if (fcp->isp_loopstate < LOOP_READY) {
3109 if (isp_pdb_sync(isp)) {
3110 return (CMD_RQLATER);
3111 }
3112 if (fcp->isp_fwstate != FW_READY ||
3113 fcp->isp_loopstate != LOOP_READY) {
3114 return (CMD_RQLATER);
3115 }
3116 }
3117
3118 /*
3119 * XXX: Here's were we would cancel any loop_dead flag
3120 * XXX: also cancel in dead_loop timeout that's running
3121 */
3122#endif
3123
3124 /*
3125 * Now check whether we should even think about pursuing this.
3126 */
3127 lp = &fcp->portdb[target];
3128 if (lp->valid == 0) {
3129 XS_SETERR(xs, HBA_SELTIMEOUT);
3130 return (CMD_COMPLETE);
3131 }
3132 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3133 isp_prt(isp, ISP_LOGDEBUG2,
3134 "Target %d does not have target service", target);
3135 XS_SETERR(xs, HBA_SELTIMEOUT);
3136 return (CMD_COMPLETE);
3137 }
3138 /*
3139 * Now turn target into what the actual Loop ID is.
3140 */
3141 target = lp->loopid;
3142 }
3143
3144 /*
3145 * Next check to see if any HBA or Device
3146 * parameters need to be updated.
3147 */
3148 if (isp->isp_update != 0) {
3149 isp_update(isp);
3150 }
3151
3152 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
3153 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3154 XS_SETERR(xs, HBA_BOTCH);
3155 return (CMD_EAGAIN);
3156 }
3157
3158 /*
3159 * Now see if we need to synchronize the ISP with respect to anything.
3160 * We do dual duty here (cough) for synchronizing for busses other
3161 * than which we got here to send a command to.
3162 */
3163 reqp = (ispreq_t *) local;
3164 if (isp->isp_sendmarker) {
3165 u_int8_t n = (IS_DUALBUS(isp)? 2: 1);
3166 /*
3167 * Check ports to send markers for...
3168 */
3169 for (i = 0; i < n; i++) {
3170 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3171 continue;
3172 }
3173 MEMZERO((void *) reqp, QENTRY_LEN);
3174 reqp->req_header.rqs_entry_count = 1;
3175 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3176 reqp->req_modifier = SYNC_ALL;
3177 reqp->req_target = i << 7; /* insert bus number */
3178 isp_put_request(isp, reqp, qep);
3179 ISP_ADD_REQUEST(isp, nxti);
3180 isp->isp_sendmarker &= ~(1 << i);
3181 if (isp_getrqentry(isp, &nxti, &optr, (void *) &qep)) {
3182 isp_prt(isp, ISP_LOGDEBUG0,
3183 "Request Queue Overflow+");
3184 XS_SETERR(xs, HBA_BOTCH);
3185 return (CMD_EAGAIN);
3186 }
3187 }
3188 }
3189
3190 MEMZERO((void *)reqp, QENTRY_LEN);
3191 reqp->req_header.rqs_entry_count = 1;
3192 if (IS_FC(isp)) {
3193 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3194 } else {
3195 if (XS_CDBLEN(xs) > 12)
3196 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3197 else
3198 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3199 }
3200 /* reqp->req_header.rqs_flags = 0; */
3201 /* reqp->req_header.rqs_seqno = 0; */
3202 if (IS_FC(isp)) {
3203 /*
3204 * See comment in isp_intr
3205 */
3206 /* XS_RESID(xs) = 0; */
3207
3208 /*
3209 * Fibre Channel always requires some kind of tag.
3210 * The Qlogic drivers seem be happy not to use a tag,
3211 * but this breaks for some devices (IBM drives).
3212 */
3213 if (XS_TAG_P(xs)) {
3214 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3215 } else {
3216 /*
3217 * If we don't know what tag to use, use HEAD OF QUEUE
3218 * for Request Sense or Simple.
3219 */
3220 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3221 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3222 else
3223 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3224 }
3225 } else {
3226 sdparam *sdp = (sdparam *)isp->isp_param;
3227 sdp += XS_CHANNEL(xs);
3228 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3229 XS_TAG_P(xs)) {
3230 reqp->req_flags = XS_TAG_TYPE(xs);
3231 }
3232 }
3233 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3234 if (IS_SCSI(isp)) {
3235 reqp->req_lun_trn = XS_LUN(xs);
3236 reqp->req_cdblen = XS_CDBLEN(xs);
3237 } else {
3238 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN)
3239 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3240 else
3241 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3242 }
3243 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3244
3245 reqp->req_time = XS_TIME(xs) / 1000;
3246 if (reqp->req_time == 0 && XS_TIME(xs)) {
3247 reqp->req_time = 1;
3248 }
3249
3250 if (isp_save_xs(isp, xs, &handle)) {
3251 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3252 XS_SETERR(xs, HBA_BOTCH);
3253 return (CMD_EAGAIN);
3254 }
3255 reqp->req_handle = handle;
3256
3257 /*
3258 * Set up DMA and/or do any bus swizzling of the request entry
3259 * so that the Qlogic F/W understands what is being asked of it.
3260 */
3261 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3262 if (i != CMD_QUEUED) {
3263 isp_destroy_handle(isp, handle);
3264 /*
3265 * dmasetup sets actual error in packet, and
3266 * return what we were given to return.
3267 */
3268 return (i);
3269 }
3270 XS_SETERR(xs, HBA_NOERROR);
3271 isp_prt(isp, ISP_LOGDEBUG2,
3272 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3273 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3274 (long) XS_XFRLEN(xs));
3275 ISP_ADD_REQUEST(isp, nxti);
3276 isp->isp_nactive++;
3277 return (CMD_QUEUED);
3278}
3279
3280/*
3281 * isp control
3282 * Locks (ints blocked) assumed held.
3283 */
3284
3285int
3286isp_control(struct ispsoftc *isp, ispctl_t ctl, void *arg)
3287{
3288 XS_T *xs;
3289 mbreg_t mbs;
3290 int bus, tgt;
3291 u_int16_t handle;
3292
3293 switch (ctl) {
3294 default:
3295 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3296 break;
3297
3298 case ISPCTL_RESET_BUS:
3299 /*
3300 * Issue a bus reset.
3301 */
3302 mbs.param[0] = MBOX_BUS_RESET;
3303 mbs.param[2] = 0;
3304 if (IS_SCSI(isp)) {
3305 mbs.param[1] =
3306 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3307 if (mbs.param[1] < 2)
3308 mbs.param[1] = 2;
3309 bus = *((int *) arg);
3310 if (IS_DUALBUS(isp))
3311 mbs.param[2] = bus;
3312 } else {
3313 mbs.param[1] = 10;
3314 bus = 0;
3315 }
3316 isp->isp_sendmarker |= (1 << bus);
3317 isp_mboxcmd(isp, &mbs, MBLOGALL);
3318 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3319 break;
3320 }
3321 isp_prt(isp, ISP_LOGINFO,
3322 "driver initiated bus reset of bus %d", bus);
3323 return (0);
3324
3325 case ISPCTL_RESET_DEV:
3326 tgt = (*((int *) arg)) & 0xffff;
3327 bus = (*((int *) arg)) >> 16;
3328 mbs.param[0] = MBOX_ABORT_TARGET;
3329 mbs.param[1] = (tgt << 8) | (bus << 15);
3330 mbs.param[2] = 3; /* 'delay', in seconds */
3331 isp_mboxcmd(isp, &mbs, MBLOGALL);
3332 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3333 break;
3334 }
3335 isp_prt(isp, ISP_LOGINFO,
3336 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3337 isp->isp_sendmarker |= (1 << bus);
3338 return (0);
3339
3340 case ISPCTL_ABORT_CMD:
3341 xs = (XS_T *) arg;
3342 tgt = XS_TGT(xs);
3343 handle = isp_find_handle(isp, xs);
3344 if (handle == 0) {
3345 isp_prt(isp, ISP_LOGWARN,
3346 "cannot find handle for command to abort");
3347 break;
3348 }
3349 bus = XS_CHANNEL(xs);
3350 mbs.param[0] = MBOX_ABORT;
3351 if (IS_FC(isp)) {
3352 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3353 mbs.param[1] = tgt << 8;
3354 mbs.param[4] = 0;
3355 mbs.param[5] = 0;
3356 mbs.param[6] = XS_LUN(xs);
3357 } else {
3358 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3359 }
3360 } else {
3361 mbs.param[1] =
3362 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3363 }
3364 mbs.param[3] = 0;
3365 mbs.param[2] = handle;
3366 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3367 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3368 return (0);
3369 }
3370 /*
3371 * XXX: Look for command in the REQUEST QUEUE. That is,
3372 * XXX: It hasen't been picked up by firmware yet.
3373 */
3374 break;
3375
3376 case ISPCTL_UPDATE_PARAMS:
3377
3378 isp_update(isp);
3379 return (0);
3380
3381 case ISPCTL_FCLINK_TEST:
3382
3383 if (IS_FC(isp)) {
3384 int usdelay = (arg)? *((int *) arg) : 250000;
3385 return (isp_fclink_test(isp, usdelay));
3386 }
3387 break;
3388
3389 case ISPCTL_SCAN_FABRIC:
3390
3391 if (IS_FC(isp)) {
3392 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3393 return (isp_scan_fabric(isp, ftype));
3394 }
3395 break;
3396
3397 case ISPCTL_SCAN_LOOP:
3398
3399 if (IS_FC(isp)) {
3400 return (isp_scan_loop(isp));
3401 }
3402 break;
3403
3404 case ISPCTL_PDB_SYNC:
3405
3406 if (IS_FC(isp)) {
3407 return (isp_pdb_sync(isp));
3408 }
3409 break;
3410
3411 case ISPCTL_SEND_LIP:
3412
3413 if (IS_FC(isp)) {
3414 mbs.param[0] = MBOX_INIT_LIP;
3415 isp_mboxcmd(isp, &mbs, MBLOGALL);
3416 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3417 return (0);
3418 }
3419 }
3420 break;
3421
3422 case ISPCTL_GET_POSMAP:
3423
3424 if (IS_FC(isp) && arg) {
3425 return (isp_getmap(isp, arg));
3426 }
3427 break;
3428
3429 case ISPCTL_RUN_MBOXCMD:
3430
3431 isp_mboxcmd(isp, arg, MBLOGALL);
3432 return(0);
3433
3434#ifdef ISP_TARGET_MODE
3435 case ISPCTL_TOGGLE_TMODE:
3436 {
3437
3438 /*
3439 * We don't check/set against role here- that's the
3440 * responsibility for the outer layer to coordinate.
3441 */
3442 if (IS_SCSI(isp)) {
3443 int param = *(int *)arg;
3444 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3445 mbs.param[1] = param & 0xffff;
3446 mbs.param[2] = param >> 16;
3447 isp_mboxcmd(isp, &mbs, MBLOGALL);
3448 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3449 break;
3450 }
3451 }
3452 return (0);
3453 }
3454#endif
3455 }
3456 return (-1);
3457}
3458
3459/*
3460 * Interrupt Service Routine(s).
3461 *
3462 * External (OS) framework has done the appropriate locking,
3463 * and the locking will be held throughout this function.
3464 */
3465
3466/*
3467 * Limit our stack depth by sticking with the max likely number
3468 * of completions on a request queue at any one time.
3469 */
3470#ifndef MAX_REQUESTQ_COMPLETIONS
3471#define MAX_REQUESTQ_COMPLETIONS 64
3472#endif
3473
3474void
3475isp_intr(struct ispsoftc *isp, u_int16_t isr, u_int16_t sema, u_int16_t mbox)
3476{
3477 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3478 u_int16_t iptr, optr, junk;
3479 int i, nlooked = 0, ndone = 0;
3480
3481again:
3482 /*
3483 * Is this a mailbox related interrupt?
3484 * The mailbox semaphore will be nonzero if so.
3485 */
3486 if (sema) {
3487 if (mbox & 0x4000) {
3488 isp->isp_intmboxc++;
3489 if (isp->isp_mboxbsy) {
3490 int i = 0, obits = isp->isp_obits;
3491 isp->isp_mboxtmp[i++] = mbox;
3492 for (i = 1; i < MAX_MAILBOX; i++) {
3493 if ((obits & (1 << i)) == 0) {
3494 continue;
3495 }
3496 isp->isp_mboxtmp[i] =
3497 ISP_READ(isp, MBOX_OFF(i));
3498 }
3499 if (isp->isp_mbxwrk0) {
3500 if (isp_mbox_continue(isp) == 0) {
3501 return;
3502 }
3503 }
3504 MBOX_NOTIFY_COMPLETE(isp);
3505 } else {
3506 isp_prt(isp, ISP_LOGWARN,
3507 "Mbox Command Async (0x%x) with no waiters",
3508 mbox);
3509 }
3510 } else if (isp_parse_async(isp, mbox) < 0) {
3511 return;
3512 }
3513 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3514 isp->isp_state != ISP_RUNSTATE) {
3515 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3516 ISP_WRITE(isp, BIU_SEMA, 0);
3517 return;
3518 }
3519 }
3520
3521 /*
3522 * We can't be getting this now.
3523 */
3524 if (isp->isp_state != ISP_RUNSTATE) {
3525 isp_prt(isp, ISP_LOGWARN,
3526 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3527 /*
3528 * Thank you very much! *Burrrp*!
3529 */
3530 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3531 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3532
3533 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3534 ISP_WRITE(isp, BIU_SEMA, 0);
3535 return;
3536 }
3537
3538 /*
3539 * Get the current Response Queue Out Pointer.
3540 *
3541 * If we're a 2300, we can ask what hardware what it thinks.
3542 */
3543 if (IS_23XX(isp)) {
3544 optr = ISP_READ(isp, isp->isp_respoutrp);
3545 /*
3546 * Debug: to be taken out eventually
3547 */
3548 if (isp->isp_residx != optr) {
3549 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3550 optr, isp->isp_residx);
3551 }
3552 } else {
3553 optr = isp->isp_residx;
3554 }
3555
3556 /*
3557 * You *must* read the Response Queue In Pointer
3558 * prior to clearing the RISC interrupt.
3559 *
3560 * Debounce the 2300 if revision less than 2.
3561 */
3562 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3563 i = 0;
3564 do {
3565 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3566 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3567 } while (junk != iptr && ++i < 1000);
3568
3569 if (iptr != junk) {
3570 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3571 isp_prt(isp, ISP_LOGWARN,
3572 "Response Queue Out Pointer Unstable (%x, %x)",
3573 iptr, junk);
3574 return;
3575 }
3576 } else {
3577 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3578 }
3579 isp->isp_resodx = iptr;
3580
3581
3582 if (optr == iptr && sema == 0) {
3583 /*
3584 * There are a lot of these- reasons unknown- mostly on
3585 * faster Alpha machines.
3586 *
3587 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3588 * make sure the old interrupt went away (to avoid 'ringing'
3589 * effects), but that didn't stop this from occurring.
3590 */
3591 if (IS_23XX(isp)) {
3592 USEC_DELAY(100);
3593 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3594 junk = ISP_READ(isp, BIU_R2HSTSLO);
3595 } else {
3596 junk = ISP_READ(isp, BIU_ISR);
3597 }
3598 if (optr == iptr) {
3599 if (IS_23XX(isp)) {
3600 ;
3601 } else {
3602 sema = ISP_READ(isp, BIU_SEMA);
3603 mbox = ISP_READ(isp, OUTMAILBOX0);
3604 if ((sema & 0x3) && (mbox & 0x8000)) {
3605 goto again;
3606 }
3607 }
3608 isp->isp_intbogus++;
3609 isp_prt(isp, ISP_LOGDEBUG1,
3610 "bogus intr- isr %x (%x) iptr %x optr %x",
3611 isr, junk, iptr, optr);
3612 }
3613 }
3614 isp->isp_resodx = iptr;
3615 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3616 ISP_WRITE(isp, BIU_SEMA, 0);
3617
3618 if (isp->isp_rspbsy) {
3619 return;
3620 }
3621 isp->isp_rspbsy = 1;
3622
3623 while (optr != iptr) {
3624 ispstatusreq_t local, *sp = &local;
3625 isphdr_t *hp;
3626 int type;
3627 u_int16_t oop;
3628 int buddaboom = 0;
3629
3630 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3631 oop = optr;
3632 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3633 nlooked++;
3634 /*
3635 * Synchronize our view of this response queue entry.
3636 */
3637 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3638
3639 type = isp_get_response_type(isp, hp);
3640
3641 if (type == RQSTYPE_RESPONSE) {
3642 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3643 } else if (type == RQSTYPE_RIO2) {
3644 isp_rio2_t rio;
3645 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3646 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3647 isp_fastpost_complete(isp, rio.req_handles[i]);
3648 }
3649 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3650 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3651 MEMZERO(hp, QENTRY_LEN); /* PERF */
3652 continue;
3653 } else {
3654 /*
3655 * Somebody reachable via isp_handle_other_response
3656 * may have updated the response queue pointers for
3657 * us, so we reload our goal index.
3658 */
3659 if (isp_handle_other_response(isp, type, hp, &optr)) {
3660 iptr = isp->isp_resodx;
3661 MEMZERO(hp, QENTRY_LEN); /* PERF */
3662 continue;
3663 }
3664
3665 /*
3666 * After this point, we'll just look at the header as
3667 * we don't know how to deal with the rest of the
3668 * response.
3669 */
3670 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3671
3672 /*
3673 * It really has to be a bounced request just copied
3674 * from the request queue to the response queue. If
3675 * not, something bad has happened.
3676 */
3677 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3678 isp_prt(isp, ISP_LOGERR, notresp,
3679 sp->req_header.rqs_entry_type, oop, optr,
3680 nlooked);
3681 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3682 isp_print_bytes(isp, "Queue Entry",
3683 QENTRY_LEN, sp);
3684 }
3685 MEMZERO(hp, QENTRY_LEN); /* PERF */
3686 continue;
3687 }
3688 buddaboom = 1;
3689 }
3690
3691 if (sp->req_header.rqs_flags & 0xf) {
3692#define _RQS_OFLAGS \
3693 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3694 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3695 isp_prt(isp, ISP_LOGWARN,
3696 "continuation segment");
3697 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3698 continue;
3699 }
3700 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3701 isp_prt(isp, ISP_LOGDEBUG1,
3702 "internal queues full");
3703 /*
3704 * We'll synthesize a QUEUE FULL message below.
3705 */
3706 }
3707 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3708 isp_prt(isp, ISP_LOGERR, "bad header flag");
3709 buddaboom++;
3710 }
3711 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3712 isp_prt(isp, ISP_LOGERR, "bad request packet");
3713 buddaboom++;
3714 }
3715 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3716 isp_prt(isp, ISP_LOGERR,
3717 "unknown flags (0x%x) in response",
3718 sp->req_header.rqs_flags);
3719 buddaboom++;
3720 }
3721#undef _RQS_OFLAGS
3722 }
3723 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3724 MEMZERO(hp, QENTRY_LEN); /* PERF */
3725 isp_prt(isp, ISP_LOGERR,
3726 "bad request handle %d (type 0x%x, flags 0x%x)",
3727 sp->req_handle, sp->req_header.rqs_entry_type,
3728 sp->req_header.rqs_flags);
3729 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3730 continue;
3731 }
3732 xs = isp_find_xs(isp, sp->req_handle);
3733 if (xs == NULL) {
3734 u_int8_t ts = sp->req_completion_status & 0xff;
3735 MEMZERO(hp, QENTRY_LEN); /* PERF */
3736 /*
3737 * Only whine if this isn't the expected fallout of
3738 * aborting the command.
3739 */
3740 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3741 isp_prt(isp, ISP_LOGERR,
3742 "cannot find handle 0x%x (type 0x%x)",
3743 sp->req_handle,
3744 sp->req_header.rqs_entry_type);
3745 } else if (ts != RQCS_ABORTED) {
3746 isp_prt(isp, ISP_LOGERR,
3747 "cannot find handle 0x%x (status 0x%x)",
3748 sp->req_handle, ts);
3749 }
3750 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3751 continue;
3752 }
3753 isp_destroy_handle(isp, sp->req_handle);
3754 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3755 XS_SETERR(xs, HBA_BUSRESET);
3756 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3757 }
3758 if (buddaboom) {
3759 XS_SETERR(xs, HBA_BOTCH);
3760 }
3761
3762 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3763 /*
3764 * Fibre Channel F/W doesn't say we got status
3765 * if there's Sense Data instead. I guess they
3766 * think it goes w/o saying.
3767 */
3768 sp->req_state_flags |= RQSF_GOT_STATUS;
3769 }
3770 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3771 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3772 }
3773
3774 switch (sp->req_header.rqs_entry_type) {
3775 case RQSTYPE_RESPONSE:
3776 XS_SET_STATE_STAT(isp, xs, sp);
3777 isp_parse_status(isp, sp, xs);
3778 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3779 (*XS_STSP(xs) == SCSI_BUSY)) {
3780 XS_SETERR(xs, HBA_TGTBSY);
3781 }
3782 if (IS_SCSI(isp)) {
3783 XS_RESID(xs) = sp->req_resid;
3784 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3785 (*XS_STSP(xs) == SCSI_CHECK) &&
3786 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3787 XS_SAVE_SENSE(xs, sp);
3788 }
3789 /*
3790 * A new synchronous rate was negotiated for
3791 * this target. Mark state such that we'll go
3792 * look up that which has changed later.
3793 */
3794 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3795 int t = XS_TGT(xs);
3796 sdparam *sdp = isp->isp_param;
3797 sdp += XS_CHANNEL(xs);
3798 sdp->isp_devparam[t].dev_refresh = 1;
3799 isp->isp_update |=
3800 (1 << XS_CHANNEL(xs));
3801 }
3802 } else {
3803 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3804 XS_RESID(xs) = 0;
3805 } else if (sp->req_scsi_status & RQCS_RESID) {
3806 XS_RESID(xs) = sp->req_resid;
3807 } else {
3808 XS_RESID(xs) = 0;
3809 }
3810 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3811 (*XS_STSP(xs) == SCSI_CHECK) &&
3812 (sp->req_scsi_status & RQCS_SV)) {
3813 XS_SAVE_SENSE(xs, sp);
3814 /* solely for the benefit of debug */
3815 sp->req_state_flags |= RQSF_GOT_SENSE;
3816 }
3817 }
3818 isp_prt(isp, ISP_LOGDEBUG2,
3819 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3820 (long) sp->req_resid);
3821 break;
3822 case RQSTYPE_REQUEST:
3823 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3824 /*
3825 * Force Queue Full status.
3826 */
3827 *XS_STSP(xs) = SCSI_QFULL;
3828 XS_SETERR(xs, HBA_NOERROR);
3829 } else if (XS_NOERR(xs)) {
3830 /*
3831 * ????
3832 */
3833 isp_prt(isp, ISP_LOGDEBUG0,
3834 "Request Queue Entry bounced back");
3835 XS_SETERR(xs, HBA_BOTCH);
3836 }
3837 XS_RESID(xs) = XS_XFRLEN(xs);
3838 break;
3839 default:
3840 isp_prt(isp, ISP_LOGWARN,
3841 "unhandled response queue type 0x%x",
3842 sp->req_header.rqs_entry_type);
3843 if (XS_NOERR(xs)) {
3844 XS_SETERR(xs, HBA_BOTCH);
3845 }
3846 break;
3847 }
3848
3849 /*
3850 * Free any dma resources. As a side effect, this may
3851 * also do any cache flushing necessary for data coherence. */
3852 if (XS_XFRLEN(xs)) {
3853 ISP_DMAFREE(isp, xs, sp->req_handle);
3854 }
3855
3856 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
3857 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
3858 (*XS_STSP(xs) != SCSI_GOOD)))) {
3859 char skey;
3860 if (sp->req_state_flags & RQSF_GOT_SENSE) {
3861 skey = XS_SNSKEY(xs) & 0xf;
3862 if (skey < 10)
3863 skey += '0';
3864 else
3865 skey += 'a' - 10;
3866 } else if (*XS_STSP(xs) == SCSI_CHECK) {
3867 skey = '?';
3868 } else {
3869 skey = '.';
3870 }
3871 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
3872 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
3873 *XS_STSP(xs), skey, XS_ERR(xs));
3874 }
3875
3876 if (isp->isp_nactive > 0)
3877 isp->isp_nactive--;
3878 complist[ndone++] = xs; /* defer completion call until later */
3879 MEMZERO(hp, QENTRY_LEN); /* PERF */
3880 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
3881 break;
3882 }
3883 }
3884
3885 /*
3886 * If we looked at any commands, then it's valid to find out
3887 * what the outpointer is. It also is a trigger to update the
3888 * ISP's notion of what we've seen so far.
3889 */
3890 if (nlooked) {
3891 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3892 /*
3893 * While we're at it, read the requst queue out pointer.
3894 */
3895 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3896 if (isp->isp_rscchiwater < ndone)
3897 isp->isp_rscchiwater = ndone;
3898 }
3899
3900 isp->isp_residx = optr;
3901 isp->isp_rspbsy = 0;
3902 for (i = 0; i < ndone; i++) {
3903 xs = complist[i];
3904 if (xs) {
3905 isp->isp_rsltccmplt++;
3906 isp_done(xs);
3907 }
3908 }
3909}
3910
3911/*
3912 * Support routines.
3913 */
3914
3915static int
3916isp_parse_async(struct ispsoftc *isp, u_int16_t mbox)
3917{
3918 int rval = 0;
3919 int bus;
3920
3921 if (IS_DUALBUS(isp)) {
3922 bus = ISP_READ(isp, OUTMAILBOX6);
3923 } else {
3924 bus = 0;
3925 }
3926 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
3927
3928 switch (mbox) {
3929 case ASYNC_BUS_RESET:
3930 isp->isp_sendmarker |= (1 << bus);
3931#ifdef ISP_TARGET_MODE
3932 if (isp_target_async(isp, bus, mbox))
3933 rval = -1;
3934#endif
3935 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
3936 break;
3937 case ASYNC_SYSTEM_ERROR:
3938#ifdef ISP_FW_CRASH_DUMP
3939 /*
3940 * If we have crash dumps enabled, it's up to the handler
3941 * for isp_async to reinit stuff and restart the firmware
3942 * after performing the crash dump. The reason we do things
3943 * this way is that we may need to activate a kernel thread
3944 * to do all the crash dump goop.
3945 */
3946 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
3947#else
3948 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
3949 isp_reinit(isp);
3950 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
3951#endif
3952 rval = -1;
3953 break;
3954
3955 case ASYNC_RQS_XFER_ERR:
3956 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
3957 break;
3958
3959 case ASYNC_RSP_XFER_ERR:
3960 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
3961 break;
3962
3963 case ASYNC_QWAKEUP:
3964 /*
3965 * We've just been notified that the Queue has woken up.
3966 * We don't need to be chatty about this- just unlatch things
3967 * and move on.
3968 */
3969 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3970 break;
3971
3972 case ASYNC_TIMEOUT_RESET:
3973 isp_prt(isp, ISP_LOGWARN,
3974 "timeout initiated SCSI bus reset of bus %d", bus);
3975 isp->isp_sendmarker |= (1 << bus);
3976#ifdef ISP_TARGET_MODE
3977 if (isp_target_async(isp, bus, mbox))
3978 rval = -1;
3979#endif
3980 break;
3981
3982 case ASYNC_DEVICE_RESET:
3983 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
3984 isp->isp_sendmarker |= (1 << bus);
3985#ifdef ISP_TARGET_MODE
3986 if (isp_target_async(isp, bus, mbox))
3987 rval = -1;
3988#endif
3989 break;
3990
3991 case ASYNC_EXTMSG_UNDERRUN:
3992 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
3993 break;
3994
3995 case ASYNC_SCAM_INT:
3996 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
3997 break;
3998
3999 case ASYNC_HUNG_SCSI:
4000 isp_prt(isp, ISP_LOGERR,
4001 "stalled SCSI Bus after DATA Overrun");
4002 /* XXX: Need to issue SCSI reset at this point */
4003 break;
4004
4005 case ASYNC_KILLED_BUS:
4006 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4007 break;
4008
4009 case ASYNC_BUS_TRANSIT:
4010 mbox = ISP_READ(isp, OUTMAILBOX2);
4011 switch (mbox & 0x1c00) {
4012 case SXP_PINS_LVD_MODE:
4013 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4014 SDPARAM(isp)->isp_diffmode = 0;
4015 SDPARAM(isp)->isp_ultramode = 0;
4016 SDPARAM(isp)->isp_lvdmode = 1;
4017 break;
4018 case SXP_PINS_HVD_MODE:
4019 isp_prt(isp, ISP_LOGINFO,
4020 "Transition to Differential mode");
4021 SDPARAM(isp)->isp_diffmode = 1;
4022 SDPARAM(isp)->isp_ultramode = 0;
4023 SDPARAM(isp)->isp_lvdmode = 0;
4024 break;
4025 case SXP_PINS_SE_MODE:
4026 isp_prt(isp, ISP_LOGINFO,
4027 "Transition to Single Ended mode");
4028 SDPARAM(isp)->isp_diffmode = 0;
4029 SDPARAM(isp)->isp_ultramode = 1;
4030 SDPARAM(isp)->isp_lvdmode = 0;
4031 break;
4032 default:
4033 isp_prt(isp, ISP_LOGWARN,
4034 "Transition to Unknown Mode 0x%x", mbox);
4035 break;
4036 }
4037 /*
4038 * XXX: Set up to renegotiate again!
4039 */
4040 /* Can only be for a 1080... */
4041 isp->isp_sendmarker |= (1 << bus);
4042 break;
4043
4044 /*
4045 * We can use bus, which will always be zero for FC cards,
4046 * as a mailbox pattern accumulator to be checked below.
4047 */
4048 case ASYNC_RIO5:
4049 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4050 break;
4051
4052 case ASYNC_RIO4:
4053 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4054 break;
4055
4056 case ASYNC_RIO3:
4057 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4058 break;
4059
4060 case ASYNC_RIO2:
4061 bus = 0x106; /* outgoing mailbox regs 1-2 */
4062 break;
4063
4064 case ASYNC_RIO1:
4065 case ASYNC_CMD_CMPLT:
4066 bus = 0x102; /* outgoing mailbox regs 1 */
4067 break;
4068
4069 case ASYNC_RIO_RESP:
4070 return (rval);
4071
4072 case ASYNC_CTIO_DONE:
4073 {
4074#ifdef ISP_TARGET_MODE
4075 int handle =
4076 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4077 (ISP_READ(isp, OUTMAILBOX1));
4078 if (isp_target_async(isp, handle, mbox))
4079 rval = -1;
4080#else
4081 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4082#endif
4083 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4084 break;
4085 }
4086 case ASYNC_LIP_F8:
4087 case ASYNC_LIP_OCCURRED:
4088 FCPARAM(isp)->isp_lipseq =
4089 ISP_READ(isp, OUTMAILBOX1);
4090 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4091 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4092 isp->isp_sendmarker = 1;
4093 isp_mark_getpdb_all(isp);
4094 isp_async(isp, ISPASYNC_LIP, NULL);
4095#ifdef ISP_TARGET_MODE
4096 if (isp_target_async(isp, bus, mbox))
4097 rval = -1;
4098#endif
4099 /*
4100 * We've had problems with data corruption occuring on
4101 * commands that complete (with no apparent error) after
4102 * we receive a LIP. This has been observed mostly on
4103 * Local Loop topologies. To be safe, let's just mark
4104 * all active commands as dead.
4105 */
4106 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4107 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4108 int i, j;
4109 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4110 XS_T *xs;
4111 xs = isp->isp_xflist[i];
4112 if (xs != NULL) {
4113 j++;
4114 XS_SETERR(xs, HBA_BUSRESET);
4115 }
4116 }
4117 if (j) {
4118 isp_prt(isp, ISP_LOGERR,
4119 "LIP destroyed %d active commands", j);
4120 }
4121 }
4122 break;
4123
4124 case ASYNC_LOOP_UP:
4125 isp->isp_sendmarker = 1;
4126 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4127 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4128 isp_mark_getpdb_all(isp);
4129 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4130#ifdef ISP_TARGET_MODE
4131 if (isp_target_async(isp, bus, mbox))
4132 rval = -1;
4133#endif
4134 break;
4135
4136 case ASYNC_LOOP_DOWN:
4137 isp->isp_sendmarker = 1;
4138 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4139 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4140 isp_mark_getpdb_all(isp);
4141 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4142#ifdef ISP_TARGET_MODE
4143 if (isp_target_async(isp, bus, mbox))
4144 rval = -1;
4145#endif
4146 break;
4147
4148 case ASYNC_LOOP_RESET:
4149 isp->isp_sendmarker = 1;
4150 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4151 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4152 isp_mark_getpdb_all(isp);
4153 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4154#ifdef ISP_TARGET_MODE
4155 if (isp_target_async(isp, bus, mbox))
4156 rval = -1;
4157#endif
4158 break;
4159
4160 case ASYNC_PDB_CHANGED:
4161 isp->isp_sendmarker = 1;
4162 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4163 isp_mark_getpdb_all(isp);
4164 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4165 break;
4166
4167 case ASYNC_CHANGE_NOTIFY:
4168 /*
4169 * Not correct, but it will force us to rescan the loop.
4170 */
4171 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4172 isp_mark_getpdb_all(isp);
4173 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4174 break;
4175
4176 case ASYNC_PTPMODE:
4177 if (FCPARAM(isp)->isp_onfabric)
4178 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4179 else
4180 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4181 isp_mark_getpdb_all(isp);
4182 isp->isp_sendmarker = 1;
4183 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4184 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4185 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4186#ifdef ISP_TARGET_MODE
4187 if (isp_target_async(isp, bus, mbox))
4188 rval = -1;
4189#endif
4190 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4191 break;
4192
4193 case ASYNC_CONNMODE:
4194 mbox = ISP_READ(isp, OUTMAILBOX1);
4195 isp_mark_getpdb_all(isp);
4196 switch (mbox) {
4197 case ISP_CONN_LOOP:
4198 isp_prt(isp, ISP_LOGINFO,
4199 "Point-to-Point -> Loop mode");
4200 break;
4201 case ISP_CONN_PTP:
4202 isp_prt(isp, ISP_LOGINFO,
4203 "Loop -> Point-to-Point mode");
4204 break;
4205 case ISP_CONN_BADLIP:
4206 isp_prt(isp, ISP_LOGWARN,
4207 "Point-to-Point -> Loop mode (BAD LIP)");
4208 break;
4209 case ISP_CONN_FATAL:
4210 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4211#ifdef ISP_FW_CRASH_DUMP
4212 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4213#else
4214 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4215 isp_reinit(isp);
4216 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4217#endif
4218 return (-1);
4219 case ISP_CONN_LOOPBACK:
4220 isp_prt(isp, ISP_LOGWARN,
4221 "Looped Back in Point-to-Point mode");
4222 break;
4223 default:
4224 isp_prt(isp, ISP_LOGWARN,
4225 "Unknown connection mode (0x%x)", mbox);
4226 break;
4227 }
4228 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4229 isp->isp_sendmarker = 1;
4230 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4231 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4232 break;
4233
4234 default:
4235 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4236 break;
4237 }
4238
4239 if (bus & 0x100) {
4240 int i, nh;
4241 u_int16_t handles[5];
4242
4243 for (nh = 0, i = 1; i < MAX_MAILBOX; i++) {
4244 if ((bus & (1 << i)) == 0) {
4245 continue;
4246 }
4247 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4248 }
4249 for (i = 0; i < nh; i++) {
4250 isp_fastpost_complete(isp, handles[i]);
4251 isp_prt(isp, ISP_LOGDEBUG3,
4252 "fast post completion of %u", handles[i]);
4253 }
4254 if (isp->isp_fpcchiwater < nh)
4255 isp->isp_fpcchiwater = nh;
4256 } else {
4257 isp->isp_intoasync++;
4258 }
4259 return (rval);
4260}
4261
4262/*
4263 * Handle other response entries. A pointer to the request queue output
4264 * index is here in case we want to eat several entries at once, although
4265 * this is not used currently.
4266 */
4267
4268static int
4269isp_handle_other_response(struct ispsoftc *isp, int type,
4270 isphdr_t *hp, u_int16_t *optrp)
4271{
4272 switch (type) {
4273 case RQSTYPE_STATUS_CONT:
4274 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4275 return (1);
4276 case RQSTYPE_ATIO:
4277 case RQSTYPE_CTIO:
4278 case RQSTYPE_ENABLE_LUN:
4279 case RQSTYPE_MODIFY_LUN:
4280 case RQSTYPE_NOTIFY:
4281 case RQSTYPE_NOTIFY_ACK:
4282 case RQSTYPE_CTIO1:
4283 case RQSTYPE_ATIO2:
4284 case RQSTYPE_CTIO2:
4285 case RQSTYPE_CTIO3:
4286 isp->isp_rsltccmplt++; /* count as a response completion */
4287#ifdef ISP_TARGET_MODE
4288 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4289 return (1);
4290 }
4291#else
4292 optrp = optrp;
4293 /* FALLTHROUGH */
4294#endif
4295 case RQSTYPE_REQUEST:
4296 default:
4297 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4298 return (1);
4299 }
4300 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4301 isp_get_response_type(isp, hp));
4302 return (0);
4303 }
4304}
4305
4306static void
4307isp_parse_status(struct ispsoftc *isp, ispstatusreq_t *sp, XS_T *xs)
4308{
4309 switch (sp->req_completion_status & 0xff) {
4310 case RQCS_COMPLETE:
4311 if (XS_NOERR(xs)) {
4312 XS_SETERR(xs, HBA_NOERROR);
4313 }
4314 return;
4315
4316 case RQCS_INCOMPLETE:
4317 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4318 isp_prt(isp, ISP_LOGDEBUG1,
4319 "Selection Timeout for %d.%d.%d",
4320 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4321 if (XS_NOERR(xs)) {
4322 XS_SETERR(xs, HBA_SELTIMEOUT);
4323 }
4324 return;
4325 }
4326 isp_prt(isp, ISP_LOGERR,
4327 "command incomplete for %d.%d.%d, state 0x%x",
4328 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4329 sp->req_state_flags);
4330 break;
4331
4332 case RQCS_DMA_ERROR:
4333 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4334 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4335 break;
4336
4337 case RQCS_TRANSPORT_ERROR:
4338 {
4339 char buf[172];
4340 SNPRINTF(buf, sizeof (buf), "states=>");
4341 if (sp->req_state_flags & RQSF_GOT_BUS) {
4342 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4343 }
4344 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4345 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4346 }
4347 if (sp->req_state_flags & RQSF_SENT_CDB) {
4348 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4349 }
4350 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4351 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4352 }
4353 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4354 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4355 }
4356 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4357 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4358 }
4359 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4360 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4361 }
4362 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4363 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4364 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4365 }
4366 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4367 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4368 }
4369 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4370 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4371 }
4372 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4373 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4374 }
4375 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4376 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4377 }
4378 if (sp->req_status_flags & RQSTF_ABORTED) {
4379 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4380 }
4381 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4382 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4383 }
4384 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4385 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4386 }
4387 isp_prt(isp, ISP_LOGERR, "%s", buf);
4388 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4389 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4390 break;
4391 }
4392 case RQCS_RESET_OCCURRED:
4393 isp_prt(isp, ISP_LOGWARN,
4394 "bus reset destroyed command for %d.%d.%d",
4395 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4396 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4397 if (XS_NOERR(xs)) {
4398 XS_SETERR(xs, HBA_BUSRESET);
4399 }
4400 return;
4401
4402 case RQCS_ABORTED:
4403 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4404 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4405 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4406 if (XS_NOERR(xs)) {
4407 XS_SETERR(xs, HBA_ABORTED);
4408 }
4409 return;
4410
4411 case RQCS_TIMEOUT:
4412 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4413 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4414 /*
4415 * Check to see if we logged out the device.
4416 */
4417 if (IS_FC(isp)) {
4418 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4419 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4420 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4421 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4422 }
4423 }
4424 if (XS_NOERR(xs)) {
4425 XS_SETERR(xs, HBA_CMDTIMEOUT);
4426 }
4427 return;
4428
4429 case RQCS_DATA_OVERRUN:
4430 XS_RESID(xs) = sp->req_resid;
4431 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4432 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4433 if (XS_NOERR(xs)) {
4434 XS_SETERR(xs, HBA_DATAOVR);
4435 }
4436 return;
4437
4438 case RQCS_COMMAND_OVERRUN:
4439 isp_prt(isp, ISP_LOGERR,
4440 "command overrun for command on %d.%d.%d",
4441 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4442 break;
4443
4444 case RQCS_STATUS_OVERRUN:
4445 isp_prt(isp, ISP_LOGERR,
4446 "status overrun for command on %d.%d.%d",
4447 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4448 break;
4449
4450 case RQCS_BAD_MESSAGE:
4451 isp_prt(isp, ISP_LOGERR,
4452 "msg not COMMAND COMPLETE after status %d.%d.%d",
4453 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4454 break;
4455
4456 case RQCS_NO_MESSAGE_OUT:
4457 isp_prt(isp, ISP_LOGERR,
4458 "No MESSAGE OUT phase after selection on %d.%d.%d",
4459 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4460 break;
4461
4462 case RQCS_EXT_ID_FAILED:
4463 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4464 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4465 break;
4466
4467 case RQCS_IDE_MSG_FAILED:
4468 isp_prt(isp, ISP_LOGERR,
4469 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4470 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4471 break;
4472
4473 case RQCS_ABORT_MSG_FAILED:
4474 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4475 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4476 break;
4477
4478 case RQCS_REJECT_MSG_FAILED:
4479 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4480 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4481 break;
4482
4483 case RQCS_NOP_MSG_FAILED:
4484 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4485 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4486 break;
4487
4488 case RQCS_PARITY_ERROR_MSG_FAILED:
4489 isp_prt(isp, ISP_LOGERR,
4490 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4491 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4492 break;
4493
4494 case RQCS_DEVICE_RESET_MSG_FAILED:
4495 isp_prt(isp, ISP_LOGWARN,
4496 "BUS DEVICE RESET rejected by %d.%d.%d",
4497 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4498 break;
4499
4500 case RQCS_ID_MSG_FAILED:
4501 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4502 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4503 break;
4504
4505 case RQCS_UNEXP_BUS_FREE:
4506 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4507 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4508 break;
4509
4510 case RQCS_DATA_UNDERRUN:
4511 {
4512 if (IS_FC(isp)) {
4513 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4514 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4515 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4516 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4517 (ru_marked)? "marked" : "not marked");
4518 if (XS_NOERR(xs)) {
4519 XS_SETERR(xs, HBA_BOTCH);
4520 }
4521 return;
4522 }
4523 }
4524 XS_RESID(xs) = sp->req_resid;
4525 if (XS_NOERR(xs)) {
4526 XS_SETERR(xs, HBA_NOERROR);
4527 }
4528 return;
4529 }
4530
4531 case RQCS_XACT_ERR1:
4532 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4533 XS_TGT(xs), XS_LUN(xs));
4534 break;
4535
4536 case RQCS_XACT_ERR2:
4537 isp_prt(isp, ISP_LOGERR, xact2,
4538 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4539 break;
4540
4541 case RQCS_XACT_ERR3:
4542 isp_prt(isp, ISP_LOGERR, xact3,
4543 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4544 break;
4545
4546 case RQCS_BAD_ENTRY:
4547 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4548 break;
4549
4550 case RQCS_QUEUE_FULL:
4551 isp_prt(isp, ISP_LOGDEBUG0,
4552 "internal queues full for %d.%d.%d status 0x%x",
4553 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4554
4555 /*
4556 * If QFULL or some other status byte is set, then this
4557 * isn't an error, per se.
4558 *
4559 * Unfortunately, some QLogic f/w writers have, in
4560 * some cases, ommitted to *set* status to QFULL.
4561 *
4562
4563 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4564 XS_SETERR(xs, HBA_NOERROR);
4565 return;
4566 }
4567
4568 *
4569 *
4570 */
4571
4572 *XS_STSP(xs) = SCSI_QFULL;
4573 XS_SETERR(xs, HBA_NOERROR);
4574 return;
4575
4576 case RQCS_PHASE_SKIPPED:
4577 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4578 XS_TGT(xs), XS_LUN(xs));
4579 break;
4580
4581 case RQCS_ARQS_FAILED:
4582 isp_prt(isp, ISP_LOGERR,
4583 "Auto Request Sense failed for %d.%d.%d",
4584 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4585 if (XS_NOERR(xs)) {
4586 XS_SETERR(xs, HBA_ARQFAIL);
4587 }
4588 return;
4589
4590 case RQCS_WIDE_FAILED:
4591 isp_prt(isp, ISP_LOGERR,
4592 "Wide Negotiation failed for %d.%d.%d",
4593 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4594 if (IS_SCSI(isp)) {
4595 sdparam *sdp = isp->isp_param;
4596 sdp += XS_CHANNEL(xs);
4597 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4598 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4599 isp->isp_update |= (1 << XS_CHANNEL(xs));
4600 }
4601 if (XS_NOERR(xs)) {
4602 XS_SETERR(xs, HBA_NOERROR);
4603 }
4604 return;
4605
4606 case RQCS_SYNCXFER_FAILED:
4607 isp_prt(isp, ISP_LOGERR,
4608 "SDTR Message failed for target %d.%d.%d",
4609 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4610 if (IS_SCSI(isp)) {
4611 sdparam *sdp = isp->isp_param;
4612 sdp += XS_CHANNEL(xs);
4613 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4614 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4615 isp->isp_update |= (1 << XS_CHANNEL(xs));
4616 }
4617 break;
4618
4619 case RQCS_LVD_BUSERR:
4620 isp_prt(isp, ISP_LOGERR,
4621 "Bad LVD condition while talking to %d.%d.%d",
4622 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4623 break;
4624
4625 case RQCS_PORT_UNAVAILABLE:
4626 /*
4627 * No such port on the loop. Moral equivalent of SELTIMEO
4628 */
4629 case RQCS_PORT_LOGGED_OUT:
4630 /*
4631 * It was there (maybe)- treat as a selection timeout.
4632 */
4633 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4634 isp_prt(isp, ISP_LOGINFO,
4635 "port unavailable for target %d", XS_TGT(xs));
4636 else
4637 isp_prt(isp, ISP_LOGINFO,
4638 "port logout for target %d", XS_TGT(xs));
4639 /*
4640 * If we're on a local loop, force a LIP (which is overkill)
4641 * to force a re-login of this unit. If we're on fabric,
4642 * then we'll have to relogin as a matter of course.
4643 */
4644 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4645 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4646 mbreg_t mbs;
4647 mbs.param[0] = MBOX_INIT_LIP;
4648 isp_mboxcmd_qnw(isp, &mbs, 1);
4649 }
4650
4651 /*
4652 * Probably overkill.
4653 */
4654 isp->isp_sendmarker = 1;
4655 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4656 isp_mark_getpdb_all(isp);
4657 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4658 if (XS_NOERR(xs)) {
4659 XS_SETERR(xs, HBA_SELTIMEOUT);
4660 }
4661 return;
4662
4663 case RQCS_PORT_CHANGED:
4664 isp_prt(isp, ISP_LOGWARN,
4665 "port changed for target %d", XS_TGT(xs));
4666 if (XS_NOERR(xs)) {
4667 XS_SETERR(xs, HBA_SELTIMEOUT);
4668 }
4669 return;
4670
4671 case RQCS_PORT_BUSY:
4672 isp_prt(isp, ISP_LOGWARN,
4673 "port busy for target %d", XS_TGT(xs));
4674 if (XS_NOERR(xs)) {
4675 XS_SETERR(xs, HBA_TGTBSY);
4676 }
4677 return;
4678
4679 default:
4680 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4681 sp->req_completion_status);
4682 break;
4683 }
4684 if (XS_NOERR(xs)) {
4685 XS_SETERR(xs, HBA_BOTCH);
4686 }
4687}
4688
4689static void
4690isp_fastpost_complete(struct ispsoftc *isp, u_int16_t fph)
4691{
4692 XS_T *xs;
4693
4694 if (fph == 0) {
4695 return;
4696 }
4697 xs = isp_find_xs(isp, fph);
4698 if (xs == NULL) {
4699 isp_prt(isp, ISP_LOGWARN,
4700 "Command for fast post handle 0x%x not found", fph);
4701 return;
4702 }
4703 isp_destroy_handle(isp, fph);
4704
4705 /*
4706 * Since we don't have a result queue entry item,
4707 * we must believe that SCSI status is zero and
4708 * that all data transferred.
4709 */
4710 XS_SET_STATE_STAT(isp, xs, NULL);
4711 XS_RESID(xs) = 0;
4712 *XS_STSP(xs) = SCSI_GOOD;
4713 if (XS_XFRLEN(xs)) {
4714 ISP_DMAFREE(isp, xs, fph);
4715 }
4716 if (isp->isp_nactive)
4717 isp->isp_nactive--;
4718 isp->isp_fphccmplt++;
4719 isp_done(xs);
4720}
4721
4722static int
4723isp_mbox_continue(struct ispsoftc *isp)
4724{
4725 mbreg_t mbs;
4726 u_int16_t *ptr;
4727
4728 switch (isp->isp_lastmbxcmd) {
4729 case MBOX_WRITE_RAM_WORD:
4730 case MBOX_READ_RAM_WORD:
4731 case MBOX_READ_RAM_WORD_EXTENDED:
4732 break;
4733 default:
4734 return (1);
4735 }
4736 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4737 isp->isp_mbxwrk0 = 0;
4738 return (-1);
4739 }
4740
4741
4742 /*
4743 * Clear the previous interrupt.
4744 */
4745 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4746 ISP_WRITE(isp, BIU_SEMA, 0);
4747
4748 /*
4749 * Continue with next word.
4750 */
4751 ptr = isp->isp_mbxworkp;
4752 switch (isp->isp_lastmbxcmd) {
4753 case MBOX_WRITE_RAM_WORD:
4754 mbs.param[2] = *ptr++;
4755 mbs.param[1] = isp->isp_mbxwrk1++;
4756 break;
4757 case MBOX_READ_RAM_WORD:
4758 case MBOX_READ_RAM_WORD_EXTENDED:
4759 *ptr++ = isp->isp_mboxtmp[2];
4760 mbs.param[1] = isp->isp_mbxwrk1++;
4761 break;
4762 }
4763 isp->isp_mbxworkp = ptr;
4764 mbs.param[0] = isp->isp_lastmbxcmd;
4765 isp->isp_mbxwrk0 -= 1;
4766 isp_mboxcmd_qnw(isp, &mbs, 0);
4767 return (0);
4768}
4769
4770
4771#define HIBYT(x) ((x) >> 0x8)
4772#define LOBYT(x) ((x) & 0xff)
4773#define ISPOPMAP(a, b) (((a) << 8) | (b))
4774static u_int16_t mbpscsi[] = {
4775 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4776 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4777 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4778 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4779 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4780 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4781 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4782 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4783 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4784 ISPOPMAP(0x00, 0x00), /* 0x09: */
4785 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4786 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4787 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4788 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4789 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4790 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4791 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4792 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4793 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4794 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4795 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4796 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4797 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4798 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4799 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4800 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4801 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4802 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4803 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4804 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4805 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4806 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4807 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4808 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4809 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4810 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4811 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4812 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4813 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4814 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4815 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4816 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4817 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4818 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4819 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4820 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4821 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4822 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4823 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4824 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4825 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4826 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4827 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4828 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4829 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4830 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4831 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4832 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4833 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4834 ISPOPMAP(0x00, 0x00), /* 0x3b: */
4835 ISPOPMAP(0x00, 0x00), /* 0x3c: */
4836 ISPOPMAP(0x00, 0x00), /* 0x3d: */
4837 ISPOPMAP(0x00, 0x00), /* 0x3e: */
4838 ISPOPMAP(0x00, 0x00), /* 0x3f: */
4839 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
4840 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
4841 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
4842 ISPOPMAP(0x00, 0x00), /* 0x43: */
4843 ISPOPMAP(0x00, 0x00), /* 0x44: */
4844 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
4845 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
4846 ISPOPMAP(0x00, 0x00), /* 0x47: */
4847 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
4848 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
4849 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
4850 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
4851 ISPOPMAP(0x00, 0x00), /* 0x4c: */
4852 ISPOPMAP(0x00, 0x00), /* 0x4d: */
4853 ISPOPMAP(0x00, 0x00), /* 0x4e: */
4854 ISPOPMAP(0x00, 0x00), /* 0x4f: */
4855 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
4856 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
4857 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
4858 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
4859 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
4860 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
4861 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
4862 ISPOPMAP(0x00, 0x00), /* 0x57: */
4863 ISPOPMAP(0x00, 0x00), /* 0x58: */
4864 ISPOPMAP(0x00, 0x00), /* 0x59: */
4865 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
4866 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
4867 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
4868 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
4869};
4870
4871#ifndef ISP_STRIPPED
4872static char *scsi_mbcmd_names[] = {
4873 "NO-OP",
4874 "LOAD RAM",
4875 "EXEC FIRMWARE",
4876 "DUMP RAM",
4877 "WRITE RAM WORD",
4878 "READ RAM WORD",
4879 "MAILBOX REG TEST",
4880 "VERIFY CHECKSUM",
4881 "ABOUT FIRMWARE",
4882 NULL,
4883 NULL,
4884 NULL,
4885 NULL,
4886 NULL,
4887 "CHECK FIRMWARE",
4888 NULL,
4889 "INIT REQUEST QUEUE",
4890 "INIT RESULT QUEUE",
4891 "EXECUTE IOCB",
4892 "WAKE UP",
4893 "STOP FIRMWARE",
4894 "ABORT",
4895 "ABORT DEVICE",
4896 "ABORT TARGET",
4897 "BUS RESET",
4898 "STOP QUEUE",
4899 "START QUEUE",
4900 "SINGLE STEP QUEUE",
4901 "ABORT QUEUE",
4902 "GET DEV QUEUE STATUS",
4903 NULL,
4904 "GET FIRMWARE STATUS",
4905 "GET INIT SCSI ID",
4906 "GET SELECT TIMEOUT",
4907 "GET RETRY COUNT",
4908 "GET TAG AGE LIMIT",
4909 "GET CLOCK RATE",
4910 "GET ACT NEG STATE",
4911 "GET ASYNC DATA SETUP TIME",
4912 "GET PCI PARAMS",
4913 "GET TARGET PARAMS",
4914 "GET DEV QUEUE PARAMS",
4915 "GET RESET DELAY PARAMS",
4916 NULL,
4917 NULL,
4918 NULL,
4919 NULL,
4920 NULL,
4921 "SET INIT SCSI ID",
4922 "SET SELECT TIMEOUT",
4923 "SET RETRY COUNT",
4924 "SET TAG AGE LIMIT",
4925 "SET CLOCK RATE",
4926 "SET ACT NEG STATE",
4927 "SET ASYNC DATA SETUP TIME",
4928 "SET PCI CONTROL PARAMS",
4929 "SET TARGET PARAMS",
4930 "SET DEV QUEUE PARAMS",
4931 "SET RESET DELAY PARAMS",
4932 NULL,
4933 NULL,
4934 NULL,
4935 NULL,
4936 NULL,
4937 "RETURN BIOS BLOCK ADDR",
4938 "WRITE FOUR RAM WORDS",
4939 "EXEC BIOS IOCB",
4940 NULL,
4941 NULL,
4942 "SET SYSTEM PARAMETER",
4943 "GET SYSTEM PARAMETER",
4944 NULL,
4945 "GET SCAM CONFIGURATION",
4946 "SET SCAM CONFIGURATION",
4947 "SET FIRMWARE FEATURES",
4948 "GET FIRMWARE FEATURES",
4949 NULL,
4950 NULL,
4951 NULL,
4952 NULL,
4953 "LOAD RAM A64",
4954 "DUMP RAM A64",
4955 "INITIALIZE REQUEST QUEUE A64",
4956 "INITIALIZE RESPONSE QUEUE A64",
4957 "EXECUTE IOCB A64",
4958 "ENABLE TARGET MODE",
4959 "GET TARGET MODE STATE",
4960 NULL,
4961 NULL,
4962 NULL,
4963 "SET DATA OVERRUN RECOVERY MODE",
4964 "GET DATA OVERRUN RECOVERY MODE",
4965 "SET HOST DATA",
4966 "GET NOST DATA",
4967};
4968#endif
4969
4970static u_int16_t mbpfc[] = {
4971 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4972 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4973 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4974 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
4975 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4976 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4977 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
4978 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
4979 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4980 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
4981 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
4982 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4983 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4984 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4985 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4986 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
4987 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
4988 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
4989 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
4990 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4991 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
4992 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
4993 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
4994 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
4995 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
4996 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
4997 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
4998 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4999 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5000 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5001 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5002 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5003 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5004 ISPOPMAP(0x00, 0x00), /* 0x21: */
5005 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5006 ISPOPMAP(0x00, 0x00), /* 0x23: */
5007 ISPOPMAP(0x00, 0x00), /* 0x24: */
5008 ISPOPMAP(0x00, 0x00), /* 0x25: */
5009 ISPOPMAP(0x00, 0x00), /* 0x26: */
5010 ISPOPMAP(0x00, 0x00), /* 0x27: */
5011 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5012 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5013 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5014 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5015 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5016 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5017 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5018 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5019 ISPOPMAP(0x00, 0x00), /* 0x30: */
5020 ISPOPMAP(0x00, 0x00), /* 0x31: */
5021 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5022 ISPOPMAP(0x00, 0x00), /* 0x33: */
5023 ISPOPMAP(0x00, 0x00), /* 0x34: */
5024 ISPOPMAP(0x00, 0x00), /* 0x35: */
5025 ISPOPMAP(0x00, 0x00), /* 0x36: */
5026 ISPOPMAP(0x00, 0x00), /* 0x37: */
5027 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5028 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5029 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5030 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5031 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5032 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5033 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5034 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5035 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5036 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5037 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5038 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5039 ISPOPMAP(0x00, 0x00), /* 0x44: */
5040 ISPOPMAP(0x00, 0x00), /* 0x45: */
5041 ISPOPMAP(0x00, 0x00), /* 0x46: */
5042 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5043 ISPOPMAP(0x00, 0x00), /* 0x48: */
5044 ISPOPMAP(0x00, 0x00), /* 0x49: */
5045 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5046 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5047 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5048 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5049 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5050 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5051 ISPOPMAP(0x00, 0x00), /* 0x50: */
5052 ISPOPMAP(0x00, 0x00), /* 0x51: */
5053 ISPOPMAP(0x00, 0x00), /* 0x52: */
5054 ISPOPMAP(0x00, 0x00), /* 0x53: */
5055 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5056 ISPOPMAP(0x00, 0x00), /* 0x55: */
5057 ISPOPMAP(0x00, 0x00), /* 0x56: */
5058 ISPOPMAP(0x00, 0x00), /* 0x57: */
5059 ISPOPMAP(0x00, 0x00), /* 0x58: */
5060 ISPOPMAP(0x00, 0x00), /* 0x59: */
5061 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5062 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5063 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5064 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5065 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5066 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5067 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5068 ISPOPMAP(0x00, 0x00), /* 0x61: */
5069 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5070 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5071 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5072 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5073 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5074 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5075 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5076 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5077 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5078 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5079 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5080 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5081 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5082 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5083 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5084 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5085 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5086 ISPOPMAP(0x00, 0x00), /* 0x73: */
5087 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5088 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5089 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5090 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5091 ISPOPMAP(0x00, 0x00), /* 0x78: */
5092 ISPOPMAP(0x00, 0x00), /* 0x79: */
5093 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5094 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5095 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5096 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5097 ISPOPMAP(0x07, 0x01) /* 0x7e: Lun RESET */
5098};
5099/*
5100 * Footnotes
5101 *
5102 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5103 * do not access at this time in the core driver. The caller is
5104 * responsible for setting this register first (Gross!).
5105 */
5106
5107#ifndef ISP_STRIPPED
5108static char *fc_mbcmd_names[] = {
5109 "NO-OP",
5110 "LOAD RAM",
5111 "EXEC FIRMWARE",
5112 "DUMP RAM",
5113 "WRITE RAM WORD",
5114 "READ RAM WORD",
5115 "MAILBOX REG TEST",
5116 "VERIFY CHECKSUM",
5117 "ABOUT FIRMWARE",
5118 "LOAD RAM",
5119 "DUMP RAM",
5120 NULL,
5121 NULL,
5122 "READ RAM WORD EXTENDED",
5123 "CHECK FIRMWARE",
5124 NULL,
5125 "INIT REQUEST QUEUE",
5126 "INIT RESULT QUEUE",
5127 "EXECUTE IOCB",
5128 "WAKE UP",
5129 "STOP FIRMWARE",
5130 "ABORT",
5131 "ABORT DEVICE",
5132 "ABORT TARGET",
5133 "BUS RESET",
5134 "STOP QUEUE",
5135 "START QUEUE",
5136 "SINGLE STEP QUEUE",
5137 "ABORT QUEUE",
5138 "GET DEV QUEUE STATUS",
5139 NULL,
5140 "GET FIRMWARE STATUS",
5141 "GET LOOP ID",
5142 NULL,
5143 "GET RETRY COUNT",
5144 NULL,
5145 NULL,
5146 NULL,
5147 NULL,
5148 NULL,
5149 "GET FIRMWARE OPTIONS",
5150 "GET PORT QUEUE PARAMS",
5151 NULL,
5152 NULL,
5153 NULL,
5154 NULL,
5155 NULL,
5156 NULL,
5157 NULL,
5158 NULL,
5159 "SET RETRY COUNT",
5160 NULL,
5161 NULL,
5162 NULL,
5163 NULL,
5164 NULL,
5165 "SET FIRMWARE OPTIONS",
5166 "SET PORT QUEUE PARAMS",
5167 NULL,
5168 NULL,
5169 NULL,
5170 NULL,
5171 NULL,
5172 NULL,
5173 "LOOP PORT BYPASS",
5174 "LOOP PORT ENABLE",
5175 "GET RESOURCE COUNTS",
5176 "REQUEST NON PARTICIPATING MODE",
5177 NULL,
5178 NULL,
5179 NULL,
5180 "GET PORT DATABASE,, ENHANCED",
5181 NULL,
5182 NULL,
5183 NULL,
5184 NULL,
5185 NULL,
5186 NULL,
5187 NULL,
5188 NULL,
5189 NULL,
5190 NULL,
5191 NULL,
5192 NULL,
5193 "EXECUTE IOCB A64",
5194 NULL,
5195 NULL,
5196 NULL,
5197 NULL,
5198 NULL,
5199 NULL,
5200 "DRIVER HEARTBEAT",
5201 NULL,
5202 "GET/SET DATA RATE",
5203 NULL,
5204 NULL,
5205 "INIT FIRMWARE",
5206 NULL,
5207 "INIT LIP",
5208 "GET FC-AL POSITION MAP",
5209 "GET PORT DATABASE",
5210 "CLEAR ACA",
5211 "TARGET RESET",
5212 "CLEAR TASK SET",
5213 "ABORT TASK SET",
5214 "GET FW STATE",
5215 "GET PORT NAME",
5216 "GET LINK STATUS",
5217 "INIT LIP RESET",
5218 NULL,
5219 "SEND SNS",
5220 "FABRIC LOGIN",
5221 "SEND CHANGE REQUEST",
5222 "FABRIC LOGOUT",
5223 "INIT LIP LOGIN",
5224 NULL,
5225 "LOGIN LOOP PORT",
5226 "GET PORT/NODE NAME LIST",
5227 "SET VENDOR ID",
5228 "INITIALIZE IP MAILBOX",
5229 NULL,
5230 NULL,
5231 NULL,
5232 NULL,
5233 "Get ID List",
5234 "SEND LFA",
5235 "Lun RESET"
5236};
5237#endif
5238
5239static void
5240isp_mboxcmd_qnw(struct ispsoftc *isp, mbreg_t *mbp, int nodelay)
5241{
5242 unsigned int ibits, obits, box, opcode;
5243 u_int16_t *mcp;
5244
5245 if (IS_FC(isp)) {
5246 mcp = mbpfc;
5247 } else {
5248 mcp = mbpscsi;
5249 }
5250 opcode = mbp->param[0];
5251 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5252 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5253 for (box = 0; box < MAX_MAILBOX; box++) {
5254 if (ibits & (1 << box)) {
5255 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5256 }
5257 if (nodelay == 0) {
5258 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5259 }
5260 }
5261 if (nodelay == 0) {
5262 isp->isp_lastmbxcmd = opcode;
5263 isp->isp_obits = obits;
5264 isp->isp_mboxbsy = 1;
5265 }
5266 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5267 /*
5268 * Oddly enough, if we're not delaying for an answer,
5269 * delay a bit to give the f/w a chance to pick up the
5270 * command.
5271 */
5272 if (nodelay) {
5273 USEC_DELAY(1000);
5274 }
5275}
5276
5277static void
5278isp_mboxcmd(struct ispsoftc *isp, mbreg_t *mbp, int logmask)
5279{
5280 char *cname, *xname, tname[16], mname[16];
5281 unsigned int lim, ibits, obits, box, opcode;
5282 u_int16_t *mcp;
5283
5284 if (IS_FC(isp)) {
5285 mcp = mbpfc;
5286 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5287 } else {
5288 mcp = mbpscsi;
5289 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5290 }
5291
5292 if ((opcode = mbp->param[0]) >= lim) {
5293 mbp->param[0] = MBOX_INVALID_COMMAND;
5294 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5295 return;
5296 }
5297
5298 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5299 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5300
5301 if (ibits == 0 && obits == 0) {
5302 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5303 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5304 return;
5305 }
5306
5307 /*
5308 * Get exclusive usage of mailbox registers.
5309 */
5310 MBOX_ACQUIRE(isp);
5311
5312 for (box = 0; box < MAX_MAILBOX; box++) {
5313 if (ibits & (1 << box)) {
5314 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5315 }
5316 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5317 }
5318
5319 isp->isp_lastmbxcmd = opcode;
5320
5321 /*
5322 * We assume that we can't overwrite a previous command.
5323 */
5324 isp->isp_obits = obits;
5325 isp->isp_mboxbsy = 1;
5326
5327 /*
5328 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5329 */
5330 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5331
5332 /*
5333 * While we haven't finished the command, spin our wheels here.
5334 */
5335 MBOX_WAIT_COMPLETE(isp);
5336
5337 if (isp->isp_mboxbsy) {
5338 /*
5339 * Command timed out.
5340 */
5341 isp->isp_mboxbsy = 0;
5342 MBOX_RELEASE(isp);
5343 return;
5344 }
5345
5346 /*
5347 * Copy back output registers.
5348 */
5349 for (box = 0; box < MAX_MAILBOX; box++) {
5350 if (obits & (1 << box)) {
5351 mbp->param[box] = isp->isp_mboxtmp[box];
5352 }
5353 }
5354
5355 MBOX_RELEASE(isp);
5356
5357 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5358 return;
5359 }
5360#ifdef ISP_STRIPPED
5361 cname = NULL;
5362#else
5363 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5364#endif
5365 if (cname == NULL) {
5366 cname = tname;
5367 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5368 }
5369
5370 /*
5371 * Just to be chatty here...
5372 */
5373 xname = NULL;
5374 switch (mbp->param[0]) {
5375 case MBOX_COMMAND_COMPLETE:
5376 break;
5377 case MBOX_INVALID_COMMAND:
5378 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5379 xname = "INVALID COMMAND";
5380 break;
5381 case MBOX_HOST_INTERFACE_ERROR:
5382 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5383 xname = "HOST INTERFACE ERROR";
5384 break;
5385 case MBOX_TEST_FAILED:
5386 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5387 xname = "TEST FAILED";
5388 break;
5389 case MBOX_COMMAND_ERROR:
5390 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5391 xname = "COMMAND ERROR";
5392 break;
5393 case MBOX_COMMAND_PARAM_ERROR:
5394 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5395 xname = "COMMAND PARAMETER ERROR";
5396 break;
5397 case MBOX_LOOP_ID_USED:
5398 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5399 xname = "LOOP ID ALREADY IN USE";
5400 break;
5401 case MBOX_PORT_ID_USED:
5402 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5403 xname = "PORT ID ALREADY IN USE";
5404 break;
5405 case MBOX_ALL_IDS_USED:
5406 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5407 xname = "ALL LOOP IDS IN USE";
5408 break;
5409 case 0: /* special case */
5410 xname = "TIMEOUT";
5411 break;
5412 default:
5413 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5414 xname = mname;
5415 break;
5416 }
5417 if (xname)
5418 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5419 cname, xname);
5420}
5421
5422static void
5423isp_fw_state(struct ispsoftc *isp)
5424{
5425 if (IS_FC(isp)) {
5426 mbreg_t mbs;
5427 fcparam *fcp = isp->isp_param;
5428
5429 mbs.param[0] = MBOX_GET_FW_STATE;
5430 isp_mboxcmd(isp, &mbs, MBLOGALL);
5431 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5432 fcp->isp_fwstate = mbs.param[1];
5433 }
5434 }
5435}
5436
5437static void
5438isp_update(struct ispsoftc *isp)
5439{
5440 int bus, upmask;
5441
5442 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5443 if (upmask & (1 << bus)) {
5444 isp_update_bus(isp, bus);
5445 }
5446 upmask &= ~(1 << bus);
5447 }
5448}
5449
5450static void
5451isp_update_bus(struct ispsoftc *isp, int bus)
5452{
5453 int tgt;
5454 mbreg_t mbs;
5455 sdparam *sdp;
5456
5457 isp->isp_update &= ~(1 << bus);
5458 if (IS_FC(isp)) {
5459 /*
5460 * There are no 'per-bus' settings for Fibre Channel.
5461 */
5462 return;
5463 }
5464 sdp = isp->isp_param;
5465 sdp += bus;
5466
5467 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5468 u_int16_t flags, period, offset;
5469 int get;
5470
5471 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5472 sdp->isp_devparam[tgt].dev_update = 0;
5473 sdp->isp_devparam[tgt].dev_refresh = 0;
5474 isp_prt(isp, ISP_LOGDEBUG0,
5475 "skipping target %d bus %d update", tgt, bus);
5476 continue;
5477 }
5478 /*
5479 * If the goal is to update the status of the device,
5480 * take what's in goal_flags and try and set the device
5481 * toward that. Otherwise, if we're just refreshing the
5482 * current device state, get the current parameters.
5483 */
5484
5485 /*
5486 * Refresh overrides set
5487 */
5488 if (sdp->isp_devparam[tgt].dev_refresh) {
5489 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5490 sdp->isp_devparam[tgt].dev_refresh = 0;
5491 get = 1;
5492 } else if (sdp->isp_devparam[tgt].dev_update) {
5493 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5494 /*
5495 * Make sure goal_flags has "Renegotiate on Error"
5496 * on and "Freeze Queue on Error" off.
5497 */
5498 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5499 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5500
5501 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5502
5503 /*
5504 * Insist that PARITY must be enabled
5505 * if SYNC or WIDE is enabled.
5506 */
5507 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5508 mbs.param[2] |= DPARM_PARITY;
5509 }
5510
5511 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5512 mbs.param[3] = 0;
5513 } else {
5514 mbs.param[3] =
5515 (sdp->isp_devparam[tgt].goal_offset << 8) |
5516 (sdp->isp_devparam[tgt].goal_period);
5517 }
5518 /*
5519 * A command completion later that has
5520 * RQSTF_NEGOTIATION set can cause
5521 * the dev_refresh/announce cycle also.
5522 *
5523 * Note: It is really important to update our current
5524 * flags with at least the state of TAG capabilities-
5525 * otherwise we might try and send a tagged command
5526 * when we have it all turned off. So change it here
5527 * to say that current already matches goal.
5528 */
5529 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5530 sdp->isp_devparam[tgt].actv_flags |=
5531 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5532 isp_prt(isp, ISP_LOGDEBUG0,
5533 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5534 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5535 mbs.param[3] & 0xff);
5536 sdp->isp_devparam[tgt].dev_update = 0;
5537 sdp->isp_devparam[tgt].dev_refresh = 1;
5538 get = 0;
5539 } else {
5540 continue;
5541 }
5542 mbs.param[1] = (bus << 15) | (tgt << 8);
5543 isp_mboxcmd(isp, &mbs, MBLOGALL);
5544 if (get == 0) {
5545 isp->isp_sendmarker |= (1 << bus);
5546 continue;
5547 }
5548 flags = mbs.param[2];
5549 period = mbs.param[3] & 0xff;
5550 offset = mbs.param[3] >> 8;
5551 sdp->isp_devparam[tgt].actv_flags = flags;
5552 sdp->isp_devparam[tgt].actv_period = period;
5553 sdp->isp_devparam[tgt].actv_offset = offset;
5554 get = (bus << 16) | tgt;
5555 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5556 }
5557
5558 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5559 if (sdp->isp_devparam[tgt].dev_update ||
5560 sdp->isp_devparam[tgt].dev_refresh) {
5561 isp->isp_update |= (1 << bus);
5562 break;
5563 }
5564 }
5565}
5566
5567#ifndef DEFAULT_FRAMESIZE
5568#define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5569#endif
5570#ifndef DEFAULT_EXEC_THROTTLE
5571#define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5572#endif
5573
5574static void
5575isp_setdfltparm(struct ispsoftc *isp, int channel)
5576{
5577 int tgt;
5578 mbreg_t mbs;
5579 sdparam *sdp;
5580
5581 if (IS_FC(isp)) {
5582 fcparam *fcp = (fcparam *) isp->isp_param;
5583 int nvfail;
5584
5585 fcp += channel;
5586 if (fcp->isp_gotdparms) {
5587 return;
5588 }
5589 fcp->isp_gotdparms = 1;
5590 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5591 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5592 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5593 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5594 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5595 /* Platform specific.... */
5596 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5597 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5598 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5599 fcp->isp_fwoptions = 0;
5600 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5601 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5602 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5603#ifndef ISP_NO_FASTPOST_FC
5604 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5605#endif
5606 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5607 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5608
5609 /*
5610 * Make sure this is turned off now until we get
5611 * extended options from NVRAM
5612 */
5613 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5614
5615 /*
5616 * Now try and read NVRAM unless told to not do so.
5617 * This will set fcparam's isp_nodewwn && isp_portwwn.
5618 */
5619 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5620 nvfail = isp_read_nvram(isp);
5621 if (nvfail)
5622 isp->isp_confopts |= ISP_CFG_NONVRAM;
5623 } else {
5624 nvfail = 1;
5625 }
5626 /*
5627 * Set node && port to override platform set defaults
5628 * unless the nvram read failed (or none was done),
5629 * or the platform code wants to use what had been
5630 * set in the defaults.
5631 */
5632 if (nvfail) {
5633 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5634 }
5635 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5636 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5637 (u_int32_t) (DEFAULT_NODEWWN(isp) >> 32),
5638 (u_int32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5639 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5640 } else {
5641 /*
5642 * We always start out with values derived
5643 * from NVRAM or our platform default.
5644 */
5645 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5646 }
5647 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5648 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5649 (u_int32_t) (DEFAULT_PORTWWN(isp) >> 32),
5650 (u_int32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5651 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5652 } else {
5653 /*
5654 * We always start out with values derived
5655 * from NVRAM or our platform default.
5656 */
5657 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5658 }
5659 return;
5660 }
5661
5662 sdp = (sdparam *) isp->isp_param;
5663 sdp += channel;
5664
5665 /*
5666 * Been there, done that, got the T-shirt...
5667 */
5668 if (sdp->isp_gotdparms) {
5669 return;
5670 }
5671 sdp->isp_gotdparms = 1;
5672
5673 /*
5674 * Establish some default parameters.
5675 */
5676 sdp->isp_cmd_dma_burst_enable = 0;
5677 sdp->isp_data_dma_burst_enabl = 1;
5678 sdp->isp_fifo_threshold = 0;
5679 sdp->isp_initiator_id = DEFAULT_IID(isp);
5680 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5681 sdp->isp_async_data_setup = 9;
5682 } else {
5683 sdp->isp_async_data_setup = 6;
5684 }
5685 sdp->isp_selection_timeout = 250;
5686 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5687 sdp->isp_tag_aging = 8;
5688 sdp->isp_bus_reset_delay = 5;
5689 /*
5690 * Don't retry selection, busy or queue full automatically- reflect
5691 * these back to us.
5692 */
5693 sdp->isp_retry_count = 0;
5694 sdp->isp_retry_delay = 0;
5695
5696 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5697 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5698 sdp->isp_devparam[tgt].dev_enable = 1;
5699 }
5700
5701 /*
5702 * If we've not been told to avoid reading NVRAM, try and read it.
5703 * If we're successful reading it, we can then return because NVRAM
5704 * will tell us what the desired settings are. Otherwise, we establish
5705 * some reasonable 'fake' nvram and goal defaults.
5706 */
5707
5708 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5709 if (isp_read_nvram(isp) == 0) {
5710 return;
5711 }
5712 }
5713
5714 /*
5715 * Now try and see whether we have specific values for them.
5716 */
5717 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5718 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5719 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5720 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5721 sdp->isp_req_ack_active_neg = 1;
5722 sdp->isp_data_line_active_neg = 1;
5723 } else {
5724 sdp->isp_req_ack_active_neg =
5725 (mbs.param[1+channel] >> 4) & 0x1;
5726 sdp->isp_data_line_active_neg =
5727 (mbs.param[1+channel] >> 5) & 0x1;
5728 }
5729 }
5730
5731 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5732 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5733 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5734 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5735 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5736 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5737 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5738 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5739
5740 /*
5741 * The trick here is to establish a default for the default (honk!)
5742 * state (goal_flags). Then try and get the current status from
5743 * the card to fill in the current state. We don't, in fact, set
5744 * the default to the SAFE default state- that's not the goal state.
5745 */
5746 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5747 u_int8_t off, per;
5748 sdp->isp_devparam[tgt].actv_offset = 0;
5749 sdp->isp_devparam[tgt].actv_period = 0;
5750 sdp->isp_devparam[tgt].actv_flags = 0;
5751
5752 sdp->isp_devparam[tgt].goal_flags =
5753 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5754
5755 /*
5756 * We default to Wide/Fast for versions less than a 1040
5757 * (unless it's SBus).
5758 */
5759 if (IS_ULTRA3(isp)) {
5760 off = ISP_80M_SYNCPARMS >> 8;
5761 per = ISP_80M_SYNCPARMS & 0xff;
5762 } else if (IS_ULTRA2(isp)) {
5763 off = ISP_40M_SYNCPARMS >> 8;
5764 per = ISP_40M_SYNCPARMS & 0xff;
5765 } else if (IS_1240(isp)) {
5766 off = ISP_20M_SYNCPARMS >> 8;
5767 per = ISP_20M_SYNCPARMS & 0xff;
5768 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5769 isp->isp_type < ISP_HA_SCSI_1020A) ||
5770 (isp->isp_bustype == ISP_BT_PCI &&
5771 isp->isp_type < ISP_HA_SCSI_1040) ||
5772 (isp->isp_clock && isp->isp_clock < 60) ||
5773 (sdp->isp_ultramode == 0)) {
5774 off = ISP_10M_SYNCPARMS >> 8;
5775 per = ISP_10M_SYNCPARMS & 0xff;
5776 } else {
5777 off = ISP_20M_SYNCPARMS_1040 >> 8;
5778 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5779 }
5780 sdp->isp_devparam[tgt].goal_offset =
5781 sdp->isp_devparam[tgt].nvrm_offset = off;
5782 sdp->isp_devparam[tgt].goal_period =
5783 sdp->isp_devparam[tgt].nvrm_period = per;
5784
5785 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5786 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5787 sdp->isp_devparam[tgt].nvrm_offset,
5788 sdp->isp_devparam[tgt].nvrm_period);
5789 }
5790}
5791
5792/*
5793 * Re-initialize the ISP and complete all orphaned commands
5794 * with a 'botched' notice. The reset/init routines should
5795 * not disturb an already active list of commands.
5796 *
5797 * Locks held prior to coming here.
5798 */
5799
5800void
5801isp_reinit(struct ispsoftc *isp)
5802{
5803 XS_T *xs;
5804 u_int16_t handle;
5805
5806 isp_reset(isp);
5807 if (isp->isp_state != ISP_RESETSTATE) {
5808 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5809 } else if (isp->isp_role != ISP_ROLE_NONE) {
5810 isp_init(isp);
5811 if (isp->isp_state == ISP_INITSTATE) {
5812 isp->isp_state = ISP_RUNSTATE;
5813 }
5814 if (isp->isp_state != ISP_RUNSTATE) {
5815 isp_prt(isp, ISP_LOGERR,
5816 "isp_reinit cannot restart card");
5817 }
5818 }
5819 isp->isp_nactive = 0;
5820
5821 for (handle = 1; (int) handle <= isp->isp_maxcmds; handle++) {
5822 xs = isp_find_xs(isp, handle);
5823 if (xs == NULL) {
5824 continue;
5825 }
5826 isp_destroy_handle(isp, handle);
5827 if (XS_XFRLEN(xs)) {
5828 ISP_DMAFREE(isp, xs, handle);
5829 XS_RESID(xs) = XS_XFRLEN(xs);
5830 } else {
5831 XS_RESID(xs) = 0;
5832 }
5833 XS_SETERR(xs, HBA_BUSRESET);
5834 isp_done(xs);
5835 }
5836}
5837
5838/*
5839 * NVRAM Routines
5840 */
5841static int
5842isp_read_nvram(struct ispsoftc *isp)
5843{
5844 int i, amt;
5845 u_int8_t csum, minversion;
5846 union {
5847 u_int8_t _x[ISP2100_NVRAM_SIZE];
5848 u_int16_t _s[ISP2100_NVRAM_SIZE>>1];
5849 } _n;
5850#define nvram_data _n._x
5851#define nvram_words _n._s
5852
5853 if (IS_FC(isp)) {
5854 amt = ISP2100_NVRAM_SIZE;
5855 minversion = 1;
5856 } else if (IS_ULTRA2(isp)) {
5857 amt = ISP1080_NVRAM_SIZE;
5858 minversion = 0;
5859 } else {
5860 amt = ISP_NVRAM_SIZE;
5861 minversion = 2;
5862 }
5863
5864 /*
5865 * Just read the first two words first to see if we have a valid
5866 * NVRAM to continue reading the rest with.
5867 */
5868 for (i = 0; i < 2; i++) {
5869 isp_rdnvram_word(isp, i, &nvram_words[i]);
5870 }
5871 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
5872 nvram_data[2] != 'P') {
5873 if (isp->isp_bustype != ISP_BT_SBUS) {
5874 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
5875 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
5876 nvram_data[0], nvram_data[1], nvram_data[2]);
5877 }
5878 return (-1);
5879 }
5880 for (i = 2; i < amt>>1; i++) {
5881 isp_rdnvram_word(isp, i, &nvram_words[i]);
5882 }
5883 for (csum = 0, i = 0; i < amt; i++) {
5884 csum += nvram_data[i];
5885 }
5886 if (csum != 0) {
5887 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
5888 return (-1);
5889 }
5890 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
5891 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
5892 ISP_NVRAM_VERSION(nvram_data));
5893 return (-1);
5894 }
5895
5896 if (IS_ULTRA3(isp)) {
5897 isp_parse_nvram_12160(isp, 0, nvram_data);
5898 if (IS_12160(isp))
5899 isp_parse_nvram_12160(isp, 1, nvram_data);
5900 } else if (IS_1080(isp)) {
5901 isp_parse_nvram_1080(isp, 0, nvram_data);
5902 } else if (IS_1280(isp) || IS_1240(isp)) {
5903 isp_parse_nvram_1080(isp, 0, nvram_data);
5904 isp_parse_nvram_1080(isp, 1, nvram_data);
5905 } else if (IS_SCSI(isp)) {
5906 isp_parse_nvram_1020(isp, nvram_data);
5907 } else {
5908 isp_parse_nvram_2100(isp, nvram_data);
5909 }
5910 return (0);
5911#undef nvram_data
5912#undef nvram_words
5913}
5914
5915static void
5916isp_rdnvram_word(struct ispsoftc *isp, int wo, u_int16_t *rp)
5917{
5918 int i, cbits;
5919 u_int16_t bit, rqst;
5920
5921 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5922 USEC_DELAY(2);
5923 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5924 USEC_DELAY(2);
5925
5926 if (IS_FC(isp)) {
5927 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
5928 if (IS_2312(isp) && isp->isp_port) {
5929 wo += 128;
5930 }
5931 rqst = (ISP_NVRAM_READ << 8) | wo;
5932 cbits = 10;
5933 } else if (IS_ULTRA2(isp)) {
5934 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
5935 rqst = (ISP_NVRAM_READ << 8) | wo;
5936 cbits = 10;
5937 } else {
5938 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
5939 rqst = (ISP_NVRAM_READ << 6) | wo;
5940 cbits = 8;
5941 }
5942
5943 /*
5944 * Clock the word select request out...
5945 */
5946 for (i = cbits; i >= 0; i--) {
5947 if ((rqst >> i) & 1) {
5948 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
5949 } else {
5950 bit = BIU_NVRAM_SELECT;
5951 }
5952 ISP_WRITE(isp, BIU_NVRAM, bit);
5953 USEC_DELAY(2);
5954 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
5955 USEC_DELAY(2);
5956 ISP_WRITE(isp, BIU_NVRAM, bit);
5957 USEC_DELAY(2);
5958 }
5959 /*
5960 * Now read the result back in (bits come back in MSB format).
5961 */
5962 *rp = 0;
5963 for (i = 0; i < 16; i++) {
5964 u_int16_t rv;
5965 *rp <<= 1;
5966 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5967 USEC_DELAY(2);
5968 rv = ISP_READ(isp, BIU_NVRAM);
5969 if (rv & BIU_NVRAM_DATAIN) {
5970 *rp |= 1;
5971 }
5972 USEC_DELAY(2);
5973 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5974 USEC_DELAY(2);
5975 }
5976 ISP_WRITE(isp, BIU_NVRAM, 0);
5977 USEC_DELAY(2);
5978 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
5979}
5980
5981static void
5982isp_parse_nvram_1020(struct ispsoftc *isp, u_int8_t *nvram_data)
5983{
5984 sdparam *sdp = (sdparam *) isp->isp_param;
5985 int tgt;
5986
5987 sdp->isp_fifo_threshold =
5988 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
5989 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
5990
5991 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
5992 sdp->isp_initiator_id =
5993 ISP_NVRAM_INITIATOR_ID(nvram_data);
5994
5995 sdp->isp_bus_reset_delay =
5996 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
5997
5998 sdp->isp_retry_count =
5999 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6000
6001 sdp->isp_retry_delay =
6002 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6003
6004 sdp->isp_async_data_setup =
6005 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6006
6007 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6008 if (sdp->isp_async_data_setup < 9) {
6009 sdp->isp_async_data_setup = 9;
6010 }
6011 } else {
6012 if (sdp->isp_async_data_setup != 6) {
6013 sdp->isp_async_data_setup = 6;
6014 }
6015 }
6016
6017 sdp->isp_req_ack_active_neg =
6018 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6019
6020 sdp->isp_data_line_active_neg =
6021 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6022
6023 sdp->isp_data_dma_burst_enabl =
6024 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6025
6026 sdp->isp_cmd_dma_burst_enable =
6027 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6028
6029 sdp->isp_tag_aging =
6030 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6031
6032 sdp->isp_selection_timeout =
6033 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6034
6035 sdp->isp_max_queue_depth =
6036 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6037
6038 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6039
6040 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6041 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6042 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6043 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6044 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6045 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6046 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6047 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6048
6049 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6050 sdp->isp_devparam[tgt].dev_enable =
6051 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6052 sdp->isp_devparam[tgt].exc_throttle =
6053 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6054 sdp->isp_devparam[tgt].nvrm_offset =
6055 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6056 sdp->isp_devparam[tgt].nvrm_period =
6057 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6058 /*
6059 * We probably shouldn't lie about this, but it
6060 * it makes it much safer if we limit NVRAM values
6061 * to sanity.
6062 */
6063 if (isp->isp_type < ISP_HA_SCSI_1040) {
6064 /*
6065 * If we're not ultra, we can't possibly
6066 * be a shorter period than this.
6067 */
6068 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6069 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6070 }
6071 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6072 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6073 }
6074 } else {
6075 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6076 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6077 }
6078 }
6079 sdp->isp_devparam[tgt].nvrm_flags = 0;
6080 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6081 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6082 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6083 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6084 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6085 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6086 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6087 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6088 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6089 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6090 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6091 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6092 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6093 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6094 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6095 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6096 sdp->isp_devparam[tgt].nvrm_offset,
6097 sdp->isp_devparam[tgt].nvrm_period);
6098 sdp->isp_devparam[tgt].goal_offset =
6099 sdp->isp_devparam[tgt].nvrm_offset;
6100 sdp->isp_devparam[tgt].goal_period =
6101 sdp->isp_devparam[tgt].nvrm_period;
6102 sdp->isp_devparam[tgt].goal_flags =
6103 sdp->isp_devparam[tgt].nvrm_flags;
6104 }
6105}
6106
6107static void
6108isp_parse_nvram_1080(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6109{
6110 sdparam *sdp = (sdparam *) isp->isp_param;
6111 int tgt;
6112
6113 sdp += bus;
6114
6115 sdp->isp_fifo_threshold =
6116 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6117
6118 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6119 sdp->isp_initiator_id =
6120 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6121
6122 sdp->isp_bus_reset_delay =
6123 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6124
6125 sdp->isp_retry_count =
6126 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6127
6128 sdp->isp_retry_delay =
6129 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6130
6131 sdp->isp_async_data_setup =
6132 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6133
6134 sdp->isp_req_ack_active_neg =
6135 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6136
6137 sdp->isp_data_line_active_neg =
6138 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6139
6140 sdp->isp_data_dma_burst_enabl =
6141 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6142
6143 sdp->isp_cmd_dma_burst_enable =
6144 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6145
6146 sdp->isp_selection_timeout =
6147 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6148
6149 sdp->isp_max_queue_depth =
6150 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6151
6152 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6153 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6154 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6155 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6156 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6157 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6158 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6159 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6160
6161
6162 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6163 sdp->isp_devparam[tgt].dev_enable =
6164 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6165 sdp->isp_devparam[tgt].exc_throttle =
6166 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6167 sdp->isp_devparam[tgt].nvrm_offset =
6168 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6169 sdp->isp_devparam[tgt].nvrm_period =
6170 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6171 sdp->isp_devparam[tgt].nvrm_flags = 0;
6172 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6173 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6174 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6175 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6176 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6177 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6178 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6179 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6180 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6181 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6182 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6183 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6184 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6185 sdp->isp_devparam[tgt].actv_flags = 0;
6186 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6187 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6188 sdp->isp_devparam[tgt].nvrm_offset,
6189 sdp->isp_devparam[tgt].nvrm_period);
6190 sdp->isp_devparam[tgt].goal_offset =
6191 sdp->isp_devparam[tgt].nvrm_offset;
6192 sdp->isp_devparam[tgt].goal_period =
6193 sdp->isp_devparam[tgt].nvrm_period;
6194 sdp->isp_devparam[tgt].goal_flags =
6195 sdp->isp_devparam[tgt].nvrm_flags;
6196 }
6197}
6198
6199static void
6200isp_parse_nvram_12160(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6201{
6202 sdparam *sdp = (sdparam *) isp->isp_param;
6203 int tgt;
6204
6205 sdp += bus;
6206
6207 sdp->isp_fifo_threshold =
6208 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6209
6210 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6211 sdp->isp_initiator_id =
6212 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6213
6214 sdp->isp_bus_reset_delay =
6215 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6216
6217 sdp->isp_retry_count =
6218 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6219
6220 sdp->isp_retry_delay =
6221 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6222
6223 sdp->isp_async_data_setup =
6224 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6225
6226 sdp->isp_req_ack_active_neg =
6227 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6228
6229 sdp->isp_data_line_active_neg =
6230 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6231
6232 sdp->isp_data_dma_burst_enabl =
6233 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6234
6235 sdp->isp_cmd_dma_burst_enable =
6236 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6237
6238 sdp->isp_selection_timeout =
6239 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6240
6241 sdp->isp_max_queue_depth =
6242 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6243
6244 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6245 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6246 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6247 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6248 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6249 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6250 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6251 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6252
6253 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6254 sdp->isp_devparam[tgt].dev_enable =
6255 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6256 sdp->isp_devparam[tgt].exc_throttle =
6257 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6258 sdp->isp_devparam[tgt].nvrm_offset =
6259 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6260 sdp->isp_devparam[tgt].nvrm_period =
6261 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6262 sdp->isp_devparam[tgt].nvrm_flags = 0;
6263 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6264 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6265 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6266 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6267 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6268 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6269 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6270 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6271 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6272 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6273 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6274 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6275 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6276 sdp->isp_devparam[tgt].actv_flags = 0;
6277 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6278 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6279 sdp->isp_devparam[tgt].nvrm_offset,
6280 sdp->isp_devparam[tgt].nvrm_period);
6281 sdp->isp_devparam[tgt].goal_offset =
6282 sdp->isp_devparam[tgt].nvrm_offset;
6283 sdp->isp_devparam[tgt].goal_period =
6284 sdp->isp_devparam[tgt].nvrm_period;
6285 sdp->isp_devparam[tgt].goal_flags =
6286 sdp->isp_devparam[tgt].nvrm_flags;
6287 }
6288}
6289
6290static void
6291isp_parse_nvram_2100(struct ispsoftc *isp, u_int8_t *nvram_data)
6292{
6293 fcparam *fcp = (fcparam *) isp->isp_param;
6294 u_int64_t wwn;
6295
6296 /*
6297 * There is NVRAM storage for both Port and Node entities-
6298 * but the Node entity appears to be unused on all the cards
6299 * I can find. However, we should account for this being set
6300 * at some point in the future.
6301 *
6302 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6303 * bits 48..60. In the case of the 2202, it appears that they do
6304 * use bit 48 to distinguish between the two instances on the card.
6305 * The 2204, which I've never seen, *probably* extends this method.
6306 */
6307 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6308 if (wwn) {
6309 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6310 (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
6311 if ((wwn >> 60) == 0) {
6312 wwn |= (((u_int64_t) 2)<< 60);
6313 }
6314 }
6315 fcp->isp_portwwn = wwn;
6316 if (IS_2200(isp) || IS_23XX(isp)) {
6317 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6318 if (wwn) {
6319 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6320 (u_int32_t) (wwn >> 32),
6321 (u_int32_t) (wwn & 0xffffffff));
6322 if ((wwn >> 60) == 0) {
6323 wwn |= (((u_int64_t) 2)<< 60);
6324 }
6325 }
6326 } else {
6327 wwn &= ~((u_int64_t) 0xfff << 48);
6328 }
6329 fcp->isp_nodewwn = wwn;
6330
6331 /*
6332 * Make sure we have both Node and Port as non-zero values.
6333 */
6334 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6335 fcp->isp_portwwn = fcp->isp_nodewwn;
6336 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6337 fcp->isp_nodewwn = fcp->isp_portwwn;
6338 }
6339
6340 /*
6341 * Make the Node and Port values sane if they're NAA == 2.
6342 * This means to clear bits 48..56 for the Node WWN and
6343 * make sure that there's some non-zero value in 48..56
6344 * for the Port WWN.
6345 */
6346 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6347 if ((fcp->isp_nodewwn & (((u_int64_t) 0xfff) << 48)) != 0 &&
6348 (fcp->isp_nodewwn >> 60) == 2) {
6349 fcp->isp_nodewwn &= ~((u_int64_t) 0xfff << 48);
6350 }
6351 if ((fcp->isp_portwwn & (((u_int64_t) 0xfff) << 48)) == 0 &&
6352 (fcp->isp_portwwn >> 60) == 2) {
6353 fcp->isp_portwwn |= ((u_int64_t) 1 << 56);
6354 }
6355 }
6356
6357 isp_prt(isp, ISP_LOGDEBUG0,
6358 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6359 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6360 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6361 ISP2100_NVRAM_OPTIONS(nvram_data),
6362 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6363
6364 fcp->isp_maxalloc =
6365 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6366 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6367 fcp->isp_maxfrmlen =
6368 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6369 fcp->isp_retry_delay =
6370 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6371 fcp->isp_retry_count =
6372 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6373 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6374 fcp->isp_loopid =
6375 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6376 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6377 fcp->isp_execthrottle =
6378 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6379 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6380}
6381
6382#ifdef ISP_FW_CRASH_DUMP
6383static void isp2200_fw_dump(struct ispsoftc *);
6384static void isp2300_fw_dump(struct ispsoftc *);
6385
6386static void
6387isp2200_fw_dump(struct ispsoftc *isp)
6388{
6389 int i, j;
6390 mbreg_t mbs;
6391 u_int16_t *ptr;
6392
6393 ptr = FCPARAM(isp)->isp_dump_data;
6394 if (ptr == NULL) {
6395 isp_prt(isp, ISP_LOGERR,
6396 "No place to dump RISC registers and SRAM");
6397 return;
6398 }
6399 if (*ptr++) {
6400 isp_prt(isp, ISP_LOGERR,
6401 "dump area for RISC registers and SRAM already used");
6402 return;
6403 }
6404 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6405 for (i = 0; i < 100; i++) {
6406 USEC_DELAY(100);
6407 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6408 break;
6409 }
6410 }
6411 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6412 /*
6413 * PBIU Registers
6414 */
6415 for (i = 0; i < 8; i++) {
6416 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6417 }
6418
6419 /*
6420 * Mailbox Registers
6421 */
6422 for (i = 0; i < 8; i++) {
6423 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6424 }
6425
6426 /*
6427 * DMA Registers
6428 */
6429 for (i = 0; i < 48; i++) {
6430 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6431 }
6432
6433 /*
6434 * RISC H/W Registers
6435 */
6436 ISP_WRITE(isp, BIU2100_CSR, 0);
6437 for (i = 0; i < 16; i++) {
6438 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6439 }
6440
6441 /*
6442 * RISC GP Registers
6443 */
6444 for (j = 0; j < 8; j++) {
6445 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6446 for (i = 0; i < 16; i++) {
6447 *ptr++ =
6448 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6449 }
6450 }
6451
6452 /*
6453 * Frame Buffer Hardware Registers
6454 */
6455 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6456 for (i = 0; i < 16; i++) {
6457 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6458 }
6459
6460 /*
6461 * Fibre Protocol Module 0 Hardware Registers
6462 */
6463 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6464 for (i = 0; i < 64; i++) {
6465 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6466 }
6467
6468 /*
6469 * Fibre Protocol Module 1 Hardware Registers
6470 */
6471 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6472 for (i = 0; i < 64; i++) {
6473 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6474 }
6475 } else {
6476 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6477 return;
6478 }
6479 isp_prt(isp, ISP_LOGALL,
6480 "isp_fw_dump: RISC registers dumped successfully");
6481 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6482 for (i = 0; i < 100; i++) {
6483 USEC_DELAY(100);
6484 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6485 break;
6486 }
6487 }
6488 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6489 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6490 return;
6491 }
6492 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6493 for (i = 0; i < 100; i++) {
6494 USEC_DELAY(100);
6495 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6496 break;
6497 }
6498 }
6499 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6500 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6501 return;
6502 }
6503 ISP_WRITE(isp, RISC_EMB, 0xf2);
6504 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6505 for (i = 0; i < 100; i++) {
6506 USEC_DELAY(100);
6507 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6508 break;
6509 }
6510 }
6511 ENABLE_INTS(isp);
6512 mbs.param[0] = MBOX_READ_RAM_WORD;
6513 mbs.param[1] = 0x1000;
6514 isp->isp_mbxworkp = (void *) ptr;
6515 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6516 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6517 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6518 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6519 isp_prt(isp, ISP_LOGWARN,
6520 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6521 return;
6522 }
6523 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6524 *ptr++ = isp->isp_mboxtmp[2];
6525 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped succesfully");
6526 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6527 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6528}
6529
6530static void
6531isp2300_fw_dump(struct ispsoftc *isp)
6532{
6533 int i, j;
6534 mbreg_t mbs;
6535 u_int16_t *ptr;
6536
6537 ptr = FCPARAM(isp)->isp_dump_data;
6538 if (ptr == NULL) {
6539 isp_prt(isp, ISP_LOGERR,
6540 "No place to dump RISC registers and SRAM");
6541 return;
6542 }
6543 if (*ptr++) {
6544 isp_prt(isp, ISP_LOGERR,
6545 "dump area for RISC registers and SRAM already used");
6546 return;
6547 }
6548 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6549 for (i = 0; i < 100; i++) {
6550 USEC_DELAY(100);
6551 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6552 break;
6553 }
6554 }
6555 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6556 /*
6557 * PBIU registers
6558 */
6559 for (i = 0; i < 8; i++) {
6560 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6561 }
6562
6563 /*
6564 * ReqQ-RspQ-Risc2Host Status registers
6565 */
6566 for (i = 0; i < 8; i++) {
6567 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6568 }
6569
6570 /*
6571 * Mailbox Registers
6572 */
6573 for (i = 0; i < 32; i++) {
6574 *ptr++ =
6575 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6576 }
6577
6578 /*
6579 * Auto Request Response DMA registers
6580 */
6581 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6582 for (i = 0; i < 32; i++) {
6583 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6584 }
6585
6586 /*
6587 * DMA registers
6588 */
6589 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6590 for (i = 0; i < 48; i++) {
6591 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6592 }
6593
6594 /*
6595 * RISC hardware registers
6596 */
6597 ISP_WRITE(isp, BIU2100_CSR, 0);
6598 for (i = 0; i < 16; i++) {
6599 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6600 }
6601
6602 /*
6603 * RISC GP? registers
6604 */
6605 for (j = 0; j < 8; j++) {
6606 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6607 for (i = 0; i < 16; i++) {
6608 *ptr++ =
6609 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6610 }
6611 }
6612
6613 /*
6614 * frame buffer hardware registers
6615 */
6616 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6617 for (i = 0; i < 64; i++) {
6618 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6619 }
6620
6621 /*
6622 * FPM B0 hardware registers
6623 */
6624 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6625 for (i = 0; i < 64; i++) {
6626 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6627 }
6628
6629 /*
6630 * FPM B1 hardware registers
6631 */
6632 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6633 for (i = 0; i < 64; i++) {
6634 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6635 }
6636 } else {
6637 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6638 return;
6639 }
6640 isp_prt(isp, ISP_LOGALL,
6641 "isp_fw_dump: RISC registers dumped successfully");
6642 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6643 for (i = 0; i < 100; i++) {
6644 USEC_DELAY(100);
6645 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6646 break;
6647 }
6648 }
6649 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6650 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6651 return;
6652 }
6653 ENABLE_INTS(isp);
6654 mbs.param[0] = MBOX_READ_RAM_WORD;
6655 mbs.param[1] = 0x800;
6656 isp->isp_mbxworkp = (void *) ptr;
6657 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6658 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6659 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6660 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6661 isp_prt(isp, ISP_LOGWARN,
6662 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6663 return;
6664 }
6665 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6666 *ptr++ = isp->isp_mboxtmp[2];
6667
6668 /*
6669 * We don't have access to mailbox registers 8.. onward
6670 * in our 'common' device model- so we have to set it
6671 * here and hope it stays the same!
6672 */
6673 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6674
6675 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6676 mbs.param[1] = 0;
6677 isp->isp_mbxworkp = (void *) ptr;
6678 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6679 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6680 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6681 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6682 isp_prt(isp, ISP_LOGWARN,
6683 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6684 return;
6685 }
6686 ptr = isp->isp_mbxworkp; /* finish final word */
6687 *ptr++ = mbs.param[2];
6688 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped succesfully");
6689 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6690 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6691}
6692
6693void
6694isp_fw_dump(struct ispsoftc *isp)
6695{
6696 if (IS_2200(isp))
6697 isp2200_fw_dump(isp);
6698 else if (IS_23XX(isp))
6699 isp2300_fw_dump(isp);
6700}
6701#endif
40/*
41 * Include header file appropriate for platform we're building on.
42 */
43
44#ifdef __NetBSD__
45#include <dev/ic/isp_netbsd.h>
46#endif
47#ifdef __FreeBSD__
48#include <dev/isp/isp_freebsd.h>
49#endif
50#ifdef __OpenBSD__
51#include <dev/ic/isp_openbsd.h>
52#endif
53#ifdef __linux__
54#include "isp_linux.h"
55#endif
56#ifdef __svr4__
57#include "isp_solaris.h"
58#endif
59
60/*
61 * General defines
62 */
63
64#define MBOX_DELAY_COUNT 1000000 / 100
65
66/*
67 * Local static data
68 */
69static const char portshift[] =
70 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
71static const char portdup[] =
72 "Target %d duplicates Target %d- killing off both";
73static const char retained[] =
74 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
75static const char lretained[] =
76 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
77static const char plogout[] =
78 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
79static const char plogierr[] =
80 "Command Error in PLOGI for Port 0x%x (0x%x)";
81static const char nopdb[] =
82 "Could not get PDB for Device @ Port 0x%x";
83static const char pdbmfail1[] =
84 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
85static const char pdbmfail2[] =
86 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
87static const char ldumped[] =
88 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
89static const char notresp[] =
90 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
91static const char xact1[] =
92 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
93static const char xact2[] =
94 "HBA attempted queued transaction to target routine %d on target %d bus %d";
95static const char xact3[] =
96 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
97static const char pskip[] =
98 "SCSI phase skipped for target %d.%d.%d";
99static const char topology[] =
100 "Loop ID %d, AL_PA 0x%x, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
101static const char swrej[] =
102 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
103static const char finmsg[] =
104 "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
105static const char sc0[] =
106 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
107static const char sc1[] =
108 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
109static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
110static const char sc3[] = "Generated";
111static const char sc4[] = "NVRAM";
112static const char bun[] =
113 "bad underrun for %d.%d (count %d, resid %d, status %s)";
114
115/*
116 * Local function prototypes.
117 */
118static int isp_parse_async(struct ispsoftc *, u_int16_t);
119static int isp_handle_other_response(struct ispsoftc *, int, isphdr_t *,
120 u_int16_t *);
121static void
122isp_parse_status(struct ispsoftc *, ispstatusreq_t *, XS_T *);
123static void isp_fastpost_complete(struct ispsoftc *, u_int16_t);
124static int isp_mbox_continue(struct ispsoftc *);
125static void isp_scsi_init(struct ispsoftc *);
126static void isp_scsi_channel_init(struct ispsoftc *, int);
127static void isp_fibre_init(struct ispsoftc *);
128static void isp_mark_getpdb_all(struct ispsoftc *);
129static int isp_getmap(struct ispsoftc *, fcpos_map_t *);
130static int isp_getpdb(struct ispsoftc *, int, isp_pdb_t *);
131static u_int64_t isp_get_portname(struct ispsoftc *, int, int);
132static int isp_fclink_test(struct ispsoftc *, int);
133static char *isp2100_fw_statename(int);
134static int isp_pdb_sync(struct ispsoftc *);
135static int isp_scan_loop(struct ispsoftc *);
136static int isp_fabric_mbox_cmd(struct ispsoftc *, mbreg_t *);
137static int isp_scan_fabric(struct ispsoftc *, int);
138static void isp_register_fc4_type(struct ispsoftc *);
139static void isp_fw_state(struct ispsoftc *);
140static void isp_mboxcmd_qnw(struct ispsoftc *, mbreg_t *, int);
141static void isp_mboxcmd(struct ispsoftc *, mbreg_t *, int);
142
143static void isp_update(struct ispsoftc *);
144static void isp_update_bus(struct ispsoftc *, int);
145static void isp_setdfltparm(struct ispsoftc *, int);
146static int isp_read_nvram(struct ispsoftc *);
147static void isp_rdnvram_word(struct ispsoftc *, int, u_int16_t *);
148static void isp_parse_nvram_1020(struct ispsoftc *, u_int8_t *);
149static void isp_parse_nvram_1080(struct ispsoftc *, int, u_int8_t *);
150static void isp_parse_nvram_12160(struct ispsoftc *, int, u_int8_t *);
151static void isp_parse_nvram_2100(struct ispsoftc *, u_int8_t *);
152
153/*
154 * Reset Hardware.
155 *
156 * Hit the chip over the head, download new f/w if available and set it running.
157 *
158 * Locking done elsewhere.
159 */
160
161void
162isp_reset(struct ispsoftc *isp)
163{
164 mbreg_t mbs;
165 u_int16_t code_org;
166 int loops, i, dodnld = 1;
167 char *btype = "????";
168
169 isp->isp_state = ISP_NILSTATE;
170
171 /*
172 * Basic types (SCSI, FibreChannel and PCI or SBus)
173 * have been set in the MD code. We figure out more
174 * here. Possibly more refined types based upon PCI
175 * identification. Chip revision has been gathered.
176 *
177 * After we've fired this chip up, zero out the conf1 register
178 * for SCSI adapters and do other settings for the 2100.
179 */
180
181 /*
182 * Get the current running firmware revision out of the
183 * chip before we hit it over the head (if this is our
184 * first time through). Note that we store this as the
185 * 'ROM' firmware revision- which it may not be. In any
186 * case, we don't really use this yet, but we may in
187 * the future.
188 */
189 if (isp->isp_touched == 0) {
190 /*
191 * First see whether or not we're sitting in the ISP PROM.
192 * If we've just been reset, we'll have the string "ISP "
193 * spread through outgoing mailbox registers 1-3. We do
194 * this for PCI cards because otherwise we really don't
195 * know what state the card is in and we could hang if
196 * we try this command otherwise.
197 *
198 * For SBus cards, we just do this because they almost
199 * certainly will be running firmware by now.
200 */
201 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
202 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
203 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
204 /*
205 * Just in case it was paused...
206 */
207 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
208 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
209 isp_mboxcmd(isp, &mbs, MBLOGNONE);
210 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
211 isp->isp_romfw_rev[0] = mbs.param[1];
212 isp->isp_romfw_rev[1] = mbs.param[2];
213 isp->isp_romfw_rev[2] = mbs.param[3];
214 }
215 }
216 isp->isp_touched = 1;
217 }
218
219 DISABLE_INTS(isp);
220
221 /*
222 * Set up default request/response queue in-pointer/out-pointer
223 * register indices.
224 */
225 if (IS_23XX(isp)) {
226 isp->isp_rqstinrp = BIU_REQINP;
227 isp->isp_rqstoutrp = BIU_REQOUTP;
228 isp->isp_respinrp = BIU_RSPINP;
229 isp->isp_respoutrp = BIU_RSPOUTP;
230 } else {
231 isp->isp_rqstinrp = INMAILBOX4;
232 isp->isp_rqstoutrp = OUTMAILBOX4;
233 isp->isp_respinrp = OUTMAILBOX5;
234 isp->isp_respoutrp = INMAILBOX5;
235 }
236
237 /*
238 * Put the board into PAUSE mode (so we can read the SXP registers
239 * or write FPM/FBM registers).
240 */
241 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
242
243 if (IS_FC(isp)) {
244 switch (isp->isp_type) {
245 case ISP_HA_FC_2100:
246 btype = "2100";
247 break;
248 case ISP_HA_FC_2200:
249 btype = "2200";
250 break;
251 case ISP_HA_FC_2300:
252 btype = "2300";
253 break;
254 case ISP_HA_FC_2312:
255 btype = "2312";
256 break;
257 default:
258 break;
259 }
260 /*
261 * While we're paused, reset the FPM module and FBM fifos.
262 */
263 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
264 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
265 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
266 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
267 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
268 } else if (IS_1240(isp)) {
269 sdparam *sdp = isp->isp_param;
270 btype = "1240";
271 isp->isp_clock = 60;
272 sdp->isp_ultramode = 1;
273 sdp++;
274 sdp->isp_ultramode = 1;
275 /*
276 * XXX: Should probably do some bus sensing.
277 */
278 } else if (IS_ULTRA2(isp)) {
279 static const char m[] = "bus %d is in %s Mode";
280 u_int16_t l;
281 sdparam *sdp = isp->isp_param;
282
283 isp->isp_clock = 100;
284
285 if (IS_1280(isp))
286 btype = "1280";
287 else if (IS_1080(isp))
288 btype = "1080";
289 else if (IS_10160(isp))
290 btype = "10160";
291 else if (IS_12160(isp))
292 btype = "12160";
293 else
294 btype = "<UNKLVD>";
295
296 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
297 switch (l) {
298 case ISP1080_LVD_MODE:
299 sdp->isp_lvdmode = 1;
300 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
301 break;
302 case ISP1080_HVD_MODE:
303 sdp->isp_diffmode = 1;
304 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
305 break;
306 case ISP1080_SE_MODE:
307 sdp->isp_ultramode = 1;
308 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
309 break;
310 default:
311 isp_prt(isp, ISP_LOGERR,
312 "unknown mode on bus %d (0x%x)", 0, l);
313 break;
314 }
315
316 if (IS_DUALBUS(isp)) {
317 sdp++;
318 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
319 l &= ISP1080_MODE_MASK;
320 switch(l) {
321 case ISP1080_LVD_MODE:
322 sdp->isp_lvdmode = 1;
323 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
324 break;
325 case ISP1080_HVD_MODE:
326 sdp->isp_diffmode = 1;
327 isp_prt(isp, ISP_LOGCONFIG,
328 m, 1, "Differential");
329 break;
330 case ISP1080_SE_MODE:
331 sdp->isp_ultramode = 1;
332 isp_prt(isp, ISP_LOGCONFIG,
333 m, 1, "Single-Ended");
334 break;
335 default:
336 isp_prt(isp, ISP_LOGERR,
337 "unknown mode on bus %d (0x%x)", 1, l);
338 break;
339 }
340 }
341 } else {
342 sdparam *sdp = isp->isp_param;
343 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
344 switch (i) {
345 default:
346 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
347 /* FALLTHROUGH */
348 case 1:
349 btype = "1020";
350 isp->isp_type = ISP_HA_SCSI_1020;
351 isp->isp_clock = 40;
352 break;
353 case 2:
354 /*
355 * Some 1020A chips are Ultra Capable, but don't
356 * run the clock rate up for that unless told to
357 * do so by the Ultra Capable bits being set.
358 */
359 btype = "1020A";
360 isp->isp_type = ISP_HA_SCSI_1020A;
361 isp->isp_clock = 40;
362 break;
363 case 3:
364 btype = "1040";
365 isp->isp_type = ISP_HA_SCSI_1040;
366 isp->isp_clock = 60;
367 break;
368 case 4:
369 btype = "1040A";
370 isp->isp_type = ISP_HA_SCSI_1040A;
371 isp->isp_clock = 60;
372 break;
373 case 5:
374 btype = "1040B";
375 isp->isp_type = ISP_HA_SCSI_1040B;
376 isp->isp_clock = 60;
377 break;
378 case 6:
379 btype = "1040C";
380 isp->isp_type = ISP_HA_SCSI_1040C;
381 isp->isp_clock = 60;
382 break;
383 }
384 /*
385 * Now, while we're at it, gather info about ultra
386 * and/or differential mode.
387 */
388 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
389 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
390 sdp->isp_diffmode = 1;
391 } else {
392 sdp->isp_diffmode = 0;
393 }
394 i = ISP_READ(isp, RISC_PSR);
395 if (isp->isp_bustype == ISP_BT_SBUS) {
396 i &= RISC_PSR_SBUS_ULTRA;
397 } else {
398 i &= RISC_PSR_PCI_ULTRA;
399 }
400 if (i != 0) {
401 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
402 sdp->isp_ultramode = 1;
403 /*
404 * If we're in Ultra Mode, we have to be 60Mhz clock-
405 * even for the SBus version.
406 */
407 isp->isp_clock = 60;
408 } else {
409 sdp->isp_ultramode = 0;
410 /*
411 * Clock is known. Gronk.
412 */
413 }
414
415 /*
416 * Machine dependent clock (if set) overrides
417 * our generic determinations.
418 */
419 if (isp->isp_mdvec->dv_clock) {
420 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
421 isp->isp_clock = isp->isp_mdvec->dv_clock;
422 }
423 }
424
425 }
426
427 /*
428 * Clear instrumentation
429 */
430 isp->isp_intcnt = isp->isp_intbogus = 0;
431
432 /*
433 * Do MD specific pre initialization
434 */
435 ISP_RESET0(isp);
436
437again:
438
439 /*
440 * Hit the chip over the head with hammer,
441 * and give the ISP a chance to recover.
442 */
443
444 if (IS_SCSI(isp)) {
445 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
446 /*
447 * A slight delay...
448 */
449 USEC_DELAY(100);
450
451 /*
452 * Clear data && control DMA engines.
453 */
454 ISP_WRITE(isp, CDMA_CONTROL,
455 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
456 ISP_WRITE(isp, DDMA_CONTROL,
457 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
458
459
460 } else {
461 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
462 /*
463 * A slight delay...
464 */
465 USEC_DELAY(100);
466
467 /*
468 * Clear data && control DMA engines.
469 */
470 ISP_WRITE(isp, CDMA2100_CONTROL,
471 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
472 ISP_WRITE(isp, TDMA2100_CONTROL,
473 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
474 ISP_WRITE(isp, RDMA2100_CONTROL,
475 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
476 }
477
478 /*
479 * Wait for ISP to be ready to go...
480 */
481 loops = MBOX_DELAY_COUNT;
482 for (;;) {
483 if (IS_SCSI(isp)) {
484 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
485 break;
486 } else {
487 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
488 break;
489 }
490 USEC_DELAY(100);
491 if (--loops < 0) {
492 ISP_DUMPREGS(isp, "chip reset timed out");
493 return;
494 }
495 }
496
497 /*
498 * After we've fired this chip up, zero out the conf1 register
499 * for SCSI adapters and other settings for the 2100.
500 */
501
502 if (IS_SCSI(isp)) {
503 ISP_WRITE(isp, BIU_CONF1, 0);
504 } else {
505 ISP_WRITE(isp, BIU2100_CSR, 0);
506 }
507
508 /*
509 * Reset RISC Processor
510 */
511 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
512 USEC_DELAY(100);
513 /* Clear semaphore register (just to be sure) */
514 ISP_WRITE(isp, BIU_SEMA, 0);
515
516 /*
517 * Establish some initial burst rate stuff.
518 * (only for the 1XX0 boards). This really should
519 * be done later after fetching from NVRAM.
520 */
521 if (IS_SCSI(isp)) {
522 u_int16_t tmp = isp->isp_mdvec->dv_conf1;
523 /*
524 * Busted FIFO. Turn off all but burst enables.
525 */
526 if (isp->isp_type == ISP_HA_SCSI_1040A) {
527 tmp &= BIU_BURST_ENABLE;
528 }
529 ISP_SETBITS(isp, BIU_CONF1, tmp);
530 if (tmp & BIU_BURST_ENABLE) {
531 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
532 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
533 }
534#ifdef PTI_CARDS
535 if (((sdparam *) isp->isp_param)->isp_ultramode) {
536 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
537 ISP_WRITE(isp, RISC_MTR, 0x1313);
538 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
539 }
540 } else {
541 ISP_WRITE(isp, RISC_MTR, 0x1212);
542 }
543 /*
544 * PTI specific register
545 */
546 ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
547#else
548 ISP_WRITE(isp, RISC_MTR, 0x1212);
549#endif
550 } else {
551 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
552 if (IS_2200(isp) || IS_23XX(isp)) {
553 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
554 }
555 }
556
557 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
558
559 /*
560 * Do MD specific post initialization
561 */
562 ISP_RESET1(isp);
563
564 /*
565 * Wait for everything to finish firing up.
566 *
567 * Avoid doing this on the 2312 because you can generate a PCI
568 * parity error (chip breakage).
569 */
570 if (IS_23XX(isp)) {
571 USEC_DELAY(5);
572 } else {
573 loops = MBOX_DELAY_COUNT;
574 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
575 USEC_DELAY(100);
576 if (--loops < 0) {
577 isp_prt(isp, ISP_LOGERR,
578 "MBOX_BUSY never cleared on reset");
579 return;
580 }
581 }
582 }
583
584 /*
585 * Up until this point we've done everything by just reading or
586 * setting registers. From this point on we rely on at least *some*
587 * kind of firmware running in the card.
588 */
589
590 /*
591 * Do some sanity checking.
592 */
593 mbs.param[0] = MBOX_NO_OP;
594 isp_mboxcmd(isp, &mbs, MBLOGALL);
595 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
596 return;
597 }
598
599 if (IS_SCSI(isp)) {
600 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
601 mbs.param[1] = 0xdead;
602 mbs.param[2] = 0xbeef;
603 mbs.param[3] = 0xffff;
604 mbs.param[4] = 0x1111;
605 mbs.param[5] = 0xa5a5;
606 isp_mboxcmd(isp, &mbs, MBLOGALL);
607 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
608 return;
609 }
610 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
611 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
612 mbs.param[5] != 0xa5a5) {
613 isp_prt(isp, ISP_LOGERR,
614 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
615 mbs.param[1], mbs.param[2], mbs.param[3],
616 mbs.param[4], mbs.param[5]);
617 return;
618 }
619
620 }
621
622 /*
623 * Download new Firmware, unless requested not to do so.
624 * This is made slightly trickier in some cases where the
625 * firmware of the ROM revision is newer than the revision
626 * compiled into the driver. So, where we used to compare
627 * versions of our f/w and the ROM f/w, now we just see
628 * whether we have f/w at all and whether a config flag
629 * has disabled our download.
630 */
631 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
632 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
633 dodnld = 0;
634 }
635
636 if (IS_23XX(isp))
637 code_org = ISP_CODE_ORG_2300;
638 else
639 code_org = ISP_CODE_ORG;
640
641 if (dodnld) {
642 isp->isp_mbxworkp = (void *) &isp->isp_mdvec->dv_ispfw[1];
643 isp->isp_mbxwrk0 = isp->isp_mdvec->dv_ispfw[3] - 1;
644 isp->isp_mbxwrk1 = code_org + 1;
645 mbs.param[0] = MBOX_WRITE_RAM_WORD;
646 mbs.param[1] = code_org;
647 mbs.param[2] = isp->isp_mdvec->dv_ispfw[0];
648 isp_mboxcmd(isp, &mbs, MBLOGNONE);
649 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
650 isp_prt(isp, ISP_LOGERR,
651 "F/W download failed at word %d",
652 isp->isp_mbxwrk1 - code_org);
653 dodnld = 0;
654 goto again;
655 }
656 /*
657 * Verify that it downloaded correctly.
658 */
659 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
660 mbs.param[1] = code_org;
661 isp_mboxcmd(isp, &mbs, MBLOGNONE);
662 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
663 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
664 return;
665 }
666 isp->isp_loaded_fw = 1;
667 } else {
668 isp->isp_loaded_fw = 0;
669 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
670 }
671
672 /*
673 * Now start it rolling.
674 *
675 * If we didn't actually download f/w,
676 * we still need to (re)start it.
677 */
678
679
680 mbs.param[0] = MBOX_EXEC_FIRMWARE;
681 mbs.param[1] = code_org;
682 isp_mboxcmd(isp, &mbs, MBLOGNONE);
683 /*
684 * Give it a chance to start.
685 */
686 USEC_DELAY(500);
687
688 if (IS_SCSI(isp)) {
689 /*
690 * Set CLOCK RATE, but only if asked to.
691 */
692 if (isp->isp_clock) {
693 mbs.param[0] = MBOX_SET_CLOCK_RATE;
694 mbs.param[1] = isp->isp_clock;
695 isp_mboxcmd(isp, &mbs, MBLOGALL);
696 /* we will try not to care if this fails */
697 }
698 }
699
700 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
701 isp_mboxcmd(isp, &mbs, MBLOGALL);
702 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
703 return;
704 }
705
706 /*
707 * The SBus firmware that we are using apparently does not return
708 * major, minor, micro revisions in the mailbox registers, which
709 * is really, really, annoying.
710 */
711 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
712 if (dodnld) {
713#ifdef ISP_TARGET_MODE
714 isp->isp_fwrev[0] = 7;
715 isp->isp_fwrev[1] = 55;
716#else
717 isp->isp_fwrev[0] = 1;
718 isp->isp_fwrev[1] = 37;
719#endif
720 isp->isp_fwrev[2] = 0;
721 }
722 } else {
723 isp->isp_fwrev[0] = mbs.param[1];
724 isp->isp_fwrev[1] = mbs.param[2];
725 isp->isp_fwrev[2] = mbs.param[3];
726 }
727 isp_prt(isp, ISP_LOGCONFIG,
728 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
729 btype, isp->isp_revision, dodnld? "loaded" : "resident",
730 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
731
732 if (IS_FC(isp)) {
733 /*
734 * We do not believe firmware attributes for 2100 code less
735 * than 1.17.0, unless it's the firmware we specifically
736 * are loading.
737 *
738 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
739 */
740 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
741#ifdef USE_SMALLER_2100_FIRMWARE
742 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
743#else
744 FCPARAM(isp)->isp_fwattr = 0;
745#endif
746 } else {
747 FCPARAM(isp)->isp_fwattr = mbs.param[6];
748 isp_prt(isp, ISP_LOGDEBUG0,
749 "Firmware Attributes = 0x%x", mbs.param[6]);
750 }
751 if (ISP_READ(isp, BIU2100_CSR) & BIU2100_PCI64) {
752 isp_prt(isp, ISP_LOGCONFIG,
753 "Installed in 64-Bit PCI slot");
754 }
755 }
756
757 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
758 isp->isp_romfw_rev[2]) {
759 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
760 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
761 isp->isp_romfw_rev[2]);
762 }
763
764 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
765 isp_mboxcmd(isp, &mbs, MBLOGALL);
766 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
767 return;
768 }
769 isp->isp_maxcmds = mbs.param[2];
770 isp_prt(isp, ISP_LOGINFO,
771 "%d max I/O commands supported", mbs.param[2]);
772 isp_fw_state(isp);
773
774 /*
775 * Set up DMA for the request and result mailboxes.
776 */
777 if (ISP_MBOXDMASETUP(isp) != 0) {
778 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
779 return;
780 }
781 isp->isp_state = ISP_RESETSTATE;
782
783 /*
784 * Okay- now that we have new firmware running, we now (re)set our
785 * notion of how many luns we support. This is somewhat tricky because
786 * if we haven't loaded firmware, we sometimes do not have an easy way
787 * of knowing how many luns we support.
788 *
789 * Expanded lun firmware gives you 32 luns for SCSI cards and
790 * 16384 luns for Fibre Channel cards.
791 *
792 * It turns out that even for QLogic 2100s with ROM 1.10 and above
793 * we do get a firmware attributes word returned in mailbox register 6.
794 *
795 * Because the lun is in a different position in the Request Queue
796 * Entry structure for Fibre Channel with expanded lun firmware, we
797 * can only support one lun (lun zero) when we don't know what kind
798 * of firmware we're running.
799 */
800 if (IS_SCSI(isp)) {
801 if (dodnld) {
802 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
803 isp->isp_maxluns = 32;
804 } else {
805 isp->isp_maxluns = 8;
806 }
807 } else {
808 isp->isp_maxluns = 8;
809 }
810 } else {
811 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
812 isp->isp_maxluns = 16384;
813 } else {
814 isp->isp_maxluns = 16;
815 }
816 }
817}
818
819/*
820 * Initialize Parameters of Hardware to a known state.
821 *
822 * Locks are held before coming here.
823 */
824
825void
826isp_init(struct ispsoftc *isp)
827{
828 /*
829 * Must do this first to get defaults established.
830 */
831 isp_setdfltparm(isp, 0);
832 if (IS_DUALBUS(isp)) {
833 isp_setdfltparm(isp, 1);
834 }
835 if (IS_FC(isp)) {
836 isp_fibre_init(isp);
837 } else {
838 isp_scsi_init(isp);
839 }
840}
841
842static void
843isp_scsi_init(struct ispsoftc *isp)
844{
845 sdparam *sdp_chan0, *sdp_chan1;
846 mbreg_t mbs;
847
848 sdp_chan0 = isp->isp_param;
849 sdp_chan1 = sdp_chan0;
850 if (IS_DUALBUS(isp)) {
851 sdp_chan1++;
852 }
853
854 /*
855 * If we have no role (neither target nor initiator), return.
856 */
857 if (isp->isp_role == ISP_ROLE_NONE) {
858 return;
859 }
860
861 /* First do overall per-card settings. */
862
863 /*
864 * If we have fast memory timing enabled, turn it on.
865 */
866 if (sdp_chan0->isp_fast_mttr) {
867 ISP_WRITE(isp, RISC_MTR, 0x1313);
868 }
869
870 /*
871 * Set Retry Delay and Count.
872 * You set both channels at the same time.
873 */
874 mbs.param[0] = MBOX_SET_RETRY_COUNT;
875 mbs.param[1] = sdp_chan0->isp_retry_count;
876 mbs.param[2] = sdp_chan0->isp_retry_delay;
877 mbs.param[6] = sdp_chan1->isp_retry_count;
878 mbs.param[7] = sdp_chan1->isp_retry_delay;
879
880 isp_mboxcmd(isp, &mbs, MBLOGALL);
881 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
882 return;
883 }
884
885 /*
886 * Set ASYNC DATA SETUP time. This is very important.
887 */
888 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
889 mbs.param[1] = sdp_chan0->isp_async_data_setup;
890 mbs.param[2] = sdp_chan1->isp_async_data_setup;
891 isp_mboxcmd(isp, &mbs, MBLOGALL);
892 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
893 return;
894 }
895
896 /*
897 * Set ACTIVE Negation State.
898 */
899 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
900 mbs.param[1] =
901 (sdp_chan0->isp_req_ack_active_neg << 4) |
902 (sdp_chan0->isp_data_line_active_neg << 5);
903 mbs.param[2] =
904 (sdp_chan1->isp_req_ack_active_neg << 4) |
905 (sdp_chan1->isp_data_line_active_neg << 5);
906
907 isp_mboxcmd(isp, &mbs, MBLOGNONE);
908 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
909 isp_prt(isp, ISP_LOGERR,
910 "failed to set active negation state (%d,%d), (%d,%d)",
911 sdp_chan0->isp_req_ack_active_neg,
912 sdp_chan0->isp_data_line_active_neg,
913 sdp_chan1->isp_req_ack_active_neg,
914 sdp_chan1->isp_data_line_active_neg);
915 /*
916 * But don't return.
917 */
918 }
919
920 /*
921 * Set the Tag Aging limit
922 */
923 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
924 mbs.param[1] = sdp_chan0->isp_tag_aging;
925 mbs.param[2] = sdp_chan1->isp_tag_aging;
926 isp_mboxcmd(isp, &mbs, MBLOGALL);
927 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
928 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
929 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
930 return;
931 }
932
933 /*
934 * Set selection timeout.
935 */
936 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
937 mbs.param[1] = sdp_chan0->isp_selection_timeout;
938 mbs.param[2] = sdp_chan1->isp_selection_timeout;
939 isp_mboxcmd(isp, &mbs, MBLOGALL);
940 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
941 return;
942 }
943
944 /* now do per-channel settings */
945 isp_scsi_channel_init(isp, 0);
946 if (IS_DUALBUS(isp))
947 isp_scsi_channel_init(isp, 1);
948
949 /*
950 * Now enable request/response queues
951 */
952
953 if (IS_ULTRA2(isp) || IS_1240(isp)) {
954 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
955 mbs.param[1] = RESULT_QUEUE_LEN(isp);
956 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
957 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
958 mbs.param[4] = 0;
959 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
960 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
961 isp_mboxcmd(isp, &mbs, MBLOGALL);
962 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
963 return;
964 }
965 isp->isp_residx = mbs.param[5];
966
967 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
968 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
969 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
970 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
971 mbs.param[5] = 0;
972 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
973 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
974 isp_mboxcmd(isp, &mbs, MBLOGALL);
975 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
976 return;
977 }
978 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
979 } else {
980 mbs.param[0] = MBOX_INIT_RES_QUEUE;
981 mbs.param[1] = RESULT_QUEUE_LEN(isp);
982 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
983 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
984 mbs.param[4] = 0;
985 isp_mboxcmd(isp, &mbs, MBLOGALL);
986 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
987 return;
988 }
989 isp->isp_residx = mbs.param[5];
990
991 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
992 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
993 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
994 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
995 mbs.param[5] = 0;
996 isp_mboxcmd(isp, &mbs, MBLOGALL);
997 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
998 return;
999 }
1000 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1001 }
1002
1003 /*
1004 * Turn on Fast Posting, LVD transitions
1005 *
1006 * Ultra2 F/W always has had fast posting (and LVD transitions)
1007 *
1008 * Ultra and older (i.e., SBus) cards may not. It's just safer
1009 * to assume not for them.
1010 */
1011
1012 mbs.param[0] = MBOX_SET_FW_FEATURES;
1013 mbs.param[1] = 0;
1014 if (IS_ULTRA2(isp))
1015 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1016#ifndef ISP_NO_RIO
1017 if (IS_ULTRA2(isp) || IS_1240(isp))
1018 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1019#else
1020#ifndef ISP_NO_FASTPOST
1021 if (IS_ULTRA2(isp) || IS_1240(isp))
1022 mbs.param[1] |= FW_FEATURE_FAST_POST;
1023#endif
1024#endif
1025 if (mbs.param[1] != 0) {
1026 u_int16_t sfeat = mbs.param[1];
1027 isp_mboxcmd(isp, &mbs, MBLOGALL);
1028 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1029 isp_prt(isp, ISP_LOGINFO,
1030 "Enabled FW features (0x%x)", sfeat);
1031 }
1032 }
1033
1034 /*
1035 * Let the outer layers decide whether to issue a SCSI bus reset.
1036 */
1037 isp->isp_state = ISP_INITSTATE;
1038}
1039
1040static void
1041isp_scsi_channel_init(struct ispsoftc *isp, int channel)
1042{
1043 sdparam *sdp;
1044 mbreg_t mbs;
1045 int tgt;
1046
1047 sdp = isp->isp_param;
1048 sdp += channel;
1049
1050 /*
1051 * Set (possibly new) Initiator ID.
1052 */
1053 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1054 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1055 isp_mboxcmd(isp, &mbs, MBLOGALL);
1056 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1057 return;
1058 }
1059 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1060 sdp->isp_initiator_id, channel);
1061
1062
1063 /*
1064 * Set current per-target parameters to an initial safe minimum.
1065 */
1066 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1067 int lun;
1068 u_int16_t sdf;
1069
1070 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1071 continue;
1072 }
1073#ifndef ISP_TARGET_MODE
1074 sdf = sdp->isp_devparam[tgt].goal_flags;
1075 sdf &= DPARM_SAFE_DFLT;
1076 /*
1077 * It is not quite clear when this changed over so that
1078 * we could force narrow and async for 1000/1020 cards,
1079 * but assume that this is only the case for loaded
1080 * firmware.
1081 */
1082 if (isp->isp_loaded_fw) {
1083 sdf |= DPARM_NARROW | DPARM_ASYNC;
1084 }
1085#else
1086 /*
1087 * The !$*!)$!$)* f/w uses the same index into some
1088 * internal table to decide how to respond to negotiations,
1089 * so if we've said "let's be safe" for ID X, and ID X
1090 * selects *us*, the negotiations will back to 'safe'
1091 * (as in narrow/async). What the f/w *should* do is
1092 * use the initiator id settings to decide how to respond.
1093 */
1094 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1095#endif
1096 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1097 mbs.param[1] = (channel << 15) | (tgt << 8);
1098 mbs.param[2] = sdf;
1099 if ((sdf & DPARM_SYNC) == 0) {
1100 mbs.param[3] = 0;
1101 } else {
1102 mbs.param[3] =
1103 (sdp->isp_devparam[tgt].goal_offset << 8) |
1104 (sdp->isp_devparam[tgt].goal_period);
1105 }
1106 isp_prt(isp, ISP_LOGDEBUG0,
1107 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1108 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1109 mbs.param[3] & 0xff);
1110 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1111 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1112 sdf = DPARM_SAFE_DFLT;
1113 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1114 mbs.param[1] = (tgt << 8) | (channel << 15);
1115 mbs.param[2] = sdf;
1116 mbs.param[3] = 0;
1117 isp_mboxcmd(isp, &mbs, MBLOGALL);
1118 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1119 continue;
1120 }
1121 }
1122
1123 /*
1124 * We don't update any information directly from the f/w
1125 * because we need to run at least one command to cause a
1126 * new state to be latched up. So, we just assume that we
1127 * converge to the values we just had set.
1128 *
1129 * Ensure that we don't believe tagged queuing is enabled yet.
1130 * It turns out that sometimes the ISP just ignores our
1131 * attempts to set parameters for devices that it hasn't
1132 * seen yet.
1133 */
1134 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1135 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1136 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1137 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1138 mbs.param[2] = sdp->isp_max_queue_depth;
1139 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1140 isp_mboxcmd(isp, &mbs, MBLOGALL);
1141 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1142 break;
1143 }
1144 }
1145 }
1146 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1147 if (sdp->isp_devparam[tgt].dev_refresh) {
1148 isp->isp_sendmarker |= (1 << channel);
1149 isp->isp_update |= (1 << channel);
1150 break;
1151 }
1152 }
1153}
1154
1155/*
1156 * Fibre Channel specific initialization.
1157 *
1158 * Locks are held before coming here.
1159 */
1160static void
1161isp_fibre_init(struct ispsoftc *isp)
1162{
1163 fcparam *fcp;
1164 isp_icb_t local, *icbp = &local;
1165 mbreg_t mbs;
1166 int loopid;
1167 u_int64_t nwwn, pwwn;
1168
1169 fcp = isp->isp_param;
1170
1171 /*
1172 * Do this *before* initializing the firmware.
1173 */
1174 isp_mark_getpdb_all(isp);
1175 fcp->isp_fwstate = FW_CONFIG_WAIT;
1176 fcp->isp_loopstate = LOOP_NIL;
1177
1178 /*
1179 * If we have no role (neither target nor initiator), return.
1180 */
1181 if (isp->isp_role == ISP_ROLE_NONE) {
1182 return;
1183 }
1184
1185 loopid = fcp->isp_loopid;
1186 MEMZERO(icbp, sizeof (*icbp));
1187 icbp->icb_version = ICB_VERSION1;
1188
1189 /*
1190 * Firmware Options are either retrieved from NVRAM or
1191 * are patched elsewhere. We check them for sanity here
1192 * and make changes based on board revision, but otherwise
1193 * let others decide policy.
1194 */
1195
1196 /*
1197 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1198 */
1199 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1200 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1201 }
1202
1203 /*
1204 * We have to use FULL LOGIN even though it resets the loop too much
1205 * because otherwise port database entries don't get updated after
1206 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1207 */
1208 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1209 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1210 }
1211
1212 /*
1213 * Insist on Port Database Update Async notifications
1214 */
1215 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1216
1217 /*
1218 * Make sure that target role reflects into fwoptions.
1219 */
1220 if (isp->isp_role & ISP_ROLE_TARGET) {
1221 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1222 } else {
1223 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1224 }
1225
1226 /*
1227 * Propagate all of this into the ICB structure.
1228 */
1229 icbp->icb_fwoptions = fcp->isp_fwoptions;
1230 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1231 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1232 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1233 isp_prt(isp, ISP_LOGERR,
1234 "bad frame length (%d) from NVRAM- using %d",
1235 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1236 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1237 }
1238 icbp->icb_maxalloc = fcp->isp_maxalloc;
1239 if (icbp->icb_maxalloc < 1) {
1240 isp_prt(isp, ISP_LOGERR,
1241 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1242 icbp->icb_maxalloc = 16;
1243 }
1244 icbp->icb_execthrottle = fcp->isp_execthrottle;
1245 if (icbp->icb_execthrottle < 1) {
1246 isp_prt(isp, ISP_LOGERR,
1247 "bad execution throttle of %d- using 16",
1248 fcp->isp_execthrottle);
1249 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1250 }
1251 icbp->icb_retry_delay = fcp->isp_retry_delay;
1252 icbp->icb_retry_count = fcp->isp_retry_count;
1253 icbp->icb_hardaddr = loopid;
1254 /*
1255 * Right now we just set extended options to prefer point-to-point
1256 * over loop based upon some soft config options.
1257 *
1258 * NB: for the 2300, ICBOPT_EXTENDED is required.
1259 */
1260 if (IS_2200(isp) || IS_23XX(isp)) {
1261 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1262 /*
1263 * Prefer or force Point-To-Point instead Loop?
1264 */
1265 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1266 case ISP_CFG_NPORT:
1267 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1268 break;
1269 case ISP_CFG_NPORT_ONLY:
1270 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1271 break;
1272 case ISP_CFG_LPORT_ONLY:
1273 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1274 break;
1275 default:
1276 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1277 break;
1278 }
1279 if (IS_23XX(isp)) {
1280 /*
1281 * QLogic recommends that FAST Posting be turned
1282 * off for 23XX cards and instead allow the HBA
1283 * to write response queue entries and interrupt
1284 * after a delay (ZIO).
1285 *
1286 * If we set ZIO, it will disable fast posting,
1287 * so we don't need to clear it in fwoptions.
1288 */
1289 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1290
1291 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1292 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1293 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1294 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1295 } else {
1296 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1297 }
1298 }
1299 }
1300
1301#ifndef ISP_NO_RIO_FC
1302 /*
1303 * RIO seems to be enabled in 2100s for fw >= 1.17.0.
1304 *
1305 * I've had some questionable problems with RIO on 2200.
1306 * More specifically, on a 2204 I had problems with RIO
1307 * on a Linux system where I was dropping commands right
1308 * and left. It's not clear to me what the actual problem
1309 * was.
1310 *
1311 * 23XX Cards do not support RIO. Instead they support ZIO.
1312 */
1313#if 0
1314 if (!IS_23XX(isp) && ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1315 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1316 icbp->icb_racctimer = 4;
1317 icbp->icb_idelaytimer = 8;
1318 }
1319#endif
1320#endif
1321
1322 /*
1323 * For 22XX > 2.1.26 && 23XX, set someoptions.
1324 * XXX: Probably okay for newer 2100 f/w too.
1325 */
1326 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1327 /*
1328 * Turn on LIP F8 async event (1)
1329 * Turn on generate AE 8013 on all LIP Resets (2)
1330 * Disable LIP F7 switching (8)
1331 */
1332 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1333 mbs.param[1] = 0xb;
1334 mbs.param[2] = 0;
1335 mbs.param[3] = 0;
1336 isp_mboxcmd(isp, &mbs, MBLOGALL);
1337 }
1338 icbp->icb_logintime = 30; /* 30 second login timeout */
1339
1340 if (IS_23XX(isp)) {
1341 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
1342 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
1343 ISP_WRITE(isp, isp->isp_respinrp, 0);
1344 ISP_WRITE(isp, isp->isp_respoutrp, 0);
1345 }
1346
1347 nwwn = ISP_NODEWWN(isp);
1348 pwwn = ISP_PORTWWN(isp);
1349 if (nwwn && pwwn) {
1350 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1351 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1352 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1353 isp_prt(isp, ISP_LOGDEBUG1,
1354 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1355 ((u_int32_t) (nwwn >> 32)),
1356 ((u_int32_t) (nwwn & 0xffffffff)),
1357 ((u_int32_t) (pwwn >> 32)),
1358 ((u_int32_t) (pwwn & 0xffffffff)));
1359 } else {
1360 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1361 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1362 }
1363 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1364 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1365 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1366 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1367 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1368 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1369 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1370 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1371 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1372 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1373 isp_prt(isp, ISP_LOGDEBUG0,
1374 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1375 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1376
1377 FC_SCRATCH_ACQUIRE(isp);
1378 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1379
1380 /*
1381 * Init the firmware
1382 */
1383 mbs.param[0] = MBOX_INIT_FIRMWARE;
1384 mbs.param[1] = 0;
1385 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1386 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1387 mbs.param[4] = 0;
1388 mbs.param[5] = 0;
1389 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1390 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1391 isp_mboxcmd(isp, &mbs, MBLOGALL);
1392 FC_SCRATCH_RELEASE(isp);
1393 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1394 return;
1395 }
1396 isp->isp_reqidx = isp->isp_reqodx = 0;
1397 isp->isp_residx = 0;
1398 isp->isp_sendmarker = 1;
1399
1400 /*
1401 * Whatever happens, we're now committed to being here.
1402 */
1403 isp->isp_state = ISP_INITSTATE;
1404}
1405
1406/*
1407 * Fibre Channel Support- get the port database for the id.
1408 *
1409 * Locks are held before coming here. Return 0 if success,
1410 * else failure.
1411 */
1412
1413static int
1414isp_getmap(struct ispsoftc *isp, fcpos_map_t *map)
1415{
1416 fcparam *fcp = (fcparam *) isp->isp_param;
1417 mbreg_t mbs;
1418
1419 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1420 mbs.param[1] = 0;
1421 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1422 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1423 /*
1424 * Unneeded. For the 2100, except for initializing f/w, registers
1425 * 4/5 have to not be written to.
1426 * mbs.param[4] = 0;
1427 * mbs.param[5] = 0;
1428 *
1429 */
1430 mbs.param[6] = 0;
1431 mbs.param[7] = 0;
1432 FC_SCRATCH_ACQUIRE(isp);
1433 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1434 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1435 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1436 map->fwmap = mbs.param[1] != 0;
1437 FC_SCRATCH_RELEASE(isp);
1438 return (0);
1439 }
1440 FC_SCRATCH_RELEASE(isp);
1441 return (-1);
1442}
1443
1444static void
1445isp_mark_getpdb_all(struct ispsoftc *isp)
1446{
1447 fcparam *fcp = (fcparam *) isp->isp_param;
1448 int i;
1449 for (i = 0; i < MAX_FC_TARG; i++) {
1450 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1451 }
1452}
1453
1454static int
1455isp_getpdb(struct ispsoftc *isp, int id, isp_pdb_t *pdbp)
1456{
1457 fcparam *fcp = (fcparam *) isp->isp_param;
1458 mbreg_t mbs;
1459
1460 mbs.param[0] = MBOX_GET_PORT_DB;
1461 mbs.param[1] = id << 8;
1462 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1463 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1464 /*
1465 * Unneeded. For the 2100, except for initializing f/w, registers
1466 * 4/5 have to not be written to.
1467 * mbs.param[4] = 0;
1468 * mbs.param[5] = 0;
1469 *
1470 */
1471 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1472 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1473 FC_SCRATCH_ACQUIRE(isp);
1474 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1475 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1476 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1477 FC_SCRATCH_RELEASE(isp);
1478 return (0);
1479 }
1480 FC_SCRATCH_RELEASE(isp);
1481 return (-1);
1482}
1483
1484static u_int64_t
1485isp_get_portname(struct ispsoftc *isp, int loopid, int nodename)
1486{
1487 u_int64_t wwn = 0;
1488 mbreg_t mbs;
1489
1490 mbs.param[0] = MBOX_GET_PORT_NAME;
1491 mbs.param[1] = loopid << 8;
1492 if (nodename)
1493 mbs.param[1] |= 1;
1494 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1495 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1496 wwn =
1497 (((u_int64_t)(mbs.param[2] & 0xff)) << 56) |
1498 (((u_int64_t)(mbs.param[2] >> 8)) << 48) |
1499 (((u_int64_t)(mbs.param[3] & 0xff)) << 40) |
1500 (((u_int64_t)(mbs.param[3] >> 8)) << 32) |
1501 (((u_int64_t)(mbs.param[6] & 0xff)) << 24) |
1502 (((u_int64_t)(mbs.param[6] >> 8)) << 16) |
1503 (((u_int64_t)(mbs.param[7] & 0xff)) << 8) |
1504 (((u_int64_t)(mbs.param[7] >> 8)));
1505 }
1506 return (wwn);
1507}
1508
1509/*
1510 * Make sure we have good FC link and know our Loop ID.
1511 */
1512
1513static int
1514isp_fclink_test(struct ispsoftc *isp, int usdelay)
1515{
1516 static char *toponames[] = {
1517 "Private Loop",
1518 "FL Port",
1519 "N-Port to N-Port",
1520 "F Port",
1521 "F Port (no FLOGI_ACC response)"
1522 };
1523 mbreg_t mbs;
1524 int count, check_for_fabric;
1525 u_int8_t lwfs;
1526 fcparam *fcp;
1527 struct lportdb *lp;
1528 isp_pdb_t pdb;
1529
1530 fcp = isp->isp_param;
1531
1532 /*
1533 * XXX: Here is where we would start a 'loop dead' timeout
1534 */
1535
1536 /*
1537 * Wait up to N microseconds for F/W to go to a ready state.
1538 */
1539 lwfs = FW_CONFIG_WAIT;
1540 count = 0;
1541 while (count < usdelay) {
1542 u_int64_t enano;
1543 u_int32_t wrk;
1544 NANOTIME_T hra, hrb;
1545
1546 GET_NANOTIME(&hra);
1547 isp_fw_state(isp);
1548 if (lwfs != fcp->isp_fwstate) {
1549 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1550 isp2100_fw_statename((int)lwfs),
1551 isp2100_fw_statename((int)fcp->isp_fwstate));
1552 lwfs = fcp->isp_fwstate;
1553 }
1554 if (fcp->isp_fwstate == FW_READY) {
1555 break;
1556 }
1557 GET_NANOTIME(&hrb);
1558
1559 /*
1560 * Get the elapsed time in nanoseconds.
1561 * Always guaranteed to be non-zero.
1562 */
1563 enano = NANOTIME_SUB(&hrb, &hra);
1564
1565 isp_prt(isp, ISP_LOGDEBUG1,
1566 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1567 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1568 (u_int32_t)(enano >> 32), (u_int32_t)(enano & 0xffffffff));
1569
1570 /*
1571 * If the elapsed time is less than 1 millisecond,
1572 * delay a period of time up to that millisecond of
1573 * waiting.
1574 *
1575 * This peculiar code is an attempt to try and avoid
1576 * invoking u_int64_t math support functions for some
1577 * platforms where linkage is a problem.
1578 */
1579 if (enano < (1000 * 1000)) {
1580 count += 1000;
1581 enano = (1000 * 1000) - enano;
1582 while (enano > (u_int64_t) 4000000000U) {
1583 USEC_SLEEP(isp, 4000000);
1584 enano -= (u_int64_t) 4000000000U;
1585 }
1586 wrk = enano;
1587 wrk /= 1000;
1588 USEC_SLEEP(isp, wrk);
1589 } else {
1590 while (enano > (u_int64_t) 4000000000U) {
1591 count += 4000000;
1592 enano -= (u_int64_t) 4000000000U;
1593 }
1594 wrk = enano;
1595 count += (wrk / 1000);
1596 }
1597 }
1598
1599 /*
1600 * If we haven't gone to 'ready' state, return.
1601 */
1602 if (fcp->isp_fwstate != FW_READY) {
1603 return (-1);
1604 }
1605
1606 /*
1607 * Get our Loop ID (if possible). We really need to have it.
1608 */
1609 mbs.param[0] = MBOX_GET_LOOP_ID;
1610 isp_mboxcmd(isp, &mbs, MBLOGALL);
1611 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1612 return (-1);
1613 }
1614 fcp->isp_loopid = mbs.param[1];
1615 if (IS_2200(isp) || IS_23XX(isp)) {
1616 int topo = (int) mbs.param[6];
1617 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1618 topo = TOPO_PTP_STUB;
1619 fcp->isp_topo = topo;
1620 } else {
1621 fcp->isp_topo = TOPO_NL_PORT;
1622 }
1623 fcp->isp_portid = fcp->isp_alpa = mbs.param[2] & 0xff;
1624
1625 /*
1626 * Check to see if we're on a fabric by trying to see if we
1627 * can talk to the fabric name server. This can be a bit
1628 * tricky because if we're a 2100, we should check always
1629 * (in case we're connected to a server doing aliasing).
1630 */
1631 fcp->isp_onfabric = 0;
1632
1633 if (IS_2100(isp)) {
1634 /*
1635 * Don't bother with fabric if we are using really old
1636 * 2100 firmware. It's just not worth it.
1637 */
1638 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1639 check_for_fabric = 1;
1640 } else {
1641 check_for_fabric = 0;
1642 }
1643 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1644 fcp->isp_topo == TOPO_F_PORT) {
1645 check_for_fabric = 1;
1646 } else
1647 check_for_fabric = 0;
1648
1649 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1650 int loopid = FL_PORT_ID;
1651 if (IS_2100(isp)) {
1652 fcp->isp_topo = TOPO_FL_PORT;
1653 }
1654
1655 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1656 /*
1657 * Crock.
1658 */
1659 fcp->isp_topo = TOPO_NL_PORT;
1660 goto not_on_fabric;
1661 }
1662 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1663
1664 /*
1665 * Save the Fabric controller's port database entry.
1666 */
1667 lp = &fcp->portdb[loopid];
1668 lp->node_wwn =
1669 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1670 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1671 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1672 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1673 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1674 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1675 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1676 (((u_int64_t)pdb.pdb_nodename[7]));
1677 lp->port_wwn =
1678 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1679 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1680 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1681 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1682 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1683 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1684 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1685 (((u_int64_t)pdb.pdb_portname[7]));
1686 lp->roles =
1687 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1688 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1689 lp->loopid = pdb.pdb_loopid;
1690 lp->loggedin = lp->valid = 1;
1691 fcp->isp_onfabric = 1;
1692 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1693 isp_register_fc4_type(isp);
1694 } else {
1695not_on_fabric:
1696 fcp->isp_onfabric = 0;
1697 fcp->portdb[FL_PORT_ID].valid = 0;
1698 }
1699
1700 fcp->isp_gbspeed = 1;
1701 if (IS_23XX(isp)) {
1702 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1703 mbs.param[1] = MBGSD_GET_RATE;
1704 /* mbs.param[2] undefined if we're just getting rate */
1705 isp_mboxcmd(isp, &mbs, MBLOGALL);
1706 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1707 if (mbs.param[1] == MBGSD_TWOGB) {
1708 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1709 fcp->isp_gbspeed = 2;
1710 }
1711 }
1712 }
1713
1714 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid, fcp->isp_alpa,
1715 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1716
1717 /*
1718 * Announce ourselves, too. This involves synthesizing an entry.
1719 */
1720 if (fcp->isp_iid_set == 0) {
1721 fcp->isp_iid_set = 1;
1722 fcp->isp_iid = fcp->isp_loopid;
1723 lp = &fcp->portdb[fcp->isp_iid];
1724 } else {
1725 lp = &fcp->portdb[fcp->isp_iid];
1726 if (fcp->isp_portid != lp->portid ||
1727 fcp->isp_loopid != lp->loopid ||
1728 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1729 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1730 lp->valid = 0;
1731 count = fcp->isp_iid;
1732 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1733 }
1734 }
1735 lp->loopid = fcp->isp_loopid;
1736 lp->portid = fcp->isp_portid;
1737 lp->node_wwn = ISP_NODEWWN(isp);
1738 lp->port_wwn = ISP_PORTWWN(isp);
1739 switch (isp->isp_role) {
1740 case ISP_ROLE_NONE:
1741 lp->roles = 0;
1742 break;
1743 case ISP_ROLE_TARGET:
1744 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1745 break;
1746 case ISP_ROLE_INITIATOR:
1747 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1748 break;
1749 case ISP_ROLE_BOTH:
1750 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1751 break;
1752 }
1753 lp->loggedin = lp->valid = 1;
1754 count = fcp->isp_iid;
1755 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1756 return (0);
1757}
1758
1759static char *
1760isp2100_fw_statename(int state)
1761{
1762 switch(state) {
1763 case FW_CONFIG_WAIT: return "Config Wait";
1764 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1765 case FW_WAIT_LOGIN: return "Wait Login";
1766 case FW_READY: return "Ready";
1767 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1768 case FW_ERROR: return "Error";
1769 case FW_REINIT: return "Re-Init";
1770 case FW_NON_PART: return "Nonparticipating";
1771 default: return "?????";
1772 }
1773}
1774
1775/*
1776 * Synchronize our soft copy of the port database with what the f/w thinks
1777 * (with a view toward possibly for a specific target....)
1778 */
1779
1780static int
1781isp_pdb_sync(struct ispsoftc *isp)
1782{
1783 struct lportdb *lp;
1784 fcparam *fcp = isp->isp_param;
1785 isp_pdb_t pdb;
1786 int loopid, base, lim;
1787
1788 /*
1789 * Make sure we're okay for doing this right now.
1790 */
1791 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1792 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1793 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1794 return (-1);
1795 }
1796
1797 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1798 fcp->isp_topo == TOPO_N_PORT) {
1799 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1800 if (isp_scan_loop(isp) != 0) {
1801 return (-1);
1802 }
1803 }
1804 }
1805 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1806
1807 /*
1808 * If we get this far, we've settled our differences with the f/w
1809 * (for local loop device) and we can say that the loop state is ready.
1810 */
1811
1812 if (fcp->isp_topo == TOPO_NL_PORT) {
1813 fcp->loop_seen_once = 1;
1814 fcp->isp_loopstate = LOOP_READY;
1815 return (0);
1816 }
1817
1818 /*
1819 * Find all Fabric Entities that didn't make it from one scan to the
1820 * next and let the world know they went away. Scan the whole database.
1821 */
1822 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1823 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1824 loopid = lp - fcp->portdb;
1825 lp->valid = 0; /* should already be set */
1826 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1827 MEMZERO((void *) lp, sizeof (*lp));
1828 continue;
1829 }
1830 lp->was_fabric_dev = lp->fabric_dev;
1831 }
1832
1833 if (fcp->isp_topo == TOPO_FL_PORT)
1834 base = FC_SNS_ID+1;
1835 else
1836 base = 0;
1837
1838 if (fcp->isp_topo == TOPO_N_PORT)
1839 lim = 1;
1840 else
1841 lim = MAX_FC_TARG;
1842
1843 /*
1844 * Now log in any fabric devices that the outer layer has
1845 * left for us to see. This seems the most sane policy
1846 * for the moment.
1847 */
1848 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1849 u_int32_t portid;
1850 mbreg_t mbs;
1851
1852 loopid = lp - fcp->portdb;
1853 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1854 continue;
1855 }
1856
1857 /*
1858 * Anything here?
1859 */
1860 if (lp->port_wwn == 0) {
1861 continue;
1862 }
1863
1864 /*
1865 * Don't try to log into yourself.
1866 */
1867 if ((portid = lp->portid) == fcp->isp_portid) {
1868 continue;
1869 }
1870
1871
1872 /*
1873 * If we'd been logged in- see if we still are and we haven't
1874 * changed. If so, no need to log ourselves out, etc..
1875 *
1876 * Unfortunately, our charming Qlogic f/w has decided to
1877 * return a valid port database entry for a fabric device
1878 * that has, in fact, gone away. And it hangs trying to
1879 * log it out.
1880 */
1881 if (lp->loggedin && lp->force_logout == 0 &&
1882 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1883 int nrole;
1884 u_int64_t nwwnn, nwwpn;
1885 nwwnn =
1886 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1887 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1888 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1889 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1890 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1891 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1892 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1893 (((u_int64_t)pdb.pdb_nodename[7]));
1894 nwwpn =
1895 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1896 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1897 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1898 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1899 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1900 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1901 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1902 (((u_int64_t)pdb.pdb_portname[7]));
1903 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1904 SVC3_ROLE_SHIFT;
1905 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1906 (u_int32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1907 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1908 lp->roles == nrole && lp->force_logout == 0) {
1909 lp->loggedin = lp->valid = 1;
1910 isp_prt(isp, ISP_LOGCONFIG, lretained,
1911 (int) (lp - fcp->portdb),
1912 (int) lp->loopid, lp->portid);
1913 continue;
1914 }
1915 }
1916
1917 if (fcp->isp_fwstate != FW_READY ||
1918 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1919 return (-1);
1920 }
1921
1922 /*
1923 * Force a logout if we were logged in.
1924 */
1925 if (lp->loggedin) {
1926 if (lp->force_logout ||
1927 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1928 mbs.param[0] = MBOX_FABRIC_LOGOUT;
1929 mbs.param[1] = lp->loopid << 8;
1930 mbs.param[2] = 0;
1931 mbs.param[3] = 0;
1932 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1933 isp_prt(isp, ISP_LOGINFO, plogout,
1934 (int) (lp - fcp->portdb), lp->loopid,
1935 lp->portid);
1936 }
1937 lp->force_logout = lp->loggedin = 0;
1938 if (fcp->isp_fwstate != FW_READY ||
1939 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1940 return (-1);
1941 }
1942 }
1943
1944 /*
1945 * And log in....
1946 */
1947 loopid = lp - fcp->portdb;
1948 lp->loopid = FL_PORT_ID;
1949 do {
1950 mbs.param[0] = MBOX_FABRIC_LOGIN;
1951 mbs.param[1] = loopid << 8;
1952 mbs.param[2] = portid >> 16;
1953 mbs.param[3] = portid & 0xffff;
1954 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
1955 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
1956 if (fcp->isp_fwstate != FW_READY ||
1957 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1958 return (-1);
1959 }
1960 switch (mbs.param[0]) {
1961 case MBOX_LOOP_ID_USED:
1962 /*
1963 * Try the next available loop id.
1964 */
1965 loopid++;
1966 break;
1967 case MBOX_PORT_ID_USED:
1968 /*
1969 * This port is already logged in.
1970 * Snaffle the loop id it's using if it's
1971 * nonzero, otherwise we're hosed.
1972 */
1973 if (mbs.param[1] != 0) {
1974 loopid = mbs.param[1];
1975 isp_prt(isp, ISP_LOGINFO, retained,
1976 loopid, (int) (lp - fcp->portdb),
1977 lp->portid);
1978 } else {
1979 loopid = MAX_FC_TARG;
1980 break;
1981 }
1982 /* FALLTHROUGH */
1983 case MBOX_COMMAND_COMPLETE:
1984 lp->loggedin = 1;
1985 lp->loopid = loopid;
1986 break;
1987 case MBOX_COMMAND_ERROR:
1988 isp_prt(isp, ISP_LOGINFO, plogierr,
1989 portid, mbs.param[1]);
1990 /* FALLTHROUGH */
1991 case MBOX_ALL_IDS_USED: /* We're outta IDs */
1992 default:
1993 loopid = MAX_FC_TARG;
1994 break;
1995 }
1996 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
1997
1998 /*
1999 * If we get here and we haven't set a Loop ID,
2000 * we failed to log into this device.
2001 */
2002
2003 if (lp->loopid == FL_PORT_ID) {
2004 lp->loopid = 0;
2005 continue;
2006 }
2007
2008 /*
2009 * Make sure we can get the approriate port information.
2010 */
2011 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2012 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2013 goto dump_em;
2014 }
2015
2016 if (fcp->isp_fwstate != FW_READY ||
2017 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2018 return (-1);
2019 }
2020
2021 if (pdb.pdb_loopid != lp->loopid) {
2022 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2023 lp->portid, pdb.pdb_loopid);
2024 goto dump_em;
2025 }
2026
2027 if (lp->portid != (u_int32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2028 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2029 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2030 goto dump_em;
2031 }
2032
2033 lp->roles =
2034 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2035 lp->node_wwn =
2036 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2037 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2038 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2039 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2040 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2041 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2042 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2043 (((u_int64_t)pdb.pdb_nodename[7]));
2044 lp->port_wwn =
2045 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2046 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2047 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2048 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2049 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2050 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2051 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2052 (((u_int64_t)pdb.pdb_portname[7]));
2053 /*
2054 * Check to make sure this all makes sense.
2055 */
2056 if (lp->node_wwn && lp->port_wwn) {
2057 lp->valid = 1;
2058 loopid = lp - fcp->portdb;
2059 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2060 continue;
2061 }
2062dump_em:
2063 lp->valid = 0;
2064 isp_prt(isp, ISP_LOGINFO,
2065 ldumped, loopid, lp->loopid, lp->portid);
2066 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2067 mbs.param[1] = lp->loopid << 8;
2068 mbs.param[2] = 0;
2069 mbs.param[3] = 0;
2070 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2071 if (fcp->isp_fwstate != FW_READY ||
2072 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2073 return (-1);
2074 }
2075 }
2076 /*
2077 * If we get here, we've for sure seen not only a valid loop
2078 * but know what is or isn't on it, so mark this for usage
2079 * in isp_start.
2080 */
2081 fcp->loop_seen_once = 1;
2082 fcp->isp_loopstate = LOOP_READY;
2083 return (0);
2084}
2085
2086static int
2087isp_scan_loop(struct ispsoftc *isp)
2088{
2089 struct lportdb *lp;
2090 fcparam *fcp = isp->isp_param;
2091 isp_pdb_t pdb;
2092 int loopid, lim, hival;
2093
2094 switch (fcp->isp_topo) {
2095 case TOPO_NL_PORT:
2096 hival = FL_PORT_ID;
2097 break;
2098 case TOPO_N_PORT:
2099 hival = 2;
2100 break;
2101 case TOPO_FL_PORT:
2102 hival = FC_PORT_ID;
2103 break;
2104 default:
2105 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2106 return (0);
2107 }
2108 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2109
2110 /*
2111 * make sure the temp port database is clean...
2112 */
2113 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2114
2115 /*
2116 * Run through the local loop ports and get port database info
2117 * for each loop ID.
2118 *
2119 * There's a somewhat unexplained situation where the f/w passes back
2120 * the wrong database entity- if that happens, just restart (up to
2121 * FL_PORT_ID times).
2122 */
2123 for (lim = loopid = 0; loopid < hival; loopid++) {
2124 lp = &fcp->tport[loopid];
2125
2126 /*
2127 * Don't even try for ourselves...
2128 */
2129 if (loopid == fcp->isp_loopid)
2130 continue;
2131
2132 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2133 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2134 return (-1);
2135 if (lp->node_wwn == 0)
2136 continue;
2137 lp->port_wwn = isp_get_portname(isp, loopid, 0);
2138 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2139 return (-1);
2140 if (lp->port_wwn == 0) {
2141 lp->node_wwn = 0;
2142 continue;
2143 }
2144
2145 /*
2146 * Get an entry....
2147 */
2148 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2149 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2150 return (-1);
2151 continue;
2152 }
2153 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2154 return (-1);
2155 }
2156
2157 /*
2158 * If the returned database element doesn't match what we
2159 * asked for, restart the process entirely (up to a point...).
2160 */
2161 if (pdb.pdb_loopid != loopid) {
2162 loopid = 0;
2163 if (lim++ < hival) {
2164 continue;
2165 }
2166 isp_prt(isp, ISP_LOGWARN,
2167 "giving up on synchronizing the port database");
2168 return (-1);
2169 }
2170
2171 /*
2172 * Save the pertinent info locally.
2173 */
2174 lp->node_wwn =
2175 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2176 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2177 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2178 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2179 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2180 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2181 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2182 (((u_int64_t)pdb.pdb_nodename[7]));
2183 lp->port_wwn =
2184 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2185 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2186 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2187 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2188 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2189 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2190 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2191 (((u_int64_t)pdb.pdb_portname[7]));
2192 lp->roles =
2193 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2194 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2195 lp->loopid = pdb.pdb_loopid;
2196 }
2197
2198 /*
2199 * Mark all of the permanent local loop database entries as invalid
2200 * (except our own entry).
2201 */
2202 for (loopid = 0; loopid < hival; loopid++) {
2203 if (loopid == fcp->isp_iid) {
2204 fcp->portdb[loopid].valid = 1;
2205 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2206 continue;
2207 }
2208 fcp->portdb[loopid].valid = 0;
2209 }
2210
2211 /*
2212 * Now merge our local copy of the port database into our saved copy.
2213 * Notify the outer layers of new devices arriving.
2214 */
2215 for (loopid = 0; loopid < hival; loopid++) {
2216 int i;
2217
2218 /*
2219 * If we don't have a non-zero Port WWN, we're not here.
2220 */
2221 if (fcp->tport[loopid].port_wwn == 0) {
2222 continue;
2223 }
2224
2225 /*
2226 * Skip ourselves.
2227 */
2228 if (loopid == fcp->isp_iid) {
2229 continue;
2230 }
2231
2232 /*
2233 * For the purposes of deciding whether this is the
2234 * 'same' device or not, we only search for an identical
2235 * Port WWN. Node WWNs may or may not be the same as
2236 * the Port WWN, and there may be multiple different
2237 * Port WWNs with the same Node WWN. It would be chaos
2238 * to have multiple identical Port WWNs, so we don't
2239 * allow that.
2240 */
2241
2242 for (i = 0; i < hival; i++) {
2243 int j;
2244 if (fcp->portdb[i].port_wwn == 0)
2245 continue;
2246 if (fcp->portdb[i].port_wwn !=
2247 fcp->tport[loopid].port_wwn)
2248 continue;
2249 /*
2250 * We found this WWN elsewhere- it's changed
2251 * loopids then. We don't change it's actual
2252 * position in our cached port database- we
2253 * just change the actual loop ID we'd use.
2254 */
2255 if (fcp->portdb[i].loopid != loopid) {
2256 isp_prt(isp, ISP_LOGINFO, portshift, i,
2257 fcp->portdb[i].loopid,
2258 fcp->portdb[i].portid, loopid,
2259 fcp->tport[loopid].portid);
2260 }
2261 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2262 fcp->portdb[i].loopid = loopid;
2263 fcp->portdb[i].valid = 1;
2264 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2265
2266 /*
2267 * Now make sure this Port WWN doesn't exist elsewhere
2268 * in the port database.
2269 */
2270 for (j = i+1; j < hival; j++) {
2271 if (fcp->portdb[i].port_wwn !=
2272 fcp->portdb[j].port_wwn) {
2273 continue;
2274 }
2275 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2276 /*
2277 * Invalidate the 'old' *and* 'new' ones.
2278 * This is really harsh and not quite right,
2279 * but if this happens, we really don't know
2280 * who is what at this point.
2281 */
2282 fcp->portdb[i].valid = 0;
2283 fcp->portdb[j].valid = 0;
2284 }
2285 break;
2286 }
2287
2288 /*
2289 * If we didn't traverse the entire port database,
2290 * then we found (and remapped) an existing entry.
2291 * No need to notify anyone- go for the next one.
2292 */
2293 if (i < hival) {
2294 isp_prt(isp, ISP_LOGINFO, retained,
2295 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2296 continue;
2297 }
2298
2299 /*
2300 * We've not found this Port WWN anywhere. It's a new entry.
2301 * See if we can leave it where it is (with target == loopid).
2302 */
2303 if (fcp->portdb[loopid].port_wwn != 0) {
2304 for (lim = 0; lim < hival; lim++) {
2305 if (fcp->portdb[lim].port_wwn == 0)
2306 break;
2307 }
2308 /* "Cannot Happen" */
2309 if (lim == hival) {
2310 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2311 continue;
2312 }
2313 i = lim;
2314 } else {
2315 i = loopid;
2316 }
2317
2318 /*
2319 * NB: The actual loopid we use here is loopid- we may
2320 * in fact be at a completely different index (target).
2321 */
2322 fcp->portdb[i].loopid = loopid;
2323 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2324 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2325 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2326 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2327 fcp->portdb[i].valid = 1;
2328
2329 /*
2330 * Tell the outside world we've arrived.
2331 */
2332 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2333 }
2334
2335 /*
2336 * Now find all previously used targets that are now invalid and
2337 * notify the outer layers that they're gone.
2338 */
2339 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2340 if (lp->valid || lp->port_wwn == 0) {
2341 continue;
2342 }
2343
2344 /*
2345 * Tell the outside world we've gone
2346 * away and erase our pdb entry.
2347 *
2348 */
2349 loopid = lp - fcp->portdb;
2350 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2351 MEMZERO((void *) lp, sizeof (*lp));
2352 }
2353 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2354 return (0);
2355}
2356
2357
2358static int
2359isp_fabric_mbox_cmd(struct ispsoftc *isp, mbreg_t *mbp)
2360{
2361 isp_mboxcmd(isp, mbp, MBLOGNONE);
2362 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2363 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2364 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2365 }
2366 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2367 char tbuf[16];
2368 char *m;
2369 switch (mbp->param[1]) {
2370 case 1:
2371 m = "No Loop";
2372 break;
2373 case 2:
2374 m = "Failed to allocate IOCB buffer";
2375 break;
2376 case 3:
2377 m = "Failed to allocate XCB buffer";
2378 break;
2379 case 4:
2380 m = "timeout or transmit failed";
2381 break;
2382 case 5:
2383 m = "no fabric loop";
2384 break;
2385 case 6:
2386 m = "remote device not a target";
2387 break;
2388 default:
2389 SNPRINTF(tbuf, sizeof tbuf, "%x",
2390 mbp->param[1]);
2391 m = tbuf;
2392 break;
2393 }
2394 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2395 }
2396 return (-1);
2397 }
2398
2399 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2400 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2401 return (-1);
2402 }
2403 return(0);
2404}
2405
2406#ifdef ISP_USE_GA_NXT
2407static int
2408isp_scan_fabric(struct ispsoftc *isp, int ftype)
2409{
2410 fcparam *fcp = isp->isp_param;
2411 u_int32_t portid, first_portid, last_portid;
2412 int hicap, last_port_same;
2413
2414 if (fcp->isp_onfabric == 0) {
2415 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2416 return (0);
2417 }
2418
2419 FC_SCRATCH_ACQUIRE(isp);
2420
2421 /*
2422 * Since Port IDs are 24 bits, we can check against having seen
2423 * anything yet with this value.
2424 */
2425 last_port_same = 0;
2426 last_portid = 0xffffffff; /* not a port */
2427 first_portid = portid = fcp->isp_portid;
2428 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2429
2430 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2431 mbreg_t mbs;
2432 sns_screq_t *rq;
2433 sns_ga_nxt_rsp_t *rs0, *rs1;
2434 struct lportdb lcl;
2435 u_int8_t sc[SNS_GA_NXT_RESP_SIZE];
2436
2437 rq = (sns_screq_t *)sc;
2438 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2439 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2440 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2441 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2442 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2443 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2444 rq->snscb_sblen = 6;
2445 rq->snscb_data[0] = SNS_GA_NXT;
2446 rq->snscb_data[4] = portid & 0xffff;
2447 rq->snscb_data[5] = (portid >> 16) & 0xff;
2448 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2449 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2450 mbs.param[0] = MBOX_SEND_SNS;
2451 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2452 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2453 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2454 /*
2455 * Leave 4 and 5 alone
2456 */
2457 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2458 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2459 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2460 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2461 fcp->isp_loopstate = LOOP_PDB_RCVD;
2462 }
2463 FC_SCRATCH_RELEASE(isp);
2464 return (-1);
2465 }
2466 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2467 rs1 = (sns_ga_nxt_rsp_t *) sc;
2468 rs0 = (sns_ga_nxt_rsp_t *) ((u_int8_t *)fcp->isp_scratch+0x100);
2469 isp_get_ga_nxt_response(isp, rs0, rs1);
2470 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2471 int level;
2472 if (rs1->snscb_cthdr.ct_reason == 9 &&
2473 rs1->snscb_cthdr.ct_explanation == 7)
2474 level = ISP_LOGDEBUG0;
2475 else
2476 level = ISP_LOGWARN;
2477 isp_prt(isp, level, swrej, "GA_NXT",
2478 rs1->snscb_cthdr.ct_reason,
2479 rs1->snscb_cthdr.ct_explanation, portid);
2480 FC_SCRATCH_RELEASE(isp);
2481 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2482 return (0);
2483 }
2484 portid =
2485 (((u_int32_t) rs1->snscb_port_id[0]) << 16) |
2486 (((u_int32_t) rs1->snscb_port_id[1]) << 8) |
2487 (((u_int32_t) rs1->snscb_port_id[2]));
2488
2489 /*
2490 * XXX: We should check to make sure that this entry
2491 * XXX: supports the type(s) we are interested in.
2492 */
2493 /*
2494 * Okay, we now have information about a fabric object.
2495 * If it is the type we're interested in, tell the outer layers
2496 * about it. The outer layer needs to know: Port ID, WWNN,
2497 * WWPN, FC4 type, and port type.
2498 *
2499 * The lportdb structure is adequate for this.
2500 */
2501 MEMZERO(&lcl, sizeof (lcl));
2502 lcl.port_type = rs1->snscb_port_type;
2503 lcl.fc4_type = ftype;
2504 lcl.portid = portid;
2505 lcl.node_wwn =
2506 (((u_int64_t)rs1->snscb_nodename[0]) << 56) |
2507 (((u_int64_t)rs1->snscb_nodename[1]) << 48) |
2508 (((u_int64_t)rs1->snscb_nodename[2]) << 40) |
2509 (((u_int64_t)rs1->snscb_nodename[3]) << 32) |
2510 (((u_int64_t)rs1->snscb_nodename[4]) << 24) |
2511 (((u_int64_t)rs1->snscb_nodename[5]) << 16) |
2512 (((u_int64_t)rs1->snscb_nodename[6]) << 8) |
2513 (((u_int64_t)rs1->snscb_nodename[7]));
2514 lcl.port_wwn =
2515 (((u_int64_t)rs1->snscb_portname[0]) << 56) |
2516 (((u_int64_t)rs1->snscb_portname[1]) << 48) |
2517 (((u_int64_t)rs1->snscb_portname[2]) << 40) |
2518 (((u_int64_t)rs1->snscb_portname[3]) << 32) |
2519 (((u_int64_t)rs1->snscb_portname[4]) << 24) |
2520 (((u_int64_t)rs1->snscb_portname[5]) << 16) |
2521 (((u_int64_t)rs1->snscb_portname[6]) << 8) |
2522 (((u_int64_t)rs1->snscb_portname[7]));
2523
2524 /*
2525 * Does this fabric object support the type we want?
2526 * If not, skip it.
2527 */
2528 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2529 if (first_portid == portid) {
2530 lcl.last_fabric_dev = 1;
2531 } else {
2532 lcl.last_fabric_dev = 0;
2533 }
2534 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2535 } else {
2536 isp_prt(isp, ISP_LOGDEBUG0,
2537 "PortID 0x%x doesn't support FC4 type 0x%x",
2538 portid, ftype);
2539 }
2540 if (first_portid == portid) {
2541 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2542 FC_SCRATCH_RELEASE(isp);
2543 return (0);
2544 }
2545 if (portid == last_portid) {
2546 if (last_port_same++ > 20) {
2547 isp_prt(isp, ISP_LOGWARN,
2548 "tangled fabric database detected");
2549 break;
2550 }
2551 } else {
2552 last_port_same = 0 ;
2553 last_portid = portid;
2554 }
2555 }
2556 FC_SCRATCH_RELEASE(isp);
2557 if (hicap >= GA_NXT_MAX) {
2558 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2559 }
2560 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2561 return (0);
2562}
2563#else
2564#define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2565#define NGENT ((GIDLEN - 16) >> 2)
2566
2567#define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2568#define GXOFF (256)
2569
2570static int
2571isp_scan_fabric(struct ispsoftc *isp, int ftype)
2572{
2573 fcparam *fcp = FCPARAM(isp);
2574 mbreg_t mbs;
2575 int i;
2576 sns_gid_ft_req_t *rq;
2577 sns_gid_ft_rsp_t *rs0, *rs1;
2578
2579 if (fcp->isp_onfabric == 0) {
2580 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2581 return (0);
2582 }
2583
2584 FC_SCRATCH_ACQUIRE(isp);
2585 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2586
2587 rq = (sns_gid_ft_req_t *)fcp->tport;
2588 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2589 rq->snscb_rblen = GIDLEN >> 1;
2590 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2591 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2592 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2593 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2594 rq->snscb_sblen = 6;
2595 rq->snscb_cmd = SNS_GID_FT;
2596 rq->snscb_mword_div_2 = NGENT;
2597 rq->snscb_fc4_type = ftype;
2598 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2599 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2600 mbs.param[0] = MBOX_SEND_SNS;
2601 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2602 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2603 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2604
2605 /*
2606 * Leave 4 and 5 alone
2607 */
2608 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2609 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2610 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2611 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2612 fcp->isp_loopstate = LOOP_PDB_RCVD;
2613 }
2614 FC_SCRATCH_RELEASE(isp);
2615 return (-1);
2616 }
2617 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2618 FC_SCRATCH_RELEASE(isp);
2619 return (-1);
2620 }
2621 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2622 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2623 rs0 = (sns_gid_ft_rsp_t *) ((u_int8_t *)fcp->isp_scratch+IGPOFF);
2624 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2625 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2626 int level;
2627 if (rs1->snscb_cthdr.ct_reason == 9 &&
2628 rs1->snscb_cthdr.ct_explanation == 7)
2629 level = ISP_LOGDEBUG0;
2630 else
2631 level = ISP_LOGWARN;
2632 isp_prt(isp, level, swrej, "GID_FT",
2633 rs1->snscb_cthdr.ct_reason,
2634 rs1->snscb_cthdr.ct_explanation, 0);
2635 FC_SCRATCH_RELEASE(isp);
2636 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2637 return (0);
2638 }
2639
2640 /*
2641 * Okay, we now have a list of Port IDs for this class of device.
2642 * Go through the list and for each one get the WWPN/WWNN for it
2643 * and tell the outer layers about it. The outer layer needs to
2644 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2645 *
2646 * The lportdb structure is adequate for this.
2647 */
2648 i = -1;
2649 do {
2650 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2651 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2652 struct lportdb lcl;
2653#if 0
2654 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2655#endif
2656
2657 i++;
2658 MEMZERO(&lcl, sizeof (lcl));
2659 lcl.fc4_type = ftype;
2660 lcl.portid =
2661 (((u_int32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2662 (((u_int32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2663 (((u_int32_t) rs1->snscb_ports[i].portid[2]));
2664
2665 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2666 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2667 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2668 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2669 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2670 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2671 gq->snscb_sblen = 6;
2672 gq->snscb_cmd = SNS_GPN_ID;
2673 gq->snscb_portid = lcl.portid;
2674 isp_put_gxn_id_request(isp, gq,
2675 (sns_gxn_id_req_t *) fcp->isp_scratch);
2676 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2677 mbs.param[0] = MBOX_SEND_SNS;
2678 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2679 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2680 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2681 /*
2682 * Leave 4 and 5 alone
2683 */
2684 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2685 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2686 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2687 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2688 fcp->isp_loopstate = LOOP_PDB_RCVD;
2689 }
2690 FC_SCRATCH_RELEASE(isp);
2691 return (-1);
2692 }
2693 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2694 FC_SCRATCH_RELEASE(isp);
2695 return (-1);
2696 }
2697 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2698 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2699 isp_get_gxn_id_response(isp, gs0, gs1);
2700 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2701 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2702 gs1->snscb_cthdr.ct_reason,
2703 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2704 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2705 FC_SCRATCH_RELEASE(isp);
2706 return (-1);
2707 }
2708 continue;
2709 }
2710 lcl.port_wwn =
2711 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2712 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2713 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2714 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2715 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2716 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2717 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2718 (((u_int64_t)gs1->snscb_wwn[7]));
2719
2720 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2721 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2722 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2723 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2724 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2725 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2726 gq->snscb_sblen = 6;
2727 gq->snscb_cmd = SNS_GNN_ID;
2728 gq->snscb_portid = lcl.portid;
2729 isp_put_gxn_id_request(isp, gq,
2730 (sns_gxn_id_req_t *) fcp->isp_scratch);
2731 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2732 mbs.param[0] = MBOX_SEND_SNS;
2733 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2734 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2735 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2736 /*
2737 * Leave 4 and 5 alone
2738 */
2739 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2740 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2741 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2742 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2743 fcp->isp_loopstate = LOOP_PDB_RCVD;
2744 }
2745 FC_SCRATCH_RELEASE(isp);
2746 return (-1);
2747 }
2748 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2749 FC_SCRATCH_RELEASE(isp);
2750 return (-1);
2751 }
2752 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2753 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2754 isp_get_gxn_id_response(isp, gs0, gs1);
2755 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2756 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2757 gs1->snscb_cthdr.ct_reason,
2758 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2759 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2760 FC_SCRATCH_RELEASE(isp);
2761 return (-1);
2762 }
2763 continue;
2764 }
2765 lcl.node_wwn =
2766 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2767 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2768 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2769 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2770 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2771 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2772 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2773 (((u_int64_t)gs1->snscb_wwn[7]));
2774
2775 /*
2776 * The QLogic f/w is bouncing this with a parameter error.
2777 */
2778#if 0
2779 /*
2780 * Try and get FC4 Features (FC-GS-3 only).
2781 * We can use the sns_gxn_id_req_t for this request.
2782 */
2783 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2784 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2785 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2786 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2787 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2788 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2789 gq->snscb_sblen = 6;
2790 gq->snscb_cmd = SNS_GFF_ID;
2791 gq->snscb_portid = lcl.portid;
2792 isp_put_gxn_id_request(isp, gq,
2793 (sns_gxn_id_req_t *) fcp->isp_scratch);
2794 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2795 mbs.param[0] = MBOX_SEND_SNS;
2796 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2797 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2798 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2799 /*
2800 * Leave 4 and 5 alone
2801 */
2802 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2803 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2804 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2805 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2806 fcp->isp_loopstate = LOOP_PDB_RCVD;
2807 }
2808 FC_SCRATCH_RELEASE(isp);
2809 return (-1);
2810 }
2811 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2812 FC_SCRATCH_RELEASE(isp);
2813 return (-1);
2814 }
2815 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2816 fs0 = (sns_gff_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2817 isp_get_gff_id_response(isp, fs0, fs1);
2818 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2819 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2820 swrej, "GFF_ID",
2821 fs1->snscb_cthdr.ct_reason,
2822 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2823 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2824 FC_SCRATCH_RELEASE(isp);
2825 return (-1);
2826 }
2827 } else {
2828 int index = (ftype >> 3);
2829 int bshft = (ftype & 0x7) * 4;
2830 int fc4_fval =
2831 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2832 if (fc4_fval & 0x1) {
2833 lcl.roles |=
2834 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2835 }
2836 if (fc4_fval & 0x2) {
2837 lcl.roles |=
2838 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
2839 }
2840 }
2841#endif
2842
2843 /*
2844 * If we really want to know what kind of port type this is,
2845 * we have to run another CT command. Otherwise, we'll leave
2846 * it as undefined.
2847 *
2848 lcl.port_type = 0;
2849 */
2850 if (rs1->snscb_ports[i].control & 0x80) {
2851 lcl.last_fabric_dev = 1;
2852 } else {
2853 lcl.last_fabric_dev = 0;
2854 }
2855 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2856
2857 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
2858
2859 /*
2860 * If we're not at the last entry, our list isn't big enough.
2861 */
2862 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
2863 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
2864 }
2865
2866 FC_SCRATCH_RELEASE(isp);
2867 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2868 return (0);
2869}
2870#endif
2871
2872static void
2873isp_register_fc4_type(struct ispsoftc *isp)
2874{
2875 fcparam *fcp = isp->isp_param;
2876 u_int8_t local[SNS_RFT_ID_REQ_SIZE];
2877 sns_screq_t *reqp = (sns_screq_t *) local;
2878 mbreg_t mbs;
2879
2880 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
2881 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
2882 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
2883 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
2884 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
2885 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
2886 reqp->snscb_sblen = 22;
2887 reqp->snscb_data[0] = SNS_RFT_ID;
2888 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
2889 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
2890 reqp->snscb_data[6] = (1 << FC4_SCSI);
2891#if 0
2892 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
2893#endif
2894 FC_SCRATCH_ACQUIRE(isp);
2895 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
2896 mbs.param[0] = MBOX_SEND_SNS;
2897 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
2898 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2899 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2900 /*
2901 * Leave 4 and 5 alone
2902 */
2903 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2904 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2905 isp_mboxcmd(isp, &mbs, MBLOGALL);
2906 FC_SCRATCH_RELEASE(isp);
2907 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2908 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
2909 }
2910}
2911
2912/*
2913 * Start a command. Locking is assumed done in the caller.
2914 */
2915
2916int
2917isp_start(XS_T *xs)
2918{
2919 struct ispsoftc *isp;
2920 u_int16_t nxti, optr, handle;
2921 u_int8_t local[QENTRY_LEN];
2922 ispreq_t *reqp, *qep;
2923 int target, i;
2924
2925 XS_INITERR(xs);
2926 isp = XS_ISP(xs);
2927
2928 /*
2929 * Check to make sure we're supporting initiator role.
2930 */
2931 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
2932 XS_SETERR(xs, HBA_SELTIMEOUT);
2933 return (CMD_COMPLETE);
2934 }
2935
2936 /*
2937 * Now make sure we're running.
2938 */
2939
2940 if (isp->isp_state != ISP_RUNSTATE) {
2941 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
2942 XS_SETERR(xs, HBA_BOTCH);
2943 return (CMD_COMPLETE);
2944 }
2945
2946 /*
2947 * Check command CDB length, etc.. We really are limited to 16 bytes
2948 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
2949 * but probably only if we're running fairly new firmware (we'll
2950 * let the old f/w choke on an extended command queue entry).
2951 */
2952
2953 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
2954 isp_prt(isp, ISP_LOGERR,
2955 "unsupported cdb length (%d, CDB[0]=0x%x)",
2956 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
2957 XS_SETERR(xs, HBA_BOTCH);
2958 return (CMD_COMPLETE);
2959 }
2960
2961 /*
2962 * Check to see whether we have good firmware state still or
2963 * need to refresh our port database for this target.
2964 */
2965 target = XS_TGT(xs);
2966 if (IS_FC(isp)) {
2967 fcparam *fcp = isp->isp_param;
2968 struct lportdb *lp;
2969#ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
2970 if (fcp->isp_fwstate != FW_READY ||
2971 fcp->isp_loopstate != LOOP_READY) {
2972 return (CMD_RQLATER);
2973 }
2974
2975 /*
2976 * If we're not on a Fabric, we can't have a target
2977 * above FL_PORT_ID-1.
2978 *
2979 * If we're on a fabric and *not* connected as an F-port,
2980 * we can't have a target less than FC_SNS_ID+1. This
2981 * keeps us from having to sort out the difference between
2982 * local public loop devices and those which we might get
2983 * from a switch's database.
2984 */
2985 if (fcp->isp_onfabric == 0) {
2986 if (target >= FL_PORT_ID) {
2987 XS_SETERR(xs, HBA_SELTIMEOUT);
2988 return (CMD_COMPLETE);
2989 }
2990 } else {
2991 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
2992 XS_SETERR(xs, HBA_SELTIMEOUT);
2993 return (CMD_COMPLETE);
2994 }
2995 /*
2996 * We used to exclude having local loop ports
2997 * at the same time that we have fabric ports.
2998 * That is, we used to exclude having ports
2999 * at < FL_PORT_ID if we're FL-port.
3000 *
3001 * That's wrong. The only thing that could be
3002 * dicey is if the switch you're connected to
3003 * has these local loop ports appear on the
3004 * fabric and we somehow attach them twice.
3005 */
3006 }
3007#else
3008 /*
3009 * Check for f/w being in ready state. If the f/w
3010 * isn't in ready state, then we don't know our
3011 * loop ID and the f/w hasn't completed logging
3012 * into all targets on the loop. If this is the
3013 * case, then bounce the command. We pretend this is
3014 * a SELECTION TIMEOUT error if we've never gone to
3015 * FW_READY state at all- in this case we may not
3016 * be hooked to a loop at all and we shouldn't hang
3017 * the machine for this. Otherwise, defer this command
3018 * until later.
3019 */
3020 if (fcp->isp_fwstate != FW_READY) {
3021 /*
3022 * Give ourselves at most a 250ms delay.
3023 */
3024 if (isp_fclink_test(isp, 250000)) {
3025 XS_SETERR(xs, HBA_SELTIMEOUT);
3026 if (fcp->loop_seen_once) {
3027 return (CMD_RQLATER);
3028 } else {
3029 return (CMD_COMPLETE);
3030 }
3031 }
3032 }
3033
3034 /*
3035 * If we're not on a Fabric, we can't have a target
3036 * above FL_PORT_ID-1.
3037 *
3038 * If we're on a fabric and *not* connected as an F-port,
3039 * we can't have a target less than FC_SNS_ID+1. This
3040 * keeps us from having to sort out the difference between
3041 * local public loop devices and those which we might get
3042 * from a switch's database.
3043 */
3044 if (fcp->isp_onfabric == 0) {
3045 if (target >= FL_PORT_ID) {
3046 XS_SETERR(xs, HBA_SELTIMEOUT);
3047 return (CMD_COMPLETE);
3048 }
3049 } else {
3050 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3051 XS_SETERR(xs, HBA_SELTIMEOUT);
3052 return (CMD_COMPLETE);
3053 }
3054 if (fcp->isp_topo != TOPO_F_PORT &&
3055 target < FL_PORT_ID) {
3056 XS_SETERR(xs, HBA_SELTIMEOUT);
3057 return (CMD_COMPLETE);
3058 }
3059 }
3060
3061 /*
3062 * If our loop state is such that we haven't yet received
3063 * a "Port Database Changed" notification (after a LIP or
3064 * a Loop Reset or firmware initialization), then defer
3065 * sending commands for a little while, but only if we've
3066 * seen a valid loop at one point (otherwise we can get
3067 * stuck at initialization time).
3068 */
3069 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3070 XS_SETERR(xs, HBA_SELTIMEOUT);
3071 if (fcp->loop_seen_once) {
3072 return (CMD_RQLATER);
3073 } else {
3074 return (CMD_COMPLETE);
3075 }
3076 }
3077
3078 /*
3079 * If we're in the middle of loop or fabric scanning
3080 * or merging the port databases, retry this command later.
3081 */
3082 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3083 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3084 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3085 return (CMD_RQLATER);
3086 }
3087
3088 /*
3089 * If our loop state is now such that we've just now
3090 * received a Port Database Change notification, then
3091 * we have to go off and (re)scan the fabric. We back
3092 * out and try again later if this doesn't work.
3093 */
3094 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3095 if (isp_scan_fabric(isp, FC4_SCSI)) {
3096 return (CMD_RQLATER);
3097 }
3098 if (fcp->isp_fwstate != FW_READY ||
3099 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3100 return (CMD_RQLATER);
3101 }
3102 }
3103
3104 /*
3105 * If our loop state is now such that we've just now
3106 * received a Port Database Change notification, then
3107 * we have to go off and (re)synchronize our port
3108 * database.
3109 */
3110 if (fcp->isp_loopstate < LOOP_READY) {
3111 if (isp_pdb_sync(isp)) {
3112 return (CMD_RQLATER);
3113 }
3114 if (fcp->isp_fwstate != FW_READY ||
3115 fcp->isp_loopstate != LOOP_READY) {
3116 return (CMD_RQLATER);
3117 }
3118 }
3119
3120 /*
3121 * XXX: Here's were we would cancel any loop_dead flag
3122 * XXX: also cancel in dead_loop timeout that's running
3123 */
3124#endif
3125
3126 /*
3127 * Now check whether we should even think about pursuing this.
3128 */
3129 lp = &fcp->portdb[target];
3130 if (lp->valid == 0) {
3131 XS_SETERR(xs, HBA_SELTIMEOUT);
3132 return (CMD_COMPLETE);
3133 }
3134 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3135 isp_prt(isp, ISP_LOGDEBUG2,
3136 "Target %d does not have target service", target);
3137 XS_SETERR(xs, HBA_SELTIMEOUT);
3138 return (CMD_COMPLETE);
3139 }
3140 /*
3141 * Now turn target into what the actual Loop ID is.
3142 */
3143 target = lp->loopid;
3144 }
3145
3146 /*
3147 * Next check to see if any HBA or Device
3148 * parameters need to be updated.
3149 */
3150 if (isp->isp_update != 0) {
3151 isp_update(isp);
3152 }
3153
3154 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
3155 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3156 XS_SETERR(xs, HBA_BOTCH);
3157 return (CMD_EAGAIN);
3158 }
3159
3160 /*
3161 * Now see if we need to synchronize the ISP with respect to anything.
3162 * We do dual duty here (cough) for synchronizing for busses other
3163 * than which we got here to send a command to.
3164 */
3165 reqp = (ispreq_t *) local;
3166 if (isp->isp_sendmarker) {
3167 u_int8_t n = (IS_DUALBUS(isp)? 2: 1);
3168 /*
3169 * Check ports to send markers for...
3170 */
3171 for (i = 0; i < n; i++) {
3172 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3173 continue;
3174 }
3175 MEMZERO((void *) reqp, QENTRY_LEN);
3176 reqp->req_header.rqs_entry_count = 1;
3177 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3178 reqp->req_modifier = SYNC_ALL;
3179 reqp->req_target = i << 7; /* insert bus number */
3180 isp_put_request(isp, reqp, qep);
3181 ISP_ADD_REQUEST(isp, nxti);
3182 isp->isp_sendmarker &= ~(1 << i);
3183 if (isp_getrqentry(isp, &nxti, &optr, (void *) &qep)) {
3184 isp_prt(isp, ISP_LOGDEBUG0,
3185 "Request Queue Overflow+");
3186 XS_SETERR(xs, HBA_BOTCH);
3187 return (CMD_EAGAIN);
3188 }
3189 }
3190 }
3191
3192 MEMZERO((void *)reqp, QENTRY_LEN);
3193 reqp->req_header.rqs_entry_count = 1;
3194 if (IS_FC(isp)) {
3195 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3196 } else {
3197 if (XS_CDBLEN(xs) > 12)
3198 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3199 else
3200 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3201 }
3202 /* reqp->req_header.rqs_flags = 0; */
3203 /* reqp->req_header.rqs_seqno = 0; */
3204 if (IS_FC(isp)) {
3205 /*
3206 * See comment in isp_intr
3207 */
3208 /* XS_RESID(xs) = 0; */
3209
3210 /*
3211 * Fibre Channel always requires some kind of tag.
3212 * The Qlogic drivers seem be happy not to use a tag,
3213 * but this breaks for some devices (IBM drives).
3214 */
3215 if (XS_TAG_P(xs)) {
3216 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3217 } else {
3218 /*
3219 * If we don't know what tag to use, use HEAD OF QUEUE
3220 * for Request Sense or Simple.
3221 */
3222 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3223 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3224 else
3225 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3226 }
3227 } else {
3228 sdparam *sdp = (sdparam *)isp->isp_param;
3229 sdp += XS_CHANNEL(xs);
3230 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3231 XS_TAG_P(xs)) {
3232 reqp->req_flags = XS_TAG_TYPE(xs);
3233 }
3234 }
3235 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3236 if (IS_SCSI(isp)) {
3237 reqp->req_lun_trn = XS_LUN(xs);
3238 reqp->req_cdblen = XS_CDBLEN(xs);
3239 } else {
3240 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN)
3241 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3242 else
3243 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3244 }
3245 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3246
3247 reqp->req_time = XS_TIME(xs) / 1000;
3248 if (reqp->req_time == 0 && XS_TIME(xs)) {
3249 reqp->req_time = 1;
3250 }
3251
3252 if (isp_save_xs(isp, xs, &handle)) {
3253 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3254 XS_SETERR(xs, HBA_BOTCH);
3255 return (CMD_EAGAIN);
3256 }
3257 reqp->req_handle = handle;
3258
3259 /*
3260 * Set up DMA and/or do any bus swizzling of the request entry
3261 * so that the Qlogic F/W understands what is being asked of it.
3262 */
3263 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3264 if (i != CMD_QUEUED) {
3265 isp_destroy_handle(isp, handle);
3266 /*
3267 * dmasetup sets actual error in packet, and
3268 * return what we were given to return.
3269 */
3270 return (i);
3271 }
3272 XS_SETERR(xs, HBA_NOERROR);
3273 isp_prt(isp, ISP_LOGDEBUG2,
3274 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3275 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3276 (long) XS_XFRLEN(xs));
3277 ISP_ADD_REQUEST(isp, nxti);
3278 isp->isp_nactive++;
3279 return (CMD_QUEUED);
3280}
3281
3282/*
3283 * isp control
3284 * Locks (ints blocked) assumed held.
3285 */
3286
3287int
3288isp_control(struct ispsoftc *isp, ispctl_t ctl, void *arg)
3289{
3290 XS_T *xs;
3291 mbreg_t mbs;
3292 int bus, tgt;
3293 u_int16_t handle;
3294
3295 switch (ctl) {
3296 default:
3297 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3298 break;
3299
3300 case ISPCTL_RESET_BUS:
3301 /*
3302 * Issue a bus reset.
3303 */
3304 mbs.param[0] = MBOX_BUS_RESET;
3305 mbs.param[2] = 0;
3306 if (IS_SCSI(isp)) {
3307 mbs.param[1] =
3308 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3309 if (mbs.param[1] < 2)
3310 mbs.param[1] = 2;
3311 bus = *((int *) arg);
3312 if (IS_DUALBUS(isp))
3313 mbs.param[2] = bus;
3314 } else {
3315 mbs.param[1] = 10;
3316 bus = 0;
3317 }
3318 isp->isp_sendmarker |= (1 << bus);
3319 isp_mboxcmd(isp, &mbs, MBLOGALL);
3320 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3321 break;
3322 }
3323 isp_prt(isp, ISP_LOGINFO,
3324 "driver initiated bus reset of bus %d", bus);
3325 return (0);
3326
3327 case ISPCTL_RESET_DEV:
3328 tgt = (*((int *) arg)) & 0xffff;
3329 bus = (*((int *) arg)) >> 16;
3330 mbs.param[0] = MBOX_ABORT_TARGET;
3331 mbs.param[1] = (tgt << 8) | (bus << 15);
3332 mbs.param[2] = 3; /* 'delay', in seconds */
3333 isp_mboxcmd(isp, &mbs, MBLOGALL);
3334 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3335 break;
3336 }
3337 isp_prt(isp, ISP_LOGINFO,
3338 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3339 isp->isp_sendmarker |= (1 << bus);
3340 return (0);
3341
3342 case ISPCTL_ABORT_CMD:
3343 xs = (XS_T *) arg;
3344 tgt = XS_TGT(xs);
3345 handle = isp_find_handle(isp, xs);
3346 if (handle == 0) {
3347 isp_prt(isp, ISP_LOGWARN,
3348 "cannot find handle for command to abort");
3349 break;
3350 }
3351 bus = XS_CHANNEL(xs);
3352 mbs.param[0] = MBOX_ABORT;
3353 if (IS_FC(isp)) {
3354 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3355 mbs.param[1] = tgt << 8;
3356 mbs.param[4] = 0;
3357 mbs.param[5] = 0;
3358 mbs.param[6] = XS_LUN(xs);
3359 } else {
3360 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3361 }
3362 } else {
3363 mbs.param[1] =
3364 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3365 }
3366 mbs.param[3] = 0;
3367 mbs.param[2] = handle;
3368 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3369 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3370 return (0);
3371 }
3372 /*
3373 * XXX: Look for command in the REQUEST QUEUE. That is,
3374 * XXX: It hasen't been picked up by firmware yet.
3375 */
3376 break;
3377
3378 case ISPCTL_UPDATE_PARAMS:
3379
3380 isp_update(isp);
3381 return (0);
3382
3383 case ISPCTL_FCLINK_TEST:
3384
3385 if (IS_FC(isp)) {
3386 int usdelay = (arg)? *((int *) arg) : 250000;
3387 return (isp_fclink_test(isp, usdelay));
3388 }
3389 break;
3390
3391 case ISPCTL_SCAN_FABRIC:
3392
3393 if (IS_FC(isp)) {
3394 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3395 return (isp_scan_fabric(isp, ftype));
3396 }
3397 break;
3398
3399 case ISPCTL_SCAN_LOOP:
3400
3401 if (IS_FC(isp)) {
3402 return (isp_scan_loop(isp));
3403 }
3404 break;
3405
3406 case ISPCTL_PDB_SYNC:
3407
3408 if (IS_FC(isp)) {
3409 return (isp_pdb_sync(isp));
3410 }
3411 break;
3412
3413 case ISPCTL_SEND_LIP:
3414
3415 if (IS_FC(isp)) {
3416 mbs.param[0] = MBOX_INIT_LIP;
3417 isp_mboxcmd(isp, &mbs, MBLOGALL);
3418 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3419 return (0);
3420 }
3421 }
3422 break;
3423
3424 case ISPCTL_GET_POSMAP:
3425
3426 if (IS_FC(isp) && arg) {
3427 return (isp_getmap(isp, arg));
3428 }
3429 break;
3430
3431 case ISPCTL_RUN_MBOXCMD:
3432
3433 isp_mboxcmd(isp, arg, MBLOGALL);
3434 return(0);
3435
3436#ifdef ISP_TARGET_MODE
3437 case ISPCTL_TOGGLE_TMODE:
3438 {
3439
3440 /*
3441 * We don't check/set against role here- that's the
3442 * responsibility for the outer layer to coordinate.
3443 */
3444 if (IS_SCSI(isp)) {
3445 int param = *(int *)arg;
3446 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3447 mbs.param[1] = param & 0xffff;
3448 mbs.param[2] = param >> 16;
3449 isp_mboxcmd(isp, &mbs, MBLOGALL);
3450 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3451 break;
3452 }
3453 }
3454 return (0);
3455 }
3456#endif
3457 }
3458 return (-1);
3459}
3460
3461/*
3462 * Interrupt Service Routine(s).
3463 *
3464 * External (OS) framework has done the appropriate locking,
3465 * and the locking will be held throughout this function.
3466 */
3467
3468/*
3469 * Limit our stack depth by sticking with the max likely number
3470 * of completions on a request queue at any one time.
3471 */
3472#ifndef MAX_REQUESTQ_COMPLETIONS
3473#define MAX_REQUESTQ_COMPLETIONS 64
3474#endif
3475
3476void
3477isp_intr(struct ispsoftc *isp, u_int16_t isr, u_int16_t sema, u_int16_t mbox)
3478{
3479 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3480 u_int16_t iptr, optr, junk;
3481 int i, nlooked = 0, ndone = 0;
3482
3483again:
3484 /*
3485 * Is this a mailbox related interrupt?
3486 * The mailbox semaphore will be nonzero if so.
3487 */
3488 if (sema) {
3489 if (mbox & 0x4000) {
3490 isp->isp_intmboxc++;
3491 if (isp->isp_mboxbsy) {
3492 int i = 0, obits = isp->isp_obits;
3493 isp->isp_mboxtmp[i++] = mbox;
3494 for (i = 1; i < MAX_MAILBOX; i++) {
3495 if ((obits & (1 << i)) == 0) {
3496 continue;
3497 }
3498 isp->isp_mboxtmp[i] =
3499 ISP_READ(isp, MBOX_OFF(i));
3500 }
3501 if (isp->isp_mbxwrk0) {
3502 if (isp_mbox_continue(isp) == 0) {
3503 return;
3504 }
3505 }
3506 MBOX_NOTIFY_COMPLETE(isp);
3507 } else {
3508 isp_prt(isp, ISP_LOGWARN,
3509 "Mbox Command Async (0x%x) with no waiters",
3510 mbox);
3511 }
3512 } else if (isp_parse_async(isp, mbox) < 0) {
3513 return;
3514 }
3515 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3516 isp->isp_state != ISP_RUNSTATE) {
3517 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3518 ISP_WRITE(isp, BIU_SEMA, 0);
3519 return;
3520 }
3521 }
3522
3523 /*
3524 * We can't be getting this now.
3525 */
3526 if (isp->isp_state != ISP_RUNSTATE) {
3527 isp_prt(isp, ISP_LOGWARN,
3528 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3529 /*
3530 * Thank you very much! *Burrrp*!
3531 */
3532 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3533 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3534
3535 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3536 ISP_WRITE(isp, BIU_SEMA, 0);
3537 return;
3538 }
3539
3540 /*
3541 * Get the current Response Queue Out Pointer.
3542 *
3543 * If we're a 2300, we can ask what hardware what it thinks.
3544 */
3545 if (IS_23XX(isp)) {
3546 optr = ISP_READ(isp, isp->isp_respoutrp);
3547 /*
3548 * Debug: to be taken out eventually
3549 */
3550 if (isp->isp_residx != optr) {
3551 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3552 optr, isp->isp_residx);
3553 }
3554 } else {
3555 optr = isp->isp_residx;
3556 }
3557
3558 /*
3559 * You *must* read the Response Queue In Pointer
3560 * prior to clearing the RISC interrupt.
3561 *
3562 * Debounce the 2300 if revision less than 2.
3563 */
3564 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3565 i = 0;
3566 do {
3567 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3568 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3569 } while (junk != iptr && ++i < 1000);
3570
3571 if (iptr != junk) {
3572 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3573 isp_prt(isp, ISP_LOGWARN,
3574 "Response Queue Out Pointer Unstable (%x, %x)",
3575 iptr, junk);
3576 return;
3577 }
3578 } else {
3579 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3580 }
3581 isp->isp_resodx = iptr;
3582
3583
3584 if (optr == iptr && sema == 0) {
3585 /*
3586 * There are a lot of these- reasons unknown- mostly on
3587 * faster Alpha machines.
3588 *
3589 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3590 * make sure the old interrupt went away (to avoid 'ringing'
3591 * effects), but that didn't stop this from occurring.
3592 */
3593 if (IS_23XX(isp)) {
3594 USEC_DELAY(100);
3595 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3596 junk = ISP_READ(isp, BIU_R2HSTSLO);
3597 } else {
3598 junk = ISP_READ(isp, BIU_ISR);
3599 }
3600 if (optr == iptr) {
3601 if (IS_23XX(isp)) {
3602 ;
3603 } else {
3604 sema = ISP_READ(isp, BIU_SEMA);
3605 mbox = ISP_READ(isp, OUTMAILBOX0);
3606 if ((sema & 0x3) && (mbox & 0x8000)) {
3607 goto again;
3608 }
3609 }
3610 isp->isp_intbogus++;
3611 isp_prt(isp, ISP_LOGDEBUG1,
3612 "bogus intr- isr %x (%x) iptr %x optr %x",
3613 isr, junk, iptr, optr);
3614 }
3615 }
3616 isp->isp_resodx = iptr;
3617 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3618 ISP_WRITE(isp, BIU_SEMA, 0);
3619
3620 if (isp->isp_rspbsy) {
3621 return;
3622 }
3623 isp->isp_rspbsy = 1;
3624
3625 while (optr != iptr) {
3626 ispstatusreq_t local, *sp = &local;
3627 isphdr_t *hp;
3628 int type;
3629 u_int16_t oop;
3630 int buddaboom = 0;
3631
3632 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3633 oop = optr;
3634 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3635 nlooked++;
3636 /*
3637 * Synchronize our view of this response queue entry.
3638 */
3639 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3640
3641 type = isp_get_response_type(isp, hp);
3642
3643 if (type == RQSTYPE_RESPONSE) {
3644 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3645 } else if (type == RQSTYPE_RIO2) {
3646 isp_rio2_t rio;
3647 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3648 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3649 isp_fastpost_complete(isp, rio.req_handles[i]);
3650 }
3651 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3652 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3653 MEMZERO(hp, QENTRY_LEN); /* PERF */
3654 continue;
3655 } else {
3656 /*
3657 * Somebody reachable via isp_handle_other_response
3658 * may have updated the response queue pointers for
3659 * us, so we reload our goal index.
3660 */
3661 if (isp_handle_other_response(isp, type, hp, &optr)) {
3662 iptr = isp->isp_resodx;
3663 MEMZERO(hp, QENTRY_LEN); /* PERF */
3664 continue;
3665 }
3666
3667 /*
3668 * After this point, we'll just look at the header as
3669 * we don't know how to deal with the rest of the
3670 * response.
3671 */
3672 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3673
3674 /*
3675 * It really has to be a bounced request just copied
3676 * from the request queue to the response queue. If
3677 * not, something bad has happened.
3678 */
3679 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3680 isp_prt(isp, ISP_LOGERR, notresp,
3681 sp->req_header.rqs_entry_type, oop, optr,
3682 nlooked);
3683 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3684 isp_print_bytes(isp, "Queue Entry",
3685 QENTRY_LEN, sp);
3686 }
3687 MEMZERO(hp, QENTRY_LEN); /* PERF */
3688 continue;
3689 }
3690 buddaboom = 1;
3691 }
3692
3693 if (sp->req_header.rqs_flags & 0xf) {
3694#define _RQS_OFLAGS \
3695 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3696 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3697 isp_prt(isp, ISP_LOGWARN,
3698 "continuation segment");
3699 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3700 continue;
3701 }
3702 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3703 isp_prt(isp, ISP_LOGDEBUG1,
3704 "internal queues full");
3705 /*
3706 * We'll synthesize a QUEUE FULL message below.
3707 */
3708 }
3709 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3710 isp_prt(isp, ISP_LOGERR, "bad header flag");
3711 buddaboom++;
3712 }
3713 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3714 isp_prt(isp, ISP_LOGERR, "bad request packet");
3715 buddaboom++;
3716 }
3717 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3718 isp_prt(isp, ISP_LOGERR,
3719 "unknown flags (0x%x) in response",
3720 sp->req_header.rqs_flags);
3721 buddaboom++;
3722 }
3723#undef _RQS_OFLAGS
3724 }
3725 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3726 MEMZERO(hp, QENTRY_LEN); /* PERF */
3727 isp_prt(isp, ISP_LOGERR,
3728 "bad request handle %d (type 0x%x, flags 0x%x)",
3729 sp->req_handle, sp->req_header.rqs_entry_type,
3730 sp->req_header.rqs_flags);
3731 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3732 continue;
3733 }
3734 xs = isp_find_xs(isp, sp->req_handle);
3735 if (xs == NULL) {
3736 u_int8_t ts = sp->req_completion_status & 0xff;
3737 MEMZERO(hp, QENTRY_LEN); /* PERF */
3738 /*
3739 * Only whine if this isn't the expected fallout of
3740 * aborting the command.
3741 */
3742 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3743 isp_prt(isp, ISP_LOGERR,
3744 "cannot find handle 0x%x (type 0x%x)",
3745 sp->req_handle,
3746 sp->req_header.rqs_entry_type);
3747 } else if (ts != RQCS_ABORTED) {
3748 isp_prt(isp, ISP_LOGERR,
3749 "cannot find handle 0x%x (status 0x%x)",
3750 sp->req_handle, ts);
3751 }
3752 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3753 continue;
3754 }
3755 isp_destroy_handle(isp, sp->req_handle);
3756 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3757 XS_SETERR(xs, HBA_BUSRESET);
3758 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3759 }
3760 if (buddaboom) {
3761 XS_SETERR(xs, HBA_BOTCH);
3762 }
3763
3764 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3765 /*
3766 * Fibre Channel F/W doesn't say we got status
3767 * if there's Sense Data instead. I guess they
3768 * think it goes w/o saying.
3769 */
3770 sp->req_state_flags |= RQSF_GOT_STATUS;
3771 }
3772 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3773 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3774 }
3775
3776 switch (sp->req_header.rqs_entry_type) {
3777 case RQSTYPE_RESPONSE:
3778 XS_SET_STATE_STAT(isp, xs, sp);
3779 isp_parse_status(isp, sp, xs);
3780 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3781 (*XS_STSP(xs) == SCSI_BUSY)) {
3782 XS_SETERR(xs, HBA_TGTBSY);
3783 }
3784 if (IS_SCSI(isp)) {
3785 XS_RESID(xs) = sp->req_resid;
3786 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3787 (*XS_STSP(xs) == SCSI_CHECK) &&
3788 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3789 XS_SAVE_SENSE(xs, sp);
3790 }
3791 /*
3792 * A new synchronous rate was negotiated for
3793 * this target. Mark state such that we'll go
3794 * look up that which has changed later.
3795 */
3796 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3797 int t = XS_TGT(xs);
3798 sdparam *sdp = isp->isp_param;
3799 sdp += XS_CHANNEL(xs);
3800 sdp->isp_devparam[t].dev_refresh = 1;
3801 isp->isp_update |=
3802 (1 << XS_CHANNEL(xs));
3803 }
3804 } else {
3805 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3806 XS_RESID(xs) = 0;
3807 } else if (sp->req_scsi_status & RQCS_RESID) {
3808 XS_RESID(xs) = sp->req_resid;
3809 } else {
3810 XS_RESID(xs) = 0;
3811 }
3812 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3813 (*XS_STSP(xs) == SCSI_CHECK) &&
3814 (sp->req_scsi_status & RQCS_SV)) {
3815 XS_SAVE_SENSE(xs, sp);
3816 /* solely for the benefit of debug */
3817 sp->req_state_flags |= RQSF_GOT_SENSE;
3818 }
3819 }
3820 isp_prt(isp, ISP_LOGDEBUG2,
3821 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3822 (long) sp->req_resid);
3823 break;
3824 case RQSTYPE_REQUEST:
3825 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3826 /*
3827 * Force Queue Full status.
3828 */
3829 *XS_STSP(xs) = SCSI_QFULL;
3830 XS_SETERR(xs, HBA_NOERROR);
3831 } else if (XS_NOERR(xs)) {
3832 /*
3833 * ????
3834 */
3835 isp_prt(isp, ISP_LOGDEBUG0,
3836 "Request Queue Entry bounced back");
3837 XS_SETERR(xs, HBA_BOTCH);
3838 }
3839 XS_RESID(xs) = XS_XFRLEN(xs);
3840 break;
3841 default:
3842 isp_prt(isp, ISP_LOGWARN,
3843 "unhandled response queue type 0x%x",
3844 sp->req_header.rqs_entry_type);
3845 if (XS_NOERR(xs)) {
3846 XS_SETERR(xs, HBA_BOTCH);
3847 }
3848 break;
3849 }
3850
3851 /*
3852 * Free any dma resources. As a side effect, this may
3853 * also do any cache flushing necessary for data coherence. */
3854 if (XS_XFRLEN(xs)) {
3855 ISP_DMAFREE(isp, xs, sp->req_handle);
3856 }
3857
3858 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
3859 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
3860 (*XS_STSP(xs) != SCSI_GOOD)))) {
3861 char skey;
3862 if (sp->req_state_flags & RQSF_GOT_SENSE) {
3863 skey = XS_SNSKEY(xs) & 0xf;
3864 if (skey < 10)
3865 skey += '0';
3866 else
3867 skey += 'a' - 10;
3868 } else if (*XS_STSP(xs) == SCSI_CHECK) {
3869 skey = '?';
3870 } else {
3871 skey = '.';
3872 }
3873 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
3874 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
3875 *XS_STSP(xs), skey, XS_ERR(xs));
3876 }
3877
3878 if (isp->isp_nactive > 0)
3879 isp->isp_nactive--;
3880 complist[ndone++] = xs; /* defer completion call until later */
3881 MEMZERO(hp, QENTRY_LEN); /* PERF */
3882 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
3883 break;
3884 }
3885 }
3886
3887 /*
3888 * If we looked at any commands, then it's valid to find out
3889 * what the outpointer is. It also is a trigger to update the
3890 * ISP's notion of what we've seen so far.
3891 */
3892 if (nlooked) {
3893 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3894 /*
3895 * While we're at it, read the requst queue out pointer.
3896 */
3897 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3898 if (isp->isp_rscchiwater < ndone)
3899 isp->isp_rscchiwater = ndone;
3900 }
3901
3902 isp->isp_residx = optr;
3903 isp->isp_rspbsy = 0;
3904 for (i = 0; i < ndone; i++) {
3905 xs = complist[i];
3906 if (xs) {
3907 isp->isp_rsltccmplt++;
3908 isp_done(xs);
3909 }
3910 }
3911}
3912
3913/*
3914 * Support routines.
3915 */
3916
3917static int
3918isp_parse_async(struct ispsoftc *isp, u_int16_t mbox)
3919{
3920 int rval = 0;
3921 int bus;
3922
3923 if (IS_DUALBUS(isp)) {
3924 bus = ISP_READ(isp, OUTMAILBOX6);
3925 } else {
3926 bus = 0;
3927 }
3928 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
3929
3930 switch (mbox) {
3931 case ASYNC_BUS_RESET:
3932 isp->isp_sendmarker |= (1 << bus);
3933#ifdef ISP_TARGET_MODE
3934 if (isp_target_async(isp, bus, mbox))
3935 rval = -1;
3936#endif
3937 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
3938 break;
3939 case ASYNC_SYSTEM_ERROR:
3940#ifdef ISP_FW_CRASH_DUMP
3941 /*
3942 * If we have crash dumps enabled, it's up to the handler
3943 * for isp_async to reinit stuff and restart the firmware
3944 * after performing the crash dump. The reason we do things
3945 * this way is that we may need to activate a kernel thread
3946 * to do all the crash dump goop.
3947 */
3948 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
3949#else
3950 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
3951 isp_reinit(isp);
3952 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
3953#endif
3954 rval = -1;
3955 break;
3956
3957 case ASYNC_RQS_XFER_ERR:
3958 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
3959 break;
3960
3961 case ASYNC_RSP_XFER_ERR:
3962 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
3963 break;
3964
3965 case ASYNC_QWAKEUP:
3966 /*
3967 * We've just been notified that the Queue has woken up.
3968 * We don't need to be chatty about this- just unlatch things
3969 * and move on.
3970 */
3971 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3972 break;
3973
3974 case ASYNC_TIMEOUT_RESET:
3975 isp_prt(isp, ISP_LOGWARN,
3976 "timeout initiated SCSI bus reset of bus %d", bus);
3977 isp->isp_sendmarker |= (1 << bus);
3978#ifdef ISP_TARGET_MODE
3979 if (isp_target_async(isp, bus, mbox))
3980 rval = -1;
3981#endif
3982 break;
3983
3984 case ASYNC_DEVICE_RESET:
3985 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
3986 isp->isp_sendmarker |= (1 << bus);
3987#ifdef ISP_TARGET_MODE
3988 if (isp_target_async(isp, bus, mbox))
3989 rval = -1;
3990#endif
3991 break;
3992
3993 case ASYNC_EXTMSG_UNDERRUN:
3994 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
3995 break;
3996
3997 case ASYNC_SCAM_INT:
3998 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
3999 break;
4000
4001 case ASYNC_HUNG_SCSI:
4002 isp_prt(isp, ISP_LOGERR,
4003 "stalled SCSI Bus after DATA Overrun");
4004 /* XXX: Need to issue SCSI reset at this point */
4005 break;
4006
4007 case ASYNC_KILLED_BUS:
4008 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4009 break;
4010
4011 case ASYNC_BUS_TRANSIT:
4012 mbox = ISP_READ(isp, OUTMAILBOX2);
4013 switch (mbox & 0x1c00) {
4014 case SXP_PINS_LVD_MODE:
4015 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4016 SDPARAM(isp)->isp_diffmode = 0;
4017 SDPARAM(isp)->isp_ultramode = 0;
4018 SDPARAM(isp)->isp_lvdmode = 1;
4019 break;
4020 case SXP_PINS_HVD_MODE:
4021 isp_prt(isp, ISP_LOGINFO,
4022 "Transition to Differential mode");
4023 SDPARAM(isp)->isp_diffmode = 1;
4024 SDPARAM(isp)->isp_ultramode = 0;
4025 SDPARAM(isp)->isp_lvdmode = 0;
4026 break;
4027 case SXP_PINS_SE_MODE:
4028 isp_prt(isp, ISP_LOGINFO,
4029 "Transition to Single Ended mode");
4030 SDPARAM(isp)->isp_diffmode = 0;
4031 SDPARAM(isp)->isp_ultramode = 1;
4032 SDPARAM(isp)->isp_lvdmode = 0;
4033 break;
4034 default:
4035 isp_prt(isp, ISP_LOGWARN,
4036 "Transition to Unknown Mode 0x%x", mbox);
4037 break;
4038 }
4039 /*
4040 * XXX: Set up to renegotiate again!
4041 */
4042 /* Can only be for a 1080... */
4043 isp->isp_sendmarker |= (1 << bus);
4044 break;
4045
4046 /*
4047 * We can use bus, which will always be zero for FC cards,
4048 * as a mailbox pattern accumulator to be checked below.
4049 */
4050 case ASYNC_RIO5:
4051 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4052 break;
4053
4054 case ASYNC_RIO4:
4055 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4056 break;
4057
4058 case ASYNC_RIO3:
4059 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4060 break;
4061
4062 case ASYNC_RIO2:
4063 bus = 0x106; /* outgoing mailbox regs 1-2 */
4064 break;
4065
4066 case ASYNC_RIO1:
4067 case ASYNC_CMD_CMPLT:
4068 bus = 0x102; /* outgoing mailbox regs 1 */
4069 break;
4070
4071 case ASYNC_RIO_RESP:
4072 return (rval);
4073
4074 case ASYNC_CTIO_DONE:
4075 {
4076#ifdef ISP_TARGET_MODE
4077 int handle =
4078 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4079 (ISP_READ(isp, OUTMAILBOX1));
4080 if (isp_target_async(isp, handle, mbox))
4081 rval = -1;
4082#else
4083 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4084#endif
4085 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4086 break;
4087 }
4088 case ASYNC_LIP_F8:
4089 case ASYNC_LIP_OCCURRED:
4090 FCPARAM(isp)->isp_lipseq =
4091 ISP_READ(isp, OUTMAILBOX1);
4092 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4093 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4094 isp->isp_sendmarker = 1;
4095 isp_mark_getpdb_all(isp);
4096 isp_async(isp, ISPASYNC_LIP, NULL);
4097#ifdef ISP_TARGET_MODE
4098 if (isp_target_async(isp, bus, mbox))
4099 rval = -1;
4100#endif
4101 /*
4102 * We've had problems with data corruption occuring on
4103 * commands that complete (with no apparent error) after
4104 * we receive a LIP. This has been observed mostly on
4105 * Local Loop topologies. To be safe, let's just mark
4106 * all active commands as dead.
4107 */
4108 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4109 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4110 int i, j;
4111 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4112 XS_T *xs;
4113 xs = isp->isp_xflist[i];
4114 if (xs != NULL) {
4115 j++;
4116 XS_SETERR(xs, HBA_BUSRESET);
4117 }
4118 }
4119 if (j) {
4120 isp_prt(isp, ISP_LOGERR,
4121 "LIP destroyed %d active commands", j);
4122 }
4123 }
4124 break;
4125
4126 case ASYNC_LOOP_UP:
4127 isp->isp_sendmarker = 1;
4128 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4129 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4130 isp_mark_getpdb_all(isp);
4131 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4132#ifdef ISP_TARGET_MODE
4133 if (isp_target_async(isp, bus, mbox))
4134 rval = -1;
4135#endif
4136 break;
4137
4138 case ASYNC_LOOP_DOWN:
4139 isp->isp_sendmarker = 1;
4140 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4141 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4142 isp_mark_getpdb_all(isp);
4143 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4144#ifdef ISP_TARGET_MODE
4145 if (isp_target_async(isp, bus, mbox))
4146 rval = -1;
4147#endif
4148 break;
4149
4150 case ASYNC_LOOP_RESET:
4151 isp->isp_sendmarker = 1;
4152 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4153 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4154 isp_mark_getpdb_all(isp);
4155 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4156#ifdef ISP_TARGET_MODE
4157 if (isp_target_async(isp, bus, mbox))
4158 rval = -1;
4159#endif
4160 break;
4161
4162 case ASYNC_PDB_CHANGED:
4163 isp->isp_sendmarker = 1;
4164 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4165 isp_mark_getpdb_all(isp);
4166 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4167 break;
4168
4169 case ASYNC_CHANGE_NOTIFY:
4170 /*
4171 * Not correct, but it will force us to rescan the loop.
4172 */
4173 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4174 isp_mark_getpdb_all(isp);
4175 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4176 break;
4177
4178 case ASYNC_PTPMODE:
4179 if (FCPARAM(isp)->isp_onfabric)
4180 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4181 else
4182 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4183 isp_mark_getpdb_all(isp);
4184 isp->isp_sendmarker = 1;
4185 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4186 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4187 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4188#ifdef ISP_TARGET_MODE
4189 if (isp_target_async(isp, bus, mbox))
4190 rval = -1;
4191#endif
4192 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4193 break;
4194
4195 case ASYNC_CONNMODE:
4196 mbox = ISP_READ(isp, OUTMAILBOX1);
4197 isp_mark_getpdb_all(isp);
4198 switch (mbox) {
4199 case ISP_CONN_LOOP:
4200 isp_prt(isp, ISP_LOGINFO,
4201 "Point-to-Point -> Loop mode");
4202 break;
4203 case ISP_CONN_PTP:
4204 isp_prt(isp, ISP_LOGINFO,
4205 "Loop -> Point-to-Point mode");
4206 break;
4207 case ISP_CONN_BADLIP:
4208 isp_prt(isp, ISP_LOGWARN,
4209 "Point-to-Point -> Loop mode (BAD LIP)");
4210 break;
4211 case ISP_CONN_FATAL:
4212 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4213#ifdef ISP_FW_CRASH_DUMP
4214 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4215#else
4216 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4217 isp_reinit(isp);
4218 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4219#endif
4220 return (-1);
4221 case ISP_CONN_LOOPBACK:
4222 isp_prt(isp, ISP_LOGWARN,
4223 "Looped Back in Point-to-Point mode");
4224 break;
4225 default:
4226 isp_prt(isp, ISP_LOGWARN,
4227 "Unknown connection mode (0x%x)", mbox);
4228 break;
4229 }
4230 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4231 isp->isp_sendmarker = 1;
4232 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4233 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4234 break;
4235
4236 default:
4237 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4238 break;
4239 }
4240
4241 if (bus & 0x100) {
4242 int i, nh;
4243 u_int16_t handles[5];
4244
4245 for (nh = 0, i = 1; i < MAX_MAILBOX; i++) {
4246 if ((bus & (1 << i)) == 0) {
4247 continue;
4248 }
4249 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4250 }
4251 for (i = 0; i < nh; i++) {
4252 isp_fastpost_complete(isp, handles[i]);
4253 isp_prt(isp, ISP_LOGDEBUG3,
4254 "fast post completion of %u", handles[i]);
4255 }
4256 if (isp->isp_fpcchiwater < nh)
4257 isp->isp_fpcchiwater = nh;
4258 } else {
4259 isp->isp_intoasync++;
4260 }
4261 return (rval);
4262}
4263
4264/*
4265 * Handle other response entries. A pointer to the request queue output
4266 * index is here in case we want to eat several entries at once, although
4267 * this is not used currently.
4268 */
4269
4270static int
4271isp_handle_other_response(struct ispsoftc *isp, int type,
4272 isphdr_t *hp, u_int16_t *optrp)
4273{
4274 switch (type) {
4275 case RQSTYPE_STATUS_CONT:
4276 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4277 return (1);
4278 case RQSTYPE_ATIO:
4279 case RQSTYPE_CTIO:
4280 case RQSTYPE_ENABLE_LUN:
4281 case RQSTYPE_MODIFY_LUN:
4282 case RQSTYPE_NOTIFY:
4283 case RQSTYPE_NOTIFY_ACK:
4284 case RQSTYPE_CTIO1:
4285 case RQSTYPE_ATIO2:
4286 case RQSTYPE_CTIO2:
4287 case RQSTYPE_CTIO3:
4288 isp->isp_rsltccmplt++; /* count as a response completion */
4289#ifdef ISP_TARGET_MODE
4290 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4291 return (1);
4292 }
4293#else
4294 optrp = optrp;
4295 /* FALLTHROUGH */
4296#endif
4297 case RQSTYPE_REQUEST:
4298 default:
4299 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4300 return (1);
4301 }
4302 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4303 isp_get_response_type(isp, hp));
4304 return (0);
4305 }
4306}
4307
4308static void
4309isp_parse_status(struct ispsoftc *isp, ispstatusreq_t *sp, XS_T *xs)
4310{
4311 switch (sp->req_completion_status & 0xff) {
4312 case RQCS_COMPLETE:
4313 if (XS_NOERR(xs)) {
4314 XS_SETERR(xs, HBA_NOERROR);
4315 }
4316 return;
4317
4318 case RQCS_INCOMPLETE:
4319 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4320 isp_prt(isp, ISP_LOGDEBUG1,
4321 "Selection Timeout for %d.%d.%d",
4322 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4323 if (XS_NOERR(xs)) {
4324 XS_SETERR(xs, HBA_SELTIMEOUT);
4325 }
4326 return;
4327 }
4328 isp_prt(isp, ISP_LOGERR,
4329 "command incomplete for %d.%d.%d, state 0x%x",
4330 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4331 sp->req_state_flags);
4332 break;
4333
4334 case RQCS_DMA_ERROR:
4335 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4336 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4337 break;
4338
4339 case RQCS_TRANSPORT_ERROR:
4340 {
4341 char buf[172];
4342 SNPRINTF(buf, sizeof (buf), "states=>");
4343 if (sp->req_state_flags & RQSF_GOT_BUS) {
4344 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4345 }
4346 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4347 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4348 }
4349 if (sp->req_state_flags & RQSF_SENT_CDB) {
4350 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4351 }
4352 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4353 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4354 }
4355 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4356 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4357 }
4358 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4359 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4360 }
4361 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4362 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4363 }
4364 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4365 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4366 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4367 }
4368 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4369 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4370 }
4371 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4372 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4373 }
4374 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4375 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4376 }
4377 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4378 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4379 }
4380 if (sp->req_status_flags & RQSTF_ABORTED) {
4381 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4382 }
4383 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4384 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4385 }
4386 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4387 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4388 }
4389 isp_prt(isp, ISP_LOGERR, "%s", buf);
4390 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4391 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4392 break;
4393 }
4394 case RQCS_RESET_OCCURRED:
4395 isp_prt(isp, ISP_LOGWARN,
4396 "bus reset destroyed command for %d.%d.%d",
4397 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4398 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4399 if (XS_NOERR(xs)) {
4400 XS_SETERR(xs, HBA_BUSRESET);
4401 }
4402 return;
4403
4404 case RQCS_ABORTED:
4405 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4406 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4407 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4408 if (XS_NOERR(xs)) {
4409 XS_SETERR(xs, HBA_ABORTED);
4410 }
4411 return;
4412
4413 case RQCS_TIMEOUT:
4414 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4415 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4416 /*
4417 * Check to see if we logged out the device.
4418 */
4419 if (IS_FC(isp)) {
4420 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4421 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4422 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4423 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4424 }
4425 }
4426 if (XS_NOERR(xs)) {
4427 XS_SETERR(xs, HBA_CMDTIMEOUT);
4428 }
4429 return;
4430
4431 case RQCS_DATA_OVERRUN:
4432 XS_RESID(xs) = sp->req_resid;
4433 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4434 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4435 if (XS_NOERR(xs)) {
4436 XS_SETERR(xs, HBA_DATAOVR);
4437 }
4438 return;
4439
4440 case RQCS_COMMAND_OVERRUN:
4441 isp_prt(isp, ISP_LOGERR,
4442 "command overrun for command on %d.%d.%d",
4443 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4444 break;
4445
4446 case RQCS_STATUS_OVERRUN:
4447 isp_prt(isp, ISP_LOGERR,
4448 "status overrun for command on %d.%d.%d",
4449 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4450 break;
4451
4452 case RQCS_BAD_MESSAGE:
4453 isp_prt(isp, ISP_LOGERR,
4454 "msg not COMMAND COMPLETE after status %d.%d.%d",
4455 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4456 break;
4457
4458 case RQCS_NO_MESSAGE_OUT:
4459 isp_prt(isp, ISP_LOGERR,
4460 "No MESSAGE OUT phase after selection on %d.%d.%d",
4461 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4462 break;
4463
4464 case RQCS_EXT_ID_FAILED:
4465 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4466 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4467 break;
4468
4469 case RQCS_IDE_MSG_FAILED:
4470 isp_prt(isp, ISP_LOGERR,
4471 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4472 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4473 break;
4474
4475 case RQCS_ABORT_MSG_FAILED:
4476 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4477 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4478 break;
4479
4480 case RQCS_REJECT_MSG_FAILED:
4481 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4482 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4483 break;
4484
4485 case RQCS_NOP_MSG_FAILED:
4486 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4487 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4488 break;
4489
4490 case RQCS_PARITY_ERROR_MSG_FAILED:
4491 isp_prt(isp, ISP_LOGERR,
4492 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4493 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4494 break;
4495
4496 case RQCS_DEVICE_RESET_MSG_FAILED:
4497 isp_prt(isp, ISP_LOGWARN,
4498 "BUS DEVICE RESET rejected by %d.%d.%d",
4499 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4500 break;
4501
4502 case RQCS_ID_MSG_FAILED:
4503 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4504 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4505 break;
4506
4507 case RQCS_UNEXP_BUS_FREE:
4508 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4509 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4510 break;
4511
4512 case RQCS_DATA_UNDERRUN:
4513 {
4514 if (IS_FC(isp)) {
4515 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4516 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4517 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4518 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4519 (ru_marked)? "marked" : "not marked");
4520 if (XS_NOERR(xs)) {
4521 XS_SETERR(xs, HBA_BOTCH);
4522 }
4523 return;
4524 }
4525 }
4526 XS_RESID(xs) = sp->req_resid;
4527 if (XS_NOERR(xs)) {
4528 XS_SETERR(xs, HBA_NOERROR);
4529 }
4530 return;
4531 }
4532
4533 case RQCS_XACT_ERR1:
4534 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4535 XS_TGT(xs), XS_LUN(xs));
4536 break;
4537
4538 case RQCS_XACT_ERR2:
4539 isp_prt(isp, ISP_LOGERR, xact2,
4540 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4541 break;
4542
4543 case RQCS_XACT_ERR3:
4544 isp_prt(isp, ISP_LOGERR, xact3,
4545 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4546 break;
4547
4548 case RQCS_BAD_ENTRY:
4549 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4550 break;
4551
4552 case RQCS_QUEUE_FULL:
4553 isp_prt(isp, ISP_LOGDEBUG0,
4554 "internal queues full for %d.%d.%d status 0x%x",
4555 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4556
4557 /*
4558 * If QFULL or some other status byte is set, then this
4559 * isn't an error, per se.
4560 *
4561 * Unfortunately, some QLogic f/w writers have, in
4562 * some cases, ommitted to *set* status to QFULL.
4563 *
4564
4565 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4566 XS_SETERR(xs, HBA_NOERROR);
4567 return;
4568 }
4569
4570 *
4571 *
4572 */
4573
4574 *XS_STSP(xs) = SCSI_QFULL;
4575 XS_SETERR(xs, HBA_NOERROR);
4576 return;
4577
4578 case RQCS_PHASE_SKIPPED:
4579 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4580 XS_TGT(xs), XS_LUN(xs));
4581 break;
4582
4583 case RQCS_ARQS_FAILED:
4584 isp_prt(isp, ISP_LOGERR,
4585 "Auto Request Sense failed for %d.%d.%d",
4586 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4587 if (XS_NOERR(xs)) {
4588 XS_SETERR(xs, HBA_ARQFAIL);
4589 }
4590 return;
4591
4592 case RQCS_WIDE_FAILED:
4593 isp_prt(isp, ISP_LOGERR,
4594 "Wide Negotiation failed for %d.%d.%d",
4595 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4596 if (IS_SCSI(isp)) {
4597 sdparam *sdp = isp->isp_param;
4598 sdp += XS_CHANNEL(xs);
4599 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4600 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4601 isp->isp_update |= (1 << XS_CHANNEL(xs));
4602 }
4603 if (XS_NOERR(xs)) {
4604 XS_SETERR(xs, HBA_NOERROR);
4605 }
4606 return;
4607
4608 case RQCS_SYNCXFER_FAILED:
4609 isp_prt(isp, ISP_LOGERR,
4610 "SDTR Message failed for target %d.%d.%d",
4611 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4612 if (IS_SCSI(isp)) {
4613 sdparam *sdp = isp->isp_param;
4614 sdp += XS_CHANNEL(xs);
4615 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4616 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4617 isp->isp_update |= (1 << XS_CHANNEL(xs));
4618 }
4619 break;
4620
4621 case RQCS_LVD_BUSERR:
4622 isp_prt(isp, ISP_LOGERR,
4623 "Bad LVD condition while talking to %d.%d.%d",
4624 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4625 break;
4626
4627 case RQCS_PORT_UNAVAILABLE:
4628 /*
4629 * No such port on the loop. Moral equivalent of SELTIMEO
4630 */
4631 case RQCS_PORT_LOGGED_OUT:
4632 /*
4633 * It was there (maybe)- treat as a selection timeout.
4634 */
4635 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4636 isp_prt(isp, ISP_LOGINFO,
4637 "port unavailable for target %d", XS_TGT(xs));
4638 else
4639 isp_prt(isp, ISP_LOGINFO,
4640 "port logout for target %d", XS_TGT(xs));
4641 /*
4642 * If we're on a local loop, force a LIP (which is overkill)
4643 * to force a re-login of this unit. If we're on fabric,
4644 * then we'll have to relogin as a matter of course.
4645 */
4646 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4647 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4648 mbreg_t mbs;
4649 mbs.param[0] = MBOX_INIT_LIP;
4650 isp_mboxcmd_qnw(isp, &mbs, 1);
4651 }
4652
4653 /*
4654 * Probably overkill.
4655 */
4656 isp->isp_sendmarker = 1;
4657 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4658 isp_mark_getpdb_all(isp);
4659 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4660 if (XS_NOERR(xs)) {
4661 XS_SETERR(xs, HBA_SELTIMEOUT);
4662 }
4663 return;
4664
4665 case RQCS_PORT_CHANGED:
4666 isp_prt(isp, ISP_LOGWARN,
4667 "port changed for target %d", XS_TGT(xs));
4668 if (XS_NOERR(xs)) {
4669 XS_SETERR(xs, HBA_SELTIMEOUT);
4670 }
4671 return;
4672
4673 case RQCS_PORT_BUSY:
4674 isp_prt(isp, ISP_LOGWARN,
4675 "port busy for target %d", XS_TGT(xs));
4676 if (XS_NOERR(xs)) {
4677 XS_SETERR(xs, HBA_TGTBSY);
4678 }
4679 return;
4680
4681 default:
4682 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4683 sp->req_completion_status);
4684 break;
4685 }
4686 if (XS_NOERR(xs)) {
4687 XS_SETERR(xs, HBA_BOTCH);
4688 }
4689}
4690
4691static void
4692isp_fastpost_complete(struct ispsoftc *isp, u_int16_t fph)
4693{
4694 XS_T *xs;
4695
4696 if (fph == 0) {
4697 return;
4698 }
4699 xs = isp_find_xs(isp, fph);
4700 if (xs == NULL) {
4701 isp_prt(isp, ISP_LOGWARN,
4702 "Command for fast post handle 0x%x not found", fph);
4703 return;
4704 }
4705 isp_destroy_handle(isp, fph);
4706
4707 /*
4708 * Since we don't have a result queue entry item,
4709 * we must believe that SCSI status is zero and
4710 * that all data transferred.
4711 */
4712 XS_SET_STATE_STAT(isp, xs, NULL);
4713 XS_RESID(xs) = 0;
4714 *XS_STSP(xs) = SCSI_GOOD;
4715 if (XS_XFRLEN(xs)) {
4716 ISP_DMAFREE(isp, xs, fph);
4717 }
4718 if (isp->isp_nactive)
4719 isp->isp_nactive--;
4720 isp->isp_fphccmplt++;
4721 isp_done(xs);
4722}
4723
4724static int
4725isp_mbox_continue(struct ispsoftc *isp)
4726{
4727 mbreg_t mbs;
4728 u_int16_t *ptr;
4729
4730 switch (isp->isp_lastmbxcmd) {
4731 case MBOX_WRITE_RAM_WORD:
4732 case MBOX_READ_RAM_WORD:
4733 case MBOX_READ_RAM_WORD_EXTENDED:
4734 break;
4735 default:
4736 return (1);
4737 }
4738 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4739 isp->isp_mbxwrk0 = 0;
4740 return (-1);
4741 }
4742
4743
4744 /*
4745 * Clear the previous interrupt.
4746 */
4747 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4748 ISP_WRITE(isp, BIU_SEMA, 0);
4749
4750 /*
4751 * Continue with next word.
4752 */
4753 ptr = isp->isp_mbxworkp;
4754 switch (isp->isp_lastmbxcmd) {
4755 case MBOX_WRITE_RAM_WORD:
4756 mbs.param[2] = *ptr++;
4757 mbs.param[1] = isp->isp_mbxwrk1++;
4758 break;
4759 case MBOX_READ_RAM_WORD:
4760 case MBOX_READ_RAM_WORD_EXTENDED:
4761 *ptr++ = isp->isp_mboxtmp[2];
4762 mbs.param[1] = isp->isp_mbxwrk1++;
4763 break;
4764 }
4765 isp->isp_mbxworkp = ptr;
4766 mbs.param[0] = isp->isp_lastmbxcmd;
4767 isp->isp_mbxwrk0 -= 1;
4768 isp_mboxcmd_qnw(isp, &mbs, 0);
4769 return (0);
4770}
4771
4772
4773#define HIBYT(x) ((x) >> 0x8)
4774#define LOBYT(x) ((x) & 0xff)
4775#define ISPOPMAP(a, b) (((a) << 8) | (b))
4776static u_int16_t mbpscsi[] = {
4777 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4778 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4779 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4780 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4781 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4782 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4783 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4784 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4785 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4786 ISPOPMAP(0x00, 0x00), /* 0x09: */
4787 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4788 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4789 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4790 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4791 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4792 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4793 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4794 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4795 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4796 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4797 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4798 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4799 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4800 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4801 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4802 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4803 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4804 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4805 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4806 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4807 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4808 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4809 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4810 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4811 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4812 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4813 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4814 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4815 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4816 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4817 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4818 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4819 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4820 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4821 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4822 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4823 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4824 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4825 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4826 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4827 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4828 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4829 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4830 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4831 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4832 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4833 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4834 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4835 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4836 ISPOPMAP(0x00, 0x00), /* 0x3b: */
4837 ISPOPMAP(0x00, 0x00), /* 0x3c: */
4838 ISPOPMAP(0x00, 0x00), /* 0x3d: */
4839 ISPOPMAP(0x00, 0x00), /* 0x3e: */
4840 ISPOPMAP(0x00, 0x00), /* 0x3f: */
4841 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
4842 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
4843 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
4844 ISPOPMAP(0x00, 0x00), /* 0x43: */
4845 ISPOPMAP(0x00, 0x00), /* 0x44: */
4846 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
4847 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
4848 ISPOPMAP(0x00, 0x00), /* 0x47: */
4849 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
4850 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
4851 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
4852 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
4853 ISPOPMAP(0x00, 0x00), /* 0x4c: */
4854 ISPOPMAP(0x00, 0x00), /* 0x4d: */
4855 ISPOPMAP(0x00, 0x00), /* 0x4e: */
4856 ISPOPMAP(0x00, 0x00), /* 0x4f: */
4857 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
4858 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
4859 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
4860 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
4861 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
4862 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
4863 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
4864 ISPOPMAP(0x00, 0x00), /* 0x57: */
4865 ISPOPMAP(0x00, 0x00), /* 0x58: */
4866 ISPOPMAP(0x00, 0x00), /* 0x59: */
4867 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
4868 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
4869 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
4870 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
4871};
4872
4873#ifndef ISP_STRIPPED
4874static char *scsi_mbcmd_names[] = {
4875 "NO-OP",
4876 "LOAD RAM",
4877 "EXEC FIRMWARE",
4878 "DUMP RAM",
4879 "WRITE RAM WORD",
4880 "READ RAM WORD",
4881 "MAILBOX REG TEST",
4882 "VERIFY CHECKSUM",
4883 "ABOUT FIRMWARE",
4884 NULL,
4885 NULL,
4886 NULL,
4887 NULL,
4888 NULL,
4889 "CHECK FIRMWARE",
4890 NULL,
4891 "INIT REQUEST QUEUE",
4892 "INIT RESULT QUEUE",
4893 "EXECUTE IOCB",
4894 "WAKE UP",
4895 "STOP FIRMWARE",
4896 "ABORT",
4897 "ABORT DEVICE",
4898 "ABORT TARGET",
4899 "BUS RESET",
4900 "STOP QUEUE",
4901 "START QUEUE",
4902 "SINGLE STEP QUEUE",
4903 "ABORT QUEUE",
4904 "GET DEV QUEUE STATUS",
4905 NULL,
4906 "GET FIRMWARE STATUS",
4907 "GET INIT SCSI ID",
4908 "GET SELECT TIMEOUT",
4909 "GET RETRY COUNT",
4910 "GET TAG AGE LIMIT",
4911 "GET CLOCK RATE",
4912 "GET ACT NEG STATE",
4913 "GET ASYNC DATA SETUP TIME",
4914 "GET PCI PARAMS",
4915 "GET TARGET PARAMS",
4916 "GET DEV QUEUE PARAMS",
4917 "GET RESET DELAY PARAMS",
4918 NULL,
4919 NULL,
4920 NULL,
4921 NULL,
4922 NULL,
4923 "SET INIT SCSI ID",
4924 "SET SELECT TIMEOUT",
4925 "SET RETRY COUNT",
4926 "SET TAG AGE LIMIT",
4927 "SET CLOCK RATE",
4928 "SET ACT NEG STATE",
4929 "SET ASYNC DATA SETUP TIME",
4930 "SET PCI CONTROL PARAMS",
4931 "SET TARGET PARAMS",
4932 "SET DEV QUEUE PARAMS",
4933 "SET RESET DELAY PARAMS",
4934 NULL,
4935 NULL,
4936 NULL,
4937 NULL,
4938 NULL,
4939 "RETURN BIOS BLOCK ADDR",
4940 "WRITE FOUR RAM WORDS",
4941 "EXEC BIOS IOCB",
4942 NULL,
4943 NULL,
4944 "SET SYSTEM PARAMETER",
4945 "GET SYSTEM PARAMETER",
4946 NULL,
4947 "GET SCAM CONFIGURATION",
4948 "SET SCAM CONFIGURATION",
4949 "SET FIRMWARE FEATURES",
4950 "GET FIRMWARE FEATURES",
4951 NULL,
4952 NULL,
4953 NULL,
4954 NULL,
4955 "LOAD RAM A64",
4956 "DUMP RAM A64",
4957 "INITIALIZE REQUEST QUEUE A64",
4958 "INITIALIZE RESPONSE QUEUE A64",
4959 "EXECUTE IOCB A64",
4960 "ENABLE TARGET MODE",
4961 "GET TARGET MODE STATE",
4962 NULL,
4963 NULL,
4964 NULL,
4965 "SET DATA OVERRUN RECOVERY MODE",
4966 "GET DATA OVERRUN RECOVERY MODE",
4967 "SET HOST DATA",
4968 "GET NOST DATA",
4969};
4970#endif
4971
4972static u_int16_t mbpfc[] = {
4973 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4974 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4975 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4976 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
4977 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4978 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4979 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
4980 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
4981 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4982 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
4983 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
4984 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4985 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4986 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4987 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4988 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
4989 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
4990 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
4991 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
4992 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4993 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
4994 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
4995 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
4996 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
4997 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
4998 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
4999 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
5000 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5001 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5002 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5003 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5004 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5005 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5006 ISPOPMAP(0x00, 0x00), /* 0x21: */
5007 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5008 ISPOPMAP(0x00, 0x00), /* 0x23: */
5009 ISPOPMAP(0x00, 0x00), /* 0x24: */
5010 ISPOPMAP(0x00, 0x00), /* 0x25: */
5011 ISPOPMAP(0x00, 0x00), /* 0x26: */
5012 ISPOPMAP(0x00, 0x00), /* 0x27: */
5013 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5014 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5015 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5016 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5017 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5018 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5019 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5020 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5021 ISPOPMAP(0x00, 0x00), /* 0x30: */
5022 ISPOPMAP(0x00, 0x00), /* 0x31: */
5023 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5024 ISPOPMAP(0x00, 0x00), /* 0x33: */
5025 ISPOPMAP(0x00, 0x00), /* 0x34: */
5026 ISPOPMAP(0x00, 0x00), /* 0x35: */
5027 ISPOPMAP(0x00, 0x00), /* 0x36: */
5028 ISPOPMAP(0x00, 0x00), /* 0x37: */
5029 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5030 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5031 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5032 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5033 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5034 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5035 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5036 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5037 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5038 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5039 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5040 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5041 ISPOPMAP(0x00, 0x00), /* 0x44: */
5042 ISPOPMAP(0x00, 0x00), /* 0x45: */
5043 ISPOPMAP(0x00, 0x00), /* 0x46: */
5044 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5045 ISPOPMAP(0x00, 0x00), /* 0x48: */
5046 ISPOPMAP(0x00, 0x00), /* 0x49: */
5047 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5048 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5049 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5050 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5051 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5052 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5053 ISPOPMAP(0x00, 0x00), /* 0x50: */
5054 ISPOPMAP(0x00, 0x00), /* 0x51: */
5055 ISPOPMAP(0x00, 0x00), /* 0x52: */
5056 ISPOPMAP(0x00, 0x00), /* 0x53: */
5057 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5058 ISPOPMAP(0x00, 0x00), /* 0x55: */
5059 ISPOPMAP(0x00, 0x00), /* 0x56: */
5060 ISPOPMAP(0x00, 0x00), /* 0x57: */
5061 ISPOPMAP(0x00, 0x00), /* 0x58: */
5062 ISPOPMAP(0x00, 0x00), /* 0x59: */
5063 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5064 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5065 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5066 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5067 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5068 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5069 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5070 ISPOPMAP(0x00, 0x00), /* 0x61: */
5071 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5072 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5073 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5074 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5075 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5076 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5077 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5078 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5079 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5080 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5081 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5082 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5083 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5084 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5085 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5086 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5087 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5088 ISPOPMAP(0x00, 0x00), /* 0x73: */
5089 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5090 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5091 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5092 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5093 ISPOPMAP(0x00, 0x00), /* 0x78: */
5094 ISPOPMAP(0x00, 0x00), /* 0x79: */
5095 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5096 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5097 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5098 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5099 ISPOPMAP(0x07, 0x01) /* 0x7e: Lun RESET */
5100};
5101/*
5102 * Footnotes
5103 *
5104 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5105 * do not access at this time in the core driver. The caller is
5106 * responsible for setting this register first (Gross!).
5107 */
5108
5109#ifndef ISP_STRIPPED
5110static char *fc_mbcmd_names[] = {
5111 "NO-OP",
5112 "LOAD RAM",
5113 "EXEC FIRMWARE",
5114 "DUMP RAM",
5115 "WRITE RAM WORD",
5116 "READ RAM WORD",
5117 "MAILBOX REG TEST",
5118 "VERIFY CHECKSUM",
5119 "ABOUT FIRMWARE",
5120 "LOAD RAM",
5121 "DUMP RAM",
5122 NULL,
5123 NULL,
5124 "READ RAM WORD EXTENDED",
5125 "CHECK FIRMWARE",
5126 NULL,
5127 "INIT REQUEST QUEUE",
5128 "INIT RESULT QUEUE",
5129 "EXECUTE IOCB",
5130 "WAKE UP",
5131 "STOP FIRMWARE",
5132 "ABORT",
5133 "ABORT DEVICE",
5134 "ABORT TARGET",
5135 "BUS RESET",
5136 "STOP QUEUE",
5137 "START QUEUE",
5138 "SINGLE STEP QUEUE",
5139 "ABORT QUEUE",
5140 "GET DEV QUEUE STATUS",
5141 NULL,
5142 "GET FIRMWARE STATUS",
5143 "GET LOOP ID",
5144 NULL,
5145 "GET RETRY COUNT",
5146 NULL,
5147 NULL,
5148 NULL,
5149 NULL,
5150 NULL,
5151 "GET FIRMWARE OPTIONS",
5152 "GET PORT QUEUE PARAMS",
5153 NULL,
5154 NULL,
5155 NULL,
5156 NULL,
5157 NULL,
5158 NULL,
5159 NULL,
5160 NULL,
5161 "SET RETRY COUNT",
5162 NULL,
5163 NULL,
5164 NULL,
5165 NULL,
5166 NULL,
5167 "SET FIRMWARE OPTIONS",
5168 "SET PORT QUEUE PARAMS",
5169 NULL,
5170 NULL,
5171 NULL,
5172 NULL,
5173 NULL,
5174 NULL,
5175 "LOOP PORT BYPASS",
5176 "LOOP PORT ENABLE",
5177 "GET RESOURCE COUNTS",
5178 "REQUEST NON PARTICIPATING MODE",
5179 NULL,
5180 NULL,
5181 NULL,
5182 "GET PORT DATABASE,, ENHANCED",
5183 NULL,
5184 NULL,
5185 NULL,
5186 NULL,
5187 NULL,
5188 NULL,
5189 NULL,
5190 NULL,
5191 NULL,
5192 NULL,
5193 NULL,
5194 NULL,
5195 "EXECUTE IOCB A64",
5196 NULL,
5197 NULL,
5198 NULL,
5199 NULL,
5200 NULL,
5201 NULL,
5202 "DRIVER HEARTBEAT",
5203 NULL,
5204 "GET/SET DATA RATE",
5205 NULL,
5206 NULL,
5207 "INIT FIRMWARE",
5208 NULL,
5209 "INIT LIP",
5210 "GET FC-AL POSITION MAP",
5211 "GET PORT DATABASE",
5212 "CLEAR ACA",
5213 "TARGET RESET",
5214 "CLEAR TASK SET",
5215 "ABORT TASK SET",
5216 "GET FW STATE",
5217 "GET PORT NAME",
5218 "GET LINK STATUS",
5219 "INIT LIP RESET",
5220 NULL,
5221 "SEND SNS",
5222 "FABRIC LOGIN",
5223 "SEND CHANGE REQUEST",
5224 "FABRIC LOGOUT",
5225 "INIT LIP LOGIN",
5226 NULL,
5227 "LOGIN LOOP PORT",
5228 "GET PORT/NODE NAME LIST",
5229 "SET VENDOR ID",
5230 "INITIALIZE IP MAILBOX",
5231 NULL,
5232 NULL,
5233 NULL,
5234 NULL,
5235 "Get ID List",
5236 "SEND LFA",
5237 "Lun RESET"
5238};
5239#endif
5240
5241static void
5242isp_mboxcmd_qnw(struct ispsoftc *isp, mbreg_t *mbp, int nodelay)
5243{
5244 unsigned int ibits, obits, box, opcode;
5245 u_int16_t *mcp;
5246
5247 if (IS_FC(isp)) {
5248 mcp = mbpfc;
5249 } else {
5250 mcp = mbpscsi;
5251 }
5252 opcode = mbp->param[0];
5253 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5254 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5255 for (box = 0; box < MAX_MAILBOX; box++) {
5256 if (ibits & (1 << box)) {
5257 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5258 }
5259 if (nodelay == 0) {
5260 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5261 }
5262 }
5263 if (nodelay == 0) {
5264 isp->isp_lastmbxcmd = opcode;
5265 isp->isp_obits = obits;
5266 isp->isp_mboxbsy = 1;
5267 }
5268 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5269 /*
5270 * Oddly enough, if we're not delaying for an answer,
5271 * delay a bit to give the f/w a chance to pick up the
5272 * command.
5273 */
5274 if (nodelay) {
5275 USEC_DELAY(1000);
5276 }
5277}
5278
5279static void
5280isp_mboxcmd(struct ispsoftc *isp, mbreg_t *mbp, int logmask)
5281{
5282 char *cname, *xname, tname[16], mname[16];
5283 unsigned int lim, ibits, obits, box, opcode;
5284 u_int16_t *mcp;
5285
5286 if (IS_FC(isp)) {
5287 mcp = mbpfc;
5288 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5289 } else {
5290 mcp = mbpscsi;
5291 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5292 }
5293
5294 if ((opcode = mbp->param[0]) >= lim) {
5295 mbp->param[0] = MBOX_INVALID_COMMAND;
5296 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5297 return;
5298 }
5299
5300 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5301 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5302
5303 if (ibits == 0 && obits == 0) {
5304 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5305 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5306 return;
5307 }
5308
5309 /*
5310 * Get exclusive usage of mailbox registers.
5311 */
5312 MBOX_ACQUIRE(isp);
5313
5314 for (box = 0; box < MAX_MAILBOX; box++) {
5315 if (ibits & (1 << box)) {
5316 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5317 }
5318 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5319 }
5320
5321 isp->isp_lastmbxcmd = opcode;
5322
5323 /*
5324 * We assume that we can't overwrite a previous command.
5325 */
5326 isp->isp_obits = obits;
5327 isp->isp_mboxbsy = 1;
5328
5329 /*
5330 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5331 */
5332 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5333
5334 /*
5335 * While we haven't finished the command, spin our wheels here.
5336 */
5337 MBOX_WAIT_COMPLETE(isp);
5338
5339 if (isp->isp_mboxbsy) {
5340 /*
5341 * Command timed out.
5342 */
5343 isp->isp_mboxbsy = 0;
5344 MBOX_RELEASE(isp);
5345 return;
5346 }
5347
5348 /*
5349 * Copy back output registers.
5350 */
5351 for (box = 0; box < MAX_MAILBOX; box++) {
5352 if (obits & (1 << box)) {
5353 mbp->param[box] = isp->isp_mboxtmp[box];
5354 }
5355 }
5356
5357 MBOX_RELEASE(isp);
5358
5359 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5360 return;
5361 }
5362#ifdef ISP_STRIPPED
5363 cname = NULL;
5364#else
5365 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5366#endif
5367 if (cname == NULL) {
5368 cname = tname;
5369 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5370 }
5371
5372 /*
5373 * Just to be chatty here...
5374 */
5375 xname = NULL;
5376 switch (mbp->param[0]) {
5377 case MBOX_COMMAND_COMPLETE:
5378 break;
5379 case MBOX_INVALID_COMMAND:
5380 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5381 xname = "INVALID COMMAND";
5382 break;
5383 case MBOX_HOST_INTERFACE_ERROR:
5384 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5385 xname = "HOST INTERFACE ERROR";
5386 break;
5387 case MBOX_TEST_FAILED:
5388 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5389 xname = "TEST FAILED";
5390 break;
5391 case MBOX_COMMAND_ERROR:
5392 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5393 xname = "COMMAND ERROR";
5394 break;
5395 case MBOX_COMMAND_PARAM_ERROR:
5396 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5397 xname = "COMMAND PARAMETER ERROR";
5398 break;
5399 case MBOX_LOOP_ID_USED:
5400 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5401 xname = "LOOP ID ALREADY IN USE";
5402 break;
5403 case MBOX_PORT_ID_USED:
5404 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5405 xname = "PORT ID ALREADY IN USE";
5406 break;
5407 case MBOX_ALL_IDS_USED:
5408 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5409 xname = "ALL LOOP IDS IN USE";
5410 break;
5411 case 0: /* special case */
5412 xname = "TIMEOUT";
5413 break;
5414 default:
5415 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5416 xname = mname;
5417 break;
5418 }
5419 if (xname)
5420 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5421 cname, xname);
5422}
5423
5424static void
5425isp_fw_state(struct ispsoftc *isp)
5426{
5427 if (IS_FC(isp)) {
5428 mbreg_t mbs;
5429 fcparam *fcp = isp->isp_param;
5430
5431 mbs.param[0] = MBOX_GET_FW_STATE;
5432 isp_mboxcmd(isp, &mbs, MBLOGALL);
5433 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5434 fcp->isp_fwstate = mbs.param[1];
5435 }
5436 }
5437}
5438
5439static void
5440isp_update(struct ispsoftc *isp)
5441{
5442 int bus, upmask;
5443
5444 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5445 if (upmask & (1 << bus)) {
5446 isp_update_bus(isp, bus);
5447 }
5448 upmask &= ~(1 << bus);
5449 }
5450}
5451
5452static void
5453isp_update_bus(struct ispsoftc *isp, int bus)
5454{
5455 int tgt;
5456 mbreg_t mbs;
5457 sdparam *sdp;
5458
5459 isp->isp_update &= ~(1 << bus);
5460 if (IS_FC(isp)) {
5461 /*
5462 * There are no 'per-bus' settings for Fibre Channel.
5463 */
5464 return;
5465 }
5466 sdp = isp->isp_param;
5467 sdp += bus;
5468
5469 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5470 u_int16_t flags, period, offset;
5471 int get;
5472
5473 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5474 sdp->isp_devparam[tgt].dev_update = 0;
5475 sdp->isp_devparam[tgt].dev_refresh = 0;
5476 isp_prt(isp, ISP_LOGDEBUG0,
5477 "skipping target %d bus %d update", tgt, bus);
5478 continue;
5479 }
5480 /*
5481 * If the goal is to update the status of the device,
5482 * take what's in goal_flags and try and set the device
5483 * toward that. Otherwise, if we're just refreshing the
5484 * current device state, get the current parameters.
5485 */
5486
5487 /*
5488 * Refresh overrides set
5489 */
5490 if (sdp->isp_devparam[tgt].dev_refresh) {
5491 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5492 sdp->isp_devparam[tgt].dev_refresh = 0;
5493 get = 1;
5494 } else if (sdp->isp_devparam[tgt].dev_update) {
5495 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5496 /*
5497 * Make sure goal_flags has "Renegotiate on Error"
5498 * on and "Freeze Queue on Error" off.
5499 */
5500 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5501 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5502
5503 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5504
5505 /*
5506 * Insist that PARITY must be enabled
5507 * if SYNC or WIDE is enabled.
5508 */
5509 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5510 mbs.param[2] |= DPARM_PARITY;
5511 }
5512
5513 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5514 mbs.param[3] = 0;
5515 } else {
5516 mbs.param[3] =
5517 (sdp->isp_devparam[tgt].goal_offset << 8) |
5518 (sdp->isp_devparam[tgt].goal_period);
5519 }
5520 /*
5521 * A command completion later that has
5522 * RQSTF_NEGOTIATION set can cause
5523 * the dev_refresh/announce cycle also.
5524 *
5525 * Note: It is really important to update our current
5526 * flags with at least the state of TAG capabilities-
5527 * otherwise we might try and send a tagged command
5528 * when we have it all turned off. So change it here
5529 * to say that current already matches goal.
5530 */
5531 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5532 sdp->isp_devparam[tgt].actv_flags |=
5533 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5534 isp_prt(isp, ISP_LOGDEBUG0,
5535 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5536 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5537 mbs.param[3] & 0xff);
5538 sdp->isp_devparam[tgt].dev_update = 0;
5539 sdp->isp_devparam[tgt].dev_refresh = 1;
5540 get = 0;
5541 } else {
5542 continue;
5543 }
5544 mbs.param[1] = (bus << 15) | (tgt << 8);
5545 isp_mboxcmd(isp, &mbs, MBLOGALL);
5546 if (get == 0) {
5547 isp->isp_sendmarker |= (1 << bus);
5548 continue;
5549 }
5550 flags = mbs.param[2];
5551 period = mbs.param[3] & 0xff;
5552 offset = mbs.param[3] >> 8;
5553 sdp->isp_devparam[tgt].actv_flags = flags;
5554 sdp->isp_devparam[tgt].actv_period = period;
5555 sdp->isp_devparam[tgt].actv_offset = offset;
5556 get = (bus << 16) | tgt;
5557 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5558 }
5559
5560 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5561 if (sdp->isp_devparam[tgt].dev_update ||
5562 sdp->isp_devparam[tgt].dev_refresh) {
5563 isp->isp_update |= (1 << bus);
5564 break;
5565 }
5566 }
5567}
5568
5569#ifndef DEFAULT_FRAMESIZE
5570#define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5571#endif
5572#ifndef DEFAULT_EXEC_THROTTLE
5573#define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5574#endif
5575
5576static void
5577isp_setdfltparm(struct ispsoftc *isp, int channel)
5578{
5579 int tgt;
5580 mbreg_t mbs;
5581 sdparam *sdp;
5582
5583 if (IS_FC(isp)) {
5584 fcparam *fcp = (fcparam *) isp->isp_param;
5585 int nvfail;
5586
5587 fcp += channel;
5588 if (fcp->isp_gotdparms) {
5589 return;
5590 }
5591 fcp->isp_gotdparms = 1;
5592 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5593 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5594 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5595 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5596 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5597 /* Platform specific.... */
5598 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5599 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5600 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5601 fcp->isp_fwoptions = 0;
5602 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5603 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5604 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5605#ifndef ISP_NO_FASTPOST_FC
5606 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5607#endif
5608 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5609 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5610
5611 /*
5612 * Make sure this is turned off now until we get
5613 * extended options from NVRAM
5614 */
5615 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5616
5617 /*
5618 * Now try and read NVRAM unless told to not do so.
5619 * This will set fcparam's isp_nodewwn && isp_portwwn.
5620 */
5621 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5622 nvfail = isp_read_nvram(isp);
5623 if (nvfail)
5624 isp->isp_confopts |= ISP_CFG_NONVRAM;
5625 } else {
5626 nvfail = 1;
5627 }
5628 /*
5629 * Set node && port to override platform set defaults
5630 * unless the nvram read failed (or none was done),
5631 * or the platform code wants to use what had been
5632 * set in the defaults.
5633 */
5634 if (nvfail) {
5635 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5636 }
5637 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5638 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5639 (u_int32_t) (DEFAULT_NODEWWN(isp) >> 32),
5640 (u_int32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5641 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5642 } else {
5643 /*
5644 * We always start out with values derived
5645 * from NVRAM or our platform default.
5646 */
5647 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5648 }
5649 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5650 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5651 (u_int32_t) (DEFAULT_PORTWWN(isp) >> 32),
5652 (u_int32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5653 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5654 } else {
5655 /*
5656 * We always start out with values derived
5657 * from NVRAM or our platform default.
5658 */
5659 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5660 }
5661 return;
5662 }
5663
5664 sdp = (sdparam *) isp->isp_param;
5665 sdp += channel;
5666
5667 /*
5668 * Been there, done that, got the T-shirt...
5669 */
5670 if (sdp->isp_gotdparms) {
5671 return;
5672 }
5673 sdp->isp_gotdparms = 1;
5674
5675 /*
5676 * Establish some default parameters.
5677 */
5678 sdp->isp_cmd_dma_burst_enable = 0;
5679 sdp->isp_data_dma_burst_enabl = 1;
5680 sdp->isp_fifo_threshold = 0;
5681 sdp->isp_initiator_id = DEFAULT_IID(isp);
5682 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5683 sdp->isp_async_data_setup = 9;
5684 } else {
5685 sdp->isp_async_data_setup = 6;
5686 }
5687 sdp->isp_selection_timeout = 250;
5688 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5689 sdp->isp_tag_aging = 8;
5690 sdp->isp_bus_reset_delay = 5;
5691 /*
5692 * Don't retry selection, busy or queue full automatically- reflect
5693 * these back to us.
5694 */
5695 sdp->isp_retry_count = 0;
5696 sdp->isp_retry_delay = 0;
5697
5698 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5699 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5700 sdp->isp_devparam[tgt].dev_enable = 1;
5701 }
5702
5703 /*
5704 * If we've not been told to avoid reading NVRAM, try and read it.
5705 * If we're successful reading it, we can then return because NVRAM
5706 * will tell us what the desired settings are. Otherwise, we establish
5707 * some reasonable 'fake' nvram and goal defaults.
5708 */
5709
5710 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5711 if (isp_read_nvram(isp) == 0) {
5712 return;
5713 }
5714 }
5715
5716 /*
5717 * Now try and see whether we have specific values for them.
5718 */
5719 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5720 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5721 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5722 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5723 sdp->isp_req_ack_active_neg = 1;
5724 sdp->isp_data_line_active_neg = 1;
5725 } else {
5726 sdp->isp_req_ack_active_neg =
5727 (mbs.param[1+channel] >> 4) & 0x1;
5728 sdp->isp_data_line_active_neg =
5729 (mbs.param[1+channel] >> 5) & 0x1;
5730 }
5731 }
5732
5733 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5734 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5735 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5736 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5737 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5738 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5739 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5740 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5741
5742 /*
5743 * The trick here is to establish a default for the default (honk!)
5744 * state (goal_flags). Then try and get the current status from
5745 * the card to fill in the current state. We don't, in fact, set
5746 * the default to the SAFE default state- that's not the goal state.
5747 */
5748 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5749 u_int8_t off, per;
5750 sdp->isp_devparam[tgt].actv_offset = 0;
5751 sdp->isp_devparam[tgt].actv_period = 0;
5752 sdp->isp_devparam[tgt].actv_flags = 0;
5753
5754 sdp->isp_devparam[tgt].goal_flags =
5755 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5756
5757 /*
5758 * We default to Wide/Fast for versions less than a 1040
5759 * (unless it's SBus).
5760 */
5761 if (IS_ULTRA3(isp)) {
5762 off = ISP_80M_SYNCPARMS >> 8;
5763 per = ISP_80M_SYNCPARMS & 0xff;
5764 } else if (IS_ULTRA2(isp)) {
5765 off = ISP_40M_SYNCPARMS >> 8;
5766 per = ISP_40M_SYNCPARMS & 0xff;
5767 } else if (IS_1240(isp)) {
5768 off = ISP_20M_SYNCPARMS >> 8;
5769 per = ISP_20M_SYNCPARMS & 0xff;
5770 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5771 isp->isp_type < ISP_HA_SCSI_1020A) ||
5772 (isp->isp_bustype == ISP_BT_PCI &&
5773 isp->isp_type < ISP_HA_SCSI_1040) ||
5774 (isp->isp_clock && isp->isp_clock < 60) ||
5775 (sdp->isp_ultramode == 0)) {
5776 off = ISP_10M_SYNCPARMS >> 8;
5777 per = ISP_10M_SYNCPARMS & 0xff;
5778 } else {
5779 off = ISP_20M_SYNCPARMS_1040 >> 8;
5780 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5781 }
5782 sdp->isp_devparam[tgt].goal_offset =
5783 sdp->isp_devparam[tgt].nvrm_offset = off;
5784 sdp->isp_devparam[tgt].goal_period =
5785 sdp->isp_devparam[tgt].nvrm_period = per;
5786
5787 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5788 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5789 sdp->isp_devparam[tgt].nvrm_offset,
5790 sdp->isp_devparam[tgt].nvrm_period);
5791 }
5792}
5793
5794/*
5795 * Re-initialize the ISP and complete all orphaned commands
5796 * with a 'botched' notice. The reset/init routines should
5797 * not disturb an already active list of commands.
5798 *
5799 * Locks held prior to coming here.
5800 */
5801
5802void
5803isp_reinit(struct ispsoftc *isp)
5804{
5805 XS_T *xs;
5806 u_int16_t handle;
5807
5808 isp_reset(isp);
5809 if (isp->isp_state != ISP_RESETSTATE) {
5810 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5811 } else if (isp->isp_role != ISP_ROLE_NONE) {
5812 isp_init(isp);
5813 if (isp->isp_state == ISP_INITSTATE) {
5814 isp->isp_state = ISP_RUNSTATE;
5815 }
5816 if (isp->isp_state != ISP_RUNSTATE) {
5817 isp_prt(isp, ISP_LOGERR,
5818 "isp_reinit cannot restart card");
5819 }
5820 }
5821 isp->isp_nactive = 0;
5822
5823 for (handle = 1; (int) handle <= isp->isp_maxcmds; handle++) {
5824 xs = isp_find_xs(isp, handle);
5825 if (xs == NULL) {
5826 continue;
5827 }
5828 isp_destroy_handle(isp, handle);
5829 if (XS_XFRLEN(xs)) {
5830 ISP_DMAFREE(isp, xs, handle);
5831 XS_RESID(xs) = XS_XFRLEN(xs);
5832 } else {
5833 XS_RESID(xs) = 0;
5834 }
5835 XS_SETERR(xs, HBA_BUSRESET);
5836 isp_done(xs);
5837 }
5838}
5839
5840/*
5841 * NVRAM Routines
5842 */
5843static int
5844isp_read_nvram(struct ispsoftc *isp)
5845{
5846 int i, amt;
5847 u_int8_t csum, minversion;
5848 union {
5849 u_int8_t _x[ISP2100_NVRAM_SIZE];
5850 u_int16_t _s[ISP2100_NVRAM_SIZE>>1];
5851 } _n;
5852#define nvram_data _n._x
5853#define nvram_words _n._s
5854
5855 if (IS_FC(isp)) {
5856 amt = ISP2100_NVRAM_SIZE;
5857 minversion = 1;
5858 } else if (IS_ULTRA2(isp)) {
5859 amt = ISP1080_NVRAM_SIZE;
5860 minversion = 0;
5861 } else {
5862 amt = ISP_NVRAM_SIZE;
5863 minversion = 2;
5864 }
5865
5866 /*
5867 * Just read the first two words first to see if we have a valid
5868 * NVRAM to continue reading the rest with.
5869 */
5870 for (i = 0; i < 2; i++) {
5871 isp_rdnvram_word(isp, i, &nvram_words[i]);
5872 }
5873 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
5874 nvram_data[2] != 'P') {
5875 if (isp->isp_bustype != ISP_BT_SBUS) {
5876 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
5877 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
5878 nvram_data[0], nvram_data[1], nvram_data[2]);
5879 }
5880 return (-1);
5881 }
5882 for (i = 2; i < amt>>1; i++) {
5883 isp_rdnvram_word(isp, i, &nvram_words[i]);
5884 }
5885 for (csum = 0, i = 0; i < amt; i++) {
5886 csum += nvram_data[i];
5887 }
5888 if (csum != 0) {
5889 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
5890 return (-1);
5891 }
5892 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
5893 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
5894 ISP_NVRAM_VERSION(nvram_data));
5895 return (-1);
5896 }
5897
5898 if (IS_ULTRA3(isp)) {
5899 isp_parse_nvram_12160(isp, 0, nvram_data);
5900 if (IS_12160(isp))
5901 isp_parse_nvram_12160(isp, 1, nvram_data);
5902 } else if (IS_1080(isp)) {
5903 isp_parse_nvram_1080(isp, 0, nvram_data);
5904 } else if (IS_1280(isp) || IS_1240(isp)) {
5905 isp_parse_nvram_1080(isp, 0, nvram_data);
5906 isp_parse_nvram_1080(isp, 1, nvram_data);
5907 } else if (IS_SCSI(isp)) {
5908 isp_parse_nvram_1020(isp, nvram_data);
5909 } else {
5910 isp_parse_nvram_2100(isp, nvram_data);
5911 }
5912 return (0);
5913#undef nvram_data
5914#undef nvram_words
5915}
5916
5917static void
5918isp_rdnvram_word(struct ispsoftc *isp, int wo, u_int16_t *rp)
5919{
5920 int i, cbits;
5921 u_int16_t bit, rqst;
5922
5923 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5924 USEC_DELAY(2);
5925 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5926 USEC_DELAY(2);
5927
5928 if (IS_FC(isp)) {
5929 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
5930 if (IS_2312(isp) && isp->isp_port) {
5931 wo += 128;
5932 }
5933 rqst = (ISP_NVRAM_READ << 8) | wo;
5934 cbits = 10;
5935 } else if (IS_ULTRA2(isp)) {
5936 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
5937 rqst = (ISP_NVRAM_READ << 8) | wo;
5938 cbits = 10;
5939 } else {
5940 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
5941 rqst = (ISP_NVRAM_READ << 6) | wo;
5942 cbits = 8;
5943 }
5944
5945 /*
5946 * Clock the word select request out...
5947 */
5948 for (i = cbits; i >= 0; i--) {
5949 if ((rqst >> i) & 1) {
5950 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
5951 } else {
5952 bit = BIU_NVRAM_SELECT;
5953 }
5954 ISP_WRITE(isp, BIU_NVRAM, bit);
5955 USEC_DELAY(2);
5956 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
5957 USEC_DELAY(2);
5958 ISP_WRITE(isp, BIU_NVRAM, bit);
5959 USEC_DELAY(2);
5960 }
5961 /*
5962 * Now read the result back in (bits come back in MSB format).
5963 */
5964 *rp = 0;
5965 for (i = 0; i < 16; i++) {
5966 u_int16_t rv;
5967 *rp <<= 1;
5968 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5969 USEC_DELAY(2);
5970 rv = ISP_READ(isp, BIU_NVRAM);
5971 if (rv & BIU_NVRAM_DATAIN) {
5972 *rp |= 1;
5973 }
5974 USEC_DELAY(2);
5975 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5976 USEC_DELAY(2);
5977 }
5978 ISP_WRITE(isp, BIU_NVRAM, 0);
5979 USEC_DELAY(2);
5980 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
5981}
5982
5983static void
5984isp_parse_nvram_1020(struct ispsoftc *isp, u_int8_t *nvram_data)
5985{
5986 sdparam *sdp = (sdparam *) isp->isp_param;
5987 int tgt;
5988
5989 sdp->isp_fifo_threshold =
5990 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
5991 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
5992
5993 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
5994 sdp->isp_initiator_id =
5995 ISP_NVRAM_INITIATOR_ID(nvram_data);
5996
5997 sdp->isp_bus_reset_delay =
5998 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
5999
6000 sdp->isp_retry_count =
6001 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6002
6003 sdp->isp_retry_delay =
6004 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6005
6006 sdp->isp_async_data_setup =
6007 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6008
6009 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6010 if (sdp->isp_async_data_setup < 9) {
6011 sdp->isp_async_data_setup = 9;
6012 }
6013 } else {
6014 if (sdp->isp_async_data_setup != 6) {
6015 sdp->isp_async_data_setup = 6;
6016 }
6017 }
6018
6019 sdp->isp_req_ack_active_neg =
6020 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6021
6022 sdp->isp_data_line_active_neg =
6023 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6024
6025 sdp->isp_data_dma_burst_enabl =
6026 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6027
6028 sdp->isp_cmd_dma_burst_enable =
6029 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6030
6031 sdp->isp_tag_aging =
6032 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6033
6034 sdp->isp_selection_timeout =
6035 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6036
6037 sdp->isp_max_queue_depth =
6038 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6039
6040 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6041
6042 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6043 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6044 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6045 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6046 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6047 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6048 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6049 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6050
6051 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6052 sdp->isp_devparam[tgt].dev_enable =
6053 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6054 sdp->isp_devparam[tgt].exc_throttle =
6055 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6056 sdp->isp_devparam[tgt].nvrm_offset =
6057 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6058 sdp->isp_devparam[tgt].nvrm_period =
6059 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6060 /*
6061 * We probably shouldn't lie about this, but it
6062 * it makes it much safer if we limit NVRAM values
6063 * to sanity.
6064 */
6065 if (isp->isp_type < ISP_HA_SCSI_1040) {
6066 /*
6067 * If we're not ultra, we can't possibly
6068 * be a shorter period than this.
6069 */
6070 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6071 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6072 }
6073 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6074 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6075 }
6076 } else {
6077 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6078 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6079 }
6080 }
6081 sdp->isp_devparam[tgt].nvrm_flags = 0;
6082 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6083 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6084 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6085 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6086 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6087 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6088 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6089 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6090 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6091 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6092 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6093 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6094 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6095 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6096 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6097 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6098 sdp->isp_devparam[tgt].nvrm_offset,
6099 sdp->isp_devparam[tgt].nvrm_period);
6100 sdp->isp_devparam[tgt].goal_offset =
6101 sdp->isp_devparam[tgt].nvrm_offset;
6102 sdp->isp_devparam[tgt].goal_period =
6103 sdp->isp_devparam[tgt].nvrm_period;
6104 sdp->isp_devparam[tgt].goal_flags =
6105 sdp->isp_devparam[tgt].nvrm_flags;
6106 }
6107}
6108
6109static void
6110isp_parse_nvram_1080(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6111{
6112 sdparam *sdp = (sdparam *) isp->isp_param;
6113 int tgt;
6114
6115 sdp += bus;
6116
6117 sdp->isp_fifo_threshold =
6118 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6119
6120 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6121 sdp->isp_initiator_id =
6122 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6123
6124 sdp->isp_bus_reset_delay =
6125 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6126
6127 sdp->isp_retry_count =
6128 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6129
6130 sdp->isp_retry_delay =
6131 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6132
6133 sdp->isp_async_data_setup =
6134 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6135
6136 sdp->isp_req_ack_active_neg =
6137 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6138
6139 sdp->isp_data_line_active_neg =
6140 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6141
6142 sdp->isp_data_dma_burst_enabl =
6143 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6144
6145 sdp->isp_cmd_dma_burst_enable =
6146 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6147
6148 sdp->isp_selection_timeout =
6149 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6150
6151 sdp->isp_max_queue_depth =
6152 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6153
6154 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6155 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6156 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6157 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6158 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6159 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6160 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6161 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6162
6163
6164 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6165 sdp->isp_devparam[tgt].dev_enable =
6166 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6167 sdp->isp_devparam[tgt].exc_throttle =
6168 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6169 sdp->isp_devparam[tgt].nvrm_offset =
6170 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6171 sdp->isp_devparam[tgt].nvrm_period =
6172 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6173 sdp->isp_devparam[tgt].nvrm_flags = 0;
6174 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6175 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6176 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6177 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6178 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6179 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6180 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6181 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6182 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6183 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6184 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6185 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6186 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6187 sdp->isp_devparam[tgt].actv_flags = 0;
6188 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6189 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6190 sdp->isp_devparam[tgt].nvrm_offset,
6191 sdp->isp_devparam[tgt].nvrm_period);
6192 sdp->isp_devparam[tgt].goal_offset =
6193 sdp->isp_devparam[tgt].nvrm_offset;
6194 sdp->isp_devparam[tgt].goal_period =
6195 sdp->isp_devparam[tgt].nvrm_period;
6196 sdp->isp_devparam[tgt].goal_flags =
6197 sdp->isp_devparam[tgt].nvrm_flags;
6198 }
6199}
6200
6201static void
6202isp_parse_nvram_12160(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6203{
6204 sdparam *sdp = (sdparam *) isp->isp_param;
6205 int tgt;
6206
6207 sdp += bus;
6208
6209 sdp->isp_fifo_threshold =
6210 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6211
6212 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6213 sdp->isp_initiator_id =
6214 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6215
6216 sdp->isp_bus_reset_delay =
6217 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6218
6219 sdp->isp_retry_count =
6220 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6221
6222 sdp->isp_retry_delay =
6223 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6224
6225 sdp->isp_async_data_setup =
6226 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6227
6228 sdp->isp_req_ack_active_neg =
6229 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6230
6231 sdp->isp_data_line_active_neg =
6232 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6233
6234 sdp->isp_data_dma_burst_enabl =
6235 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6236
6237 sdp->isp_cmd_dma_burst_enable =
6238 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6239
6240 sdp->isp_selection_timeout =
6241 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6242
6243 sdp->isp_max_queue_depth =
6244 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6245
6246 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6247 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6248 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6249 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6250 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6251 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6252 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6253 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6254
6255 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6256 sdp->isp_devparam[tgt].dev_enable =
6257 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6258 sdp->isp_devparam[tgt].exc_throttle =
6259 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6260 sdp->isp_devparam[tgt].nvrm_offset =
6261 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6262 sdp->isp_devparam[tgt].nvrm_period =
6263 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6264 sdp->isp_devparam[tgt].nvrm_flags = 0;
6265 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6266 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6267 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6268 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6269 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6270 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6271 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6272 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6273 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6274 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6275 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6276 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6277 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6278 sdp->isp_devparam[tgt].actv_flags = 0;
6279 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6280 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6281 sdp->isp_devparam[tgt].nvrm_offset,
6282 sdp->isp_devparam[tgt].nvrm_period);
6283 sdp->isp_devparam[tgt].goal_offset =
6284 sdp->isp_devparam[tgt].nvrm_offset;
6285 sdp->isp_devparam[tgt].goal_period =
6286 sdp->isp_devparam[tgt].nvrm_period;
6287 sdp->isp_devparam[tgt].goal_flags =
6288 sdp->isp_devparam[tgt].nvrm_flags;
6289 }
6290}
6291
6292static void
6293isp_parse_nvram_2100(struct ispsoftc *isp, u_int8_t *nvram_data)
6294{
6295 fcparam *fcp = (fcparam *) isp->isp_param;
6296 u_int64_t wwn;
6297
6298 /*
6299 * There is NVRAM storage for both Port and Node entities-
6300 * but the Node entity appears to be unused on all the cards
6301 * I can find. However, we should account for this being set
6302 * at some point in the future.
6303 *
6304 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6305 * bits 48..60. In the case of the 2202, it appears that they do
6306 * use bit 48 to distinguish between the two instances on the card.
6307 * The 2204, which I've never seen, *probably* extends this method.
6308 */
6309 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6310 if (wwn) {
6311 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6312 (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
6313 if ((wwn >> 60) == 0) {
6314 wwn |= (((u_int64_t) 2)<< 60);
6315 }
6316 }
6317 fcp->isp_portwwn = wwn;
6318 if (IS_2200(isp) || IS_23XX(isp)) {
6319 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6320 if (wwn) {
6321 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6322 (u_int32_t) (wwn >> 32),
6323 (u_int32_t) (wwn & 0xffffffff));
6324 if ((wwn >> 60) == 0) {
6325 wwn |= (((u_int64_t) 2)<< 60);
6326 }
6327 }
6328 } else {
6329 wwn &= ~((u_int64_t) 0xfff << 48);
6330 }
6331 fcp->isp_nodewwn = wwn;
6332
6333 /*
6334 * Make sure we have both Node and Port as non-zero values.
6335 */
6336 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6337 fcp->isp_portwwn = fcp->isp_nodewwn;
6338 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6339 fcp->isp_nodewwn = fcp->isp_portwwn;
6340 }
6341
6342 /*
6343 * Make the Node and Port values sane if they're NAA == 2.
6344 * This means to clear bits 48..56 for the Node WWN and
6345 * make sure that there's some non-zero value in 48..56
6346 * for the Port WWN.
6347 */
6348 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6349 if ((fcp->isp_nodewwn & (((u_int64_t) 0xfff) << 48)) != 0 &&
6350 (fcp->isp_nodewwn >> 60) == 2) {
6351 fcp->isp_nodewwn &= ~((u_int64_t) 0xfff << 48);
6352 }
6353 if ((fcp->isp_portwwn & (((u_int64_t) 0xfff) << 48)) == 0 &&
6354 (fcp->isp_portwwn >> 60) == 2) {
6355 fcp->isp_portwwn |= ((u_int64_t) 1 << 56);
6356 }
6357 }
6358
6359 isp_prt(isp, ISP_LOGDEBUG0,
6360 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6361 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6362 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6363 ISP2100_NVRAM_OPTIONS(nvram_data),
6364 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6365
6366 fcp->isp_maxalloc =
6367 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6368 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6369 fcp->isp_maxfrmlen =
6370 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6371 fcp->isp_retry_delay =
6372 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6373 fcp->isp_retry_count =
6374 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6375 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6376 fcp->isp_loopid =
6377 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6378 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6379 fcp->isp_execthrottle =
6380 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6381 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6382}
6383
6384#ifdef ISP_FW_CRASH_DUMP
6385static void isp2200_fw_dump(struct ispsoftc *);
6386static void isp2300_fw_dump(struct ispsoftc *);
6387
6388static void
6389isp2200_fw_dump(struct ispsoftc *isp)
6390{
6391 int i, j;
6392 mbreg_t mbs;
6393 u_int16_t *ptr;
6394
6395 ptr = FCPARAM(isp)->isp_dump_data;
6396 if (ptr == NULL) {
6397 isp_prt(isp, ISP_LOGERR,
6398 "No place to dump RISC registers and SRAM");
6399 return;
6400 }
6401 if (*ptr++) {
6402 isp_prt(isp, ISP_LOGERR,
6403 "dump area for RISC registers and SRAM already used");
6404 return;
6405 }
6406 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6407 for (i = 0; i < 100; i++) {
6408 USEC_DELAY(100);
6409 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6410 break;
6411 }
6412 }
6413 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6414 /*
6415 * PBIU Registers
6416 */
6417 for (i = 0; i < 8; i++) {
6418 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6419 }
6420
6421 /*
6422 * Mailbox Registers
6423 */
6424 for (i = 0; i < 8; i++) {
6425 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6426 }
6427
6428 /*
6429 * DMA Registers
6430 */
6431 for (i = 0; i < 48; i++) {
6432 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6433 }
6434
6435 /*
6436 * RISC H/W Registers
6437 */
6438 ISP_WRITE(isp, BIU2100_CSR, 0);
6439 for (i = 0; i < 16; i++) {
6440 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6441 }
6442
6443 /*
6444 * RISC GP Registers
6445 */
6446 for (j = 0; j < 8; j++) {
6447 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6448 for (i = 0; i < 16; i++) {
6449 *ptr++ =
6450 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6451 }
6452 }
6453
6454 /*
6455 * Frame Buffer Hardware Registers
6456 */
6457 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6458 for (i = 0; i < 16; i++) {
6459 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6460 }
6461
6462 /*
6463 * Fibre Protocol Module 0 Hardware Registers
6464 */
6465 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6466 for (i = 0; i < 64; i++) {
6467 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6468 }
6469
6470 /*
6471 * Fibre Protocol Module 1 Hardware Registers
6472 */
6473 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6474 for (i = 0; i < 64; i++) {
6475 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6476 }
6477 } else {
6478 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6479 return;
6480 }
6481 isp_prt(isp, ISP_LOGALL,
6482 "isp_fw_dump: RISC registers dumped successfully");
6483 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6484 for (i = 0; i < 100; i++) {
6485 USEC_DELAY(100);
6486 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6487 break;
6488 }
6489 }
6490 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6491 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6492 return;
6493 }
6494 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6495 for (i = 0; i < 100; i++) {
6496 USEC_DELAY(100);
6497 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6498 break;
6499 }
6500 }
6501 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6502 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6503 return;
6504 }
6505 ISP_WRITE(isp, RISC_EMB, 0xf2);
6506 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6507 for (i = 0; i < 100; i++) {
6508 USEC_DELAY(100);
6509 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6510 break;
6511 }
6512 }
6513 ENABLE_INTS(isp);
6514 mbs.param[0] = MBOX_READ_RAM_WORD;
6515 mbs.param[1] = 0x1000;
6516 isp->isp_mbxworkp = (void *) ptr;
6517 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6518 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6519 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6520 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6521 isp_prt(isp, ISP_LOGWARN,
6522 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6523 return;
6524 }
6525 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6526 *ptr++ = isp->isp_mboxtmp[2];
6527 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped succesfully");
6528 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6529 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6530}
6531
6532static void
6533isp2300_fw_dump(struct ispsoftc *isp)
6534{
6535 int i, j;
6536 mbreg_t mbs;
6537 u_int16_t *ptr;
6538
6539 ptr = FCPARAM(isp)->isp_dump_data;
6540 if (ptr == NULL) {
6541 isp_prt(isp, ISP_LOGERR,
6542 "No place to dump RISC registers and SRAM");
6543 return;
6544 }
6545 if (*ptr++) {
6546 isp_prt(isp, ISP_LOGERR,
6547 "dump area for RISC registers and SRAM already used");
6548 return;
6549 }
6550 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6551 for (i = 0; i < 100; i++) {
6552 USEC_DELAY(100);
6553 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6554 break;
6555 }
6556 }
6557 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6558 /*
6559 * PBIU registers
6560 */
6561 for (i = 0; i < 8; i++) {
6562 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6563 }
6564
6565 /*
6566 * ReqQ-RspQ-Risc2Host Status registers
6567 */
6568 for (i = 0; i < 8; i++) {
6569 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6570 }
6571
6572 /*
6573 * Mailbox Registers
6574 */
6575 for (i = 0; i < 32; i++) {
6576 *ptr++ =
6577 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6578 }
6579
6580 /*
6581 * Auto Request Response DMA registers
6582 */
6583 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6584 for (i = 0; i < 32; i++) {
6585 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6586 }
6587
6588 /*
6589 * DMA registers
6590 */
6591 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6592 for (i = 0; i < 48; i++) {
6593 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6594 }
6595
6596 /*
6597 * RISC hardware registers
6598 */
6599 ISP_WRITE(isp, BIU2100_CSR, 0);
6600 for (i = 0; i < 16; i++) {
6601 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6602 }
6603
6604 /*
6605 * RISC GP? registers
6606 */
6607 for (j = 0; j < 8; j++) {
6608 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6609 for (i = 0; i < 16; i++) {
6610 *ptr++ =
6611 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6612 }
6613 }
6614
6615 /*
6616 * frame buffer hardware registers
6617 */
6618 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6619 for (i = 0; i < 64; i++) {
6620 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6621 }
6622
6623 /*
6624 * FPM B0 hardware registers
6625 */
6626 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6627 for (i = 0; i < 64; i++) {
6628 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6629 }
6630
6631 /*
6632 * FPM B1 hardware registers
6633 */
6634 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6635 for (i = 0; i < 64; i++) {
6636 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6637 }
6638 } else {
6639 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6640 return;
6641 }
6642 isp_prt(isp, ISP_LOGALL,
6643 "isp_fw_dump: RISC registers dumped successfully");
6644 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6645 for (i = 0; i < 100; i++) {
6646 USEC_DELAY(100);
6647 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6648 break;
6649 }
6650 }
6651 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6652 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6653 return;
6654 }
6655 ENABLE_INTS(isp);
6656 mbs.param[0] = MBOX_READ_RAM_WORD;
6657 mbs.param[1] = 0x800;
6658 isp->isp_mbxworkp = (void *) ptr;
6659 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6660 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6661 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6662 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6663 isp_prt(isp, ISP_LOGWARN,
6664 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6665 return;
6666 }
6667 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6668 *ptr++ = isp->isp_mboxtmp[2];
6669
6670 /*
6671 * We don't have access to mailbox registers 8.. onward
6672 * in our 'common' device model- so we have to set it
6673 * here and hope it stays the same!
6674 */
6675 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6676
6677 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6678 mbs.param[1] = 0;
6679 isp->isp_mbxworkp = (void *) ptr;
6680 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6681 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6682 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6683 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6684 isp_prt(isp, ISP_LOGWARN,
6685 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6686 return;
6687 }
6688 ptr = isp->isp_mbxworkp; /* finish final word */
6689 *ptr++ = mbs.param[2];
6690 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped succesfully");
6691 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6692 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6693}
6694
6695void
6696isp_fw_dump(struct ispsoftc *isp)
6697{
6698 if (IS_2200(isp))
6699 isp2200_fw_dump(isp);
6700 else if (IS_23XX(isp))
6701 isp2300_fw_dump(isp);
6702}
6703#endif