osm_vendor_mlx_txn.h revision 219820
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#ifndef _OSMV_TXN_H_ 37219820Sjeff#define _OSMV_TXN_H_ 38219820Sjeff 39219820Sjeff#include <sys/types.h> 40219820Sjeff#include <unistd.h> 41219820Sjeff 42219820Sjeff#include <complib/cl_qmap.h> 43219820Sjeff#include <opensm/osm_madw.h> 44219820Sjeff#include <complib/cl_event_wheel.h> 45219820Sjeff 46219820Sjeff#include <vendor/osm_vendor_mlx_rmpp_ctx.h> 47219820Sjeff 48219820Sjeff#ifdef __cplusplus 49219820Sjeff# define BEGIN_C_DECLS extern "C" { 50219820Sjeff# define END_C_DECLS } 51219820Sjeff#else /* !__cplusplus */ 52219820Sjeff# define BEGIN_C_DECLS 53219820Sjeff# define END_C_DECLS 54219820Sjeff#endif /* __cplusplus */ 55219820Sjeff 56219820SjeffBEGIN_C_DECLS 57219820Sjeff 58219820Sjefftypedef enum _osmv_txn_rmpp_state { 59219820Sjeff 60219820Sjeff OSMV_TXN_RMPP_NONE = 0, /* Not part of RMPP transaction */ 61219820Sjeff 62219820Sjeff OSMV_TXN_RMPP_SENDER, 63219820Sjeff OSMV_TXN_RMPP_RECEIVER 64219820Sjeff} osmv_txn_rmpp_state_t; 65219820Sjeff 66219820Sjefftypedef struct _osmv_rmpp_txfr { 67219820Sjeff 68219820Sjeff osmv_txn_rmpp_state_t rmpp_state; 69219820Sjeff boolean_t is_rmpp_init_by_peer; 70219820Sjeff osmv_rmpp_send_ctx_t *p_rmpp_send_ctx; 71219820Sjeff osmv_rmpp_recv_ctx_t *p_rmpp_recv_ctx; 72219820Sjeff 73219820Sjeff} osmv_rmpp_txfr_t; 74219820Sjeff 75219820Sjefftypedef struct _osmv_txn_ctx { 76219820Sjeff 77219820Sjeff /* The original Transaction ID */ 78219820Sjeff uint64_t tid; 79219820Sjeff /* The key by which the Transaction is stored */ 80219820Sjeff uint64_t key; 81219820Sjeff 82219820Sjeff /* RMPP Send/Receive contexts, if applicable */ 83219820Sjeff osmv_rmpp_txfr_t rmpp_txfr; 84219820Sjeff 85219820Sjeff /* A MAD that was sent during the transaction (request or response) */ 86219820Sjeff osm_madw_t *p_madw; 87219820Sjeff 88219820Sjeff /* Reference to a log to enable tracing */ 89219820Sjeff osm_log_t *p_log; 90219820Sjeff 91219820Sjeff} osmv_txn_ctx_t; 92219820Sjeff 93219820Sjefftypedef struct _osmv_txn_mgr { 94219820Sjeff 95219820Sjeff /* Container of all the transactions */ 96219820Sjeff cl_qmap_t *p_txn_map; 97219820Sjeff 98219820Sjeff /* The timeouts DB */ 99219820Sjeff cl_event_wheel_t *p_event_wheel; 100219820Sjeff 101219820Sjeff /* Reference to a log to enable tracing */ 102219820Sjeff osm_log_t *p_log; 103219820Sjeff 104219820Sjeff} osmv_txn_mgr_t; 105219820Sjeff 106219820Sjeff/* * * * * * * osmv_txn_ctx_t functions * * * * * * * * */ 107219820Sjeff 108219820Sjeff/* 109219820Sjeff * NAME 110219820Sjeff * osmv_txn_init 111219820Sjeff * 112219820Sjeff * DESCRIPTION 113219820Sjeff * allocs & inits the osmv_txn_ctx obj and insert it into the db 114219820Sjeff * SEE ALSO 115219820Sjeff * 116219820Sjeff */ 117219820Sjeffib_api_status_t 118219820Sjeffosmv_txn_init(IN osm_bind_handle_t h_bind, 119219820Sjeff IN uint64_t tid, IN uint64_t key, OUT osmv_txn_ctx_t ** pp_txn); 120219820Sjeff 121219820Sjeff/* 122219820Sjeff * NAME 123219820Sjeff * osmv_rmpp_txfr_init_sender 124219820Sjeff * 125219820Sjeff * DESCRIPTION 126219820Sjeff * init the rmpp send ctx in the transaction 127219820Sjeff * 128219820Sjeff * SEE ALSO 129219820Sjeff * 130219820Sjeff */ 131219820Sjeffib_api_status_t 132219820Sjeffosmv_txn_init_rmpp_sender(IN osm_bind_handle_t h_bind, 133219820Sjeff IN osmv_txn_ctx_t * p_txn, IN osm_madw_t * p_madw); 134219820Sjeff 135219820Sjeff/* 136219820Sjeff * NAME 137219820Sjeff * osmv_rmpp_txfr_init_receiver 138219820Sjeff * 139219820Sjeff * DESCRIPTION 140219820Sjeff * init the rmpp recv ctx in the transaction 141219820Sjeff * 142219820Sjeff * SEE ALSO 143219820Sjeff * 144219820Sjeff */ 145219820Sjeffib_api_status_t 146219820Sjeffosmv_txn_init_rmpp_receiver(IN osm_bind_handle_t h_bind, 147219820Sjeff IN osmv_txn_ctx_t * p_txn, 148219820Sjeff IN boolean_t is_init_by_peer); 149219820Sjeff 150219820Sjeff/* 151219820Sjeff * NAME 152219820Sjeff * osmv_txn_done 153219820Sjeff * 154219820Sjeff * DESCRIPTION 155219820Sjeff * destroys txn object and removes it from the db 156219820Sjeff * 157219820Sjeff * SEE ALSO 158219820Sjeff * 159219820Sjeff */ 160219820Sjeffvoid 161219820Sjeffosmv_txn_done(IN osm_bind_handle_t h_bind, 162219820Sjeff IN uint64_t key, IN boolean_t is_in_cb); 163219820Sjeff/* 164219820Sjeff * NAME 165219820Sjeff * osmv_txn_get_tid 166219820Sjeff * 167219820Sjeff * DESCRIPTION 168219820Sjeff * returns tid of the transaction 169219820Sjeff * SEE ALSO 170219820Sjeff * 171219820Sjeff */ 172219820Sjeffstatic inline uint64_t osmv_txn_get_tid(IN osmv_txn_ctx_t * p_txn) 173219820Sjeff{ 174219820Sjeff CL_ASSERT(NULL != p_txn); 175219820Sjeff return p_txn->tid; 176219820Sjeff} 177219820Sjeff 178219820Sjeff/* 179219820Sjeff * NAME 180219820Sjeff * osmv_txn_get_key 181219820Sjeff * 182219820Sjeff * DESCRIPTION 183219820Sjeff * returns key of the transaction 184219820Sjeff * SEE ALSO 185219820Sjeff * 186219820Sjeff */ 187219820Sjeff 188219820Sjeffstatic inline uint64_t osmv_txn_get_key(IN osmv_txn_ctx_t * p_txn) 189219820Sjeff{ 190219820Sjeff CL_ASSERT(NULL != p_txn); 191219820Sjeff return p_txn->key; 192219820Sjeff} 193219820Sjeff 194219820Sjeff/* 195219820Sjeff * NAME 196219820Sjeff * osmv_txn_is_rmpp_init_by_peer 197219820Sjeff * 198219820Sjeff * DESCRIPTION 199219820Sjeff * returns whether the rmpp txfr was init by the peer 200219820Sjeff * 201219820Sjeff * SEE ALSO 202219820Sjeff * 203219820Sjeff */ 204219820Sjeffstatic inline boolean_t osmv_txn_is_rmpp_init_by_peer(IN osmv_txn_ctx_t * p_txn) 205219820Sjeff{ 206219820Sjeff CL_ASSERT(NULL != p_txn); 207219820Sjeff return p_txn->rmpp_txfr.is_rmpp_init_by_peer; 208219820Sjeff} 209219820Sjeff 210219820Sjeff/* 211219820Sjeff * NAME 212219820Sjeff * osmv_txn_get_rmpp_send_ctx 213219820Sjeff * 214219820Sjeff * DESCRIPTION 215219820Sjeff * returns osmv_rmpp_send_ctx obj 216219820Sjeff * SEE ALSO 217219820Sjeff * 218219820Sjeff */ 219219820Sjeffstatic inline osmv_rmpp_send_ctx_t *osmv_txn_get_rmpp_send_ctx(IN osmv_txn_ctx_t 220219820Sjeff * p_txn) 221219820Sjeff{ 222219820Sjeff CL_ASSERT(NULL != p_txn); 223219820Sjeff return p_txn->rmpp_txfr.p_rmpp_send_ctx; 224219820Sjeff} 225219820Sjeff 226219820Sjeff/* 227219820Sjeff * NAME 228219820Sjeff * osmv_txn_get_rmpp_recv_ctx 229219820Sjeff * 230219820Sjeff * DESCRIPTION 231219820Sjeff * returns osmv_rmpp_recv_ctx obj 232219820Sjeff * SEE ALSO 233219820Sjeff * 234219820Sjeff */ 235219820Sjeffstatic inline osmv_rmpp_recv_ctx_t *osmv_txn_get_rmpp_recv_ctx(IN osmv_txn_ctx_t 236219820Sjeff * p_txn) 237219820Sjeff{ 238219820Sjeff CL_ASSERT(NULL != p_txn); 239219820Sjeff return p_txn->rmpp_txfr.p_rmpp_recv_ctx; 240219820Sjeff} 241219820Sjeff 242219820Sjeff/* 243219820Sjeff * NAME 244219820Sjeff * osmv_txn_get_rmpp_state 245219820Sjeff * 246219820Sjeff * DESCRIPTION 247219820Sjeff * returns the rmpp role of the transactino ( send/ recv) 248219820Sjeff * SEE ALSO 249219820Sjeff * 250219820Sjeff */ 251219820Sjeffstatic inline osmv_txn_rmpp_state_t 252219820Sjeffosmv_txn_get_rmpp_state(IN osmv_txn_ctx_t * p_txn) 253219820Sjeff{ 254219820Sjeff CL_ASSERT(NULL != p_txn); 255219820Sjeff return p_txn->rmpp_txfr.rmpp_state; 256219820Sjeff} 257219820Sjeff 258219820Sjeff/* 259219820Sjeff * NAME 260219820Sjeff * osmv_txn_set_rmpp_state 261219820Sjeff * 262219820Sjeff * DESCRIPTION 263219820Sjeff * sets the rmpp role of the transaction (send/ recv) 264219820Sjeff * SEE ALSO 265219820Sjeff * 266219820Sjeff */ 267219820Sjeffstatic inline void 268219820Sjeffosmv_txn_set_rmpp_state(IN osmv_txn_ctx_t * p_txn, 269219820Sjeff IN osmv_txn_rmpp_state_t state) 270219820Sjeff{ 271219820Sjeff CL_ASSERT(NULL != p_txn); 272219820Sjeff p_txn->rmpp_txfr.rmpp_state = state; 273219820Sjeff} 274219820Sjeff 275219820Sjeff/* 276219820Sjeff * NAME 277219820Sjeff * osmv_txn_get_madw 278219820Sjeff * 279219820Sjeff * DESCRIPTION 280219820Sjeff * returns the requester madw 281219820Sjeff * SEE ALSO 282219820Sjeff * 283219820Sjeff */ 284219820Sjeffstatic inline osm_madw_t *osmv_txn_get_madw(IN osmv_txn_ctx_t * p_txn) 285219820Sjeff{ 286219820Sjeff CL_ASSERT(NULL != p_txn); 287219820Sjeff return p_txn->p_madw; 288219820Sjeff} 289219820Sjeff 290219820Sjeff/* 291219820Sjeff * NAME 292219820Sjeff * osmv_txn_set_madw 293219820Sjeff * 294219820Sjeff * DESCRIPTION 295219820Sjeff * sets the requester madw 296219820Sjeff * SEE ALSO 297219820Sjeff * 298219820Sjeff */ 299219820Sjeffstatic inline void 300219820Sjeffosmv_txn_set_madw(IN osmv_txn_ctx_t * p_txn, IN osm_madw_t * p_madw) 301219820Sjeff{ 302219820Sjeff CL_ASSERT(NULL != p_txn); 303219820Sjeff p_txn->p_madw = p_madw; 304219820Sjeff} 305219820Sjeff 306219820Sjeff/* 307219820Sjeff * NAME 308219820Sjeff * osmv_txn_set_timeout_ev 309219820Sjeff * 310219820Sjeff * DESCRIPTION 311219820Sjeff * 312219820Sjeff * SEE ALSO 313219820Sjeff * 314219820Sjeff */ 315219820Sjeffib_api_status_t 316219820Sjeffosmv_txn_set_timeout_ev(IN osm_bind_handle_t h_bind, 317219820Sjeff IN uint64_t key, IN uint64_t msec); 318219820Sjeff/* 319219820Sjeff * NAME 320219820Sjeff * osmv_txn_remove_timeout_ev 321219820Sjeff * 322219820Sjeff * DESCRIPTION 323219820Sjeff 324219820Sjeff * SEE ALSO 325219820Sjeff * 326219820Sjeff */ 327219820Sjeffvoid osmv_txn_remove_timeout_ev(IN osm_bind_handle_t h_bind, IN uint64_t key); 328219820Sjeff/* 329219820Sjeff * NAME 330219820Sjeff * osmv_txn_lookup 331219820Sjeff * 332219820Sjeff * DESCRIPTION 333219820Sjeff * get a transaction by its key 334219820Sjeff * 335219820Sjeff * SEE ALSO 336219820Sjeff * 337219820Sjeff */ 338219820Sjeffib_api_status_t 339219820Sjeffosmv_txn_lookup(IN osm_bind_handle_t h_bind, 340219820Sjeff IN uint64_t key, OUT osmv_txn_ctx_t ** pp_txn); 341219820Sjeff 342219820Sjeffvoid osmv_txn_abort_rmpp_txns(IN osm_bind_handle_t h_bind); 343219820Sjeff 344219820Sjeff/* * * * * * * * * * * * */ 345219820Sjeff/* 346219820Sjeff * NAME 347219820Sjeff * osmv_txnmgr_init 348219820Sjeff * 349219820Sjeff * DESCRIPTION 350219820Sjeff * c'tor for txn mgr obj 351219820Sjeff * SEE ALSO 352219820Sjeff * 353219820Sjeff */ 354219820Sjeffib_api_status_t 355219820Sjeffosmv_txnmgr_init(IN osmv_txn_mgr_t * p_tx_mgr, 356219820Sjeff IN osm_log_t * p_log, IN cl_spinlock_t * p_lock); 357219820Sjeff 358219820Sjeff/* 359219820Sjeff * NAME 360219820Sjeff * osmv_txnmgr_done 361219820Sjeff * 362219820Sjeff * DESCRIPTION 363219820Sjeff * c'tor for txn mgr obj 364219820Sjeff * SEE ALSO 365219820Sjeff * 366219820Sjeff */ 367219820Sjeffvoid osmv_txnmgr_done(IN osm_bind_handle_t h_bind); 368219820Sjeff 369219820Sjeffvoid osmv_txn_lock(IN osm_bind_handle_t h_bind); 370219820Sjeffvoid osmv_txn_unlock(IN osm_bind_handle_t h_bind); 371219820Sjeff 372219820Sjeffinline static uint64_t osmv_txn_uniq_key(IN uint64_t tid) 373219820Sjeff{ 374219820Sjeff uint64_t pid = getpid(); 375219820Sjeff 376219820Sjeff return ((pid << 32) | (tid & 0xFFFFFFFF)); 377219820Sjeff} 378219820Sjeff 379219820SjeffEND_C_DECLS 380219820Sjeff#endif /* _OSMV_TXN_H_ */ 381