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