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