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) 2002-2003, Network Appliance, Inc. All rights reserved.
24  */
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 /*
32  *
33  * MODULE: dapl_evd_qp_async_error_callback.c
34  *
35  * PURPOSE: implements QP callbacks from verbs
36  *
37  * $Id: dapl_evd_qp_async_error_callb.c,v 1.17 2003/07/31 13:55:18 hobie16 Exp $
38  */
39 
40 #include "dapl.h"
41 #include "dapl_evd_util.h"
42 #include "dapl_adapter_util.h"
43 
44 /*
45  * dapl_evd_qp_async_error_callback
46  *
47  * The callback function registered with verbs for qp async erros
48  *
49  * Input:
50  * 	ib_cm_handle,
51  * 	ib_cm_event
52  * 	cause_ptr
53  * 	context (evd)
54  *
55  * Output:
56  * 	None
57  *
58  */
59 
60 void
dapl_evd_qp_async_error_callback(IN ib_hca_handle_t ib_hca_handle,IN ib_qp_handle_t ib_qp_handle,IN ib_error_record_t * cause_ptr,IN void * context)61 dapl_evd_qp_async_error_callback(
62 	IN	ib_hca_handle_t 	ib_hca_handle,
63 	IN	ib_qp_handle_t		ib_qp_handle,
64 	IN	ib_error_record_t	*cause_ptr,
65 	IN	void			*context) /* ARGSUSED */
66 
67 {
68 	/*
69 	 * This is an affiliated error and hence should be able to
70 	 * supply us with exact information on the error type and QP.
71 	 *
72 	 * However the Mellanox and IBM APIs for registering this callback
73 	 * are different.
74 	 *
75 	 * The IBM API allows consumers to register the callback with
76 	 *
77 	 * ib_int32_t
78 	 * ib_set_qp_async_error_eh_us (
79 	 * 		ib_hca_handle_t 	hca_handle,
80 	 * 		ib_qp_async_handler_t 	handler )
81 	 *
82 	 * Notice that this function does not take a context. The context is
83 	 * specified per QP in the call to ib_qp_create_us().
84 	 *
85 	 * In contrast the Mellanox API requires that the context be specified
86 	 * when the funciton is registered:
87 	 *
88 	 * VAPI_ret_t
89 	 * VAPI_set_async_event_handler (
90 	 * 		IN VAPI_hca_hndl_t 		hca_hndl,
91 	 * 		IN VAPI_async_event_handler_t 	handler,
92 	 * 		IN void* 			private_data )
93 	 *
94 	 * Therefore we always specify the context as the asyncronous EVD
95 	 * to be compatible with both APIs.
96 	 */
97 
98 	DAPL_IA		*ia_ptr;
99 	DAPL_EP		*ep_ptr;
100 	DAPL_EVD		*async_evd;
101 	DAT_EVENT_NUMBER	async_event;
102 	DAT_RETURN		dat_status;
103 
104 	ep_ptr    = (DAPL_EP *) context;
105 	ia_ptr    = ep_ptr->header.owner_ia;
106 	async_evd = (DAPL_EVD *) ia_ptr->async_error_evd;
107 
108 	dapl_dbg_log(DAPL_DBG_TYPE_CALLBACK | DAPL_DBG_TYPE_EXCEPTION,
109 	    "--> dapl_evd_qp_async_error_callback: ep %p qp %p (%x) state %d\n",
110 	    ep_ptr,
111 	    ep_ptr->qp_handle,
112 	    ep_ptr->qpn,
113 	    ep_ptr->param.ep_state);
114 
115 	/*
116 	 * Transition to ERROR if we are connected; other states need to
117 	 * complete first (e.g. pending states)
118 	 */
119 	if (ep_ptr->param.ep_state == DAT_EP_STATE_CONNECTED) {
120 		ep_ptr->param.ep_state = DAT_EP_STATE_ERROR;
121 	}
122 
123 	dapl_os_assert(async_evd != NULL);
124 
125 	dat_status = dapls_ib_get_async_event(cause_ptr, &async_event);
126 	if (dat_status == DAT_SUCCESS) {
127 		/*
128 		 * If dapls_ib_get_async_event is not successful,
129 		 * an event has been generated by the provide that
130 		 * we are not interested in.
131 		 */
132 		(void) dapls_evd_post_async_error_event(async_evd,
133 		    async_event,
134 		    async_evd->header.owner_ia);
135 	}
136 	dapl_dbg_log(DAPL_DBG_TYPE_CALLBACK | DAPL_DBG_TYPE_EXCEPTION,
137 	    "dapl_evd_qp_async_error_callback () returns\n");
138 }
139 
140 /*
141  * Local variables:
142  *  c-indent-level: 4
143  *  c-basic-offset: 4
144  *  tab-width: 8
145  * End:
146  */
147