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
hermon_eq_init_all(hermon_state_t * state)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
hermon_eq_fini_all(hermon_state_t * state)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
hermon_eq_reset_uar_baseaddr(hermon_state_t * state)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
hermon_eq_arm_all(hermon_state_t * state)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
hermon_isr(caddr_t arg1,caddr_t arg2)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
hermon_eq_poll(hermon_state_t * state,hermon_eqhdl_t eq)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 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*eq))
522
523 /* Get the consumer pointer index */
524 cons_indx = eq->eq_consindx;
525 shift = eq->eq_log_eqsz - HERMON_EQE_OWNER_SHIFT;
526
527 /*
528 * Calculate the wrap around mask. Note: This operation only works
529 * because all Hermon event queues have power-of-2 sizes
530 */
531 wrap_around_mask = (eq->eq_bufsz - 1);
532
533 /* Calculate the pointer to the first EQ entry */
534 eqe = &eq->eq_buf[(cons_indx & wrap_around_mask)];
535
536
537 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*eqe))
538
539 /*
540 * Pull the handler function for this EQ from the Hermon Event Queue
541 * handle
542 */
543 eqfunction = eq->eq_func;
544
545 for (;;) {
546 polled_some = 0;
547 while (HERMON_EQE_OWNER_IS_SW(eq, eqe, cons_indx, shift)) {
548
549 /*
550 * Call the EQ handler function. But only call if we
551 * are not in polled I/O mode (i.e. not processing
552 * because of a system panic). Note: We don't call
553 * the EQ handling functions from a system panic
554 * because we are primarily concerned only with
555 * ensuring that the event queues do not overflow (or,
556 * more specifically, the event queue associated with
557 * the CQ that is being used in the sync/dump process).
558 * Also, we don't want to make any upcalls (to the
559 * IBTF) because we can't guarantee when/if those
560 * calls would ever return. And, if we're in panic,
561 * then we reached here through a PollCQ() call (from
562 * hermon_cq_poll()), and we need to ensure that we
563 * successfully return any work completions to the
564 * caller.
565 */
566 if (ddi_in_panic() == 0) {
567 eqfunction(state, eq, eqe);
568 }
569
570 /* Reset to hardware ownership is implicit */
571
572 /* Increment the consumer index */
573 cons_indx++;
574
575 /* Update the pointer to the next EQ entry */
576 eqe = &eq->eq_buf[(cons_indx & wrap_around_mask)];
577
578 polled_some = 1;
579 }
580
581 /*
582 * write consumer index via EQ set CI Doorbell, to keep overflow
583 * from occuring during poll
584 */
585
586 eq->eq_consindx = cons_indx;
587
588 /* the FMA retry loop starts. */
589 hermon_pio_start(state, uarhdl, pio_error, fm_loop_cnt,
590 fm_status, fm_test);
591
592 ddi_put32(uarhdl, eq->eq_doorbell,
593 (cons_indx & HERMON_EQ_CI_MASK) | EQ_ARM_BIT);
594
595 /* the FMA retry loop starts. */
596 hermon_pio_end(state, uarhdl, pio_error, fm_loop_cnt,
597 fm_status, fm_test);
598
599 if (polled_some == 0)
600 break;
601 };
602 return;
603
604 pio_error:
605 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_FATAL);
606 }
607
608
609 /*
610 * hermon_eq_catastrophic
611 * Context: Only called from interrupt context (and during panic)
612 */
613 static void
hermon_eq_catastrophic(hermon_state_t * state)614 hermon_eq_catastrophic(hermon_state_t *state)
615 {
616 ddi_acc_handle_t cmdhdl = hermon_get_cmdhdl(state);
617 ibt_async_code_t type;
618 ibc_async_event_t event;
619 uint32_t *base_addr;
620 uint32_t buf_size;
621 uint32_t word;
622 uint8_t err_type;
623 uint32_t err_buf;
624 int i;
625
626 /* initialize the FMA retry loop */
627 hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
628
629 bzero(&event, sizeof (ibc_async_event_t));
630 base_addr = state->hs_cmd_regs.fw_err_buf;
631
632 buf_size = state->hs_fw.error_buf_sz; /* in #dwords */
633
634 /* the FMA retry loop starts. */
635 hermon_pio_start(state, cmdhdl, pio_error, fm_loop_cnt, fm_status,
636 fm_test);
637
638 word = ddi_get32(cmdhdl, base_addr);
639
640 /* the FMA retry loop ends. */
641 hermon_pio_end(state, cmdhdl, pio_error, fm_loop_cnt, fm_status,
642 fm_test);
643
644 err_type = (word & 0xFF000000) >> 24;
645 type = IBT_ERROR_LOCAL_CATASTROPHIC;
646
647 switch (err_type) {
648 case HERMON_CATASTROPHIC_INTERNAL_ERROR:
649 cmn_err(CE_WARN, "Catastrophic Internal Error: 0x%02x",
650 err_type);
651
652 break;
653
654 case HERMON_CATASTROPHIC_UPLINK_BUS_ERROR:
655 cmn_err(CE_WARN, "Catastrophic Uplink Bus Error: 0x%02x",
656 err_type);
657
658 break;
659
660 case HERMON_CATASTROPHIC_DDR_DATA_ERROR:
661 cmn_err(CE_WARN, "Catastrophic DDR Data Error: 0x%02x",
662 err_type);
663
664 break;
665
666 case HERMON_CATASTROPHIC_INTERNAL_PARITY_ERROR:
667 cmn_err(CE_WARN, "Catastrophic Internal Parity Error: 0x%02x",
668 err_type);
669
670 break;
671
672 default:
673 /* Unknown type of Catastrophic error */
674 cmn_err(CE_WARN, "Catastrophic Unknown Error: 0x%02x",
675 err_type);
676
677 break;
678 }
679
680 /* the FMA retry loop starts. */
681 hermon_pio_start(state, cmdhdl, pio_error, fm_loop_cnt, fm_status,
682 fm_test);
683
684 /*
685 * Read in the catastrophic error buffer from the hardware.
686 */
687 for (i = 0; i < buf_size; i++) {
688 base_addr =
689 (state->hs_cmd_regs.fw_err_buf + i);
690 err_buf = ddi_get32(cmdhdl, base_addr);
691 cmn_err(CE_NOTE, "hermon%d: catastrophic_error[%02x]: %08X",
692 state->hs_instance, i, err_buf);
693 }
694
695 /* the FMA retry loop ends. */
696 hermon_pio_end(state, cmdhdl, pio_error, fm_loop_cnt, fm_status,
697 fm_test);
698
699 /*
700 * We also call the IBTF here to inform it of the catastrophic error.
701 * Note: Since no event information (i.e. QP handles, CQ handles,
702 * etc.) is necessary, we pass a NULL pointer instead of a pointer to
703 * an empty ibc_async_event_t struct.
704 *
705 * But we also check if "hs_ibtfpriv" is NULL. If it is then it
706 * means that we've have either received this event before we
707 * finished attaching to the IBTF or we've received it while we
708 * are in the process of detaching.
709 */
710 if (state->hs_ibtfpriv != NULL) {
711 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
712 }
713
714 pio_error:
715 /* ignore these errors but log them because they're harmless. */
716 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_NON_FATAL);
717 }
718
719
720 /*
721 * hermon_eq_alloc()
722 * Context: Only called from attach() path context
723 */
724 static int
hermon_eq_alloc(hermon_state_t * state,uint32_t log_eq_size,uint_t intr,hermon_eqhdl_t * eqhdl)725 hermon_eq_alloc(hermon_state_t *state, uint32_t log_eq_size, uint_t intr,
726 hermon_eqhdl_t *eqhdl)
727 {
728 hermon_rsrc_t *eqc, *rsrc;
729 hermon_hw_eqc_t eqc_entry;
730 hermon_eqhdl_t eq;
731 ibt_mr_attr_t mr_attr;
732 hermon_mr_options_t op;
733 hermon_pdhdl_t pd;
734 hermon_mrhdl_t mr;
735 hermon_hw_eqe_t *buf;
736 int status;
737
738 /* Use the internal protection domain (PD) for setting up EQs */
739 pd = state->hs_pdhdl_internal;
740
741 /* Increment the reference count on the protection domain (PD) */
742 hermon_pd_refcnt_inc(pd);
743
744 /*
745 * Allocate an EQ context entry. This will be filled in with all
746 * the necessary parameters to define the Event Queue. And then
747 * ownership will be passed to the hardware in the final step
748 * below. If we fail here, we must undo the protection domain
749 * reference count.
750 */
751 status = hermon_rsrc_alloc(state, HERMON_EQC, 1, HERMON_SLEEP, &eqc);
752 if (status != DDI_SUCCESS) {
753 status = DDI_FAILURE;
754 goto eqalloc_fail1;
755 }
756
757 /*
758 * Allocate the software structure for tracking the event queue (i.e.
759 * the Hermon Event Queue handle). If we fail here, we must undo the
760 * protection domain reference count and the previous resource
761 * allocation.
762 */
763 status = hermon_rsrc_alloc(state, HERMON_EQHDL, 1, HERMON_SLEEP, &rsrc);
764 if (status != DDI_SUCCESS) {
765 status = DDI_FAILURE;
766 goto eqalloc_fail2;
767 }
768
769 eq = (hermon_eqhdl_t)rsrc->hr_addr;
770
771 /*
772 * Allocate the memory for Event Queue.
773 */
774 eq->eq_eqinfo.qa_size = (1 << log_eq_size) * sizeof (hermon_hw_eqe_t);
775 eq->eq_eqinfo.qa_alloc_align = eq->eq_eqinfo.qa_bind_align = PAGESIZE;
776
777 eq->eq_eqinfo.qa_location = HERMON_QUEUE_LOCATION_NORMAL;
778 status = hermon_queue_alloc(state, &eq->eq_eqinfo, HERMON_SLEEP);
779 if (status != DDI_SUCCESS) {
780 status = DDI_FAILURE;
781 goto eqalloc_fail3;
782 }
783
784 buf = (hermon_hw_eqe_t *)eq->eq_eqinfo.qa_buf_aligned;
785 /*
786 * Initializing each of the Event Queue Entries (EQE) by setting their
787 * ownership to hardware ("owner" bit set to HW) is now done by HW
788 * when the transfer of ownership (below) of the
789 * EQ context itself is done.
790 */
791
792 /*
793 * Register the memory for the EQ.
794 *
795 * Because we are in the attach path we use NOSLEEP here so that we
796 * SPIN in the HCR since the event queues are not setup yet, and we
797 * cannot NOSPIN at this point in time.
798 */
799
800 mr_attr.mr_vaddr = (uint64_t)(uintptr_t)buf;
801 mr_attr.mr_len = eq->eq_eqinfo.qa_size;
802 mr_attr.mr_as = NULL;
803 mr_attr.mr_flags = IBT_MR_NOSLEEP | IBT_MR_ENABLE_LOCAL_WRITE;
804 op.mro_bind_type = state->hs_cfg_profile->cp_iommu_bypass;
805 op.mro_bind_dmahdl = eq->eq_eqinfo.qa_dmahdl;
806 op.mro_bind_override_addr = 0;
807 status = hermon_mr_register(state, pd, &mr_attr, &mr, &op,
808 HERMON_EQ_CMPT);
809 if (status != DDI_SUCCESS) {
810 status = DDI_FAILURE;
811 goto eqalloc_fail4;
812 }
813 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mr))
814
815 /*
816 * Fill in the EQC entry. This is the final step before passing
817 * ownership of the EQC entry to the Hermon hardware. We use all of
818 * the information collected/calculated above to fill in the
819 * requisite portions of the EQC. Note: We create all EQs in the
820 * "fired" state. We will arm them later (after our interrupt
821 * routine had been registered.)
822 */
823 bzero(&eqc_entry, sizeof (hermon_hw_eqc_t));
824 eqc_entry.state = HERMON_EQ_ARMED;
825 eqc_entry.log_eq_sz = log_eq_size;
826 eqc_entry.intr = intr;
827 eqc_entry.log2_pgsz = mr->mr_log2_pgsz;
828 eqc_entry.pg_offs = eq->eq_eqinfo.qa_pgoffs >> 5;
829 eqc_entry.mtt_base_addrh = (uint32_t)((mr->mr_mttaddr >> 32) & 0xFF);
830 eqc_entry.mtt_base_addrl = mr->mr_mttaddr >> 3;
831 eqc_entry.cons_indx = 0x0;
832 eqc_entry.prod_indx = 0x0;
833
834 /*
835 * Write the EQC entry to hardware. Lastly, we pass ownership of
836 * the entry to the hardware (using the Hermon SW2HW_EQ firmware
837 * command). Note: in general, this operation shouldn't fail. But
838 * if it does, we have to undo everything we've done above before
839 * returning error.
840 */
841 status = hermon_cmn_ownership_cmd_post(state, SW2HW_EQ, &eqc_entry,
842 sizeof (hermon_hw_eqc_t), eqc->hr_indx, HERMON_CMD_NOSLEEP_SPIN);
843 if (status != HERMON_CMD_SUCCESS) {
844 cmn_err(CE_NOTE, "hermon%d: SW2HW_EQ command failed: %08x\n",
845 state->hs_instance, status);
846 if (status == HERMON_CMD_INVALID_STATUS) {
847 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_SRV_LOST);
848 }
849 status = ibc_get_ci_failure(0);
850 goto eqalloc_fail5;
851 }
852
853 /*
854 * Fill in the rest of the Hermon Event Queue handle. Having
855 * successfully transferred ownership of the EQC, we can update the
856 * following fields for use in further operations on the EQ.
857 */
858 eq->eq_eqcrsrcp = eqc;
859 eq->eq_rsrcp = rsrc;
860 eq->eq_consindx = 0;
861 eq->eq_eqnum = eqc->hr_indx;
862 eq->eq_buf = buf;
863 eq->eq_bufsz = (1 << log_eq_size);
864 eq->eq_log_eqsz = log_eq_size;
865 eq->eq_mrhdl = mr;
866 eq->eq_doorbell = (uint32_t *)((uintptr_t)state->hs_reg_uar_baseaddr +
867 (uint32_t)ARM_EQ_INDEX(eq->eq_eqnum));
868 *eqhdl = eq;
869
870 return (DDI_SUCCESS);
871
872 /*
873 * The following is cleanup for all possible failure cases in this routine
874 */
875 eqalloc_fail5:
876 if (hermon_mr_deregister(state, &mr, HERMON_MR_DEREG_ALL,
877 HERMON_NOSLEEP) != DDI_SUCCESS) {
878 HERMON_WARNING(state, "failed to deregister EQ memory");
879 }
880 eqalloc_fail4:
881 hermon_queue_free(&eq->eq_eqinfo);
882 eqalloc_fail3:
883 hermon_rsrc_free(state, &rsrc);
884 eqalloc_fail2:
885 hermon_rsrc_free(state, &eqc);
886 eqalloc_fail1:
887 hermon_pd_refcnt_dec(pd);
888 return (status);
889 }
890
891
892 /*
893 * hermon_eq_free()
894 * Context: Only called from attach() and/or detach() path contexts
895 */
896 static int
hermon_eq_free(hermon_state_t * state,hermon_eqhdl_t * eqhdl)897 hermon_eq_free(hermon_state_t *state, hermon_eqhdl_t *eqhdl)
898 {
899 hermon_rsrc_t *eqc, *rsrc;
900 hermon_hw_eqc_t eqc_entry;
901 hermon_pdhdl_t pd;
902 hermon_mrhdl_t mr;
903 hermon_eqhdl_t eq;
904 uint32_t eqnum;
905 int status;
906
907 /*
908 * Pull all the necessary information from the Hermon Event Queue
909 * handle. This is necessary here because the resource for the
910 * EQ handle is going to be freed up as part of this operation.
911 */
912 eq = *eqhdl;
913 eqc = eq->eq_eqcrsrcp;
914 rsrc = eq->eq_rsrcp;
915 pd = state->hs_pdhdl_internal;
916 mr = eq->eq_mrhdl;
917 eqnum = eq->eq_eqnum;
918
919 /*
920 * Reclaim EQC entry from hardware (using the Hermon HW2SW_EQ
921 * firmware command). If the ownership transfer fails for any reason,
922 * then it is an indication that something (either in HW or SW) has
923 * gone seriously wrong.
924 */
925 status = hermon_cmn_ownership_cmd_post(state, HW2SW_EQ, &eqc_entry,
926 sizeof (hermon_hw_eqc_t), eqnum, HERMON_CMD_NOSLEEP_SPIN);
927 if (status != HERMON_CMD_SUCCESS) {
928 HERMON_WARNING(state, "failed to reclaim EQC ownership");
929 cmn_err(CE_CONT, "Hermon: HW2SW_EQ command failed: %08x\n",
930 status);
931 return (DDI_FAILURE);
932 }
933
934 /*
935 * Deregister the memory for the Event Queue. If this fails
936 * for any reason, then it is an indication that something (either
937 * in HW or SW) has gone seriously wrong. So we print a warning
938 * message and continue.
939 */
940 status = hermon_mr_deregister(state, &mr, HERMON_MR_DEREG_ALL,
941 HERMON_NOSLEEP);
942 if (status != DDI_SUCCESS) {
943 HERMON_WARNING(state, "failed to deregister EQ memory");
944 }
945
946 /* Free the memory for the EQ */
947 hermon_queue_free(&eq->eq_eqinfo);
948
949 /* Free the Hermon Event Queue handle */
950 hermon_rsrc_free(state, &rsrc);
951
952 /* Free up the EQC entry resource */
953 hermon_rsrc_free(state, &eqc);
954
955 /* Decrement the reference count on the protection domain (PD) */
956 hermon_pd_refcnt_dec(pd);
957
958 /* Set the eqhdl pointer to NULL and return success */
959 *eqhdl = NULL;
960
961 return (DDI_SUCCESS);
962 }
963
964
965 /*
966 * hermon_eq_handler_init
967 * Context: Only called from attach() path context
968 */
969 static int
hermon_eq_handler_init(hermon_state_t * state,hermon_eqhdl_t eq,uint_t evt_type_mask,int (* eq_func)(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe))970 hermon_eq_handler_init(hermon_state_t *state, hermon_eqhdl_t eq,
971 uint_t evt_type_mask, int (*eq_func)(hermon_state_t *state,
972 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe))
973 {
974 int status;
975
976 /*
977 * Save away the EQ handler function and the event type mask. These
978 * will be used later during interrupt and event queue processing.
979 */
980 eq->eq_func = eq_func;
981 eq->eq_evttypemask = evt_type_mask;
982
983 /*
984 * Map the EQ to a specific class of event (or events) depending
985 * on the mask value passed in. The HERMON_EVT_NO_MASK means not
986 * to attempt associating the EQ with any specific class of event.
987 * This is particularly useful when initializing the events queues
988 * used for CQ events. The mapping is done using the Hermon MAP_EQ
989 * firmware command. Note: This command should not, in general, fail.
990 * If it does, then something (probably HW related) has gone seriously
991 * wrong.
992 */
993 if (evt_type_mask != HERMON_EVT_NO_MASK) {
994 status = hermon_map_eq_cmd_post(state,
995 HERMON_CMD_MAP_EQ_EVT_MAP, eq->eq_eqnum, evt_type_mask,
996 HERMON_CMD_NOSLEEP_SPIN);
997 if (status != HERMON_CMD_SUCCESS) {
998 cmn_err(CE_NOTE, "hermon%d: MAP_EQ command failed: "
999 "%08x\n", state->hs_instance, status);
1000 return (DDI_FAILURE);
1001 }
1002 }
1003
1004 return (DDI_SUCCESS);
1005 }
1006
1007
1008 /*
1009 * hermon_eq_handler_fini
1010 * Context: Only called from attach() and/or detach() path contexts
1011 */
1012 static int
hermon_eq_handler_fini(hermon_state_t * state,hermon_eqhdl_t eq)1013 hermon_eq_handler_fini(hermon_state_t *state, hermon_eqhdl_t eq)
1014 {
1015 int status;
1016
1017 /*
1018 * Unmap the EQ from the event class to which it had been previously
1019 * mapped. The unmapping is done using the Hermon MAP_EQ (in much
1020 * the same way that the initial mapping was done). The difference,
1021 * however, is in the HERMON_EQ_EVT_UNMAP flag that is passed to the
1022 * MAP_EQ firmware command. The HERMON_EVT_NO_MASK (which may have
1023 * been passed in at init time) still means that no association has
1024 * been made between the EQ and any specific class of event (and,
1025 * hence, no unmapping is necessary). Note: This command should not,
1026 * in general, fail. If it does, then something (probably HW related)
1027 * has gone seriously wrong.
1028 */
1029 if (eq->eq_evttypemask != HERMON_EVT_NO_MASK) {
1030 status = hermon_map_eq_cmd_post(state,
1031 HERMON_CMD_MAP_EQ_EVT_UNMAP, eq->eq_eqnum,
1032 eq->eq_evttypemask, HERMON_CMD_NOSLEEP_SPIN);
1033 if (status != HERMON_CMD_SUCCESS) {
1034 cmn_err(CE_NOTE, "hermon%d: MAP_EQ command failed: "
1035 "%08x\n", state->hs_instance, status);
1036 return (DDI_FAILURE);
1037 }
1038 }
1039
1040 return (DDI_SUCCESS);
1041 }
1042
1043
1044 /*
1045 * hermon_eq_demux()
1046 * Context: Called only from interrupt context
1047 * Usage: to demux the various type reported on one EQ
1048 */
1049 static int
hermon_eq_demux(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1050 hermon_eq_demux(hermon_state_t *state, hermon_eqhdl_t eq,
1051 hermon_hw_eqe_t *eqe)
1052 {
1053 uint_t eqe_evttype;
1054 int status = DDI_FAILURE;
1055
1056 eqe_evttype = HERMON_EQE_EVTTYPE_GET(eq, eqe);
1057
1058 switch (eqe_evttype) {
1059
1060 case HERMON_EVT_PORT_STATE_CHANGE:
1061 status = hermon_port_state_change_handler(state, eq, eqe);
1062 break;
1063
1064 case HERMON_EVT_COMM_ESTABLISHED:
1065 status = hermon_comm_estbl_handler(state, eq, eqe);
1066 break;
1067
1068 case HERMON_EVT_COMMAND_INTF_COMP:
1069 status = hermon_cmd_complete_handler(state, eq, eqe);
1070 break;
1071
1072 case HERMON_EVT_LOCAL_WQ_CAT_ERROR:
1073 HERMON_WARNING(state, HERMON_FMA_LOCCAT);
1074 status = hermon_local_wq_cat_err_handler(state, eq, eqe);
1075 break;
1076
1077 case HERMON_EVT_INV_REQ_LOCAL_WQ_ERROR:
1078 HERMON_WARNING(state, HERMON_FMA_LOCINV);
1079 status = hermon_invreq_local_wq_err_handler(state, eq, eqe);
1080 break;
1081
1082 case HERMON_EVT_LOCAL_ACC_VIO_WQ_ERROR:
1083 HERMON_WARNING(state, HERMON_FMA_LOCACEQ);
1084 IBTF_DPRINTF_L2("async", HERMON_FMA_LOCACEQ);
1085 status = hermon_local_acc_vio_wq_err_handler(state, eq, eqe);
1086 break;
1087 case HERMON_EVT_SEND_QUEUE_DRAINED:
1088 status = hermon_sendq_drained_handler(state, eq, eqe);
1089 break;
1090
1091 case HERMON_EVT_PATH_MIGRATED:
1092 status = hermon_path_mig_handler(state, eq, eqe);
1093 break;
1094
1095 case HERMON_EVT_PATH_MIGRATE_FAILED:
1096 HERMON_WARNING(state, HERMON_FMA_PATHMIG);
1097 status = hermon_path_mig_err_handler(state, eq, eqe);
1098 break;
1099
1100 case HERMON_EVT_SRQ_CATASTROPHIC_ERROR:
1101 HERMON_WARNING(state, HERMON_FMA_SRQCAT);
1102 status = hermon_catastrophic_handler(state, eq, eqe);
1103 break;
1104
1105 case HERMON_EVT_SRQ_LAST_WQE_REACHED:
1106 status = hermon_srq_last_wqe_reached_handler(state, eq, eqe);
1107 break;
1108
1109 case HERMON_EVT_FEXCH_ERROR:
1110 status = hermon_fexch_error_handler(state, eq, eqe);
1111 break;
1112
1113 default:
1114 break;
1115 }
1116 return (status);
1117 }
1118
1119 /*
1120 * hermon_port_state_change_handler()
1121 * Context: Only called from interrupt context
1122 */
1123 /* ARGSUSED */
1124 static int
hermon_port_state_change_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1125 hermon_port_state_change_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1126 hermon_hw_eqe_t *eqe)
1127 {
1128 ibc_async_event_t event;
1129 ibt_async_code_t type;
1130 uint_t subtype;
1131 uint8_t port;
1132 char link_msg[24];
1133
1134 /*
1135 * Depending on the type of Port State Change event, pass the
1136 * appropriate asynch event to the IBTF.
1137 */
1138 port = (uint8_t)HERMON_EQE_PORTNUM_GET(eq, eqe);
1139
1140 /* Check for valid port number in event */
1141 if ((port == 0) || (port > state->hs_cfg_profile->cp_num_ports)) {
1142 HERMON_WARNING(state, "Unexpected port number in port state "
1143 "change event");
1144 cmn_err(CE_CONT, " Port number: %02x\n", port);
1145 return (DDI_FAILURE);
1146 }
1147
1148 subtype = HERMON_EQE_EVTSUBTYPE_GET(eq, eqe);
1149 if (subtype == HERMON_PORT_LINK_ACTIVE) {
1150 event.ev_port = port;
1151 type = IBT_EVENT_PORT_UP;
1152
1153 (void) snprintf(link_msg, 23, "port %d up", port);
1154 ddi_dev_report_fault(state->hs_dip, DDI_SERVICE_RESTORED,
1155 DDI_EXTERNAL_FAULT, link_msg);
1156 } else if (subtype == HERMON_PORT_LINK_DOWN) {
1157 event.ev_port = port;
1158 type = IBT_ERROR_PORT_DOWN;
1159
1160 (void) snprintf(link_msg, 23, "port %d down", port);
1161 ddi_dev_report_fault(state->hs_dip, DDI_SERVICE_LOST,
1162 DDI_EXTERNAL_FAULT, link_msg);
1163 } else {
1164 HERMON_WARNING(state, "Unexpected subtype in port state change "
1165 "event");
1166 cmn_err(CE_CONT, " Event type: %02x, subtype: %02x\n",
1167 HERMON_EQE_EVTTYPE_GET(eq, eqe), subtype);
1168 return (DDI_FAILURE);
1169 }
1170
1171 /*
1172 * Deliver the event to the IBTF. Note: If "hs_ibtfpriv" is NULL,
1173 * then we have either received this event before we finished
1174 * attaching to the IBTF or we've received it while we are in the
1175 * process of detaching.
1176 */
1177 if (state->hs_ibtfpriv != NULL) {
1178 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1179 }
1180
1181 return (DDI_SUCCESS);
1182 }
1183
1184
1185 /*
1186 * hermon_comm_estbl_handler()
1187 * Context: Only called from interrupt context
1188 */
1189 /* ARGSUSED */
1190 static int
hermon_comm_estbl_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1191 hermon_comm_estbl_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1192 hermon_hw_eqe_t *eqe)
1193 {
1194 hermon_qphdl_t qp;
1195 uint_t qpnum;
1196 ibc_async_event_t event;
1197 ibt_async_code_t type;
1198
1199 /* Get the QP handle from QP number in event descriptor */
1200 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1201 qp = hermon_qphdl_from_qpnum(state, qpnum);
1202
1203 /*
1204 * If the QP handle is NULL, this is probably an indication
1205 * that the QP has been freed already. In which case, we
1206 * should not deliver this event.
1207 *
1208 * We also check that the QP number in the handle is the
1209 * same as the QP number in the event queue entry. This
1210 * extra check allows us to handle the case where a QP was
1211 * freed and then allocated again in the time it took to
1212 * handle the event queue processing. By constantly incrementing
1213 * the non-constrained portion of the QP number every time
1214 * a new QP is allocated, we mitigate (somewhat) the chance
1215 * that a stale event could be passed to the client's QP
1216 * handler.
1217 *
1218 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1219 * means that we've have either received this event before we
1220 * finished attaching to the IBTF or we've received it while we
1221 * are in the process of detaching.
1222 */
1223 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1224 (state->hs_ibtfpriv != NULL)) {
1225 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1226 type = IBT_EVENT_COM_EST_QP;
1227
1228 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1229 }
1230
1231 return (DDI_SUCCESS);
1232 }
1233
1234
1235 /*
1236 * hermon_local_wq_cat_err_handler()
1237 * Context: Only called from interrupt context
1238 */
1239 /* ARGSUSED */
1240 static int
hermon_local_wq_cat_err_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1241 hermon_local_wq_cat_err_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1242 hermon_hw_eqe_t *eqe)
1243 {
1244 hermon_qphdl_t qp;
1245 uint_t qpnum;
1246 ibc_async_event_t event;
1247 ibt_async_code_t type;
1248
1249 /* Get the QP handle from QP number in event descriptor */
1250 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1251 qp = hermon_qphdl_from_qpnum(state, qpnum);
1252
1253 /*
1254 * If the QP handle is NULL, this is probably an indication
1255 * that the QP has been freed already. In which case, we
1256 * should not deliver this event.
1257 *
1258 * We also check that the QP number in the handle is the
1259 * same as the QP number in the event queue entry. This
1260 * extra check allows us to handle the case where a QP was
1261 * freed and then allocated again in the time it took to
1262 * handle the event queue processing. By constantly incrementing
1263 * the non-constrained portion of the QP number every time
1264 * a new QP is allocated, we mitigate (somewhat) the chance
1265 * that a stale event could be passed to the client's QP
1266 * handler.
1267 *
1268 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1269 * means that we've have either received this event before we
1270 * finished attaching to the IBTF or we've received it while we
1271 * are in the process of detaching.
1272 */
1273 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1274 (state->hs_ibtfpriv != NULL)) {
1275 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1276 type = IBT_ERROR_CATASTROPHIC_QP;
1277
1278 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1279 }
1280
1281 return (DDI_SUCCESS);
1282 }
1283
1284
1285 /*
1286 * hermon_invreq_local_wq_err_handler()
1287 * Context: Only called from interrupt context
1288 */
1289 /* ARGSUSED */
1290 static int
hermon_invreq_local_wq_err_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1291 hermon_invreq_local_wq_err_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1292 hermon_hw_eqe_t *eqe)
1293 {
1294 hermon_qphdl_t qp;
1295 uint_t qpnum;
1296 ibc_async_event_t event;
1297 ibt_async_code_t type;
1298
1299 /* Get the QP handle from QP number in event descriptor */
1300 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1301 qp = hermon_qphdl_from_qpnum(state, qpnum);
1302
1303 /*
1304 * If the QP handle is NULL, this is probably an indication
1305 * that the QP has been freed already. In which case, we
1306 * should not deliver this event.
1307 *
1308 * We also check that the QP number in the handle is the
1309 * same as the QP number in the event queue entry. This
1310 * extra check allows us to handle the case where a QP was
1311 * freed and then allocated again in the time it took to
1312 * handle the event queue processing. By constantly incrementing
1313 * the non-constrained portion of the QP number every time
1314 * a new QP is allocated, we mitigate (somewhat) the chance
1315 * that a stale event could be passed to the client's QP
1316 * handler.
1317 *
1318 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1319 * means that we've have either received this event before we
1320 * finished attaching to the IBTF or we've received it while we
1321 * are in the process of detaching.
1322 */
1323 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1324 (state->hs_ibtfpriv != NULL)) {
1325 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1326 type = IBT_ERROR_INVALID_REQUEST_QP;
1327
1328 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1329 }
1330
1331 return (DDI_SUCCESS);
1332 }
1333
1334
1335 /*
1336 * hermon_local_acc_vio_wq_err_handler()
1337 * Context: Only called from interrupt context
1338 */
1339 /* ARGSUSED */
1340 static int
hermon_local_acc_vio_wq_err_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1341 hermon_local_acc_vio_wq_err_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1342 hermon_hw_eqe_t *eqe)
1343 {
1344 hermon_qphdl_t qp;
1345 uint_t qpnum;
1346 ibc_async_event_t event;
1347 ibt_async_code_t type;
1348
1349 /* Get the QP handle from QP number in event descriptor */
1350 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1351 qp = hermon_qphdl_from_qpnum(state, qpnum);
1352
1353 /*
1354 * If the QP handle is NULL, this is probably an indication
1355 * that the QP has been freed already. In which case, we
1356 * should not deliver this event.
1357 *
1358 * We also check that the QP number in the handle is the
1359 * same as the QP number in the event queue entry. This
1360 * extra check allows us to handle the case where a QP was
1361 * freed and then allocated again in the time it took to
1362 * handle the event queue processing. By constantly incrementing
1363 * the non-constrained portion of the QP number every time
1364 * a new QP is allocated, we mitigate (somewhat) the chance
1365 * that a stale event could be passed to the client's QP
1366 * handler.
1367 *
1368 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1369 * means that we've have either received this event before we
1370 * finished attaching to the IBTF or we've received it while we
1371 * are in the process of detaching.
1372 */
1373 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1374 (state->hs_ibtfpriv != NULL)) {
1375 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1376 type = IBT_ERROR_ACCESS_VIOLATION_QP;
1377
1378 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1379 }
1380
1381 return (DDI_SUCCESS);
1382 }
1383
1384
1385 /*
1386 * hermon_sendq_drained_handler()
1387 * Context: Only called from interrupt context
1388 */
1389 /* ARGSUSED */
1390 static int
hermon_sendq_drained_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1391 hermon_sendq_drained_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1392 hermon_hw_eqe_t *eqe)
1393 {
1394 hermon_qphdl_t qp;
1395 uint_t qpnum;
1396 ibc_async_event_t event;
1397 uint_t forward_sqd_event;
1398 ibt_async_code_t type;
1399
1400 /* Get the QP handle from QP number in event descriptor */
1401 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1402 qp = hermon_qphdl_from_qpnum(state, qpnum);
1403
1404 /*
1405 * If the QP handle is NULL, this is probably an indication
1406 * that the QP has been freed already. In which case, we
1407 * should not deliver this event.
1408 *
1409 * We also check that the QP number in the handle is the
1410 * same as the QP number in the event queue entry. This
1411 * extra check allows us to handle the case where a QP was
1412 * freed and then allocated again in the time it took to
1413 * handle the event queue processing. By constantly incrementing
1414 * the non-constrained portion of the QP number every time
1415 * a new QP is allocated, we mitigate (somewhat) the chance
1416 * that a stale event could be passed to the client's QP
1417 * handler.
1418 *
1419 * And then we check if "hs_ibtfpriv" is NULL. If it is then it
1420 * means that we've have either received this event before we
1421 * finished attaching to the IBTF or we've received it while we
1422 * are in the process of detaching.
1423 */
1424 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1425 (state->hs_ibtfpriv != NULL)) {
1426 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1427 type = IBT_EVENT_SQD;
1428
1429 /*
1430 * Grab the QP lock and update the QP state to reflect that
1431 * the Send Queue Drained event has arrived. Also determine
1432 * whether the event is intended to be forwarded on to the
1433 * consumer or not. This information is used below in
1434 * determining whether or not to call the IBTF.
1435 */
1436 mutex_enter(&qp->qp_lock);
1437 forward_sqd_event = qp->qp_forward_sqd_event;
1438 qp->qp_forward_sqd_event = 0;
1439 qp->qp_sqd_still_draining = 0;
1440 mutex_exit(&qp->qp_lock);
1441
1442 if (forward_sqd_event != 0) {
1443 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1444 }
1445 }
1446
1447 return (DDI_SUCCESS);
1448 }
1449
1450
1451 /*
1452 * hermon_path_mig_handler()
1453 * Context: Only called from interrupt context
1454 */
1455 /* ARGSUSED */
1456 static int
hermon_path_mig_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1457 hermon_path_mig_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1458 hermon_hw_eqe_t *eqe)
1459 {
1460 hermon_qphdl_t qp;
1461 uint_t qpnum;
1462 ibc_async_event_t event;
1463 ibt_async_code_t type;
1464
1465 /* Get the QP handle from QP number in event descriptor */
1466 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1467 qp = hermon_qphdl_from_qpnum(state, qpnum);
1468
1469 /*
1470 * If the QP handle is NULL, this is probably an indication
1471 * that the QP has been freed already. In which case, we
1472 * should not deliver this event.
1473 *
1474 * We also check that the QP number in the handle is the
1475 * same as the QP number in the event queue entry. This
1476 * extra check allows us to handle the case where a QP was
1477 * freed and then allocated again in the time it took to
1478 * handle the event queue processing. By constantly incrementing
1479 * the non-constrained portion of the QP number every time
1480 * a new QP is allocated, we mitigate (somewhat) the chance
1481 * that a stale event could be passed to the client's QP
1482 * handler.
1483 *
1484 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1485 * means that we've have either received this event before we
1486 * finished attaching to the IBTF or we've received it while we
1487 * are in the process of detaching.
1488 */
1489 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1490 (state->hs_ibtfpriv != NULL)) {
1491 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1492 type = IBT_EVENT_PATH_MIGRATED_QP;
1493
1494 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1495 }
1496
1497 return (DDI_SUCCESS);
1498 }
1499
1500
1501 /*
1502 * hermon_path_mig_err_handler()
1503 * Context: Only called from interrupt context
1504 */
1505 /* ARGSUSED */
1506 static int
hermon_path_mig_err_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1507 hermon_path_mig_err_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1508 hermon_hw_eqe_t *eqe)
1509 {
1510 hermon_qphdl_t qp;
1511 uint_t qpnum;
1512 ibc_async_event_t event;
1513 ibt_async_code_t type;
1514
1515 /* Get the QP handle from QP number in event descriptor */
1516 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1517 qp = hermon_qphdl_from_qpnum(state, qpnum);
1518
1519 /*
1520 * If the QP handle is NULL, this is probably an indication
1521 * that the QP has been freed already. In which case, we
1522 * should not deliver this event.
1523 *
1524 * We also check that the QP number in the handle is the
1525 * same as the QP number in the event queue entry. This
1526 * extra check allows us to handle the case where a QP was
1527 * freed and then allocated again in the time it took to
1528 * handle the event queue processing. By constantly incrementing
1529 * the non-constrained portion of the QP number every time
1530 * a new QP is allocated, we mitigate (somewhat) the chance
1531 * that a stale event could be passed to the client's QP
1532 * handler.
1533 *
1534 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1535 * means that we've have either received this event before we
1536 * finished attaching to the IBTF or we've received it while we
1537 * are in the process of detaching.
1538 */
1539 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1540 (state->hs_ibtfpriv != NULL)) {
1541 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1542 type = IBT_ERROR_PATH_MIGRATE_REQ_QP;
1543
1544 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1545 }
1546
1547 return (DDI_SUCCESS);
1548 }
1549
1550
1551 /*
1552 * hermon_catastrophic_handler()
1553 * Context: Only called from interrupt context
1554 */
1555 /* ARGSUSED */
1556 static int
hermon_catastrophic_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1557 hermon_catastrophic_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1558 hermon_hw_eqe_t *eqe)
1559 {
1560 hermon_qphdl_t qp;
1561 uint_t qpnum;
1562 ibc_async_event_t event;
1563 ibt_async_code_t type;
1564
1565 if (eq->eq_evttypemask == HERMON_EVT_MSK_LOCAL_CAT_ERROR) {
1566 HERMON_FMANOTE(state, HERMON_FMA_INTERNAL);
1567 hermon_eq_catastrophic(state);
1568 return (DDI_SUCCESS);
1569 }
1570
1571 /* Get the QP handle from QP number in event descriptor */
1572 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1573 qp = hermon_qphdl_from_qpnum(state, qpnum);
1574
1575 /*
1576 * If the QP handle is NULL, this is probably an indication
1577 * that the QP has been freed already. In which case, we
1578 * should not deliver this event.
1579 *
1580 * We also check that the QP number in the handle is the
1581 * same as the QP number in the event queue entry. This
1582 * extra check allows us to handle the case where a QP was
1583 * freed and then allocated again in the time it took to
1584 * handle the event queue processing. By constantly incrementing
1585 * the non-constrained portion of the QP number every time
1586 * a new QP is allocated, we mitigate (somewhat) the chance
1587 * that a stale event could be passed to the client's QP
1588 * handler.
1589 *
1590 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1591 * means that we've have either received this event before we
1592 * finished attaching to the IBTF or we've received it while we
1593 * are in the process of detaching.
1594 */
1595 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1596 (state->hs_ibtfpriv != NULL)) {
1597 event.ev_srq_hdl = (ibt_srq_hdl_t)qp->qp_srqhdl->srq_hdlrarg;
1598 type = IBT_ERROR_CATASTROPHIC_SRQ;
1599
1600 mutex_enter(&qp->qp_srqhdl->srq_lock);
1601 qp->qp_srqhdl->srq_state = HERMON_SRQ_STATE_ERROR;
1602 mutex_exit(&qp->qp_srqhdl->srq_lock);
1603
1604 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1605 }
1606
1607 return (DDI_SUCCESS);
1608 }
1609
1610
1611 /*
1612 * hermon_srq_last_wqe_reached_handler()
1613 * Context: Only called from interrupt context
1614 */
1615 /* ARGSUSED */
1616 static int
hermon_srq_last_wqe_reached_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1617 hermon_srq_last_wqe_reached_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1618 hermon_hw_eqe_t *eqe)
1619 {
1620 hermon_qphdl_t qp;
1621 uint_t qpnum;
1622 ibc_async_event_t event;
1623 ibt_async_code_t type;
1624
1625 /* Get the QP handle from QP number in event descriptor */
1626 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1627 qp = hermon_qphdl_from_qpnum(state, qpnum);
1628
1629 /*
1630 * If the QP handle is NULL, this is probably an indication
1631 * that the QP has been freed already. In which case, we
1632 * should not deliver this event.
1633 *
1634 * We also check that the QP number in the handle is the
1635 * same as the QP number in the event queue entry. This
1636 * extra check allows us to handle the case where a QP was
1637 * freed and then allocated again in the time it took to
1638 * handle the event queue processing. By constantly incrementing
1639 * the non-constrained portion of the QP number every time
1640 * a new QP is allocated, we mitigate (somewhat) the chance
1641 * that a stale event could be passed to the client's QP
1642 * handler.
1643 *
1644 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1645 * means that we've have either received this event before we
1646 * finished attaching to the IBTF or we've received it while we
1647 * are in the process of detaching.
1648 */
1649 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1650 (state->hs_ibtfpriv != NULL)) {
1651 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1652 type = IBT_EVENT_EMPTY_CHAN;
1653
1654 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1655 }
1656
1657 return (DDI_SUCCESS);
1658 }
1659
1660
1661 /* ARGSUSED */
hermon_fexch_error_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1662 static int hermon_fexch_error_handler(hermon_state_t *state,
1663 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe)
1664 {
1665 hermon_qphdl_t qp;
1666 uint_t qpnum;
1667 ibc_async_event_t event;
1668 ibt_async_code_t type;
1669
1670 /* Get the QP handle from QP number in event descriptor */
1671 event.ev_port = HERMON_EQE_FEXCH_PORTNUM_GET(eq, eqe);
1672 qpnum = hermon_fcoib_qpnum_from_fexch(state,
1673 event.ev_port, HERMON_EQE_FEXCH_FEXCH_GET(eq, eqe));
1674 qp = hermon_qphdl_from_qpnum(state, qpnum);
1675
1676 event.ev_fc = HERMON_EQE_FEXCH_SYNDROME_GET(eq, eqe);
1677
1678 /*
1679 * If the QP handle is NULL, this is probably an indication
1680 * that the QP has been freed already. In which case, we
1681 * should not deliver this event.
1682 *
1683 * We also check that the QP number in the handle is the
1684 * same as the QP number in the event queue entry. This
1685 * extra check allows us to handle the case where a QP was
1686 * freed and then allocated again in the time it took to
1687 * handle the event queue processing. By constantly incrementing
1688 * the non-constrained portion of the QP number every time
1689 * a new QP is allocated, we mitigate (somewhat) the chance
1690 * that a stale event could be passed to the client's QP
1691 * handler.
1692 *
1693 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1694 * means that we've have either received this event before we
1695 * finished attaching to the IBTF or we've received it while we
1696 * are in the process of detaching.
1697 */
1698 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1699 (state->hs_ibtfpriv != NULL)) {
1700 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1701 type = IBT_FEXCH_ERROR;
1702
1703 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1704 }
1705
1706 return (DDI_SUCCESS);
1707 }
1708
1709
1710 /*
1711 * hermon_no_eqhandler
1712 * Context: Only called from interrupt context
1713 */
1714 /* ARGSUSED */
1715 static int
hermon_no_eqhandler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1716 hermon_no_eqhandler(hermon_state_t *state, hermon_eqhdl_t eq,
1717 hermon_hw_eqe_t *eqe)
1718 {
1719 uint_t data;
1720 int i;
1721
1722 /*
1723 * This "unexpected event" handler (or "catch-all" handler) will
1724 * receive all events for which no other handler has been registered.
1725 * If we end up here, then something has probably gone seriously wrong
1726 * with the Hermon hardware (or, perhaps, with the software... though
1727 * it's unlikely in this case). The EQE provides all the information
1728 * about the event. So we print a warning message here along with
1729 * the contents of the EQE.
1730 */
1731 HERMON_WARNING(state, "Unexpected Event handler");
1732 cmn_err(CE_CONT, " Event type: %02x, subtype: %02x\n",
1733 HERMON_EQE_EVTTYPE_GET(eq, eqe),
1734 HERMON_EQE_EVTSUBTYPE_GET(eq, eqe));
1735 for (i = 0; i < sizeof (hermon_hw_eqe_t) >> 2; i++) {
1736 data = ((uint_t *)eqe)[i];
1737 cmn_err(CE_CONT, " EQE[%02x]: %08x\n", i, data);
1738 }
1739
1740 return (DDI_SUCCESS);
1741 }
1742