1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff/*
37219820Sjeff * Abstract:
38219820Sjeff * 	Definition of interface for the TS Vendor
39219820Sjeff *	   This object is part of the OpenSM family of objects.
40219820Sjeff */
41219820Sjeff
42219820Sjeff#ifndef _OSM_VENDOR_TS_H_
43219820Sjeff#define _OSM_VENDOR_TS_H_
44219820Sjeff
45219820Sjeff#undef IN
46219820Sjeff#undef OUT
47219820Sjeff#include <vapi_types.h>
48219820Sjeff#include <evapi.h>
49219820Sjeff#include <ib/ts_api_ng/useraccess/include/ts_ib_useraccess.h>
50219820Sjeff#define IN
51219820Sjeff#define OUT
52219820Sjeff#include "iba/ib_types.h"
53219820Sjeff#include "iba/ib_al.h"
54219820Sjeff#include <complib/cl_thread.h>
55219820Sjeff#include <complib/cl_types_osd.h>
56219820Sjeff#include <opensm/osm_base.h>
57219820Sjeff#include <opensm/osm_log.h>
58219820Sjeff
59219820Sjeff#ifdef __cplusplus
60219820Sjeff#  define BEGIN_C_DECLS extern "C" {
61219820Sjeff#  define END_C_DECLS   }
62219820Sjeff#else				/* !__cplusplus */
63219820Sjeff#  define BEGIN_C_DECLS
64219820Sjeff#  define END_C_DECLS
65219820Sjeff#endif				/* __cplusplus */
66219820Sjeff
67219820SjeffBEGIN_C_DECLS
68219820Sjeff/****s* OpenSM: Vendor TS/osm_bind_handle_t
69219820Sjeff * NAME
70219820Sjeff *   osm_bind_handle_t
71219820Sjeff *
72219820Sjeff * DESCRIPTION
73219820Sjeff * 	handle returned by the vendor transport bind call.
74219820Sjeff *
75219820Sjeff * SYNOPSIS
76219820Sjeff */
77219820Sjefftypedef void *osm_bind_handle_t;
78219820Sjeff/*
79219820Sjeff**********/
80219820Sjeff#define OSM_DEFAULT_RETRY_COUNT 3
81219820Sjeff
82219820Sjeff/****s* OpenSM: Vendor osm_ts_bind_info_t
83219820Sjeff * NAME
84219820Sjeff *   osm_ts_bind_info_t
85219820Sjeff *
86219820Sjeff * DESCRIPTION
87219820Sjeff * 	Handle to the result of binding a class callbacks .
88219820Sjeff *
89219820Sjeff * SYNOPSIS
90219820Sjeff */
91219820Sjefftypedef struct _osm_ts_bind_info {
92219820Sjeff	int ul_dev_fd;
93219820Sjeff	VAPI_hca_hndl_t hca_hndl;
94219820Sjeff	struct _osm_vendor *p_vend;
95219820Sjeff	void *client_context;
96219820Sjeff	uint8_t port_num;
97219820Sjeff	void *rcv_callback;
98219820Sjeff	void *send_err_callback;
99219820Sjeff	struct _osm_mad_pool *p_osm_pool;
100219820Sjeff	cl_thread_t poller;
101219820Sjeff} osm_ts_bind_info_t;
102219820Sjeff/*
103219820Sjeff * FIELDS
104219820Sjeff *	ul_dev_file_hdl
105219820Sjeff *		the file handle to be used for sending the MADs
106219820Sjeff *
107219820Sjeff * hca_hndl
108219820Sjeff *     Handle to the HCA provided by the underlying VAPI
109219820Sjeff *
110219820Sjeff *	p_vend
111219820Sjeff *		Pointer to the vendor object.
112219820Sjeff *
113219820Sjeff *	client_context
114219820Sjeff *		User's context passed during osm_bind
115219820Sjeff *
116219820Sjeff *  hca_id
117219820Sjeff *     HCA Id we bind to.
118219820Sjeff *
119219820Sjeff *	port_num
120219820Sjeff *		Port number (within the HCA) of the bound port.
121219820Sjeff *
122219820Sjeff *	rcv_callback
123219820Sjeff *		OSM Callback function to be called on receive of MAD.
124219820Sjeff *
125219820Sjeff *  send_err_callback
126219820Sjeff *     OSM Callback to be called on send error.
127219820Sjeff *
128219820Sjeff *  p_osm_pool
129219820Sjeff *     Points to the MAD pool used by OSM
130219820Sjeff *
131219820Sjeff *  poller
132219820Sjeff *     A thread reading from the device file handle
133219820Sjeff *
134219820Sjeff * SEE ALSO
135219820Sjeff *********/
136219820Sjeff
137219820Sjeff/****h* OpenSM/Vendor TS
138219820Sjeff * NAME
139219820Sjeff *	Vendor TS
140219820Sjeff *
141219820Sjeff * DESCRIPTION
142219820Sjeff *
143219820Sjeff *	The Vendor TS object is thread safe.
144219820Sjeff *
145219820Sjeff *	This object should be treated as opaque and should be
146219820Sjeff *	manipulated only through the provided functions.
147219820Sjeff *
148219820Sjeff *
149219820Sjeff * AUTHOR
150219820Sjeff *
151219820Sjeff *
152219820Sjeff *********/
153219820Sjeff
154219820Sjeff/****s* OpenSM: Vendor TS/osm_ca_info_t
155219820Sjeff * NAME
156219820Sjeff *   osm_ca_info_t
157219820Sjeff *
158219820Sjeff * DESCRIPTION
159219820Sjeff * 	Structure containing information about local Channle Adapters.
160219820Sjeff *
161219820Sjeff * SYNOPSIS
162219820Sjeff */
163219820Sjefftypedef struct _osm_ca_info {
164219820Sjeff	ib_net64_t guid;
165219820Sjeff	size_t attr_size;
166219820Sjeff	ib_ca_attr_t *p_attr;
167219820Sjeff
168219820Sjeff} osm_ca_info_t;
169219820Sjeff
170219820Sjeff/*
171219820Sjeff * FIELDS
172219820Sjeff *	guid
173219820Sjeff *		Node GUID of the local CA.
174219820Sjeff *
175219820Sjeff *	attr_size
176219820Sjeff *		Size of the CA attributes for this CA.
177219820Sjeff *
178219820Sjeff *	p_attr
179219820Sjeff *		Pointer to dynamicly allocated CA Attribute structure.
180219820Sjeff *
181219820Sjeff * SEE ALSO
182219820Sjeff *********/
183219820Sjeff
184219820Sjeff/***** OpenSM: Vendor TS/osm_vendor_t
185219820Sjeff * NAME
186219820Sjeff *  osm_vendor_t
187219820Sjeff *
188219820Sjeff * DESCRIPTION
189219820Sjeff * 	The structure defining a TS vendor
190219820Sjeff *
191219820Sjeff * SYNOPSIS
192219820Sjeff */
193219820Sjefftypedef struct _osm_vendor {
194219820Sjeff	osm_log_t *p_log;
195219820Sjeff	uint32_t ca_count;
196219820Sjeff	osm_ca_info_t *p_ca_info;
197219820Sjeff	uint32_t timeout;
198219820Sjeff	struct _osm_transaction_mgr *p_transaction_mgr;
199219820Sjeff	osm_ts_bind_info_t smi_bind;
200219820Sjeff	osm_ts_bind_info_t gsi_bind;
201219820Sjeff} osm_vendor_t;
202219820Sjeff
203219820Sjeff/*
204219820Sjeff * FIELDS
205219820Sjeff *	h_al
206219820Sjeff *		Handle returned by TS open call .
207219820Sjeff *
208219820Sjeff *	p_log
209219820Sjeff *		Pointer to the log object.
210219820Sjeff *
211219820Sjeff *	ca_count
212219820Sjeff *		Number of CA's in the array pointed to by p_ca_info.
213219820Sjeff *
214219820Sjeff *	p_ca_info
215219820Sjeff *		Pointer to dynamically allocated array of CA info objects.
216219820Sjeff *
217219820Sjeff *	timeout
218219820Sjeff *		Transaction timeout time in milliseconds.
219219820Sjeff *
220219820Sjeff *  p_transaction_mgr
221219820Sjeff *     Pointer to Transaction Manager.
222219820Sjeff *
223219820Sjeff *  smi_bind
224219820Sjeff *     Bind information for handling SMI MADs
225219820Sjeff *
226219820Sjeff *  gsi_bind
227219820Sjeff *     Bind information for GSI MADs
228219820Sjeff *
229219820Sjeff * SEE ALSO
230219820Sjeff *********/
231219820Sjeff
232219820Sjeff/****f* OpenSM: Vendor TS/CA Info/osm_ca_info_get_port_guid
233219820Sjeff * NAME
234219820Sjeff *	osm_ca_info_get_port_guid
235219820Sjeff *
236219820Sjeff * DESCRIPTION
237219820Sjeff *	Returns the port GUID of the specified port owned by this CA.
238219820Sjeff *
239219820Sjeff * SYNOPSIS
240219820Sjeff */
241219820Sjeffstatic inline ib_net64_t
242219820Sjeffosm_ca_info_get_port_guid(IN const osm_ca_info_t * const p_ca_info,
243219820Sjeff			  IN const uint8_t index)
244219820Sjeff{
245219820Sjeff	return (p_ca_info->p_attr->p_port_attr[index].port_guid);
246219820Sjeff}
247219820Sjeff
248219820Sjeff/*
249219820Sjeff * PARAMETERS
250219820Sjeff *	p_ca_info
251219820Sjeff *		[in] Pointer to a CA Info object.
252219820Sjeff *
253219820Sjeff *	index
254219820Sjeff *		[in] Port "index" for which to retrieve the port GUID.
255219820Sjeff *		The index is the offset into the ca's internal array
256219820Sjeff *		of port attributes.
257219820Sjeff *
258219820Sjeff * RETURN VALUE
259219820Sjeff *	Returns the port GUID of the specified port owned by this CA.
260219820Sjeff *
261219820Sjeff * NOTES
262219820Sjeff *
263219820Sjeff * SEE ALSO
264219820Sjeff *********/
265219820Sjeff
266219820Sjeff/****f* OpenSM: Vendor TS/CA Info/osm_ca_info_get_num_ports
267219820Sjeff * NAME
268219820Sjeff *	osm_ca_info_get_num_ports
269219820Sjeff *
270219820Sjeff * DESCRIPTION
271219820Sjeff *	Returns the number of ports of the given ca_info
272219820Sjeff *
273219820Sjeff * SYNOPSIS
274219820Sjeff */
275219820Sjeffstatic inline uint8_t
276219820Sjeffosm_ca_info_get_num_ports(IN const osm_ca_info_t * const p_ca_info)
277219820Sjeff{
278219820Sjeff	return (p_ca_info->p_attr->num_ports);
279219820Sjeff}
280219820Sjeff
281219820Sjeff/*
282219820Sjeff * PARAMETERS
283219820Sjeff *	p_ca_info
284219820Sjeff *		[in] Pointer to a CA Info object.
285219820Sjeff *
286219820Sjeff * RETURN VALUE
287219820Sjeff *	Returns the number of CA ports
288219820Sjeff *
289219820Sjeff * NOTES
290219820Sjeff *
291219820Sjeff * SEE ALSO
292219820Sjeff *********/
293219820Sjeff
294219820Sjeff/****f* OpenSM: SM Vendor/osm_vendor_get_guid_ca_and_port
295219820Sjeff * NAME
296219820Sjeff *	osm_vendor_get_guid_ca_and_port
297219820Sjeff *
298219820Sjeff * DESCRIPTION
299219820Sjeff * Given the vendor obj and a guid
300219820Sjeff * return the ca id and port number that have that guid
301219820Sjeff *
302219820Sjeff * SYNOPSIS
303219820Sjeff */
304219820Sjeffib_api_status_t
305219820Sjeffosm_vendor_get_guid_ca_and_port(IN osm_vendor_t * const p_vend,
306219820Sjeff				IN ib_net64_t const guid,
307219820Sjeff				OUT VAPI_hca_hndl_t * p_hca_hndl,
308219820Sjeff				OUT VAPI_hca_id_t * p_hca_id,
309219820Sjeff				OUT uint32_t * p_port_num);
310219820Sjeff
311219820Sjeff/*
312219820Sjeff * PARAMETERS
313219820Sjeff *	p_vend
314219820Sjeff *		[in] Pointer to an osm_vendor_t object.
315219820Sjeff *
316219820Sjeff *	guid
317219820Sjeff *		[in] The guid to search for.
318219820Sjeff *
319219820Sjeff *	p_hca_id
320219820Sjeff *		[out] The HCA Id (VAPI_hca_id_t *) that the port is found on.
321219820Sjeff *
322219820Sjeff *	p_port_num
323219820Sjeff *		[out] Pointer to a port number arg to be filled with the port number with the given guid.
324219820Sjeff *
325219820Sjeff * RETURN VALUES
326219820Sjeff *	IB_SUCCESS on SUCCESS
327219820Sjeff *  IB_INVALID_GUID if the guid is notfound on any Local HCA Port
328219820Sjeff *
329219820Sjeff * NOTES
330219820Sjeff *
331219820Sjeff * SEE ALSO
332219820Sjeff *********/
333219820Sjeff
334219820Sjeff/****f* OpenSM: Vendor TS/osm_vendor_get_all_port_attr
335219820Sjeff * NAME
336219820Sjeff *	osm_vendor_get_all_port_attr
337219820Sjeff *
338219820Sjeff * DESCRIPTION
339219820Sjeff * Fill in the array of port_attr with all available ports on ALL the
340219820Sjeff * avilable CAs on this machine.
341219820Sjeff * ALSO -
342219820Sjeff * UPDATE THE VENDOR OBJECT LIST OF CA_INFO STRUCTS
343219820Sjeff *
344219820Sjeff * SYNOPSIS
345219820Sjeff */
346219820Sjeffib_api_status_t osm_vendor_get_all_port_attr(IN osm_vendor_t * const p_vend,
347219820Sjeff					     IN ib_port_attr_t *
348219820Sjeff					     const p_attr_array,
349219820Sjeff					     IN uint32_t * const p_num_ports);
350219820Sjeff
351219820Sjeff/*
352219820Sjeff * PARAMETERS
353219820Sjeff *	p_vend
354219820Sjeff *		[in] Pointer to an osm_vendor_t object.
355219820Sjeff *
356219820Sjeff *	p_attr_array
357219820Sjeff *		[out] Pre-allocated array of port attributes to be filled in
358219820Sjeff *
359219820Sjeff *	p_num_ports
360219820Sjeff *		[out] The size of the given array. Filled in by the actual numberof ports found.
361219820Sjeff *
362219820Sjeff * RETURN VALUES
363219820Sjeff *	IB_SUCCESS if OK
364219820Sjeff *  IB_INSUFFICIENT_MEMORY if not enough place for all ports was provided.
365219820Sjeff *
366219820Sjeff * NOTES
367219820Sjeff *
368219820Sjeff * SEE ALSO
369219820Sjeff *********/
370219820Sjeff
371219820Sjeff#define OSM_BIND_INVALID_HANDLE 0
372219820Sjeff
373219820Sjeff/****s* OpenSM: Vendor TS/osm_vend_wrap_t
374219820Sjeff * NAME
375219820Sjeff *   TS Vendor MAD Wrapper
376219820Sjeff *
377219820Sjeff * DESCRIPTION
378219820Sjeff *	TS specific MAD wrapper. TS transport layer uses this for
379219820Sjeff *	housekeeping.
380219820Sjeff *
381219820Sjeff * SYNOPSIS
382219820Sjeff *********/
383219820Sjefftypedef struct _osm_vend_wrap_t {
384219820Sjeff	uint32_t size;
385219820Sjeff	osm_bind_handle_t h_bind;
386219820Sjeff	ib_mad_t *p_mad_buf;
387219820Sjeff	void *p_resp_madw;
388219820Sjeff} osm_vend_wrap_t;
389219820Sjeff
390219820Sjeff/*
391219820Sjeff * FIELDS
392219820Sjeff *	size
393219820Sjeff *		Size of the allocated MAD
394219820Sjeff *
395219820Sjeff *	h_bind
396219820Sjeff *		Bind handle used on this transaction
397219820Sjeff *
398219820Sjeff *	h_av
399219820Sjeff *		Address vector handle used for this transaction.
400219820Sjeff *
401219820Sjeff *	p_resp_madw
402219820Sjeff *		Pointer to the mad wrapper structure used to hold the pending
403219820Sjeff *		reponse to the mad, if any.  If a response is expected, the
404219820Sjeff *		wrapper for the reponse is allocated during the send call.
405219820Sjeff *
406219820Sjeff * SEE ALSO
407219820Sjeff *********/
408219820Sjeff
409219820SjeffEND_C_DECLS
410219820Sjeff#endif				/* _OSM_VENDOR_TS_H_ */
411