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