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