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
39 #include <sys/types.h>
42 #include <complib/cl_qmap.h>
43 #include <opensm/osm_madw.h>
44 #include <complib/cl_event_wheel.h>
46 #include <vendor/osm_vendor_mlx_rmpp_ctx.h>
49 # define BEGIN_C_DECLS extern "C" {
50 # define END_C_DECLS }
51 #else /* !__cplusplus */
52 # define BEGIN_C_DECLS
54 #endif /* __cplusplus */
58 typedef enum _osmv_txn_rmpp_state {
60 OSMV_TXN_RMPP_NONE = 0, /* Not part of RMPP transaction */
63 OSMV_TXN_RMPP_RECEIVER
64 } osmv_txn_rmpp_state_t;
66 typedef struct _osmv_rmpp_txfr {
68 osmv_txn_rmpp_state_t rmpp_state;
69 boolean_t is_rmpp_init_by_peer;
70 osmv_rmpp_send_ctx_t *p_rmpp_send_ctx;
71 osmv_rmpp_recv_ctx_t *p_rmpp_recv_ctx;
75 typedef struct _osmv_txn_ctx {
77 /* The original Transaction ID */
79 /* The key by which the Transaction is stored */
82 /* RMPP Send/Receive contexts, if applicable */
83 osmv_rmpp_txfr_t rmpp_txfr;
85 /* A MAD that was sent during the transaction (request or response) */
88 /* Reference to a log to enable tracing */
93 typedef struct _osmv_txn_mgr {
95 /* Container of all the transactions */
99 cl_event_wheel_t *p_event_wheel;
101 /* Reference to a log to enable tracing */
106 /* * * * * * * osmv_txn_ctx_t functions * * * * * * * * */
113 * allocs & inits the osmv_txn_ctx obj and insert it into the db
118 osmv_txn_init(IN osm_bind_handle_t h_bind,
119 IN uint64_t tid, IN uint64_t key, OUT osmv_txn_ctx_t ** pp_txn);
123 * osmv_rmpp_txfr_init_sender
126 * init the rmpp send ctx in the transaction
132 osmv_txn_init_rmpp_sender(IN osm_bind_handle_t h_bind,
133 IN osmv_txn_ctx_t * p_txn, IN osm_madw_t * p_madw);
137 * osmv_rmpp_txfr_init_receiver
140 * init the rmpp recv ctx in the transaction
146 osmv_txn_init_rmpp_receiver(IN osm_bind_handle_t h_bind,
147 IN osmv_txn_ctx_t * p_txn,
148 IN boolean_t is_init_by_peer);
155 * destroys txn object and removes it from the db
161 osmv_txn_done(IN osm_bind_handle_t h_bind,
162 IN uint64_t key, IN boolean_t is_in_cb);
168 * returns tid of the transaction
172 static inline uint64_t osmv_txn_get_tid(IN osmv_txn_ctx_t * p_txn)
174 CL_ASSERT(NULL != p_txn);
183 * returns key of the transaction
188 static inline uint64_t osmv_txn_get_key(IN osmv_txn_ctx_t * p_txn)
190 CL_ASSERT(NULL != p_txn);
196 * osmv_txn_is_rmpp_init_by_peer
199 * returns whether the rmpp txfr was init by the peer
204 static inline boolean_t osmv_txn_is_rmpp_init_by_peer(IN osmv_txn_ctx_t * p_txn)
206 CL_ASSERT(NULL != p_txn);
207 return p_txn->rmpp_txfr.is_rmpp_init_by_peer;
212 * osmv_txn_get_rmpp_send_ctx
215 * returns osmv_rmpp_send_ctx obj
219 static inline osmv_rmpp_send_ctx_t *osmv_txn_get_rmpp_send_ctx(IN osmv_txn_ctx_t
222 CL_ASSERT(NULL != p_txn);
223 return p_txn->rmpp_txfr.p_rmpp_send_ctx;
228 * osmv_txn_get_rmpp_recv_ctx
231 * returns osmv_rmpp_recv_ctx obj
235 static inline osmv_rmpp_recv_ctx_t *osmv_txn_get_rmpp_recv_ctx(IN osmv_txn_ctx_t
238 CL_ASSERT(NULL != p_txn);
239 return p_txn->rmpp_txfr.p_rmpp_recv_ctx;
244 * osmv_txn_get_rmpp_state
247 * returns the rmpp role of the transactino ( send/ recv)
251 static inline osmv_txn_rmpp_state_t
252 osmv_txn_get_rmpp_state(IN osmv_txn_ctx_t * p_txn)
254 CL_ASSERT(NULL != p_txn);
255 return p_txn->rmpp_txfr.rmpp_state;
260 * osmv_txn_set_rmpp_state
263 * sets the rmpp role of the transaction (send/ recv)
268 osmv_txn_set_rmpp_state(IN osmv_txn_ctx_t * p_txn,
269 IN osmv_txn_rmpp_state_t state)
271 CL_ASSERT(NULL != p_txn);
272 p_txn->rmpp_txfr.rmpp_state = state;
280 * returns the requester madw
284 static inline osm_madw_t *osmv_txn_get_madw(IN osmv_txn_ctx_t * p_txn)
286 CL_ASSERT(NULL != p_txn);
287 return p_txn->p_madw;
295 * sets the requester madw
300 osmv_txn_set_madw(IN osmv_txn_ctx_t * p_txn, IN osm_madw_t * p_madw)
302 CL_ASSERT(NULL != p_txn);
303 p_txn->p_madw = p_madw;
308 * osmv_txn_set_timeout_ev
316 osmv_txn_set_timeout_ev(IN osm_bind_handle_t h_bind,
317 IN uint64_t key, IN uint64_t msec);
320 * osmv_txn_remove_timeout_ev
327 void osmv_txn_remove_timeout_ev(IN osm_bind_handle_t h_bind, IN uint64_t key);
333 * get a transaction by its key
339 osmv_txn_lookup(IN osm_bind_handle_t h_bind,
340 IN uint64_t key, OUT osmv_txn_ctx_t ** pp_txn);
342 void osmv_txn_abort_rmpp_txns(IN osm_bind_handle_t h_bind);
344 /* * * * * * * * * * * * */
350 * c'tor for txn mgr obj
355 osmv_txnmgr_init(IN osmv_txn_mgr_t * p_tx_mgr,
356 IN osm_log_t * p_log, IN cl_spinlock_t * p_lock);
363 * c'tor for txn mgr obj
367 void osmv_txnmgr_done(IN osm_bind_handle_t h_bind);
369 void osmv_txn_lock(IN osm_bind_handle_t h_bind);
370 void osmv_txn_unlock(IN osm_bind_handle_t h_bind);
372 inline static uint64_t osmv_txn_uniq_key(IN uint64_t tid)
374 uint64_t pid = getpid();
376 return ((pid << 32) | (tid & 0xFFFFFFFF));
380 #endif /* _OSMV_TXN_H_ */