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 eqalloc_fail:
889 return (status);
890 }
891
892
893 /*
894 * hermon_eq_free()
895 * Context: Only called from attach() and/or detach() path contexts
896 */
897 static int
hermon_eq_free(hermon_state_t * state,hermon_eqhdl_t * eqhdl)898 hermon_eq_free(hermon_state_t *state, hermon_eqhdl_t *eqhdl)
899 {
900 hermon_rsrc_t *eqc, *rsrc;
901 hermon_hw_eqc_t eqc_entry;
902 hermon_pdhdl_t pd;
903 hermon_mrhdl_t mr;
904 hermon_eqhdl_t eq;
905 uint32_t eqnum;
906 int status;
907
908 /*
909 * Pull all the necessary information from the Hermon Event Queue
910 * handle. This is necessary here because the resource for the
911 * EQ handle is going to be freed up as part of this operation.
912 */
913 eq = *eqhdl;
914 eqc = eq->eq_eqcrsrcp;
915 rsrc = eq->eq_rsrcp;
916 pd = state->hs_pdhdl_internal;
917 mr = eq->eq_mrhdl;
918 eqnum = eq->eq_eqnum;
919
920 /*
921 * Reclaim EQC entry from hardware (using the Hermon HW2SW_EQ
922 * firmware command). If the ownership transfer fails for any reason,
923 * then it is an indication that something (either in HW or SW) has
924 * gone seriously wrong.
925 */
926 status = hermon_cmn_ownership_cmd_post(state, HW2SW_EQ, &eqc_entry,
927 sizeof (hermon_hw_eqc_t), eqnum, HERMON_CMD_NOSLEEP_SPIN);
928 if (status != HERMON_CMD_SUCCESS) {
929 HERMON_WARNING(state, "failed to reclaim EQC ownership");
930 cmn_err(CE_CONT, "Hermon: HW2SW_EQ command failed: %08x\n",
931 status);
932 return (DDI_FAILURE);
933 }
934
935 /*
936 * Deregister the memory for the Event Queue. If this fails
937 * for any reason, then it is an indication that something (either
938 * in HW or SW) has gone seriously wrong. So we print a warning
939 * message and continue.
940 */
941 status = hermon_mr_deregister(state, &mr, HERMON_MR_DEREG_ALL,
942 HERMON_NOSLEEP);
943 if (status != DDI_SUCCESS) {
944 HERMON_WARNING(state, "failed to deregister EQ memory");
945 }
946
947 /* Free the memory for the EQ */
948 hermon_queue_free(&eq->eq_eqinfo);
949
950 /* Free the Hermon Event Queue handle */
951 hermon_rsrc_free(state, &rsrc);
952
953 /* Free up the EQC entry resource */
954 hermon_rsrc_free(state, &eqc);
955
956 /* Decrement the reference count on the protection domain (PD) */
957 hermon_pd_refcnt_dec(pd);
958
959 /* Set the eqhdl pointer to NULL and return success */
960 *eqhdl = NULL;
961
962 return (DDI_SUCCESS);
963 }
964
965
966 /*
967 * hermon_eq_handler_init
968 * Context: Only called from attach() path context
969 */
970 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))971 hermon_eq_handler_init(hermon_state_t *state, hermon_eqhdl_t eq,
972 uint_t evt_type_mask, int (*eq_func)(hermon_state_t *state,
973 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe))
974 {
975 int status;
976
977 /*
978 * Save away the EQ handler function and the event type mask. These
979 * will be used later during interrupt and event queue processing.
980 */
981 eq->eq_func = eq_func;
982 eq->eq_evttypemask = evt_type_mask;
983
984 /*
985 * Map the EQ to a specific class of event (or events) depending
986 * on the mask value passed in. The HERMON_EVT_NO_MASK means not
987 * to attempt associating the EQ with any specific class of event.
988 * This is particularly useful when initializing the events queues
989 * used for CQ events. The mapping is done using the Hermon MAP_EQ
990 * firmware command. Note: This command should not, in general, fail.
991 * If it does, then something (probably HW related) has gone seriously
992 * wrong.
993 */
994 if (evt_type_mask != HERMON_EVT_NO_MASK) {
995 status = hermon_map_eq_cmd_post(state,
996 HERMON_CMD_MAP_EQ_EVT_MAP, eq->eq_eqnum, evt_type_mask,
997 HERMON_CMD_NOSLEEP_SPIN);
998 if (status != HERMON_CMD_SUCCESS) {
999 cmn_err(CE_NOTE, "hermon%d: MAP_EQ command failed: "
1000 "%08x\n", state->hs_instance, status);
1001 return (DDI_FAILURE);
1002 }
1003 }
1004
1005 return (DDI_SUCCESS);
1006 }
1007
1008
1009 /*
1010 * hermon_eq_handler_fini
1011 * Context: Only called from attach() and/or detach() path contexts
1012 */
1013 static int
hermon_eq_handler_fini(hermon_state_t * state,hermon_eqhdl_t eq)1014 hermon_eq_handler_fini(hermon_state_t *state, hermon_eqhdl_t eq)
1015 {
1016 int status;
1017
1018 /*
1019 * Unmap the EQ from the event class to which it had been previously
1020 * mapped. The unmapping is done using the Hermon MAP_EQ (in much
1021 * the same way that the initial mapping was done). The difference,
1022 * however, is in the HERMON_EQ_EVT_UNMAP flag that is passed to the
1023 * MAP_EQ firmware command. The HERMON_EVT_NO_MASK (which may have
1024 * been passed in at init time) still means that no association has
1025 * been made between the EQ and any specific class of event (and,
1026 * hence, no unmapping is necessary). Note: This command should not,
1027 * in general, fail. If it does, then something (probably HW related)
1028 * has gone seriously wrong.
1029 */
1030 if (eq->eq_evttypemask != HERMON_EVT_NO_MASK) {
1031 status = hermon_map_eq_cmd_post(state,
1032 HERMON_CMD_MAP_EQ_EVT_UNMAP, eq->eq_eqnum,
1033 eq->eq_evttypemask, HERMON_CMD_NOSLEEP_SPIN);
1034 if (status != HERMON_CMD_SUCCESS) {
1035 cmn_err(CE_NOTE, "hermon%d: MAP_EQ command failed: "
1036 "%08x\n", state->hs_instance, status);
1037 return (DDI_FAILURE);
1038 }
1039 }
1040
1041 return (DDI_SUCCESS);
1042 }
1043
1044
1045 /*
1046 * hermon_eq_demux()
1047 * Context: Called only from interrupt context
1048 * Usage: to demux the various type reported on one EQ
1049 */
1050 static int
hermon_eq_demux(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1051 hermon_eq_demux(hermon_state_t *state, hermon_eqhdl_t eq,
1052 hermon_hw_eqe_t *eqe)
1053 {
1054 uint_t eqe_evttype;
1055 int status = DDI_FAILURE;
1056
1057 eqe_evttype = HERMON_EQE_EVTTYPE_GET(eq, eqe);
1058
1059 switch (eqe_evttype) {
1060
1061 case HERMON_EVT_PORT_STATE_CHANGE:
1062 status = hermon_port_state_change_handler(state, eq, eqe);
1063 break;
1064
1065 case HERMON_EVT_COMM_ESTABLISHED:
1066 status = hermon_comm_estbl_handler(state, eq, eqe);
1067 break;
1068
1069 case HERMON_EVT_COMMAND_INTF_COMP:
1070 status = hermon_cmd_complete_handler(state, eq, eqe);
1071 break;
1072
1073 case HERMON_EVT_LOCAL_WQ_CAT_ERROR:
1074 HERMON_WARNING(state, HERMON_FMA_LOCCAT);
1075 status = hermon_local_wq_cat_err_handler(state, eq, eqe);
1076 break;
1077
1078 case HERMON_EVT_INV_REQ_LOCAL_WQ_ERROR:
1079 HERMON_WARNING(state, HERMON_FMA_LOCINV);
1080 status = hermon_invreq_local_wq_err_handler(state, eq, eqe);
1081 break;
1082
1083 case HERMON_EVT_LOCAL_ACC_VIO_WQ_ERROR:
1084 HERMON_WARNING(state, HERMON_FMA_LOCACEQ);
1085 IBTF_DPRINTF_L2("async", HERMON_FMA_LOCACEQ);
1086 status = hermon_local_acc_vio_wq_err_handler(state, eq, eqe);
1087 break;
1088 case HERMON_EVT_SEND_QUEUE_DRAINED:
1089 status = hermon_sendq_drained_handler(state, eq, eqe);
1090 break;
1091
1092 case HERMON_EVT_PATH_MIGRATED:
1093 status = hermon_path_mig_handler(state, eq, eqe);
1094 break;
1095
1096 case HERMON_EVT_PATH_MIGRATE_FAILED:
1097 HERMON_WARNING(state, HERMON_FMA_PATHMIG);
1098 status = hermon_path_mig_err_handler(state, eq, eqe);
1099 break;
1100
1101 case HERMON_EVT_SRQ_CATASTROPHIC_ERROR:
1102 HERMON_WARNING(state, HERMON_FMA_SRQCAT);
1103 status = hermon_catastrophic_handler(state, eq, eqe);
1104 break;
1105
1106 case HERMON_EVT_SRQ_LAST_WQE_REACHED:
1107 status = hermon_srq_last_wqe_reached_handler(state, eq, eqe);
1108 break;
1109
1110 case HERMON_EVT_FEXCH_ERROR:
1111 status = hermon_fexch_error_handler(state, eq, eqe);
1112 break;
1113
1114 default:
1115 break;
1116 }
1117 return (status);
1118 }
1119
1120 /*
1121 * hermon_port_state_change_handler()
1122 * Context: Only called from interrupt context
1123 */
1124 /* ARGSUSED */
1125 static int
hermon_port_state_change_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1126 hermon_port_state_change_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1127 hermon_hw_eqe_t *eqe)
1128 {
1129 ibc_async_event_t event;
1130 ibt_async_code_t type;
1131 uint_t subtype;
1132 uint8_t port;
1133 char link_msg[24];
1134
1135 /*
1136 * Depending on the type of Port State Change event, pass the
1137 * appropriate asynch event to the IBTF.
1138 */
1139 port = (uint8_t)HERMON_EQE_PORTNUM_GET(eq, eqe);
1140
1141 /* Check for valid port number in event */
1142 if ((port == 0) || (port > state->hs_cfg_profile->cp_num_ports)) {
1143 HERMON_WARNING(state, "Unexpected port number in port state "
1144 "change event");
1145 cmn_err(CE_CONT, " Port number: %02x\n", port);
1146 return (DDI_FAILURE);
1147 }
1148
1149 subtype = HERMON_EQE_EVTSUBTYPE_GET(eq, eqe);
1150 if (subtype == HERMON_PORT_LINK_ACTIVE) {
1151 event.ev_port = port;
1152 type = IBT_EVENT_PORT_UP;
1153
1154 (void) snprintf(link_msg, 23, "port %d up", port);
1155 ddi_dev_report_fault(state->hs_dip, DDI_SERVICE_RESTORED,
1156 DDI_EXTERNAL_FAULT, link_msg);
1157 } else if (subtype == HERMON_PORT_LINK_DOWN) {
1158 event.ev_port = port;
1159 type = IBT_ERROR_PORT_DOWN;
1160
1161 (void) snprintf(link_msg, 23, "port %d down", port);
1162 ddi_dev_report_fault(state->hs_dip, DDI_SERVICE_LOST,
1163 DDI_EXTERNAL_FAULT, link_msg);
1164 } else {
1165 HERMON_WARNING(state, "Unexpected subtype in port state change "
1166 "event");
1167 cmn_err(CE_CONT, " Event type: %02x, subtype: %02x\n",
1168 HERMON_EQE_EVTTYPE_GET(eq, eqe), subtype);
1169 return (DDI_FAILURE);
1170 }
1171
1172 /*
1173 * Deliver the event to the IBTF. Note: If "hs_ibtfpriv" is NULL,
1174 * then we have either received this event before we finished
1175 * attaching to the IBTF or we've received it while we are in the
1176 * process of detaching.
1177 */
1178 if (state->hs_ibtfpriv != NULL) {
1179 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1180 }
1181
1182 return (DDI_SUCCESS);
1183 }
1184
1185
1186 /*
1187 * hermon_comm_estbl_handler()
1188 * Context: Only called from interrupt context
1189 */
1190 /* ARGSUSED */
1191 static int
hermon_comm_estbl_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1192 hermon_comm_estbl_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1193 hermon_hw_eqe_t *eqe)
1194 {
1195 hermon_qphdl_t qp;
1196 uint_t qpnum;
1197 ibc_async_event_t event;
1198 ibt_async_code_t type;
1199
1200 /* Get the QP handle from QP number in event descriptor */
1201 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1202 qp = hermon_qphdl_from_qpnum(state, qpnum);
1203
1204 /*
1205 * If the QP handle is NULL, this is probably an indication
1206 * that the QP has been freed already. In which case, we
1207 * should not deliver this event.
1208 *
1209 * We also check that the QP number in the handle is the
1210 * same as the QP number in the event queue entry. This
1211 * extra check allows us to handle the case where a QP was
1212 * freed and then allocated again in the time it took to
1213 * handle the event queue processing. By constantly incrementing
1214 * the non-constrained portion of the QP number every time
1215 * a new QP is allocated, we mitigate (somewhat) the chance
1216 * that a stale event could be passed to the client's QP
1217 * handler.
1218 *
1219 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1220 * means that we've have either received this event before we
1221 * finished attaching to the IBTF or we've received it while we
1222 * are in the process of detaching.
1223 */
1224 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1225 (state->hs_ibtfpriv != NULL)) {
1226 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1227 type = IBT_EVENT_COM_EST_QP;
1228
1229 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1230 }
1231
1232 return (DDI_SUCCESS);
1233 }
1234
1235
1236 /*
1237 * hermon_local_wq_cat_err_handler()
1238 * Context: Only called from interrupt context
1239 */
1240 /* ARGSUSED */
1241 static int
hermon_local_wq_cat_err_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1242 hermon_local_wq_cat_err_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1243 hermon_hw_eqe_t *eqe)
1244 {
1245 hermon_qphdl_t qp;
1246 uint_t qpnum;
1247 ibc_async_event_t event;
1248 ibt_async_code_t type;
1249
1250 /* Get the QP handle from QP number in event descriptor */
1251 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1252 qp = hermon_qphdl_from_qpnum(state, qpnum);
1253
1254 /*
1255 * If the QP handle is NULL, this is probably an indication
1256 * that the QP has been freed already. In which case, we
1257 * should not deliver this event.
1258 *
1259 * We also check that the QP number in the handle is the
1260 * same as the QP number in the event queue entry. This
1261 * extra check allows us to handle the case where a QP was
1262 * freed and then allocated again in the time it took to
1263 * handle the event queue processing. By constantly incrementing
1264 * the non-constrained portion of the QP number every time
1265 * a new QP is allocated, we mitigate (somewhat) the chance
1266 * that a stale event could be passed to the client's QP
1267 * handler.
1268 *
1269 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1270 * means that we've have either received this event before we
1271 * finished attaching to the IBTF or we've received it while we
1272 * are in the process of detaching.
1273 */
1274 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1275 (state->hs_ibtfpriv != NULL)) {
1276 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1277 type = IBT_ERROR_CATASTROPHIC_QP;
1278
1279 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1280 }
1281
1282 return (DDI_SUCCESS);
1283 }
1284
1285
1286 /*
1287 * hermon_invreq_local_wq_err_handler()
1288 * Context: Only called from interrupt context
1289 */
1290 /* ARGSUSED */
1291 static int
hermon_invreq_local_wq_err_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1292 hermon_invreq_local_wq_err_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1293 hermon_hw_eqe_t *eqe)
1294 {
1295 hermon_qphdl_t qp;
1296 uint_t qpnum;
1297 ibc_async_event_t event;
1298 ibt_async_code_t type;
1299
1300 /* Get the QP handle from QP number in event descriptor */
1301 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1302 qp = hermon_qphdl_from_qpnum(state, qpnum);
1303
1304 /*
1305 * If the QP handle is NULL, this is probably an indication
1306 * that the QP has been freed already. In which case, we
1307 * should not deliver this event.
1308 *
1309 * We also check that the QP number in the handle is the
1310 * same as the QP number in the event queue entry. This
1311 * extra check allows us to handle the case where a QP was
1312 * freed and then allocated again in the time it took to
1313 * handle the event queue processing. By constantly incrementing
1314 * the non-constrained portion of the QP number every time
1315 * a new QP is allocated, we mitigate (somewhat) the chance
1316 * that a stale event could be passed to the client's QP
1317 * handler.
1318 *
1319 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1320 * means that we've have either received this event before we
1321 * finished attaching to the IBTF or we've received it while we
1322 * are in the process of detaching.
1323 */
1324 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1325 (state->hs_ibtfpriv != NULL)) {
1326 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1327 type = IBT_ERROR_INVALID_REQUEST_QP;
1328
1329 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1330 }
1331
1332 return (DDI_SUCCESS);
1333 }
1334
1335
1336 /*
1337 * hermon_local_acc_vio_wq_err_handler()
1338 * Context: Only called from interrupt context
1339 */
1340 /* ARGSUSED */
1341 static int
hermon_local_acc_vio_wq_err_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1342 hermon_local_acc_vio_wq_err_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1343 hermon_hw_eqe_t *eqe)
1344 {
1345 hermon_qphdl_t qp;
1346 uint_t qpnum;
1347 ibc_async_event_t event;
1348 ibt_async_code_t type;
1349
1350 /* Get the QP handle from QP number in event descriptor */
1351 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1352 qp = hermon_qphdl_from_qpnum(state, qpnum);
1353
1354 /*
1355 * If the QP handle is NULL, this is probably an indication
1356 * that the QP has been freed already. In which case, we
1357 * should not deliver this event.
1358 *
1359 * We also check that the QP number in the handle is the
1360 * same as the QP number in the event queue entry. This
1361 * extra check allows us to handle the case where a QP was
1362 * freed and then allocated again in the time it took to
1363 * handle the event queue processing. By constantly incrementing
1364 * the non-constrained portion of the QP number every time
1365 * a new QP is allocated, we mitigate (somewhat) the chance
1366 * that a stale event could be passed to the client's QP
1367 * handler.
1368 *
1369 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1370 * means that we've have either received this event before we
1371 * finished attaching to the IBTF or we've received it while we
1372 * are in the process of detaching.
1373 */
1374 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1375 (state->hs_ibtfpriv != NULL)) {
1376 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1377 type = IBT_ERROR_ACCESS_VIOLATION_QP;
1378
1379 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1380 }
1381
1382 return (DDI_SUCCESS);
1383 }
1384
1385
1386 /*
1387 * hermon_sendq_drained_handler()
1388 * Context: Only called from interrupt context
1389 */
1390 /* ARGSUSED */
1391 static int
hermon_sendq_drained_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1392 hermon_sendq_drained_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1393 hermon_hw_eqe_t *eqe)
1394 {
1395 hermon_qphdl_t qp;
1396 uint_t qpnum;
1397 ibc_async_event_t event;
1398 uint_t forward_sqd_event;
1399 ibt_async_code_t type;
1400
1401 /* Get the QP handle from QP number in event descriptor */
1402 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1403 qp = hermon_qphdl_from_qpnum(state, qpnum);
1404
1405 /*
1406 * If the QP handle is NULL, this is probably an indication
1407 * that the QP has been freed already. In which case, we
1408 * should not deliver this event.
1409 *
1410 * We also check that the QP number in the handle is the
1411 * same as the QP number in the event queue entry. This
1412 * extra check allows us to handle the case where a QP was
1413 * freed and then allocated again in the time it took to
1414 * handle the event queue processing. By constantly incrementing
1415 * the non-constrained portion of the QP number every time
1416 * a new QP is allocated, we mitigate (somewhat) the chance
1417 * that a stale event could be passed to the client's QP
1418 * handler.
1419 *
1420 * And then we check if "hs_ibtfpriv" is NULL. If it is then it
1421 * means that we've have either received this event before we
1422 * finished attaching to the IBTF or we've received it while we
1423 * are in the process of detaching.
1424 */
1425 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1426 (state->hs_ibtfpriv != NULL)) {
1427 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1428 type = IBT_EVENT_SQD;
1429
1430 /*
1431 * Grab the QP lock and update the QP state to reflect that
1432 * the Send Queue Drained event has arrived. Also determine
1433 * whether the event is intended to be forwarded on to the
1434 * consumer or not. This information is used below in
1435 * determining whether or not to call the IBTF.
1436 */
1437 mutex_enter(&qp->qp_lock);
1438 forward_sqd_event = qp->qp_forward_sqd_event;
1439 qp->qp_forward_sqd_event = 0;
1440 qp->qp_sqd_still_draining = 0;
1441 mutex_exit(&qp->qp_lock);
1442
1443 if (forward_sqd_event != 0) {
1444 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1445 }
1446 }
1447
1448 return (DDI_SUCCESS);
1449 }
1450
1451
1452 /*
1453 * hermon_path_mig_handler()
1454 * Context: Only called from interrupt context
1455 */
1456 /* ARGSUSED */
1457 static int
hermon_path_mig_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1458 hermon_path_mig_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1459 hermon_hw_eqe_t *eqe)
1460 {
1461 hermon_qphdl_t qp;
1462 uint_t qpnum;
1463 ibc_async_event_t event;
1464 ibt_async_code_t type;
1465
1466 /* Get the QP handle from QP number in event descriptor */
1467 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1468 qp = hermon_qphdl_from_qpnum(state, qpnum);
1469
1470 /*
1471 * If the QP handle is NULL, this is probably an indication
1472 * that the QP has been freed already. In which case, we
1473 * should not deliver this event.
1474 *
1475 * We also check that the QP number in the handle is the
1476 * same as the QP number in the event queue entry. This
1477 * extra check allows us to handle the case where a QP was
1478 * freed and then allocated again in the time it took to
1479 * handle the event queue processing. By constantly incrementing
1480 * the non-constrained portion of the QP number every time
1481 * a new QP is allocated, we mitigate (somewhat) the chance
1482 * that a stale event could be passed to the client's QP
1483 * handler.
1484 *
1485 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1486 * means that we've have either received this event before we
1487 * finished attaching to the IBTF or we've received it while we
1488 * are in the process of detaching.
1489 */
1490 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1491 (state->hs_ibtfpriv != NULL)) {
1492 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1493 type = IBT_EVENT_PATH_MIGRATED_QP;
1494
1495 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1496 }
1497
1498 return (DDI_SUCCESS);
1499 }
1500
1501
1502 /*
1503 * hermon_path_mig_err_handler()
1504 * Context: Only called from interrupt context
1505 */
1506 /* ARGSUSED */
1507 static int
hermon_path_mig_err_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1508 hermon_path_mig_err_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1509 hermon_hw_eqe_t *eqe)
1510 {
1511 hermon_qphdl_t qp;
1512 uint_t qpnum;
1513 ibc_async_event_t event;
1514 ibt_async_code_t type;
1515
1516 /* Get the QP handle from QP number in event descriptor */
1517 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1518 qp = hermon_qphdl_from_qpnum(state, qpnum);
1519
1520 /*
1521 * If the QP handle is NULL, this is probably an indication
1522 * that the QP has been freed already. In which case, we
1523 * should not deliver this event.
1524 *
1525 * We also check that the QP number in the handle is the
1526 * same as the QP number in the event queue entry. This
1527 * extra check allows us to handle the case where a QP was
1528 * freed and then allocated again in the time it took to
1529 * handle the event queue processing. By constantly incrementing
1530 * the non-constrained portion of the QP number every time
1531 * a new QP is allocated, we mitigate (somewhat) the chance
1532 * that a stale event could be passed to the client's QP
1533 * handler.
1534 *
1535 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1536 * means that we've have either received this event before we
1537 * finished attaching to the IBTF or we've received it while we
1538 * are in the process of detaching.
1539 */
1540 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1541 (state->hs_ibtfpriv != NULL)) {
1542 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1543 type = IBT_ERROR_PATH_MIGRATE_REQ_QP;
1544
1545 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1546 }
1547
1548 return (DDI_SUCCESS);
1549 }
1550
1551
1552 /*
1553 * hermon_catastrophic_handler()
1554 * Context: Only called from interrupt context
1555 */
1556 /* ARGSUSED */
1557 static int
hermon_catastrophic_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1558 hermon_catastrophic_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1559 hermon_hw_eqe_t *eqe)
1560 {
1561 hermon_qphdl_t qp;
1562 uint_t qpnum;
1563 ibc_async_event_t event;
1564 ibt_async_code_t type;
1565
1566 if (eq->eq_evttypemask == HERMON_EVT_MSK_LOCAL_CAT_ERROR) {
1567 HERMON_FMANOTE(state, HERMON_FMA_INTERNAL);
1568 hermon_eq_catastrophic(state);
1569 return (DDI_SUCCESS);
1570 }
1571
1572 /* Get the QP handle from QP number in event descriptor */
1573 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1574 qp = hermon_qphdl_from_qpnum(state, qpnum);
1575
1576 /*
1577 * If the QP handle is NULL, this is probably an indication
1578 * that the QP has been freed already. In which case, we
1579 * should not deliver this event.
1580 *
1581 * We also check that the QP number in the handle is the
1582 * same as the QP number in the event queue entry. This
1583 * extra check allows us to handle the case where a QP was
1584 * freed and then allocated again in the time it took to
1585 * handle the event queue processing. By constantly incrementing
1586 * the non-constrained portion of the QP number every time
1587 * a new QP is allocated, we mitigate (somewhat) the chance
1588 * that a stale event could be passed to the client's QP
1589 * handler.
1590 *
1591 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1592 * means that we've have either received this event before we
1593 * finished attaching to the IBTF or we've received it while we
1594 * are in the process of detaching.
1595 */
1596 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1597 (state->hs_ibtfpriv != NULL)) {
1598 event.ev_srq_hdl = (ibt_srq_hdl_t)qp->qp_srqhdl->srq_hdlrarg;
1599 type = IBT_ERROR_CATASTROPHIC_SRQ;
1600
1601 mutex_enter(&qp->qp_srqhdl->srq_lock);
1602 qp->qp_srqhdl->srq_state = HERMON_SRQ_STATE_ERROR;
1603 mutex_exit(&qp->qp_srqhdl->srq_lock);
1604
1605 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1606 }
1607
1608 return (DDI_SUCCESS);
1609 }
1610
1611
1612 /*
1613 * hermon_srq_last_wqe_reached_handler()
1614 * Context: Only called from interrupt context
1615 */
1616 /* ARGSUSED */
1617 static int
hermon_srq_last_wqe_reached_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1618 hermon_srq_last_wqe_reached_handler(hermon_state_t *state, hermon_eqhdl_t eq,
1619 hermon_hw_eqe_t *eqe)
1620 {
1621 hermon_qphdl_t qp;
1622 uint_t qpnum;
1623 ibc_async_event_t event;
1624 ibt_async_code_t type;
1625
1626 /* Get the QP handle from QP number in event descriptor */
1627 qpnum = HERMON_EQE_QPNUM_GET(eq, eqe);
1628 qp = hermon_qphdl_from_qpnum(state, qpnum);
1629
1630 /*
1631 * If the QP handle is NULL, this is probably an indication
1632 * that the QP has been freed already. In which case, we
1633 * should not deliver this event.
1634 *
1635 * We also check that the QP number in the handle is the
1636 * same as the QP number in the event queue entry. This
1637 * extra check allows us to handle the case where a QP was
1638 * freed and then allocated again in the time it took to
1639 * handle the event queue processing. By constantly incrementing
1640 * the non-constrained portion of the QP number every time
1641 * a new QP is allocated, we mitigate (somewhat) the chance
1642 * that a stale event could be passed to the client's QP
1643 * handler.
1644 *
1645 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1646 * means that we've have either received this event before we
1647 * finished attaching to the IBTF or we've received it while we
1648 * are in the process of detaching.
1649 */
1650 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1651 (state->hs_ibtfpriv != NULL)) {
1652 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1653 type = IBT_EVENT_EMPTY_CHAN;
1654
1655 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1656 }
1657
1658 return (DDI_SUCCESS);
1659 }
1660
1661
1662 /* ARGSUSED */
hermon_fexch_error_handler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1663 static int hermon_fexch_error_handler(hermon_state_t *state,
1664 hermon_eqhdl_t eq, hermon_hw_eqe_t *eqe)
1665 {
1666 hermon_qphdl_t qp;
1667 uint_t qpnum;
1668 ibc_async_event_t event;
1669 ibt_async_code_t type;
1670
1671 /* Get the QP handle from QP number in event descriptor */
1672 event.ev_port = HERMON_EQE_FEXCH_PORTNUM_GET(eq, eqe);
1673 qpnum = hermon_fcoib_qpnum_from_fexch(state,
1674 event.ev_port, HERMON_EQE_FEXCH_FEXCH_GET(eq, eqe));
1675 qp = hermon_qphdl_from_qpnum(state, qpnum);
1676
1677 event.ev_fc = HERMON_EQE_FEXCH_SYNDROME_GET(eq, eqe);
1678
1679 /*
1680 * If the QP handle is NULL, this is probably an indication
1681 * that the QP has been freed already. In which case, we
1682 * should not deliver this event.
1683 *
1684 * We also check that the QP number in the handle is the
1685 * same as the QP number in the event queue entry. This
1686 * extra check allows us to handle the case where a QP was
1687 * freed and then allocated again in the time it took to
1688 * handle the event queue processing. By constantly incrementing
1689 * the non-constrained portion of the QP number every time
1690 * a new QP is allocated, we mitigate (somewhat) the chance
1691 * that a stale event could be passed to the client's QP
1692 * handler.
1693 *
1694 * Lastly, we check if "hs_ibtfpriv" is NULL. If it is then it
1695 * means that we've have either received this event before we
1696 * finished attaching to the IBTF or we've received it while we
1697 * are in the process of detaching.
1698 */
1699 if ((qp != NULL) && (qp->qp_qpnum == qpnum) &&
1700 (state->hs_ibtfpriv != NULL)) {
1701 event.ev_qp_hdl = (ibtl_qp_hdl_t)qp->qp_hdlrarg;
1702 type = IBT_FEXCH_ERROR;
1703
1704 HERMON_DO_IBTF_ASYNC_CALLB(state, type, &event);
1705 }
1706
1707 return (DDI_SUCCESS);
1708 }
1709
1710
1711 /*
1712 * hermon_no_eqhandler
1713 * Context: Only called from interrupt context
1714 */
1715 /* ARGSUSED */
1716 static int
hermon_no_eqhandler(hermon_state_t * state,hermon_eqhdl_t eq,hermon_hw_eqe_t * eqe)1717 hermon_no_eqhandler(hermon_state_t *state, hermon_eqhdl_t eq,
1718 hermon_hw_eqe_t *eqe)
1719 {
1720 uint_t data;
1721 int i;
1722
1723 /*
1724 * This "unexpected event" handler (or "catch-all" handler) will
1725 * receive all events for which no other handler has been registered.
1726 * If we end up here, then something has probably gone seriously wrong
1727 * with the Hermon hardware (or, perhaps, with the software... though
1728 * it's unlikely in this case). The EQE provides all the information
1729 * about the event. So we print a warning message here along with
1730 * the contents of the EQE.
1731 */
1732 HERMON_WARNING(state, "Unexpected Event handler");
1733 cmn_err(CE_CONT, " Event type: %02x, subtype: %02x\n",
1734 HERMON_EQE_EVTTYPE_GET(eq, eqe),
1735 HERMON_EQE_EVTSUBTYPE_GET(eq, eqe));
1736 for (i = 0; i < sizeof (hermon_hw_eqe_t) >> 2; i++) {
1737 data = ((uint_t *)eqe)[i];
1738 cmn_err(CE_CONT, " EQE[%02x]: %08x\n", i, data);
1739 }
1740
1741 return (DDI_SUCCESS);
1742 }
1743