1321936Shselasky/*
2321936Shselasky * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3321936Shselasky * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4321936Shselasky * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5321936Shselasky *
6321936Shselasky * This software is available to you under a choice of one of two
7321936Shselasky * licenses.  You may choose to be licensed under the terms of the GNU
8321936Shselasky * General Public License (GPL) Version 2, available from the file
9321936Shselasky * COPYING in the main directory of this source tree, or the
10321936Shselasky * OpenIB.org BSD license below:
11321936Shselasky *
12321936Shselasky *     Redistribution and use in source and binary forms, with or
13321936Shselasky *     without modification, are permitted provided that the following
14321936Shselasky *     conditions are met:
15321936Shselasky *
16321936Shselasky *      - Redistributions of source code must retain the above
17321936Shselasky *        copyright notice, this list of conditions and the following
18321936Shselasky *        disclaimer.
19321936Shselasky *
20321936Shselasky *      - Redistributions in binary form must reproduce the above
21321936Shselasky *        copyright notice, this list of conditions and the following
22321936Shselasky *        disclaimer in the documentation and/or other materials
23321936Shselasky *        provided with the distribution.
24321936Shselasky *
25321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32321936Shselasky * SOFTWARE.
33321936Shselasky *
34321936Shselasky */
35321936Shselasky
36321936Shselasky/*
37321936Shselasky * Abstract:
38321936Shselasky * 	Definition of interface for the MTL Vendor
39321936Shselasky *	   This object is part of the OpenSM family of objects.
40321936Shselasky */
41321936Shselasky
42321936Shselasky#ifndef _OSM_TRANSACTION_MGR_H_
43321936Shselasky#define _OSM_TRANSACTION_MGR_H_
44321936Shselasky
45321936Shselasky  /*
46321936Shselasky     #include <vapi_types.h>
47321936Shselasky     #include <evapi.h>
48321936Shselasky   */
49321936Shselasky
50321936Shselasky#include <iba/ib_types.h>
51321936Shselasky#include <iba/ib_al.h>
52321936Shselasky#include <complib/cl_qlist.h>
53321936Shselasky#include <complib/cl_qmap.h>
54321936Shselasky#include <complib/cl_timer.h>
55321936Shselasky#include <complib/cl_thread.h>
56321936Shselasky#include <complib/cl_types_osd.h>
57321936Shselasky#include <complib/cl_spinlock.h>
58321936Shselasky#include <opensm/osm_base.h>
59321936Shselasky#include <opensm/osm_log.h>
60321936Shselasky#include <opensm/osm_madw.h>
61321936Shselasky#ifdef OSM_VENDOR_INTF_MTL
62321936Shselasky#include <ib_mgt.h>
63321936Shselasky#include <opensm/osm_mtl_bind.h>
64321936Shselasky#endif
65321936Shselasky
66321936Shselasky#ifdef __cplusplus
67321936Shselasky#  define BEGIN_C_DECLS extern "C" {
68321936Shselasky#  define END_C_DECLS   }
69321936Shselasky#else				/* !__cplusplus */
70321936Shselasky#  define BEGIN_C_DECLS
71321936Shselasky#  define END_C_DECLS
72321936Shselasky#endif				/* __cplusplus */
73321936Shselasky
74321936ShselaskyBEGIN_C_DECLS
75321936Shselasky/****s* OpenSM: Transaction Manager/osm_madw_req_t
76321936Shselasky* NAME
77321936Shselasky*  osm_madw_req_t
78321936Shselasky*
79321936Shselasky* DESCRIPTION
80321936Shselasky*  The structure defining each object in the transaction_mgr.
81321936Shselasky*  For every request mad sent, we will save such an object for it.
82321936Shselasky*
83321936Shselasky* SYNOPSIS
84321936Shselasky*/
85321936Shselaskytypedef struct _osm_madw_req {
86321936Shselasky	cl_list_item_t list_item;
87321936Shselasky	cl_map_item_t map_item;
88321936Shselasky	osm_madw_t *p_madw;
89321936Shselasky	uint64_t waking_time;
90321936Shselasky	uint8_t retry_cnt;
91321936Shselasky	osm_bind_handle_t *p_bind;
92321936Shselasky} osm_madw_req_t;
93321936Shselasky
94321936Shselasky/*
95321936Shselasky* FIELDS
96321936Shselasky*  list_item
97321936Shselasky*     List item for qlist linkage. Must be first element!!
98321936Shselasky*
99321936Shselasky*  map_item
100321936Shselasky*     Map item for qmap linkage.
101321936Shselasky*
102321936Shselasky*  p_madw
103321936Shselasky*     pointer to mad wrapper that is expecting to get a response.
104321936Shselasky*
105321936Shselasky*  waking_time
106321936Shselasky*     Time stamp (in microseconds) when the p_madw needs to wake up.
107321936Shselasky*     This value is
108321936Shselasky*      cl_get_time_stamp() + timeout  during the sending of the mad.
109321936Shselasky*      where timeout should be given in microseconds.
110321936Shselasky*
111321936Shselasky*  retry_cnt
112321936Shselasky*     The number of outstanding retries to be called.
113321936Shselasky*********/
114321936Shselasky
115321936Shselasky/****s* OpenSM: Transaction Manager/osm_transaction_mgr_t
116321936Shselasky* NAME
117321936Shselasky*  osm_transaction_mgr_t
118321936Shselasky*
119321936Shselasky* DESCRIPTION
120321936Shselasky*  This structure defines the transaction manager.
121321936Shselasky*  It holds a qlist and a qmap, a lock on the transaction manager, and
122321936Shselasky*  a timer used for the list.
123321936Shselasky*  The manager is responsible for keeping track of every request mad that was
124321936Shselasky*  sent. It is used for finding mads according to their transaction id, and for
125321936Shselasky*  acting as an event wheel - reporting as error each packet was supposed to get
126321936Shselasky*  a response and didn't get one by the timeout time expected.
127321936Shselasky*
128321936Shselasky*  Both the list and the map hold the osm_madw_req_t objects - one for every madw.
129321936Shselasky*
130321936Shselasky*  Managing of the list:
131321936Shselasky*  The timer wakes on the timeout of the first madw. If the waking_time is greater than
132321936Shselasky*  the current time - then the mad received a response. If not - the mad didn't get
133321936Shselasky*  its response.
134321936Shselasky*
135321936Shselasky* SYNOPSIS
136321936Shselasky*/
137321936Shselaskytypedef struct _osm_transaction_mgr {
138321936Shselasky	cl_qmap_t *madw_by_tid_map_p;
139321936Shselasky	cl_qlist_t *madw_reqs_list_p;
140321936Shselasky	cl_spinlock_t transaction_mgr_lock;
141321936Shselasky	cl_timer_t madw_list_timer;
142321936Shselasky} osm_transaction_mgr_t;
143321936Shselasky
144321936Shselasky/*
145321936Shselasky* FIELDS
146321936Shselasky*  madw_by_tid_map_p
147321936Shselasky*     A qmap with key = transaction id. and value of osm_madw_req_t.
148321936Shselasky*
149321936Shselasky*  madw_reqs_list_p
150321936Shselasky*     A qlist of all the madw with their waking time.
151321936Shselasky*
152321936Shselasky*  transaction_mgr_lock
153321936Shselasky*     Lock used on the transaction manager - make sure changes on it are serial.
154321936Shselasky*
155321936Shselasky*  madw_list_timer
156321936Shselasky*     Timer on the list.
157321936Shselasky*********/
158321936Shselasky
159321936Shselasky/****f* OpenSM: Transaction Manager/osm_transaction_mgr_init
160321936Shselasky* NAME
161321936Shselasky*	osm_transaction_mgr_init
162321936Shselasky*
163321936Shselasky* DESCRIPTION
164321936Shselasky*	Initialize the transaction manager.
165321936Shselasky*  Will update the p_transaction_mgr in the vendor object with
166321936Shselasky*  the new Transaction Manager created.*
167321936Shselasky*
168321936Shselasky* SYNOPSIS
169321936Shselasky*/
170321936Shselaskyvoid osm_transaction_mgr_init(IN osm_vendor_t * const p_vend);
171321936Shselasky
172321936Shselasky/*
173321936Shselasky* PARAMETERS
174321936Shselasky*	p_vend
175321936Shselasky*		[in] Pointer to a Osm Vendor object.
176321936Shselasky*
177321936Shselasky*********/
178321936Shselasky
179321936Shselasky/****f* OpenSM: Transaction Manager/osm_transaction_mgr_destroy
180321936Shselasky* NAME
181321936Shselasky*	osm_transaction_mgr_destroy
182321936Shselasky*
183321936Shselasky* DESCRIPTION
184321936Shselasky*	Destroy the transaction manager.
185321936Shselasky*  Will de-allocate all memory allocated by the Transaction
186321936Shselasky*  Manager up to now.
187321936Shselasky*
188321936Shselasky* SYNOPSIS
189321936Shselasky*/
190321936Shselaskyvoid osm_transaction_mgr_destroy(IN osm_vendor_t * const p_vend);
191321936Shselasky
192321936Shselasky/*
193321936Shselasky* PARAMETERS
194321936Shselasky*	p_vend
195321936Shselasky*		[in] Pointer to a Osm Vendor object.
196321936Shselasky*
197321936Shselasky*********/
198321936Shselasky
199321936Shselasky/****f* OpenSM: Transaction Manager/osm_transaction_mgr_insert_madw
200321936Shselasky* NAME
201321936Shselasky*	osm_transaction_mgr_insert_madw
202321936Shselasky*
203321936Shselasky* DESCRIPTION
204321936Shselasky*	Insert a new madw to the manager. The madw is added with a waking_time,
205321936Shselasky*  Which is equal to the current_time + timeout. This is the maximum time
206321936Shselasky*  that the madw can leave without being handled (e.g - get a response).
207321936Shselasky*  If there are no madw saved in the manager - start the timer for vendor
208321936Shselasky*  timeout period.
209321936Shselasky*
210321936Shselasky* SYNOPSIS
211321936Shselasky*/
212321936Shselaskyib_api_status_t
213321936Shselaskyosm_transaction_mgr_insert_madw(IN osm_bind_handle_t * p_bind,
214321936Shselasky				IN osm_madw_t * p_madw);
215321936Shselasky/*
216321936Shselasky* PARAMETERS
217321936Shselasky*	p_vend
218321936Shselasky*		[in] Pointer to a mtl bind object.
219321936Shselasky*
220321936Shselasky*  p_madw
221321936Shselasky*     [in] Pointer to the Mad Wrapper to be added.
222321936Shselasky*
223321936Shselasky*********/
224321936Shselasky
225321936Shselasky/****f* OpenSM: Transaction Manager/osm_transaction_mgr_erase_madw
226321936Shselasky* NAME
227321936Shselasky*	osm_transaction_mgr_erase_madw
228321936Shselasky*
229321936Shselasky* DESCRIPTION
230321936Shselasky*	Erase a madw object from the manager.
231321936Shselasky*  The removal is done using the transaction id of the mad - using
232321936Shselasky*  it the madw_p is allocated (in the qmap) and removed from the
233321936Shselasky*  qmap and qlist.
234321936Shselasky*
235321936Shselasky* SYNOPSIS
236321936Shselasky*/
237321936Shselaskyib_api_status_t
238321936Shselaskyosm_transaction_mgr_erase_madw(IN osm_vendor_t * const p_vend,
239321936Shselasky			       IN ib_mad_t * p_mad);
240321936Shselasky/*
241321936Shselasky* PARAMETERS
242321936Shselasky*	p_vend
243321936Shselasky*		[in] Pointer to a Osm Vendor object.
244321936Shselasky*
245321936Shselasky*  p_mad
246321936Shselasky*      [in] Pointer to the Mad to be removed.
247321936Shselasky*
248321936Shselasky*********/
249321936Shselasky
250321936Shselasky/****f* OpenSM: Transaction Manager/osm_transaction_mgr_get_madw_for_tid
251321936Shselasky* NAME
252321936Shselasky*	osm_transaction_mgr_get_madw_for_tid
253321936Shselasky*
254321936Shselasky* DESCRIPTION
255321936Shselasky*	Return the mad wrapper, given the p_mad (and in it the transaction id)
256321936Shselasky*
257321936Shselasky* SYNOPSIS
258321936Shselasky*/
259321936Shselaskyib_api_status_t
260321936Shselaskyosm_transaction_mgr_get_madw_for_tid(IN osm_vendor_t * const p_vend,
261321936Shselasky				     IN ib_mad_t * const p_mad,
262321936Shselasky				     OUT osm_madw_t ** req_madw_p);
263321936Shselasky/*
264321936Shselasky* PARAMETERS
265321936Shselasky*	p_vend
266321936Shselasky*		[in] Pointer to a Osm Vendor object.
267321936Shselasky*
268321936Shselasky*  p_mad
269321936Shselasky*      [in] Pointer to the Mad to be located.
270321936Shselasky*
271321936Shselasky* req_madw_p
272321936Shselasky*      [out] Pointer to the mad Wrapper to be found.
273321936Shselasky*
274321936Shselasky*********/
275321936Shselasky
276321936Shselasky/****f* OpenSM: Transaction Manager/osm_transaction_mgr_callback
277321936Shselasky* NAME
278321936Shselasky*	osm_transaction_mgr_callback
279321936Shselasky*
280321936Shselasky* DESCRIPTION
281321936Shselasky*	This callback is called on timeout of the timer.
282321936Shselasky*  It checks the time of the head madw in the qlist, and compares it to
283321936Shselasky*  the current time.
284321936Shselasky*  Will send an error callback if the time of the madw is less than the
285321936Shselasky*  current time - this means that the madw wasn't removed in the timeout
286321936Shselasky*  it was supposed to be handled.
287321936Shselasky*
288321936Shselasky* SYNOPSIS
289321936Shselasky*/
290321936Shselaskyvoid osm_transaction_mgr_callback(IN void *context);
291321936Shselasky/*
292321936Shselasky* PARAMETERS
293321936Shselasky*	context
294321936Shselasky*		[in] void* context
295321936Shselasky*
296321936Shselasky*********/
297321936Shselasky
298321936ShselaskyEND_C_DECLS
299321936Shselasky#endif				/* _OSM_TRANSACTION_MGR_H_ */
300