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.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
38 * Definition of interface for the MTL Vendor
39 * This object is part of the OpenSM family of objects.
42 #ifndef _OSM_TRANSACTION_MGR_H_
43 #define _OSM_TRANSACTION_MGR_H_
46 #include <vapi_types.h>
50 #include <iba/ib_types.h>
51 #include <iba/ib_al.h>
52 #include <complib/cl_qlist.h>
53 #include <complib/cl_qmap.h>
54 #include <complib/cl_timer.h>
55 #include <complib/cl_thread.h>
56 #include <complib/cl_types_osd.h>
57 #include <complib/cl_spinlock.h>
58 #include <opensm/osm_base.h>
59 #include <opensm/osm_log.h>
60 #include <opensm/osm_madw.h>
61 #ifdef OSM_VENDOR_INTF_MTL
63 #include <opensm/osm_mtl_bind.h>
67 # define BEGIN_C_DECLS extern "C" {
68 # define END_C_DECLS }
69 #else /* !__cplusplus */
70 # define BEGIN_C_DECLS
72 #endif /* __cplusplus */
75 /****s* OpenSM: Transaction Manager/osm_madw_req_t
80 * The structure defining each object in the transaction_mgr.
81 * For every request mad sent, we will save such an object for it.
85 typedef struct _osm_madw_req {
86 cl_list_item_t list_item;
87 cl_map_item_t map_item;
91 osm_bind_handle_t *p_bind;
97 * List item for qlist linkage. Must be first element!!
100 * Map item for qmap linkage.
103 * pointer to mad wrapper that is expecting to get a response.
106 * Time stamp (in microseconds) when the p_madw needs to wake up.
108 * cl_get_time_stamp() + timeout during the sending of the mad.
109 * where timeout should be given in microseconds.
112 * The number of outstanding retries to be called.
115 /****s* OpenSM: Transaction Manager/osm_transaction_mgr_t
117 * osm_transaction_mgr_t
120 * This structure defines the transaction manager.
121 * It holds a qlist and a qmap, a lock on the transaction manager, and
122 * a timer used for the list.
123 * The manager is responsible for keeping track of every request mad that was
124 * sent. It is used for finding mads according to their transaction id, and for
125 * acting as an event wheel - reporting as error each packet was supposed to get
126 * a response and didn't get one by the timeout time expected.
128 * Both the list and the map hold the osm_madw_req_t objects - one for every madw.
130 * Managing of the list:
131 * The timer wakes on the timeout of the first madw. If the waking_time is greater than
132 * the current time - then the mad received a response. If not - the mad didn't get
137 typedef struct _osm_transaction_mgr {
138 cl_qmap_t *madw_by_tid_map_p;
139 cl_qlist_t *madw_reqs_list_p;
140 cl_spinlock_t transaction_mgr_lock;
141 cl_timer_t madw_list_timer;
142 } osm_transaction_mgr_t;
147 * A qmap with key = transaction id. and value of osm_madw_req_t.
150 * A qlist of all the madw with their waking time.
152 * transaction_mgr_lock
153 * Lock used on the transaction manager - make sure changes on it are serial.
159 /****f* OpenSM: Transaction Manager/osm_transaction_mgr_init
161 * osm_transaction_mgr_init
164 * Initialize the transaction manager.
165 * Will update the p_transaction_mgr in the vendor object with
166 * the new Transaction Manager created.*
170 void osm_transaction_mgr_init(IN osm_vendor_t * const p_vend);
175 * [in] Pointer to a Osm Vendor object.
179 /****f* OpenSM: Transaction Manager/osm_transaction_mgr_destroy
181 * osm_transaction_mgr_destroy
184 * Destroy the transaction manager.
185 * Will de-allocate all memory allocated by the Transaction
190 void osm_transaction_mgr_destroy(IN osm_vendor_t * const p_vend);
195 * [in] Pointer to a Osm Vendor object.
199 /****f* OpenSM: Transaction Manager/osm_transaction_mgr_insert_madw
201 * osm_transaction_mgr_insert_madw
204 * Insert a new madw to the manager. The madw is added with a waking_time,
205 * Which is equal to the current_time + timeout. This is the maximum time
206 * that the madw can leave without being handled (e.g - get a response).
207 * If there are no madw saved in the manager - start the timer for vendor
213 osm_transaction_mgr_insert_madw(IN osm_bind_handle_t * p_bind,
214 IN osm_madw_t * p_madw);
218 * [in] Pointer to a mtl bind object.
221 * [in] Pointer to the Mad Wrapper to be added.
225 /****f* OpenSM: Transaction Manager/osm_transaction_mgr_erase_madw
227 * osm_transaction_mgr_erase_madw
230 * Erase a madw object from the manager.
231 * The removal is done using the transaction id of the mad - using
232 * it the madw_p is allocated (in the qmap) and removed from the
238 osm_transaction_mgr_erase_madw(IN osm_vendor_t * const p_vend,
239 IN ib_mad_t * p_mad);
243 * [in] Pointer to a Osm Vendor object.
246 * [in] Pointer to the Mad to be removed.
250 /****f* OpenSM: Transaction Manager/osm_transaction_mgr_get_madw_for_tid
252 * osm_transaction_mgr_get_madw_for_tid
255 * Return the mad wrapper, given the p_mad (and in it the transaction id)
260 osm_transaction_mgr_get_madw_for_tid(IN osm_vendor_t * const p_vend,
261 IN ib_mad_t * const p_mad,
262 OUT osm_madw_t ** req_madw_p);
266 * [in] Pointer to a Osm Vendor object.
269 * [in] Pointer to the Mad to be located.
272 * [out] Pointer to the mad Wrapper to be found.
276 /****f* OpenSM: Transaction Manager/osm_transaction_mgr_callback
278 * osm_transaction_mgr_callback
281 * This callback is called on timeout of the timer.
282 * It checks the time of the head madw in the qlist, and compares it to
284 * Will send an error callback if the time of the madw is less than the
285 * current time - this means that the madw wasn't removed in the timeout
286 * it was supposed to be handled.
290 void osm_transaction_mgr_callback(IN void *context);
299 #endif /* _OSM_TRANSACTION_MGR_H_ */