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