1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 /* 27 * hermon_event.c 28 * Hermon Interrupt and Event Processing Routines 29 * 30 * Implements all the routines necessary for allocating, freeing, and 31 * handling all of the various event types that the Hermon hardware can 32 * generate. 33 * These routines include the main Hermon interrupt service routine 34 * (hermon_isr()) as well as all the code necessary to setup and handle 35 * events from each of the many event queues used by the Hermon device. 36 */ 37 38 #include <sys/types.h> 39 #include <sys/conf.h> 40 #include <sys/ddi.h> 41 #include <sys/sunddi.h> 42 #include <sys/modctl.h> 43 44 #include <sys/ib/adapters/hermon/hermon.h> 45 46 static void hermon_eq_poll(hermon_state_t *state, hermon_eqhdl_t eq); 47 static void hermon_eq_catastrophic(hermon_state_t *state); 48 static int hermon_eq_alloc(hermon_state_t *state, uint32_t log_eq_size, 49 uint_t intr, hermon_eqhdl_t *eqhdl); 50 static int hermon_eq_free(hermon_state_t *state, hermon_eqhdl_t *eqhdl); 51 static int hermon_eq_handler_init(hermon_state_t *state, hermon_eqhdl_t eq, 52 uint_t evt_type_mask, int (*eqfunc)(hermon_state_t *state, 53 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe)); 54 static int hermon_eq_handler_fini(hermon_state_t *state, hermon_eqhdl_t eq); 55 static int hermon_port_state_change_handler(hermon_state_t *state, 56 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 57 static int hermon_comm_estbl_handler(hermon_state_t *state, 58 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 59 static int hermon_local_wq_cat_err_handler(hermon_state_t *state, 60 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 61 static int hermon_invreq_local_wq_err_handler(hermon_state_t *state, 62 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 63 static int hermon_local_acc_vio_wq_err_handler(hermon_state_t *state, 64 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 65 static int hermon_sendq_drained_handler(hermon_state_t *state, 66 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 67 static int hermon_path_mig_handler(hermon_state_t *state, 68 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 69 static int hermon_path_mig_err_handler(hermon_state_t *state, 70 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 71 static int hermon_catastrophic_handler(hermon_state_t *state, 72 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 73 static int hermon_srq_last_wqe_reached_handler(hermon_state_t *state, 74 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 75 static int hermon_fexch_error_handler(hermon_state_t *state, 76 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe); 77 static int hermon_no_eqhandler(hermon_state_t *state, hermon_eqhdl_t eq, 78 hermon_hw_eqe_t *eqe); 79 static int hermon_eq_demux(hermon_state_t *state, hermon_eqhdl_t eq, 80 hermon_hw_eqe_t *eqe); 81 82 /* 83 * hermon_eq_init_all 84 * Context: Only called from attach() path context 85 */ 86 int 87 hermon_eq_init_all(hermon_state_t *state) 88 { 89 uint_t log_eq_size, intr_num; 90 uint_t num_eq, num_eq_init, num_eq_unmap, num_eq_rsvd; 91 uint32_t event_mask; /* used for multiple event types */ 92 int status, i, num_extra; 93 struct hermon_sw_eq_s **eq; 94 ddi_acc_handle_t uarhdl = hermon_get_uarhdl(state); 95 96 /* initialize the FMA retry loop */ 97 hermon_pio_init(fm_loop_cnt, fm_status, fm_test); 98 99 /* 100 * For now, all Event Queues default to the same size (pulled from 101 * the current configuration profile) and are all assigned to the 102 * same interrupt or MSI. In the future we may support assigning 103 * EQs to specific interrupts or MSIs XXX 104 */ 105 log_eq_size = state->hs_cfg_profile->cp_log_eq_sz; 106 107 /* 108 * Total number of supported EQs is fixed. Hermon hardware 109 * supports up to 512 EQs, though in theory they will one day be 110 * alloc'd to virtual HCA's. We are currently using only 47 of them 111 * - that is, in Arbel and Tavor, before HERMON, where 112 * we had set aside the first 32 for use with Completion Queues (CQ) 113 * and reserved a few of the other 32 for each specific class of event 114 * 115 * However, with the coming of vitualization, we'll have only 4 per 116 * potential guest - so, we'll try alloc'ing them differntly 117 * (see below for more details). 118 */ 119 num_eq = HERMON_NUM_EQ_USED; 120 num_eq_rsvd = state->hs_rsvd_eqs; 121 eq = &state->hs_eqhdl[num_eq_rsvd]; 122 123 /* 124 * If MSI is to be used, then set intr_num to the MSI number. 125 * Otherwise, for fixed (i.e. 'legacy') interrupts, 126 * it is what the card tells us in 'inta_pin'. 127 */ 128 if (state->hs_intr_type_chosen == DDI_INTR_TYPE_FIXED) { 129 intr_num = state->hs_adapter.inta_pin; 130 num_extra = 0; 131 } else { 132 /* If we have more than one MSI-X vector, init them. */ 133 for (i = 0; i + 1 < state->hs_intrmsi_allocd; i++) { 134 status = hermon_eq_alloc(state, log_eq_size, i, &eq[i]); 135 if (status != DDI_SUCCESS) { 136 while (--i >= 0) { 137 (void) hermon_eq_handler_fini(state, 138 eq[i]); 139 (void) hermon_eq_free(state, &eq[i]); 140 } 141 return (DDI_FAILURE); 142 } 143 144 (void) hermon_eq_handler_init(state, eq[i], 145 HERMON_EVT_NO_MASK, hermon_cq_handler); 146 } 147 intr_num = i; 148 num_extra = i; 149 } 150 151 /* 152 * Allocate and initialize the rest of the Event Queues to be used. 153 * If any of these EQ allocations fail then jump to the end, cleanup 154 * what had been successfully initialized, and return an error. 155 */ 156 for (i = 0; i < num_eq; i++) { 157 status = hermon_eq_alloc(state, log_eq_size, intr_num, 158 &eq[num_extra + i]); 159 if (status != DDI_SUCCESS) { 160 num_eq_init = i; 161 goto all_eq_init_fail; 162 } 163 } 164 num_eq_init = num_eq; 165 /* 166 * The "num_eq_unmap" variable is used in any possible failure 167 * cleanup (below) to indicate which events queues might require 168 * possible event class unmapping. 169 */ 170 num_eq_unmap = 0; 171 172 /* 173 * Setup EQ0 (first avail) for use with Completion Queues. Note: We can 174 * cast the return value to void here because, when we use the 175 * HERMON_EVT_NO_MASK flag, it is not possible for 176 * hermon_eq_handler_init() to return an error. 177 */ 178 (void) hermon_eq_handler_init(state, eq[num_eq_unmap + num_extra], 179 HERMON_EVT_NO_MASK, hermon_cq_handler); 180 181 num_eq_unmap++; 182 183 /* 184 * Setup EQ1 for handling Completion Queue Error Events. 185 * 186 * These events include things like CQ overflow or CQ access 187 * violation errors. If this setup fails for any reason (which, in 188 * general, it really never should), then jump to the end, cleanup 189 * everything that has been successfully initialized, and return an 190 * error. 191 */ 192 status = hermon_eq_handler_init(state, eq[num_eq_unmap + num_extra], 193 HERMON_EVT_MSK_CQ_ERRORS, hermon_cq_err_handler); 194 if (status != DDI_SUCCESS) { 195 goto all_eq_init_fail; 196 } 197 state->hs_cq_erreqnum = num_eq_unmap + num_extra + num_eq_rsvd; 198 num_eq_unmap++; 199 200 /* 201 * Setup EQ2 for handling most other things including: 202 * 203 * Port State Change Events 204 * These events include things like Port Up and Port Down events. 205 * 206 * Communication Established Events 207 * These events correspond to the IB affiliated asynchronous events 208 * that are used for connection management 209 * 210 * Path Migration Succeeded Events 211 * These evens corresponid to the IB affiliated asynchronous events 212 * that are used to indicate successful completion of a 213 * Path Migration. 214 * 215 * Command Completion Events 216 * These events correspond to the Arbel generated events that are used 217 * to indicate Arbel firmware command completion. 218 * 219 * Local WQ Catastrophic Error Events 220 * Invalid Req Local WQ Error Events 221 * Local Access Violation WQ Error Events 222 * SRQ Catastrophic Error Events 223 * SRQ Last WQE Reached Events 224 * ECC error detection events 225 * These events also correspond to the similarly-named IB affiliated 226 * asynchronous error type. 227 * 228 * Send Queue Drained Events 229 * These events correspond to the IB affiliated asynchronous events 230 * that are used to indicate completion of a Send Queue Drained QP 231 * state transition. 232 * 233 * Path Migration Failed Events 234 * These events correspond to the IB affiliated asynchronous events 235 * that are used to indicate that path migration was not successful. 236 * 237 * Fibre Channel Error Event 238 * This event is affiliated with an Fexch QP. 239 * 240 * NOTE: When an event fires on this EQ, it will demux the type and 241 * send it to the right specific handler routine 242 * 243 */ 244 event_mask = 245 HERMON_EVT_MSK_PORT_STATE_CHANGE | 246 HERMON_EVT_MSK_COMM_ESTABLISHED | 247 HERMON_EVT_MSK_COMMAND_INTF_COMP | 248 HERMON_EVT_MSK_LOCAL_WQ_CAT_ERROR | 249 HERMON_EVT_MSK_INV_REQ_LOCAL_WQ_ERROR | 250 HERMON_EVT_MSK_LOCAL_ACC_VIO_WQ_ERROR | 251 HERMON_EVT_MSK_SEND_QUEUE_DRAINED | 252 HERMON_EVT_MSK_PATH_MIGRATED | 253 HERMON_EVT_MSK_PATH_MIGRATE_FAILED | 254 HERMON_EVT_MSK_SRQ_CATASTROPHIC_ERROR | 255 HERMON_EVT_MSK_SRQ_LAST_WQE_REACHED | 256 HERMON_EVT_MSK_FEXCH_ERROR; 257 258 status = hermon_eq_handler_init(state, eq[num_eq_unmap + num_extra], 259 event_mask, hermon_eq_demux); 260 if (status != DDI_SUCCESS) { 261 goto all_eq_init_fail; 262 } 263 num_eq_unmap++; 264 265 /* 266 * Setup EQ3 to catch all other types of events. Specifically, we 267 * do not catch the "Local EEC Catastrophic Error Event" because we 268 * should have no EEC (the Arbel driver does not support RD). We also 269 * choose not to handle any of the address translation page fault 270 * event types. Since we are not doing any page fault handling (and 271 * since the Arbel firmware does not currently support any such 272 * handling), we allow these events to go to the catch-all handler. 273 */ 274 status = hermon_eq_handler_init(state, eq[num_eq_unmap + num_extra], 275 HERMON_EVT_CATCHALL_MASK, hermon_no_eqhandler); 276 if (status != DDI_SUCCESS) { 277 goto all_eq_init_fail; 278 } 279 num_eq_unmap++; 280 281 /* the FMA retry loop starts. */ 282 hermon_pio_start(state, uarhdl, all_eq_init_fail, fm_loop_cnt, 283 fm_status, fm_test); 284 285 /* 286 * Run through and initialize the Consumer Index for each EQC. 287 */ 288 for (i = 0; i < num_eq + num_extra; i++) { 289 ddi_put32(uarhdl, eq[i]->eq_doorbell, 0x0); 290 } 291 292 /* the FMA retry loop ends. */ 293 hermon_pio_end(state, uarhdl, all_eq_init_fail, fm_loop_cnt, 294 fm_status, fm_test); 295 296 return (DDI_SUCCESS); 297 298 all_eq_init_fail: 299 300 /* Unmap any of the partially mapped EQs from above */ 301 for (i = 0; i < num_eq_unmap + num_extra; i++) { 302 (void) hermon_eq_handler_fini(state, eq[i]); 303 } 304 305 /* Free up any of the partially allocated EQs from above */ 306 for (i = 0; i < num_eq_init + num_extra; i++) { 307 (void) hermon_eq_free(state, &eq[i]); 308 } 309 310 /* If a HW error happen during ddi_pio, return DDI_FAILURE */ 311 if (fm_status == HCA_PIO_PERSISTENT) { 312 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_NON_FATAL); 313 status = DDI_FAILURE; 314 } 315 316 return (status); 317 } 318 319 320 /* 321 * hermon_eq_fini_all 322 * Context: Only called from attach() and/or detach() path contexts 323 */ 324 int 325 hermon_eq_fini_all(hermon_state_t *state) 326 { 327 uint_t num_eq, num_eq_rsvd; 328 int status, i; 329 struct hermon_sw_eq_s **eq; 330 331 /* 332 * Grab the total number of supported EQs again. This is the same 333 * hardcoded value that was used above (during the event queue 334 * initialization.) 335 */ 336 num_eq = HERMON_NUM_EQ_USED + state->hs_intrmsi_allocd - 1; 337 num_eq_rsvd = state->hs_rsvd_eqs; 338 eq = &state->hs_eqhdl[num_eq_rsvd]; 339 340 /* 341 * For each of the event queues that we initialized and mapped 342 * earlier, attempt to unmap the events from the EQ. 343 */ 344 for (i = 0; i < num_eq; i++) { 345 status = hermon_eq_handler_fini(state, eq[i]); 346 if (status != DDI_SUCCESS) { 347 return (DDI_FAILURE); 348 } 349 } 350 351 /* 352 * Teardown and free up all the Event Queues that were allocated 353 * earlier. 354 */ 355 for (i = 0; i < num_eq; i++) { 356 status = hermon_eq_free(state, &eq[i]); 357 if (status != DDI_SUCCESS) { 358 return (DDI_FAILURE); 359 } 360 } 361 362 return (DDI_SUCCESS); 363 } 364 365 366 /* 367 * hermon_eq_reset_uar_baseaddr 368 * Context: Only called from attach() 369 */ 370 void 371 hermon_eq_reset_uar_baseaddr(hermon_state_t *state) 372 { 373 int i, num_eq; 374 hermon_eqhdl_t eq, *eqh; 375 376 num_eq = HERMON_NUM_EQ_USED + state->hs_intrmsi_allocd - 1; 377 eqh = &state->hs_eqhdl[state->hs_rsvd_eqs]; 378 for (i = 0; i < num_eq; i++) { 379 eq = eqh[i]; 380 eq->eq_doorbell = (uint32_t *) 381 ((uintptr_t)state->hs_reg_uar_baseaddr + 382 (uint32_t)ARM_EQ_INDEX(eq->eq_eqnum)); 383 } 384 } 385 386 387 /* 388 * hermon_eq_arm_all 389 * Context: Only called from attach() and/or detach() path contexts 390 */ 391 int 392 hermon_eq_arm_all(hermon_state_t *state) 393 { 394 uint_t num_eq, num_eq_rsvd; 395 uint64_t offset; 396 hermon_eqhdl_t eq; 397 uint32_t eq_ci; 398 int i; 399 ddi_acc_handle_t uarhdl = hermon_get_uarhdl(state); 400 401 /* initialize the FMA retry loop */ 402 hermon_pio_init(fm_loop_cnt, fm_status, fm_test); 403 404 num_eq = HERMON_NUM_EQ_USED + state->hs_intrmsi_allocd - 1; 405 num_eq_rsvd = state->hs_rsvd_eqs; 406 407 /* the FMA retry loop starts. */ 408 hermon_pio_start(state, uarhdl, pio_error, fm_loop_cnt, fm_status, 409 fm_test); 410 411 for (i = 0; i < num_eq; i++) { 412 offset = ARM_EQ_INDEX(i + num_eq_rsvd); 413 eq = state->hs_eqhdl[i + num_eq_rsvd]; 414 eq_ci = (eq->eq_consindx & HERMON_EQ_CI_MASK) | EQ_ARM_BIT; 415 ddi_put32(uarhdl, 416 (uint32_t *)((uintptr_t)state->hs_reg_uar_baseaddr + 417 (uint32_t)offset), eq_ci); 418 } 419 420 /* the FMA retry loop ends. */ 421 hermon_pio_end(state, uarhdl, pio_error, fm_loop_cnt, fm_status, 422 fm_test); 423 424 return (DDI_SUCCESS); 425 426 pio_error: 427 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_NON_FATAL); 428 return (DDI_FAILURE); 429 } 430 431 432 /* 433 * hermon_isr() 434 * Context: Only called from interrupt context (and during panic) 435 */ 436 uint_t 437 hermon_isr(caddr_t arg1, caddr_t arg2) 438 { 439 hermon_state_t *state; 440 int i, r; 441 int intr; 442 443 /* 444 * Grab the Hermon softstate pointer from the input parameter 445 */ 446 state = (hermon_state_t *)(void *)arg1; 447 448 /* Get the interrupt number */ 449 intr = (int)(uintptr_t)arg2; 450 451 /* 452 * Clear the interrupt. Note: This is only needed for 453 * fixed interrupts as the framework does what is needed for 454 * MSI-X interrupts. 455 */ 456 if (state->hs_intr_type_chosen == DDI_INTR_TYPE_FIXED) { 457 ddi_acc_handle_t cmdhdl = hermon_get_cmdhdl(state); 458 459 /* initialize the FMA retry loop */ 460 hermon_pio_init(fm_loop_cnt, fm_status, fm_test); 461 462 /* the FMA retry loop starts. */ 463 hermon_pio_start(state, cmdhdl, pio_error, fm_loop_cnt, 464 fm_status, fm_test); 465 466 ddi_put64(cmdhdl, state->hs_cmd_regs.clr_intr, 467 (uint64_t)1 << state->hs_adapter.inta_pin); 468 469 /* the FMA retry loop ends. */ 470 hermon_pio_end(state, cmdhdl, pio_error, fm_loop_cnt, fm_status, 471 fm_test); 472 } 473 474 /* 475 * Loop through all the EQs looking for ones that have "fired". 476 * To determine if an EQ is fired, the ownership will be the SW 477 * (the HW will set the owner appropriately). Update the Consumer Index 478 * of the Event Queue Entry (EQE) and pass it to HW by writing it 479 * to the respective Set CI DB Register. 480 * 481 * The "else" case handles the extra EQs used only for completion 482 * events, whereas the "if" case deals with the required interrupt 483 * vector that is used for all classes of events. 484 */ 485 r = state->hs_rsvd_eqs; 486 487 if (intr + 1 == state->hs_intrmsi_allocd) { /* last intr */ 488 r += state->hs_intrmsi_allocd - 1; 489 for (i = 0; i < HERMON_NUM_EQ_USED; i++) { 490 hermon_eq_poll(state, state->hs_eqhdl[i + r]); 491 } 492 } else { /* only poll the one EQ */ 493 hermon_eq_poll(state, state->hs_eqhdl[intr + r]); 494 } 495 496 return (DDI_INTR_CLAIMED); 497 498 pio_error: 499 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_FATAL); 500 return (DDI_INTR_UNCLAIMED); 501 } 502 503 504 /* 505 * hermon_eq_poll 506 * Context: Only called from interrupt context (and during panic) 507 */ 508 static void 509 hermon_eq_poll(hermon_state_t *state, hermon_eqhdl_t eq) 510 { 511 hermon_hw_eqe_t *eqe; 512 int polled_some; 513 uint32_t cons_indx, wrap_around_mask, shift; 514 int (*eqfunction)(hermon_state_t *state, hermon_eqhdl_t eq, 515 hermon_hw_eqe_t *eqe); 516 ddi_acc_handle_t uarhdl = hermon_get_uarhdl(state); 517 518 /* initialize the FMA retry loop */ 519 hermon_pio_init(fm_loop_cnt, fm_status, fm_test); 520 521 /* Get the consumer pointer index */ 522 cons_indx = eq->eq_consindx; 523 shift = eq->eq_log_eqsz - HERMON_EQE_OWNER_SHIFT; 524 525 /* 526 * Calculate the wrap around mask. Note: This operation only works 527 * because all Hermon event queues have power-of-2 sizes 528 */ 529 wrap_around_mask = (eq->eq_bufsz - 1); 530 531 /* Calculate the pointer to the first EQ entry */ 532 eqe = &eq->eq_buf[(cons_indx & wrap_around_mask)]; 533 534 535 /* 536 * Pull the handler function for this EQ from the Hermon Event Queue 537 * handle 538 */ 539 eqfunction = eq->eq_func; 540 541 for (;;) { 542 polled_some = 0; 543 while (HERMON_EQE_OWNER_IS_SW(eq, eqe, cons_indx, shift)) { 544 545 /* 546 * Call the EQ handler function. But only call if we 547 * are not in polled I/O mode (i.e. not processing 548 * because of a system panic). Note: We don't call 549 * the EQ handling functions from a system panic 550 * because we are primarily concerned only with 551 * ensuring that the event queues do not overflow (or, 552 * more specifically, the event queue associated with 553 * the CQ that is being used in the sync/dump process). 554 * Also, we don't want to make any upcalls (to the 555 * IBTF) because we can't guarantee when/if those 556 * calls would ever return. And, if we're in panic, 557 * then we reached here through a PollCQ() call (from 558 * hermon_cq_poll()), and we need to ensure that we 559 * successfully return any work completions to the 560 * caller. 561 */ 562 if (ddi_in_panic() == 0) { 563 eqfunction(state, eq, eqe); 564 } 565 566 /* Reset to hardware ownership is implicit */ 567 568 /* Increment the consumer index */ 569 cons_indx++; 570 571 /* Update the pointer to the next EQ entry */ 572 eqe = &eq->eq_buf[(cons_indx & wrap_around_mask)]; 573 574 polled_some = 1; 575 } 576 577 /* 578 * write consumer index via EQ set CI Doorbell, to keep overflow 579 * from occuring during poll 580 */ 581 582 eq->eq_consindx = cons_indx; 583 584 /* the FMA retry loop starts. */ 585 hermon_pio_start(state, uarhdl, pio_error, fm_loop_cnt, 586 fm_status, fm_test); 587 588 ddi_put32(uarhdl, eq->eq_doorbell, 589 (cons_indx & HERMON_EQ_CI_MASK) | EQ_ARM_BIT); 590 591 /* the FMA retry loop starts. */ 592 hermon_pio_end(state, uarhdl, pio_error, fm_loop_cnt, 593 fm_status, fm_test); 594 595 if (polled_some == 0) 596 break; 597 }; 598 return; 599 600 pio_error: 601 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_FATAL); 602 } 603 604 605 /* 606 * hermon_eq_catastrophic 607 * Context: Only called from interrupt context (and during panic) 608 */ 609 static void 610 hermon_eq_catastrophic(hermon_state_t *state) 611 { 612 ddi_acc_handle_t cmdhdl = hermon_get_cmdhdl(state); 613 ibt_async_code_t type; 614 ibc_async_event_t event; 615 uint32_t *base_addr; 616 uint32_t buf_size; 617 uint32_t word; 618 uint8_t err_type; 619 uint32_t err_buf; 620 int i; 621 622 /* initialize the FMA retry loop */ 623 hermon_pio_init(fm_loop_cnt, fm_status, fm_test); 624 625 bzero(&event, sizeof (ibc_async_event_t)); 626 base_addr = state->hs_cmd_regs.fw_err_buf; 627 628 buf_size = state->hs_fw.error_buf_sz; /* in #dwords */ 629 630 /* the FMA retry loop starts. */ 631 hermon_pio_start(state, cmdhdl, pio_error, fm_loop_cnt, fm_status, 632 fm_test); 633 634 word = ddi_get32(cmdhdl, base_addr); 635 636 /* the FMA retry loop ends. */ 637 hermon_pio_end(state, cmdhdl, pio_error, fm_loop_cnt, fm_status, 638 fm_test); 639 640 err_type = (word & 0xFF000000) >> 24; 641 type = IBT_ERROR_LOCAL_CATASTROPHIC; 642 643 switch (err_type) { 644 case HERMON_CATASTROPHIC_INTERNAL_ERROR: 645 cmn_err(CE_WARN, "Catastrophic Internal Error: 0x%02x", 646 err_type); 647 648 break; 649 650 case HERMON_CATASTROPHIC_UPLINK_BUS_ERROR: 651 cmn_err(CE_WARN, "Catastrophic Uplink Bus Error: 0x%02x", 652 err_type); 653 654 break; 655 656 case HERMON_CATASTROPHIC_DDR_DATA_ERROR: 657 cmn_err(CE_WARN, "Catastrophic DDR Data Error: 0x%02x", 658 err_type); 659 660 break; 661 662 case HERMON_CATASTROPHIC_INTERNAL_PARITY_ERROR: 663 cmn_err(CE_WARN, "Catastrophic Internal Parity Error: 0x%02x", 664 err_type); 665 666 break; 667 668 default: 669 /* Unknown type of Catastrophic error */ 670 cmn_err(CE_WARN, "Catastrophic Unknown Error: 0x%02x", 671 err_type); 672 673 break; 674 } 675 676 /* the FMA retry loop starts. */ 677 hermon_pio_start(state, cmdhdl, pio_error, fm_loop_cnt, fm_status, 678 fm_test); 679 680 /* 681 * Read in the catastrophic error buffer from the hardware. 682 */ 683 for (i = 0; i < buf_size; i++) { 684 base_addr = 685 (state->hs_cmd_regs.fw_err_buf + i); 686 err_buf = ddi_get32(cmdhdl, base_addr); 687 cmn_err(CE_NOTE, "hermon%d: catastrophic_error[%02x]: %08X", 688 state->hs_instance, i, err_buf); 689 } 690 691 /* the FMA retry loop ends. */ 692 hermon_pio_end(state, cmdhdl, pio_error, fm_loop_cnt, fm_status, 693 fm_test); 694 695 /* 696 * We also call the IBTF here to inform it of the catastrophic error. 697 * Note: Since no event information (i.e. QP handles, CQ handles, 698 * etc.) is necessary, we pass a NULL pointer instead of a pointer to 699 * an empty ibc_async_event_t struct. 700 * 701 * But we also check if "hs_ibtfpriv" is NULL. If it is then it 702 * means that we've have either received this event before we 703 * finished attaching to the IBTF or we've received it while we 704 * are in the process of detaching. 705 */ 706 if (state->hs_ibtfpriv != NULL) { 707 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 708 } 709 710 pio_error: 711 /* ignore these errors but log them because they're harmless. */ 712 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_NON_FATAL); 713 } 714 715 716 /* 717 * hermon_eq_alloc() 718 * Context: Only called from attach() path context 719 */ 720 static int 721 hermon_eq_alloc(hermon_state_t *state, uint32_t log_eq_size, uint_t intr, 722 hermon_eqhdl_t *eqhdl) 723 { 724 hermon_rsrc_t *eqc, *rsrc; 725 hermon_hw_eqc_t eqc_entry; 726 hermon_eqhdl_t eq; 727 ibt_mr_attr_t mr_attr; 728 hermon_mr_options_t op; 729 hermon_pdhdl_t pd; 730 hermon_mrhdl_t mr; 731 hermon_hw_eqe_t *buf; 732 int status; 733 734 /* Use the internal protection domain (PD) for setting up EQs */ 735 pd = state->hs_pdhdl_internal; 736 737 /* Increment the reference count on the protection domain (PD) */ 738 hermon_pd_refcnt_inc(pd); 739 740 /* 741 * Allocate an EQ context entry. This will be filled in with all 742 * the necessary parameters to define the Event Queue. And then 743 * ownership will be passed to the hardware in the final step 744 * below. If we fail here, we must undo the protection domain 745 * reference count. 746 */ 747 status = hermon_rsrc_alloc(state, HERMON_EQC, 1, HERMON_SLEEP, &eqc); 748 if (status != DDI_SUCCESS) { 749 status = DDI_FAILURE; 750 goto eqalloc_fail1; 751 } 752 753 /* 754 * Allocate the software structure for tracking the event queue (i.e. 755 * the Hermon Event Queue handle). If we fail here, we must undo the 756 * protection domain reference count and the previous resource 757 * allocation. 758 */ 759 status = hermon_rsrc_alloc(state, HERMON_EQHDL, 1, HERMON_SLEEP, &rsrc); 760 if (status != DDI_SUCCESS) { 761 status = DDI_FAILURE; 762 goto eqalloc_fail2; 763 } 764 765 eq = (hermon_eqhdl_t)rsrc->hr_addr; 766 767 /* 768 * Allocate the memory for Event Queue. 769 */ 770 eq->eq_eqinfo.qa_size = (1 << log_eq_size) * sizeof (hermon_hw_eqe_t); 771 eq->eq_eqinfo.qa_alloc_align = eq->eq_eqinfo.qa_bind_align = PAGESIZE; 772 773 eq->eq_eqinfo.qa_location = HERMON_QUEUE_LOCATION_NORMAL; 774 status = hermon_queue_alloc(state, &eq->eq_eqinfo, HERMON_SLEEP); 775 if (status != DDI_SUCCESS) { 776 status = DDI_FAILURE; 777 goto eqalloc_fail3; 778 } 779 780 buf = (hermon_hw_eqe_t *)eq->eq_eqinfo.qa_buf_aligned; 781 /* 782 * Initializing each of the Event Queue Entries (EQE) by setting their 783 * ownership to hardware ("owner" bit set to HW) is now done by HW 784 * when the transfer of ownership (below) of the 785 * EQ context itself is done. 786 */ 787 788 /* 789 * Register the memory for the EQ. 790 * 791 * Because we are in the attach path we use NOSLEEP here so that we 792 * SPIN in the HCR since the event queues are not setup yet, and we 793 * cannot NOSPIN at this point in time. 794 */ 795 796 mr_attr.mr_vaddr = (uint64_t)(uintptr_t)buf; 797 mr_attr.mr_len = eq->eq_eqinfo.qa_size; 798 mr_attr.mr_as = NULL; 799 mr_attr.mr_flags = IBT_MR_NOSLEEP | IBT_MR_ENABLE_LOCAL_WRITE; 800 op.mro_bind_type = state->hs_cfg_profile->cp_iommu_bypass; 801 op.mro_bind_dmahdl = eq->eq_eqinfo.qa_dmahdl; 802 op.mro_bind_override_addr = 0; 803 status = hermon_mr_register(state, pd, &mr_attr, &mr, &op, 804 HERMON_EQ_CMPT); 805 if (status != DDI_SUCCESS) { 806 status = DDI_FAILURE; 807 goto eqalloc_fail4; 808 } 809 810 /* 811 * Fill in the EQC entry. This is the final step before passing 812 * ownership of the EQC entry to the Hermon hardware. We use all of 813 * the information collected/calculated above to fill in the 814 * requisite portions of the EQC. Note: We create all EQs in the 815 * "fired" state. We will arm them later (after our interrupt 816 * routine had been registered.) 817 */ 818 bzero(&eqc_entry, sizeof (hermon_hw_eqc_t)); 819 eqc_entry.state = HERMON_EQ_ARMED; 820 eqc_entry.log_eq_sz = log_eq_size; 821 eqc_entry.intr = intr; 822 eqc_entry.log2_pgsz = mr->mr_log2_pgsz; 823 eqc_entry.pg_offs = eq->eq_eqinfo.qa_pgoffs >> 5; 824 eqc_entry.mtt_base_addrh = (uint32_t)((mr->mr_mttaddr >> 32) & 0xFF); 825 eqc_entry.mtt_base_addrl = mr->mr_mttaddr >> 3; 826 eqc_entry.cons_indx = 0x0; 827 eqc_entry.prod_indx = 0x0; 828 829 /* 830 * Write the EQC entry to hardware. Lastly, we pass ownership of 831 * the entry to the hardware (using the Hermon SW2HW_EQ firmware 832 * command). Note: in general, this operation shouldn't fail. But 833 * if it does, we have to undo everything we've done above before 834 * returning error. 835 */ 836 status = hermon_cmn_ownership_cmd_post(state, SW2HW_EQ, &eqc_entry, 837 sizeof (hermon_hw_eqc_t), eqc->hr_indx, HERMON_CMD_NOSLEEP_SPIN); 838 if (status != HERMON_CMD_SUCCESS) { 839 cmn_err(CE_NOTE, "hermon%d: SW2HW_EQ command failed: %08x\n", 840 state->hs_instance, status); 841 if (status == HERMON_CMD_INVALID_STATUS) { 842 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_SRV_LOST); 843 } 844 status = ibc_get_ci_failure(0); 845 goto eqalloc_fail5; 846 } 847 848 /* 849 * Fill in the rest of the Hermon Event Queue handle. Having 850 * successfully transferred ownership of the EQC, we can update the 851 * following fields for use in further operations on the EQ. 852 */ 853 eq->eq_eqcrsrcp = eqc; 854 eq->eq_rsrcp = rsrc; 855 eq->eq_consindx = 0; 856 eq->eq_eqnum = eqc->hr_indx; 857 eq->eq_buf = buf; 858 eq->eq_bufsz = (1 << log_eq_size); 859 eq->eq_log_eqsz = log_eq_size; 860 eq->eq_mrhdl = mr; 861 eq->eq_doorbell = (uint32_t *)((uintptr_t)state->hs_reg_uar_baseaddr + 862 (uint32_t)ARM_EQ_INDEX(eq->eq_eqnum)); 863 *eqhdl = eq; 864 865 return (DDI_SUCCESS); 866 867 /* 868 * The following is cleanup for all possible failure cases in this routine 869 */ 870 eqalloc_fail5: 871 if (hermon_mr_deregister(state, &mr, HERMON_MR_DEREG_ALL, 872 HERMON_NOSLEEP) != DDI_SUCCESS) { 873 HERMON_WARNING(state, "failed to deregister EQ memory"); 874 } 875 eqalloc_fail4: 876 hermon_queue_free(&eq->eq_eqinfo); 877 eqalloc_fail3: 878 hermon_rsrc_free(state, &rsrc); 879 eqalloc_fail2: 880 hermon_rsrc_free(state, &eqc); 881 eqalloc_fail1: 882 hermon_pd_refcnt_dec(pd); 883 eqalloc_fail: 884 return (status); 885 } 886 887 888 /* 889 * hermon_eq_free() 890 * Context: Only called from attach() and/or detach() path contexts 891 */ 892 static int 893 hermon_eq_free(hermon_state_t *state, hermon_eqhdl_t *eqhdl) 894 { 895 hermon_rsrc_t *eqc, *rsrc; 896 hermon_hw_eqc_t eqc_entry; 897 hermon_pdhdl_t pd; 898 hermon_mrhdl_t mr; 899 hermon_eqhdl_t eq; 900 uint32_t eqnum; 901 int status; 902 903 /* 904 * Pull all the necessary information from the Hermon Event Queue 905 * handle. This is necessary here because the resource for the 906 * EQ handle is going to be freed up as part of this operation. 907 */ 908 eq = *eqhdl; 909 eqc = eq->eq_eqcrsrcp; 910 rsrc = eq->eq_rsrcp; 911 pd = state->hs_pdhdl_internal; 912 mr = eq->eq_mrhdl; 913 eqnum = eq->eq_eqnum; 914 915 /* 916 * Reclaim EQC entry from hardware (using the Hermon HW2SW_EQ 917 * firmware command). If the ownership transfer fails for any reason, 918 * then it is an indication that something (either in HW or SW) has 919 * gone seriously wrong. 920 */ 921 status = hermon_cmn_ownership_cmd_post(state, HW2SW_EQ, &eqc_entry, 922 sizeof (hermon_hw_eqc_t), eqnum, HERMON_CMD_NOSLEEP_SPIN); 923 if (status != HERMON_CMD_SUCCESS) { 924 HERMON_WARNING(state, "failed to reclaim EQC ownership"); 925 cmn_err(CE_CONT, "Hermon: HW2SW_EQ command failed: %08x\n", 926 status); 927 return (DDI_FAILURE); 928 } 929 930 /* 931 * Deregister the memory for the Event Queue. If this fails 932 * for any reason, then it is an indication that something (either 933 * in HW or SW) has gone seriously wrong. So we print a warning 934 * message and continue. 935 */ 936 status = hermon_mr_deregister(state, &mr, HERMON_MR_DEREG_ALL, 937 HERMON_NOSLEEP); 938 if (status != DDI_SUCCESS) { 939 HERMON_WARNING(state, "failed to deregister EQ memory"); 940 } 941 942 /* Free the memory for the EQ */ 943 hermon_queue_free(&eq->eq_eqinfo); 944 945 /* Free the Hermon Event Queue handle */ 946 hermon_rsrc_free(state, &rsrc); 947 948 /* Free up the EQC entry resource */ 949 hermon_rsrc_free(state, &eqc); 950 951 /* Decrement the reference count on the protection domain (PD) */ 952 hermon_pd_refcnt_dec(pd); 953 954 /* Set the eqhdl pointer to NULL and return success */ 955 *eqhdl = NULL; 956 957 return (DDI_SUCCESS); 958 } 959 960 961 /* 962 * hermon_eq_handler_init 963 * Context: Only called from attach() path context 964 */ 965 static int 966 hermon_eq_handler_init(hermon_state_t *state, hermon_eqhdl_t eq, 967 uint_t evt_type_mask, int (*eq_func)(hermon_state_t *state, 968 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe)) 969 { 970 int status; 971 972 /* 973 * Save away the EQ handler function and the event type mask. These 974 * will be used later during interrupt and event queue processing. 975 */ 976 eq->eq_func = eq_func; 977 eq->eq_evttypemask = evt_type_mask; 978 979 /* 980 * Map the EQ to a specific class of event (or events) depending 981 * on the mask value passed in. The HERMON_EVT_NO_MASK means not 982 * to attempt associating the EQ with any specific class of event. 983 * This is particularly useful when initializing the events queues 984 * used for CQ events. The mapping is done using the Hermon MAP_EQ 985 * firmware command. Note: This command should not, in general, fail. 986 * If it does, then something (probably HW related) has gone seriously 987 * wrong. 988 */ 989 if (evt_type_mask != HERMON_EVT_NO_MASK) { 990 status = hermon_map_eq_cmd_post(state, 991 HERMON_CMD_MAP_EQ_EVT_MAP, eq->eq_eqnum, evt_type_mask, 992 HERMON_CMD_NOSLEEP_SPIN); 993 if (status != HERMON_CMD_SUCCESS) { 994 cmn_err(CE_NOTE, "hermon%d: MAP_EQ command failed: " 995 "%08x\n", state->hs_instance, status); 996 return (DDI_FAILURE); 997 } 998 } 999 1000 return (DDI_SUCCESS); 1001 } 1002 1003 1004 /* 1005 * hermon_eq_handler_fini 1006 * Context: Only called from attach() and/or detach() path contexts 1007 */ 1008 static int 1009 hermon_eq_handler_fini(hermon_state_t *state, hermon_eqhdl_t eq) 1010 { 1011 int status; 1012 1013 /* 1014 * Unmap the EQ from the event class to which it had been previously 1015 * mapped. The unmapping is done using the Hermon MAP_EQ (in much 1016 * the same way that the initial mapping was done). The difference, 1017 * however, is in the HERMON_EQ_EVT_UNMAP flag that is passed to the 1018 * MAP_EQ firmware command. The HERMON_EVT_NO_MASK (which may have 1019 * been passed in at init time) still means that no association has 1020 * been made between the EQ and any specific class of event (and, 1021 * hence, no unmapping is necessary). Note: This command should not, 1022 * in general, fail. If it does, then something (probably HW related) 1023 * has gone seriously wrong. 1024 */ 1025 if (eq->eq_evttypemask != HERMON_EVT_NO_MASK) { 1026 status = hermon_map_eq_cmd_post(state, 1027 HERMON_CMD_MAP_EQ_EVT_UNMAP, eq->eq_eqnum, 1028 eq->eq_evttypemask, HERMON_CMD_NOSLEEP_SPIN); 1029 if (status != HERMON_CMD_SUCCESS) { 1030 cmn_err(CE_NOTE, "hermon%d: MAP_EQ command failed: " 1031 "%08x\n", state->hs_instance, status); 1032 return (DDI_FAILURE); 1033 } 1034 } 1035 1036 return (DDI_SUCCESS); 1037 } 1038 1039 1040 /* 1041 * hermon_eq_demux() 1042 * Context: Called only from interrupt context 1043 * Usage: to demux the various type reported on one EQ 1044 */ 1045 static int 1046 hermon_eq_demux(hermon_state_t *state, hermon_eqhdl_t eq, 1047 hermon_hw_eqe_t *eqe) 1048 { 1049 uint_t eqe_evttype; 1050 int status = DDI_FAILURE; 1051 1052 eqe_evttype = HERMON_EQE_EVTTYPE_GET(eq, eqe); 1053 1054 switch (eqe_evttype) { 1055 1056 case HERMON_EVT_PORT_STATE_CHANGE: 1057 status = hermon_port_state_change_handler(state, eq, eqe); 1058 break; 1059 1060 case HERMON_EVT_COMM_ESTABLISHED: 1061 status = hermon_comm_estbl_handler(state, eq, eqe); 1062 break; 1063 1064 case HERMON_EVT_COMMAND_INTF_COMP: 1065 status = hermon_cmd_complete_handler(state, eq, eqe); 1066 break; 1067 1068 case HERMON_EVT_LOCAL_WQ_CAT_ERROR: 1069 HERMON_WARNING(state, HERMON_FMA_LOCCAT); 1070 status = hermon_local_wq_cat_err_handler(state, eq, eqe); 1071 break; 1072 1073 case HERMON_EVT_INV_REQ_LOCAL_WQ_ERROR: 1074 HERMON_WARNING(state, HERMON_FMA_LOCINV); 1075 status = hermon_invreq_local_wq_err_handler(state, eq, eqe); 1076 break; 1077 1078 case HERMON_EVT_LOCAL_ACC_VIO_WQ_ERROR: 1079 HERMON_WARNING(state, HERMON_FMA_LOCACEQ); 1080 IBTF_DPRINTF_L2("async", HERMON_FMA_LOCACEQ); 1081 status = hermon_local_acc_vio_wq_err_handler(state, eq, eqe); 1082 break; 1083 case HERMON_EVT_SEND_QUEUE_DRAINED: 1084 status = hermon_sendq_drained_handler(state, eq, eqe); 1085 break; 1086 1087 case HERMON_EVT_PATH_MIGRATED: 1088 status = hermon_path_mig_handler(state, eq, eqe); 1089 break; 1090 1091 case HERMON_EVT_PATH_MIGRATE_FAILED: 1092 HERMON_WARNING(state, HERMON_FMA_PATHMIG); 1093 status = hermon_path_mig_err_handler(state, eq, eqe); 1094 break; 1095 1096 case HERMON_EVT_SRQ_CATASTROPHIC_ERROR: 1097 HERMON_WARNING(state, HERMON_FMA_SRQCAT); 1098 status = hermon_catastrophic_handler(state, eq, eqe); 1099 break; 1100 1101 case HERMON_EVT_SRQ_LAST_WQE_REACHED: 1102 status = hermon_srq_last_wqe_reached_handler(state, eq, eqe); 1103 break; 1104 1105 case HERMON_EVT_FEXCH_ERROR: 1106 status = hermon_fexch_error_handler(state, eq, eqe); 1107 break; 1108 1109 default: 1110 break; 1111 } 1112 return (status); 1113 } 1114 1115 /* 1116 * hermon_port_state_change_handler() 1117 * Context: Only called from interrupt context 1118 */ 1119 /* ARGSUSED */ 1120 static int 1121 hermon_port_state_change_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1122 hermon_hw_eqe_t *eqe) 1123 { 1124 ibc_async_event_t event; 1125 ibt_async_code_t type; 1126 uint_t subtype; 1127 uint8_t port; 1128 char link_msg[24]; 1129 1130 /* 1131 * Depending on the type of Port State Change event, pass the 1132 * appropriate asynch event to the IBTF. 1133 */ 1134 port = (uint8_t)HERMON_EQE_PORTNUM_GET(eq, eqe); 1135 1136 /* Check for valid port number in event */ 1137 if ((port == 0) || (port > state->hs_cfg_profile->cp_num_ports)) { 1138 HERMON_WARNING(state, "Unexpected port number in port state " 1139 "change event"); 1140 cmn_err(CE_CONT, " Port number: %02x\n", port); 1141 return (DDI_FAILURE); 1142 } 1143 1144 subtype = HERMON_EQE_EVTSUBTYPE_GET(eq, eqe); 1145 if (subtype == HERMON_PORT_LINK_ACTIVE) { 1146 event.ev_port = port; 1147 type = IBT_EVENT_PORT_UP; 1148 1149 (void) snprintf(link_msg, 23, "port %d up", port); 1150 ddi_dev_report_fault(state->hs_dip, DDI_SERVICE_RESTORED, 1151 DDI_EXTERNAL_FAULT, link_msg); 1152 } else if (subtype == HERMON_PORT_LINK_DOWN) { 1153 event.ev_port = port; 1154 type = IBT_ERROR_PORT_DOWN; 1155 1156 (void) snprintf(link_msg, 23, "port %d down", port); 1157 ddi_dev_report_fault(state->hs_dip, DDI_SERVICE_LOST, 1158 DDI_EXTERNAL_FAULT, link_msg); 1159 } else { 1160 HERMON_WARNING(state, "Unexpected subtype in port state change " 1161 "event"); 1162 cmn_err(CE_CONT, " Event type: %02x, subtype: %02x\n", 1163 HERMON_EQE_EVTTYPE_GET(eq, eqe), subtype); 1164 return (DDI_FAILURE); 1165 } 1166 1167 /* 1168 * Deliver the event to the IBTF. Note: If "hs_ibtfpriv" is NULL, 1169 * then we have either received this event before we finished 1170 * attaching to the IBTF or we've received it while we are in the 1171 * process of detaching. 1172 */ 1173 if (state->hs_ibtfpriv != NULL) { 1174 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1175 } 1176 1177 return (DDI_SUCCESS); 1178 } 1179 1180 1181 /* 1182 * hermon_comm_estbl_handler() 1183 * Context: Only called from interrupt context 1184 */ 1185 /* ARGSUSED */ 1186 static int 1187 hermon_comm_estbl_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1188 hermon_hw_eqe_t *eqe) 1189 { 1190 hermon_qphdl_t qp; 1191 uint_t qpnum; 1192 ibc_async_event_t event; 1193 ibt_async_code_t type; 1194 1195 /* Get the QP handle from QP number in event descriptor */ 1196 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe); 1197 qp = hermon_qphdl_from_qpnum(state, qpnum); 1198 1199 /* 1200 * If the QP handle is NULL, this is probably an indication 1201 * that the QP has been freed already. In which case, we 1202 * should not deliver this event. 1203 * 1204 * We also check that the QP number in the handle is the 1205 * same as the QP number in the event queue entry. This 1206 * extra check allows us to handle the case where a QP was 1207 * freed and then allocated again in the time it took to 1208 * handle the event queue processing. By constantly incrementing 1209 * the non-constrained portion of the QP number every time 1210 * a new QP is allocated, we mitigate (somewhat) the chance 1211 * that a stale event could be passed to the client's QP 1212 * handler. 1213 * 1214 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it 1215 * means that we've have either received this event before we 1216 * finished attaching to the IBTF or we've received it while we 1217 * are in the process of detaching. 1218 */ 1219 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1220 (state->hs_ibtfpriv != NULL)) { 1221 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg; 1222 type = IBT_EVENT_COM_EST_QP; 1223 1224 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1225 } 1226 1227 return (DDI_SUCCESS); 1228 } 1229 1230 1231 /* 1232 * hermon_local_wq_cat_err_handler() 1233 * Context: Only called from interrupt context 1234 */ 1235 /* ARGSUSED */ 1236 static int 1237 hermon_local_wq_cat_err_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1238 hermon_hw_eqe_t *eqe) 1239 { 1240 hermon_qphdl_t qp; 1241 uint_t qpnum; 1242 ibc_async_event_t event; 1243 ibt_async_code_t type; 1244 1245 /* Get the QP handle from QP number in event descriptor */ 1246 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe); 1247 qp = hermon_qphdl_from_qpnum(state, qpnum); 1248 1249 /* 1250 * If the QP handle is NULL, this is probably an indication 1251 * that the QP has been freed already. In which case, we 1252 * should not deliver this event. 1253 * 1254 * We also check that the QP number in the handle is the 1255 * same as the QP number in the event queue entry. This 1256 * extra check allows us to handle the case where a QP was 1257 * freed and then allocated again in the time it took to 1258 * handle the event queue processing. By constantly incrementing 1259 * the non-constrained portion of the QP number every time 1260 * a new QP is allocated, we mitigate (somewhat) the chance 1261 * that a stale event could be passed to the client's QP 1262 * handler. 1263 * 1264 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it 1265 * means that we've have either received this event before we 1266 * finished attaching to the IBTF or we've received it while we 1267 * are in the process of detaching. 1268 */ 1269 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1270 (state->hs_ibtfpriv != NULL)) { 1271 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg; 1272 type = IBT_ERROR_CATASTROPHIC_QP; 1273 1274 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1275 } 1276 1277 return (DDI_SUCCESS); 1278 } 1279 1280 1281 /* 1282 * hermon_invreq_local_wq_err_handler() 1283 * Context: Only called from interrupt context 1284 */ 1285 /* ARGSUSED */ 1286 static int 1287 hermon_invreq_local_wq_err_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1288 hermon_hw_eqe_t *eqe) 1289 { 1290 hermon_qphdl_t qp; 1291 uint_t qpnum; 1292 ibc_async_event_t event; 1293 ibt_async_code_t type; 1294 1295 /* Get the QP handle from QP number in event descriptor */ 1296 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe); 1297 qp = hermon_qphdl_from_qpnum(state, qpnum); 1298 1299 /* 1300 * If the QP handle is NULL, this is probably an indication 1301 * that the QP has been freed already. In which case, we 1302 * should not deliver this event. 1303 * 1304 * We also check that the QP number in the handle is the 1305 * same as the QP number in the event queue entry. This 1306 * extra check allows us to handle the case where a QP was 1307 * freed and then allocated again in the time it took to 1308 * handle the event queue processing. By constantly incrementing 1309 * the non-constrained portion of the QP number every time 1310 * a new QP is allocated, we mitigate (somewhat) the chance 1311 * that a stale event could be passed to the client's QP 1312 * handler. 1313 * 1314 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it 1315 * means that we've have either received this event before we 1316 * finished attaching to the IBTF or we've received it while we 1317 * are in the process of detaching. 1318 */ 1319 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1320 (state->hs_ibtfpriv != NULL)) { 1321 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg; 1322 type = IBT_ERROR_INVALID_REQUEST_QP; 1323 1324 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1325 } 1326 1327 return (DDI_SUCCESS); 1328 } 1329 1330 1331 /* 1332 * hermon_local_acc_vio_wq_err_handler() 1333 * Context: Only called from interrupt context 1334 */ 1335 /* ARGSUSED */ 1336 static int 1337 hermon_local_acc_vio_wq_err_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1338 hermon_hw_eqe_t *eqe) 1339 { 1340 hermon_qphdl_t qp; 1341 uint_t qpnum; 1342 ibc_async_event_t event; 1343 ibt_async_code_t type; 1344 1345 /* Get the QP handle from QP number in event descriptor */ 1346 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe); 1347 qp = hermon_qphdl_from_qpnum(state, qpnum); 1348 1349 /* 1350 * If the QP handle is NULL, this is probably an indication 1351 * that the QP has been freed already. In which case, we 1352 * should not deliver this event. 1353 * 1354 * We also check that the QP number in the handle is the 1355 * same as the QP number in the event queue entry. This 1356 * extra check allows us to handle the case where a QP was 1357 * freed and then allocated again in the time it took to 1358 * handle the event queue processing. By constantly incrementing 1359 * the non-constrained portion of the QP number every time 1360 * a new QP is allocated, we mitigate (somewhat) the chance 1361 * that a stale event could be passed to the client's QP 1362 * handler. 1363 * 1364 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it 1365 * means that we've have either received this event before we 1366 * finished attaching to the IBTF or we've received it while we 1367 * are in the process of detaching. 1368 */ 1369 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1370 (state->hs_ibtfpriv != NULL)) { 1371 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg; 1372 type = IBT_ERROR_ACCESS_VIOLATION_QP; 1373 1374 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1375 } 1376 1377 return (DDI_SUCCESS); 1378 } 1379 1380 1381 /* 1382 * hermon_sendq_drained_handler() 1383 * Context: Only called from interrupt context 1384 */ 1385 /* ARGSUSED */ 1386 static int 1387 hermon_sendq_drained_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1388 hermon_hw_eqe_t *eqe) 1389 { 1390 hermon_qphdl_t qp; 1391 uint_t qpnum; 1392 ibc_async_event_t event; 1393 uint_t forward_sqd_event; 1394 ibt_async_code_t type; 1395 1396 /* Get the QP handle from QP number in event descriptor */ 1397 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe); 1398 qp = hermon_qphdl_from_qpnum(state, qpnum); 1399 1400 /* 1401 * If the QP handle is NULL, this is probably an indication 1402 * that the QP has been freed already. In which case, we 1403 * should not deliver this event. 1404 * 1405 * We also check that the QP number in the handle is the 1406 * same as the QP number in the event queue entry. This 1407 * extra check allows us to handle the case where a QP was 1408 * freed and then allocated again in the time it took to 1409 * handle the event queue processing. By constantly incrementing 1410 * the non-constrained portion of the QP number every time 1411 * a new QP is allocated, we mitigate (somewhat) the chance 1412 * that a stale event could be passed to the client's QP 1413 * handler. 1414 * 1415 * And then we check if "hs_ibtfpriv" is NULL. If it is then it 1416 * means that we've have either received this event before we 1417 * finished attaching to the IBTF or we've received it while we 1418 * are in the process of detaching. 1419 */ 1420 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1421 (state->hs_ibtfpriv != NULL)) { 1422 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg; 1423 type = IBT_EVENT_SQD; 1424 1425 /* 1426 * Grab the QP lock and update the QP state to reflect that 1427 * the Send Queue Drained event has arrived. Also determine 1428 * whether the event is intended to be forwarded on to the 1429 * consumer or not. This information is used below in 1430 * determining whether or not to call the IBTF. 1431 */ 1432 mutex_enter(&qp->qp_lock); 1433 forward_sqd_event = qp->qp_forward_sqd_event; 1434 qp->qp_forward_sqd_event = 0; 1435 qp->qp_sqd_still_draining = 0; 1436 mutex_exit(&qp->qp_lock); 1437 1438 if (forward_sqd_event != 0) { 1439 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1440 } 1441 } 1442 1443 return (DDI_SUCCESS); 1444 } 1445 1446 1447 /* 1448 * hermon_path_mig_handler() 1449 * Context: Only called from interrupt context 1450 */ 1451 /* ARGSUSED */ 1452 static int 1453 hermon_path_mig_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1454 hermon_hw_eqe_t *eqe) 1455 { 1456 hermon_qphdl_t qp; 1457 uint_t qpnum; 1458 ibc_async_event_t event; 1459 ibt_async_code_t type; 1460 1461 /* Get the QP handle from QP number in event descriptor */ 1462 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe); 1463 qp = hermon_qphdl_from_qpnum(state, qpnum); 1464 1465 /* 1466 * If the QP handle is NULL, this is probably an indication 1467 * that the QP has been freed already. In which case, we 1468 * should not deliver this event. 1469 * 1470 * We also check that the QP number in the handle is the 1471 * same as the QP number in the event queue entry. This 1472 * extra check allows us to handle the case where a QP was 1473 * freed and then allocated again in the time it took to 1474 * handle the event queue processing. By constantly incrementing 1475 * the non-constrained portion of the QP number every time 1476 * a new QP is allocated, we mitigate (somewhat) the chance 1477 * that a stale event could be passed to the client's QP 1478 * handler. 1479 * 1480 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it 1481 * means that we've have either received this event before we 1482 * finished attaching to the IBTF or we've received it while we 1483 * are in the process of detaching. 1484 */ 1485 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1486 (state->hs_ibtfpriv != NULL)) { 1487 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg; 1488 type = IBT_EVENT_PATH_MIGRATED_QP; 1489 1490 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1491 } 1492 1493 return (DDI_SUCCESS); 1494 } 1495 1496 1497 /* 1498 * hermon_path_mig_err_handler() 1499 * Context: Only called from interrupt context 1500 */ 1501 /* ARGSUSED */ 1502 static int 1503 hermon_path_mig_err_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1504 hermon_hw_eqe_t *eqe) 1505 { 1506 hermon_qphdl_t qp; 1507 uint_t qpnum; 1508 ibc_async_event_t event; 1509 ibt_async_code_t type; 1510 1511 /* Get the QP handle from QP number in event descriptor */ 1512 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe); 1513 qp = hermon_qphdl_from_qpnum(state, qpnum); 1514 1515 /* 1516 * If the QP handle is NULL, this is probably an indication 1517 * that the QP has been freed already. In which case, we 1518 * should not deliver this event. 1519 * 1520 * We also check that the QP number in the handle is the 1521 * same as the QP number in the event queue entry. This 1522 * extra check allows us to handle the case where a QP was 1523 * freed and then allocated again in the time it took to 1524 * handle the event queue processing. By constantly incrementing 1525 * the non-constrained portion of the QP number every time 1526 * a new QP is allocated, we mitigate (somewhat) the chance 1527 * that a stale event could be passed to the client's QP 1528 * handler. 1529 * 1530 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it 1531 * means that we've have either received this event before we 1532 * finished attaching to the IBTF or we've received it while we 1533 * are in the process of detaching. 1534 */ 1535 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1536 (state->hs_ibtfpriv != NULL)) { 1537 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg; 1538 type = IBT_ERROR_PATH_MIGRATE_REQ_QP; 1539 1540 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1541 } 1542 1543 return (DDI_SUCCESS); 1544 } 1545 1546 1547 /* 1548 * hermon_catastrophic_handler() 1549 * Context: Only called from interrupt context 1550 */ 1551 /* ARGSUSED */ 1552 static int 1553 hermon_catastrophic_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1554 hermon_hw_eqe_t *eqe) 1555 { 1556 hermon_qphdl_t qp; 1557 uint_t qpnum; 1558 ibc_async_event_t event; 1559 ibt_async_code_t type; 1560 1561 if (eq->eq_evttypemask == HERMON_EVT_MSK_LOCAL_CAT_ERROR) { 1562 HERMON_FMANOTE(state, HERMON_FMA_INTERNAL); 1563 hermon_eq_catastrophic(state); 1564 return (DDI_SUCCESS); 1565 } 1566 1567 /* Get the QP handle from QP number in event descriptor */ 1568 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe); 1569 qp = hermon_qphdl_from_qpnum(state, qpnum); 1570 1571 /* 1572 * If the QP handle is NULL, this is probably an indication 1573 * that the QP has been freed already. In which case, we 1574 * should not deliver this event. 1575 * 1576 * We also check that the QP number in the handle is the 1577 * same as the QP number in the event queue entry. This 1578 * extra check allows us to handle the case where a QP was 1579 * freed and then allocated again in the time it took to 1580 * handle the event queue processing. By constantly incrementing 1581 * the non-constrained portion of the QP number every time 1582 * a new QP is allocated, we mitigate (somewhat) the chance 1583 * that a stale event could be passed to the client's QP 1584 * handler. 1585 * 1586 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it 1587 * means that we've have either received this event before we 1588 * finished attaching to the IBTF or we've received it while we 1589 * are in the process of detaching. 1590 */ 1591 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1592 (state->hs_ibtfpriv != NULL)) { 1593 event.ev_srq_hdl = (ibt_srq_hdl_t)qp->qp_srqhdl->srq_hdlrarg; 1594 type = IBT_ERROR_CATASTROPHIC_SRQ; 1595 1596 mutex_enter(&qp->qp_srqhdl->srq_lock); 1597 qp->qp_srqhdl->srq_state = HERMON_SRQ_STATE_ERROR; 1598 mutex_exit(&qp->qp_srqhdl->srq_lock); 1599 1600 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1601 } 1602 1603 return (DDI_SUCCESS); 1604 } 1605 1606 1607 /* 1608 * hermon_srq_last_wqe_reached_handler() 1609 * Context: Only called from interrupt context 1610 */ 1611 /* ARGSUSED */ 1612 static int 1613 hermon_srq_last_wqe_reached_handler(hermon_state_t *state, hermon_eqhdl_t eq, 1614 hermon_hw_eqe_t *eqe) 1615 { 1616 hermon_qphdl_t qp; 1617 uint_t qpnum; 1618 ibc_async_event_t event; 1619 ibt_async_code_t type; 1620 1621 /* Get the QP handle from QP number in event descriptor */ 1622 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe); 1623 qp = hermon_qphdl_from_qpnum(state, qpnum); 1624 1625 /* 1626 * If the QP handle is NULL, this is probably an indication 1627 * that the QP has been freed already. In which case, we 1628 * should not deliver this event. 1629 * 1630 * We also check that the QP number in the handle is the 1631 * same as the QP number in the event queue entry. This 1632 * extra check allows us to handle the case where a QP was 1633 * freed and then allocated again in the time it took to 1634 * handle the event queue processing. By constantly incrementing 1635 * the non-constrained portion of the QP number every time 1636 * a new QP is allocated, we mitigate (somewhat) the chance 1637 * that a stale event could be passed to the client's QP 1638 * handler. 1639 * 1640 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it 1641 * means that we've have either received this event before we 1642 * finished attaching to the IBTF or we've received it while we 1643 * are in the process of detaching. 1644 */ 1645 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1646 (state->hs_ibtfpriv != NULL)) { 1647 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg; 1648 type = IBT_EVENT_EMPTY_CHAN; 1649 1650 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1651 } 1652 1653 return (DDI_SUCCESS); 1654 } 1655 1656 1657 /* ARGSUSED */ 1658 static int hermon_fexch_error_handler(hermon_state_t *state, 1659 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe) 1660 { 1661 hermon_qphdl_t qp; 1662 uint_t qpnum; 1663 ibc_async_event_t event; 1664 ibt_async_code_t type; 1665 1666 /* Get the QP handle from QP number in event descriptor */ 1667 event.ev_port = HERMON_EQE_FEXCH_PORTNUM_GET(eq, eqe); 1668 qpnum = hermon_fcoib_qpnum_from_fexch(state, 1669 event.ev_port, HERMON_EQE_FEXCH_FEXCH_GET(eq, eqe)); 1670 qp = hermon_qphdl_from_qpnum(state, qpnum); 1671 1672 event.ev_fc = HERMON_EQE_FEXCH_SYNDROME_GET(eq, eqe); 1673 1674 /* 1675 * If the QP handle is NULL, this is probably an indication 1676 * that the QP has been freed already. In which case, we 1677 * should not deliver this event. 1678 * 1679 * We also check that the QP number in the handle is the 1680 * same as the QP number in the event queue entry. This 1681 * extra check allows us to handle the case where a QP was 1682 * freed and then allocated again in the time it took to 1683 * handle the event queue processing. By constantly incrementing 1684 * the non-constrained portion of the QP number every time 1685 * a new QP is allocated, we mitigate (somewhat) the chance 1686 * that a stale event could be passed to the client's QP 1687 * handler. 1688 * 1689 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it 1690 * means that we've have either received this event before we 1691 * finished attaching to the IBTF or we've received it while we 1692 * are in the process of detaching. 1693 */ 1694 if ((qp != NULL) && (qp->qp_qpnum == qpnum) && 1695 (state->hs_ibtfpriv != NULL)) { 1696 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg; 1697 type = IBT_FEXCH_ERROR; 1698 1699 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event); 1700 } 1701 1702 return (DDI_SUCCESS); 1703 } 1704 1705 1706 /* 1707 * hermon_no_eqhandler 1708 * Context: Only called from interrupt context 1709 */ 1710 /* ARGSUSED */ 1711 static int 1712 hermon_no_eqhandler(hermon_state_t *state, hermon_eqhdl_t eq, 1713 hermon_hw_eqe_t *eqe) 1714 { 1715 uint_t data; 1716 int i; 1717 1718 /* 1719 * This "unexpected event" handler (or "catch-all" handler) will 1720 * receive all events for which no other handler has been registered. 1721 * If we end up here, then something has probably gone seriously wrong 1722 * with the Hermon hardware (or, perhaps, with the software... though 1723 * it's unlikely in this case). The EQE provides all the information 1724 * about the event. So we print a warning message here along with 1725 * the contents of the EQE. 1726 */ 1727 HERMON_WARNING(state, "Unexpected Event handler"); 1728 cmn_err(CE_CONT, " Event type: %02x, subtype: %02x\n", 1729 HERMON_EQE_EVTTYPE_GET(eq, eqe), 1730 HERMON_EQE_EVTSUBTYPE_GET(eq, eqe)); 1731 for (i = 0; i < sizeof (hermon_hw_eqe_t) >> 2; i++) { 1732 data = ((uint_t *)eqe)[i]; 1733 cmn_err(CE_CONT, " EQE[%02x]: %08x\n", i, data); 1734 } 1735 1736 return (DDI_SUCCESS); 1737 }