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 MTL Vendor
39219820Sjeff *	   This object is part of the OpenSM family of objects.
40219820Sjeff */
41219820Sjeff
42219820Sjeff#ifndef _OSM_TRANSACTION_MGR_H_
43219820Sjeff#define _OSM_TRANSACTION_MGR_H_
44219820Sjeff
45219820Sjeff  /*
46219820Sjeff     #include <vapi_types.h>
47219820Sjeff     #include <evapi.h>
48219820Sjeff   */
49219820Sjeff
50219820Sjeff#include <iba/ib_types.h>
51219820Sjeff#include <iba/ib_al.h>
52219820Sjeff#include <complib/cl_qlist.h>
53219820Sjeff#include <complib/cl_qmap.h>
54219820Sjeff#include <complib/cl_timer.h>
55219820Sjeff#include <complib/cl_thread.h>
56219820Sjeff#include <complib/cl_types_osd.h>
57219820Sjeff#include <complib/cl_spinlock.h>
58219820Sjeff#include <opensm/osm_base.h>
59219820Sjeff#include <opensm/osm_log.h>
60219820Sjeff#include <opensm/osm_madw.h>
61219820Sjeff#ifdef OSM_VENDOR_INTF_MTL
62219820Sjeff#include <ib_mgt.h>
63219820Sjeff#include <opensm/osm_mtl_bind.h>
64219820Sjeff#endif
65219820Sjeff
66219820Sjeff#ifdef __cplusplus
67219820Sjeff#  define BEGIN_C_DECLS extern "C" {
68219820Sjeff#  define END_C_DECLS   }
69219820Sjeff#else				/* !__cplusplus */
70219820Sjeff#  define BEGIN_C_DECLS
71219820Sjeff#  define END_C_DECLS
72219820Sjeff#endif				/* __cplusplus */
73219820Sjeff
74219820SjeffBEGIN_C_DECLS
75219820Sjeff/****s* OpenSM: Transaction Manager/osm_madw_req_t
76219820Sjeff* NAME
77219820Sjeff*  osm_madw_req_t
78219820Sjeff*
79219820Sjeff* DESCRIPTION
80219820Sjeff*  The structure defining each object in the transaction_mgr.
81219820Sjeff*  For every request mad sent, we will save such an object for it.
82219820Sjeff*
83219820Sjeff* SYNOPSIS
84219820Sjeff*/
85219820Sjefftypedef struct _osm_madw_req {
86219820Sjeff	cl_list_item_t list_item;
87219820Sjeff	cl_map_item_t map_item;
88219820Sjeff	osm_madw_t *p_madw;
89219820Sjeff	uint64_t waking_time;
90219820Sjeff	uint8_t retry_cnt;
91219820Sjeff	osm_bind_handle_t *p_bind;
92219820Sjeff} osm_madw_req_t;
93219820Sjeff
94219820Sjeff/*
95219820Sjeff* FIELDS
96219820Sjeff*  list_item
97219820Sjeff*     List item for qlist linkage. Must be first element!!
98219820Sjeff*
99219820Sjeff*  map_item
100219820Sjeff*     Map item for qmap linkage.
101219820Sjeff*
102219820Sjeff*  p_madw
103219820Sjeff*     pointer to mad wrapper that is expecting to get a response.
104219820Sjeff*
105219820Sjeff*  waking_time
106219820Sjeff*     Time stamp (in microseconds) when the p_madw needs to wake up.
107219820Sjeff*     This value is
108219820Sjeff*      cl_get_time_stamp() + timeout  during the sending of the mad.
109219820Sjeff*      where timeout should be given in microseconds.
110219820Sjeff*
111219820Sjeff*  retry_cnt
112219820Sjeff*     The number of outstanding retries to be called.
113219820Sjeff*********/
114219820Sjeff
115219820Sjeff/****s* OpenSM: Transaction Manager/osm_transaction_mgr_t
116219820Sjeff* NAME
117219820Sjeff*  osm_transaction_mgr_t
118219820Sjeff*
119219820Sjeff* DESCRIPTION
120219820Sjeff*  This structure defines the transaction manager.
121219820Sjeff*  It holds a qlist and a qmap, a lock on the transaction manager, and
122219820Sjeff*  a timer used for the list.
123219820Sjeff*  The manager is responsible for keeping track of every request mad that was
124219820Sjeff*  sent. It is used for finding mads according to their transaction id, and for
125219820Sjeff*  acting as an event wheel - reporting as error each packet was supposed to get
126219820Sjeff*  a response and didn't get one by the timeout time expected.
127219820Sjeff*
128219820Sjeff*  Both the list and the map hold the osm_madw_req_t objects - one for every madw.
129219820Sjeff*
130219820Sjeff*  Managing of the list:
131219820Sjeff*  The timer wakes on the timeout of the first madw. If the waking_time is greater than
132219820Sjeff*  the current time - then the mad received a response. If not - the mad didn't get
133219820Sjeff*  its response.
134219820Sjeff*
135219820Sjeff* SYNOPSIS
136219820Sjeff*/
137219820Sjefftypedef struct _osm_transaction_mgr {
138219820Sjeff	cl_qmap_t *madw_by_tid_map_p;
139219820Sjeff	cl_qlist_t *madw_reqs_list_p;
140219820Sjeff	cl_spinlock_t transaction_mgr_lock;
141219820Sjeff	cl_timer_t madw_list_timer;
142219820Sjeff} osm_transaction_mgr_t;
143219820Sjeff
144219820Sjeff/*
145219820Sjeff* FIELDS
146219820Sjeff*  madw_by_tid_map_p
147219820Sjeff*     A qmap with key = transaction id. and value of osm_madw_req_t.
148219820Sjeff*
149219820Sjeff*  madw_reqs_list_p
150219820Sjeff*     A qlist of all the madw with their waking time.
151219820Sjeff*
152219820Sjeff*  transaction_mgr_lock
153219820Sjeff*     Lock used on the transaction manager - make sure changes on it are serial.
154219820Sjeff*
155219820Sjeff*  madw_list_timer
156219820Sjeff*     Timer on the list.
157219820Sjeff*********/
158219820Sjeff
159219820Sjeff/****f* OpenSM: Transaction Manager/osm_transaction_mgr_init
160219820Sjeff* NAME
161219820Sjeff*	osm_transaction_mgr_init
162219820Sjeff*
163219820Sjeff* DESCRIPTION
164219820Sjeff*	Initialize the transaction manager.
165219820Sjeff*  Will update the p_transaction_mgr in the vendor object with
166219820Sjeff*  the new Transaction Manager created.*
167219820Sjeff*
168219820Sjeff* SYNOPSIS
169219820Sjeff*/
170219820Sjeffvoid osm_transaction_mgr_init(IN osm_vendor_t * const p_vend);
171219820Sjeff
172219820Sjeff/*
173219820Sjeff* PARAMETERS
174219820Sjeff*	p_vend
175219820Sjeff*		[in] Pointer to a Osm Vendor object.
176219820Sjeff*
177219820Sjeff*********/
178219820Sjeff
179219820Sjeff/****f* OpenSM: Transaction Manager/osm_transaction_mgr_destroy
180219820Sjeff* NAME
181219820Sjeff*	osm_transaction_mgr_destroy
182219820Sjeff*
183219820Sjeff* DESCRIPTION
184219820Sjeff*	Destroy the transaction manager.
185219820Sjeff*  Will de-allocate all memory allocated by the Transaction
186219820Sjeff*  Manager up to now.
187219820Sjeff*
188219820Sjeff* SYNOPSIS
189219820Sjeff*/
190219820Sjeffvoid osm_transaction_mgr_destroy(IN osm_vendor_t * const p_vend);
191219820Sjeff
192219820Sjeff/*
193219820Sjeff* PARAMETERS
194219820Sjeff*	p_vend
195219820Sjeff*		[in] Pointer to a Osm Vendor object.
196219820Sjeff*
197219820Sjeff*********/
198219820Sjeff
199219820Sjeff/****f* OpenSM: Transaction Manager/osm_transaction_mgr_insert_madw
200219820Sjeff* NAME
201219820Sjeff*	osm_transaction_mgr_insert_madw
202219820Sjeff*
203219820Sjeff* DESCRIPTION
204219820Sjeff*	Insert a new madw to the manager. The madw is added with a waking_time,
205219820Sjeff*  Which is equal to the current_time + timeout. This is the maximum time
206219820Sjeff*  that the madw can leave without being handled (e.g - get a response).
207219820Sjeff*  If there are no madw saved in the manager - start the timer for vendor
208219820Sjeff*  timeout period.
209219820Sjeff*
210219820Sjeff* SYNOPSIS
211219820Sjeff*/
212219820Sjeffib_api_status_t
213219820Sjeffosm_transaction_mgr_insert_madw(IN osm_bind_handle_t * p_bind,
214219820Sjeff				IN osm_madw_t * p_madw);
215219820Sjeff/*
216219820Sjeff* PARAMETERS
217219820Sjeff*	p_vend
218219820Sjeff*		[in] Pointer to a mtl bind object.
219219820Sjeff*
220219820Sjeff*  p_madw
221219820Sjeff*     [in] Pointer to the Mad Wrapper to be added.
222219820Sjeff*
223219820Sjeff*********/
224219820Sjeff
225219820Sjeff/****f* OpenSM: Transaction Manager/osm_transaction_mgr_erase_madw
226219820Sjeff* NAME
227219820Sjeff*	osm_transaction_mgr_erase_madw
228219820Sjeff*
229219820Sjeff* DESCRIPTION
230219820Sjeff*	Erase a madw object from the manager.
231219820Sjeff*  The removal is done using the transaction id of the mad - using
232219820Sjeff*  it the madw_p is allocated (in the qmap) and removed from the
233219820Sjeff*  qmap and qlist.
234219820Sjeff*
235219820Sjeff* SYNOPSIS
236219820Sjeff*/
237219820Sjeffib_api_status_t
238219820Sjeffosm_transaction_mgr_erase_madw(IN osm_vendor_t * const p_vend,
239219820Sjeff			       IN ib_mad_t * p_mad);
240219820Sjeff/*
241219820Sjeff* PARAMETERS
242219820Sjeff*	p_vend
243219820Sjeff*		[in] Pointer to a Osm Vendor object.
244219820Sjeff*
245219820Sjeff*  p_mad
246219820Sjeff*      [in] Pointer to the Mad to be removed.
247219820Sjeff*
248219820Sjeff*********/
249219820Sjeff
250219820Sjeff/****f* OpenSM: Transaction Manager/osm_transaction_mgr_get_madw_for_tid
251219820Sjeff* NAME
252219820Sjeff*	osm_transaction_mgr_get_madw_for_tid
253219820Sjeff*
254219820Sjeff* DESCRIPTION
255219820Sjeff*	Return the mad wrapper, given the p_mad (and in it the transaction id)
256219820Sjeff*
257219820Sjeff* SYNOPSIS
258219820Sjeff*/
259219820Sjeffib_api_status_t
260219820Sjeffosm_transaction_mgr_get_madw_for_tid(IN osm_vendor_t * const p_vend,
261219820Sjeff				     IN ib_mad_t * const p_mad,
262219820Sjeff				     OUT osm_madw_t ** req_madw_p);
263219820Sjeff/*
264219820Sjeff* PARAMETERS
265219820Sjeff*	p_vend
266219820Sjeff*		[in] Pointer to a Osm Vendor object.
267219820Sjeff*
268219820Sjeff*  p_mad
269219820Sjeff*      [in] Pointer to the Mad to be located.
270219820Sjeff*
271219820Sjeff* req_madw_p
272219820Sjeff*      [out] Pointer to the mad Wrapper to be found.
273219820Sjeff*
274219820Sjeff*********/
275219820Sjeff
276219820Sjeff/****f* OpenSM: Transaction Manager/osm_transaction_mgr_callback
277219820Sjeff* NAME
278219820Sjeff*	osm_transaction_mgr_callback
279219820Sjeff*
280219820Sjeff* DESCRIPTION
281219820Sjeff*	This callback is called on timeout of the timer.
282219820Sjeff*  It checks the time of the head madw in the qlist, and compares it to
283219820Sjeff*  the current time.
284219820Sjeff*  Will send an error callback if the time of the madw is less than the
285219820Sjeff*  current time - this means that the madw wasn't removed in the timeout
286219820Sjeff*  it was supposed to be handled.
287219820Sjeff*
288219820Sjeff* SYNOPSIS
289219820Sjeff*/
290219820Sjeffvoid osm_transaction_mgr_callback(IN void *context);
291219820Sjeff/*
292219820Sjeff* PARAMETERS
293219820Sjeff*	context
294219820Sjeff*		[in] void* context
295219820Sjeff*
296219820Sjeff*********/
297219820Sjeff
298219820SjeffEND_C_DECLS
299219820Sjeff#endif				/* _OSM_TRANSACTION_MGR_H_ */
300