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