1 /*
2  * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3  * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  *
34  */
35 
36 /*
37  * Abstract:
38  * 	Declaration of osm_mad_wrapper_t.
39  *	This object represents the context wrapper for OpenSM MAD processing.
40  *	This object is part of the OpenSM family of objects.
41  */
42 
43 #ifndef _OSM_VENDOR_AL_H_
44 #define _OSM_VENDOR_AL_H_
45 
46 #include <iba/ib_types.h>
47 #include <iba/ib_al.h>
48 #include <complib/cl_qlist.h>
49 #include <complib/cl_thread.h>
50 #include <opensm/osm_base.h>
51 #include <opensm/osm_log.h>
52 
53 #ifdef __cplusplus
54 #  define BEGIN_C_DECLS extern "C" {
55 #  define END_C_DECLS   }
56 #else				/* !__cplusplus */
57 #  define BEGIN_C_DECLS
58 #  define END_C_DECLS
59 #endif				/* __cplusplus */
60 
61 BEGIN_C_DECLS
62 /****h* OpenSM/Vendor AL
63 * NAME
64 *	Vendor AL
65 *
66 * DESCRIPTION
67 *
68 *	The Vendor AL object is thread safe.
69 *
70 *	This object should be treated as opaque and should be
71 *	manipulated only through the provided functions.
72 *
73 *	Enable various hacks to compensate for bugs in external code...
74 *
75 *
76 * AUTHOR
77 *
78 *
79 *********/
80 /****h* OpenSM/Vendor Access Layer (AL)
81 * NAME
82 *	Vendor AL
83 *
84 * DESCRIPTION
85 *	This file is the vendor specific file for the AL Infiniband API.
86 *
87 * AUTHOR
88 *	Steve King, Intel
89 *
90 *********/
91 #define OSM_AL_SQ_SGE 256
92 #define OSM_AL_RQ_SGE 256
93 #define OSM_DEFAULT_RETRY_COUNT 3
94 /* AL supports RMPP */
95 #define VENDOR_RMPP_SUPPORT 1
96 /****s* OpenSM: Vendor AL/osm_ca_info_t
97 * NAME
98 *   osm_ca_info_t
99 *
100 * DESCRIPTION
101 * 	Structure containing information about local Channle Adapters.
102 *
103 * SYNOPSIS
104 */
105 typedef struct _osm_ca_info {
106 	ib_net64_t guid;
107 	size_t attr_size;
108 	ib_ca_attr_t *p_attr;
109 
110 } osm_ca_info_t;
111 /*
112 * FIELDS
113 *	guid
114 *		Node GUID of the local CA.
115 *
116 *	attr_size
117 *		Size of the CA attributes for this CA.
118 *
119 *	p_attr
120 *		Pointer to dynamicly allocated CA Attribute structure.
121 *
122 * SEE ALSO
123 *********/
124 
125 /****f* OpenSM: CA Info/osm_ca_info_get_num_ports
126 * NAME
127 *	osm_ca_info_get_num_ports
128 *
129 * DESCRIPTION
130 *	Returns the number of ports owned by this CA.
131 *
132 * SYNOPSIS
133 */
134 static inline uint8_t
osm_ca_info_get_num_ports(IN const osm_ca_info_t * const p_ca_info)135 osm_ca_info_get_num_ports(IN const osm_ca_info_t * const p_ca_info)
136 {
137 	return (p_ca_info->p_attr->num_ports);
138 }
139 
140 /*
141 * PARAMETERS
142 *	p_ca_info
143 *		[in] Pointer to a CA Info object.
144 *
145 * RETURN VALUE
146 *	Returns the number of ports owned by this CA.
147 *
148 * NOTES
149 *
150 * SEE ALSO
151 *********/
152 
153 /****f* OpenSM: CA Info/osm_ca_info_get_port_guid
154 * NAME
155 *	osm_ca_info_get_port_guid
156 *
157 * DESCRIPTION
158 *	Returns the port GUID of the specified port owned by this CA.
159 *
160 * SYNOPSIS
161 */
162 static inline ib_net64_t
osm_ca_info_get_port_guid(IN const osm_ca_info_t * const p_ca_info,IN const uint8_t index)163 osm_ca_info_get_port_guid(IN const osm_ca_info_t * const p_ca_info,
164 			  IN const uint8_t index)
165 {
166 	return (p_ca_info->p_attr->p_port_attr[index].port_guid);
167 }
168 
169 /*
170 * PARAMETERS
171 *	p_ca_info
172 *		[in] Pointer to a CA Info object.
173 *
174 *	index
175 *		[in] Port "index" for which to retrieve the port GUID.
176 *		The index is the offset into the ca's internal array
177 *		of port attributes.
178 *
179 * RETURN VALUE
180 *	Returns the port GUID of the specified port owned by this CA.
181 *
182 * NOTES
183 *
184 * SEE ALSO
185 *********/
186 
187 /****f* OpenSM: CA Info/osm_ca_info_get_port_num
188 * NAME
189 *	osm_ca_info_get_port_num
190 *
191 * DESCRIPTION
192 *	Returns the port number of the specified port owned by this CA.
193 *	Port numbers start with 1 for HCA's.
194 *
195 * SYNOPSIS
196 */
197 static inline uint8_t
osm_ca_info_get_port_num(IN const osm_ca_info_t * const p_ca_info,IN const uint8_t index)198 osm_ca_info_get_port_num(IN const osm_ca_info_t * const p_ca_info,
199 			 IN const uint8_t index)
200 {
201 	return (p_ca_info->p_attr->p_port_attr[index].port_num);
202 }
203 
204 /*
205 * PARAMETERS
206 *	p_ca_info
207 *		[in] Pointer to a CA Info object.
208 *
209 *	index
210 *		[in] Port "index" for which to retrieve the port GUID.
211 *		The index is the offset into the ca's internal array
212 *		of port attributes.
213 *
214 * RETURN VALUE
215 *	Returns the port GUID of the specified port owned by this CA.
216 *
217 * NOTES
218 *
219 * SEE ALSO
220 *********/
221 
222 /****f* OpenSM: CA Info/osm_ca_info_get_ca_guid
223 * NAME
224 *	osm_ca_info_get_ca_guid
225 *
226 * DESCRIPTION
227 *	Returns the GUID of the specified CA.
228 *
229 * SYNOPSIS
230 */
231 static inline ib_net64_t
osm_ca_info_get_ca_guid(IN const osm_ca_info_t * const p_ca_info)232 osm_ca_info_get_ca_guid(IN const osm_ca_info_t * const p_ca_info)
233 {
234 	return (p_ca_info->p_attr->ca_guid);
235 }
236 
237 /*
238 * PARAMETERS
239 *	p_ca_info
240 *		[in] Pointer to a CA Info object.
241 *
242 * RETURN VALUE
243 *	Returns the GUID of the specified CA.
244 *
245 * NOTES
246 *
247 * SEE ALSO
248 *********/
249 
250 /****s* OpenSM: Vendor AL/osm_bind_handle_t
251 * NAME
252 *   osm_bind_handle_t
253 *
254 * DESCRIPTION
255 * 	handle returned by the vendor transport bind call.
256 *
257 * SYNOPSIS
258 */
259 typedef struct _osm_vendor {
260 	ib_al_handle_t h_al;
261 	osm_log_t *p_log;
262 	uint32_t ca_count;
263 	osm_ca_info_t *p_ca_info;
264 	uint32_t timeout;
265 	ib_ca_handle_t h_ca;
266 	ib_pd_handle_t h_pd;
267 
268 } osm_vendor_t;
269 /*
270 * FIELDS
271 *	h_al
272 *		Handle returned by AL open call (ib_open_al).
273 *
274 *	p_log
275 *		Pointer to the log object.
276 *
277 *	ca_count
278 *		Number of CA's in the array pointed to by p_ca_info.
279 *
280 *	p_ca_info
281 *		Pointer to dynamically allocated array of CA info objects.
282 *
283 *	h_pool
284 *		MAD Pool handle returned by ib_create_mad_pool at init time.
285 *
286 *	timeout
287 *		Transaction timeout time in milliseconds.
288 *
289 * SEE ALSO
290 *********/
291 
292 #define OSM_BIND_INVALID_HANDLE 0
293 
294 /****s* OpenSM: Vendor AL/osm_bind_handle_t
295 * NAME
296 *   osm_bind_handle_t
297 *
298 * DESCRIPTION
299 * 	handle returned by the vendor transport bind call.
300 *
301 * SYNOPSIS
302 */
303 typedef void *osm_bind_handle_t;
304 /***********/
305 
306 /****s* OpenSM/osm_vend_wrap_t
307 * NAME
308 *   AL Vendor MAD Wrapper
309 *
310 * DESCRIPTION
311 *	AL specific MAD wrapper. AL transport layer uses this for
312 *	housekeeping.
313 *
314 * SYNOPSIS
315 *********/
316 typedef struct _osm_vend_wrap_t {
317 	uint32_t size;
318 	osm_bind_handle_t h_bind;
319 	ib_mad_element_t *p_elem;
320 	ib_av_handle_t h_av;
321 	void *p_resp_madw;
322 
323 } osm_vend_wrap_t;
324 /*
325 * FIELDS
326 *	size
327 *		Size of the allocated MAD
328 *
329 *	h_bind
330 *		Bind handle used on this transaction
331 *
332 *	p_elem
333 *		Pointer to the mad element structure associated with
334 *		this mad.
335 *
336 *	h_av
337 *		Address vector handle used for this transaction.
338 *
339 *	p_resp_madw
340 *		Pointer to the mad wrapper structure used to hold the pending
341 *		reponse to the mad, if any.  If a response is expected, the
342 *		wrapper for the reponse is allocated during the send call.
343 *
344 * SEE ALSO
345 *********/
346 
347 END_C_DECLS
348 #endif				/* _OSM_VENDOR_AL_H_ */
349