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