1321936Shselasky/* 2321936Shselasky * Copyright (c) 2005-2014 Intel Corporation. All rights reserved. 3321936Shselasky * 4321936Shselasky * This software is available to you under a choice of one of two 5321936Shselasky * licenses. You may choose to be licensed under the terms of the GNU 6321936Shselasky * General Public License (GPL) Version 2, available from the file 7321936Shselasky * COPYING in the main directory of this source tree, or the 8321936Shselasky * OpenIB.org BSD license below: 9321936Shselasky * 10321936Shselasky * Redistribution and use in source and binary forms, with or 11321936Shselasky * without modification, are permitted provided that the following 12321936Shselasky * conditions are met: 13321936Shselasky * 14321936Shselasky * - Redistributions of source code must retain the above 15321936Shselasky * copyright notice, this list of conditions and the following 16321936Shselasky * disclaimer. 17321936Shselasky * 18321936Shselasky * - Redistributions in binary form must reproduce the above 19321936Shselasky * copyright notice, this list of conditions and the following 20321936Shselasky * disclaimer in the documentation and/or other materials 21321936Shselasky * provided with the distribution. 22321936Shselasky * 23321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30321936Shselasky * SOFTWARE. 31321936Shselasky * 32321936Shselasky */ 33321936Shselasky 34321936Shselasky#if !defined(CMA_H) 35321936Shselasky#define CMA_H 36321936Shselasky 37321936Shselasky#include <config.h> 38321936Shselasky 39321936Shselasky#include <stdlib.h> 40321936Shselasky#include <errno.h> 41321936Shselasky#include <infiniband/endian.h> 42321936Shselasky#include <semaphore.h> 43321936Shselasky#include <stdatomic.h> 44321936Shselasky 45321936Shselasky#include <rdma/rdma_cma.h> 46321936Shselasky#include <infiniband/ib.h> 47321936Shselasky 48321936Shselasky#define PFX "librdmacm: " 49321936Shselasky 50321936Shselasky/* 51321936Shselasky * Fast synchronization for low contention locking. 52321936Shselasky */ 53321936Shselaskytypedef struct { 54321936Shselasky sem_t sem; 55321936Shselasky _Atomic(int) cnt; 56321936Shselasky} fastlock_t; 57321936Shselaskystatic inline void fastlock_init(fastlock_t *lock) 58321936Shselasky{ 59321936Shselasky sem_init(&lock->sem, 0, 0); 60321936Shselasky atomic_store(&lock->cnt, 0); 61321936Shselasky} 62321936Shselaskystatic inline void fastlock_destroy(fastlock_t *lock) 63321936Shselasky{ 64321936Shselasky sem_destroy(&lock->sem); 65321936Shselasky} 66321936Shselaskystatic inline void fastlock_acquire(fastlock_t *lock) 67321936Shselasky{ 68321936Shselasky if (atomic_fetch_add(&lock->cnt, 1) > 0) 69321936Shselasky sem_wait(&lock->sem); 70321936Shselasky} 71321936Shselaskystatic inline void fastlock_release(fastlock_t *lock) 72321936Shselasky{ 73321936Shselasky if (atomic_fetch_sub(&lock->cnt, 1) > 1) 74321936Shselasky sem_post(&lock->sem); 75321936Shselasky} 76321936Shselasky 77321936Shselasky__be16 ucma_get_port(struct sockaddr *addr); 78321936Shselaskyint ucma_addrlen(struct sockaddr *addr); 79321936Shselaskyvoid ucma_set_sid(enum rdma_port_space ps, struct sockaddr *addr, 80321936Shselasky struct sockaddr_ib *sib); 81321936Shselaskyint ucma_max_qpsize(struct rdma_cm_id *id); 82321936Shselaskyint ucma_complete(struct rdma_cm_id *id); 83321936Shselaskyint ucma_shutdown(struct rdma_cm_id *id); 84321936Shselasky 85321936Shselaskystatic inline int ERR(int err) 86321936Shselasky{ 87321936Shselasky errno = err; 88321936Shselasky return -1; 89321936Shselasky} 90321936Shselasky 91321936Shselaskyint ucma_init(void); 92321936Shselaskyextern int af_ib_support; 93321936Shselasky 94321936Shselasky#define RAI_ROUTEONLY 0x01000000 95321936Shselasky 96321936Shselaskyvoid ucma_ib_init(void); 97321936Shselaskyvoid ucma_ib_cleanup(void); 98321936Shselaskyvoid ucma_ib_resolve(struct rdma_addrinfo **rai, 99321936Shselasky const struct rdma_addrinfo *hints); 100321936Shselasky 101321936Shselaskystruct ib_connect_hdr { 102321936Shselasky uint8_t cma_version; 103321936Shselasky uint8_t ip_version; /* IP version: 7:4 */ 104321936Shselasky uint16_t port; 105321936Shselasky uint32_t src_addr[4]; 106321936Shselasky uint32_t dst_addr[4]; 107321936Shselasky#define cma_src_ip4 src_addr[3] 108321936Shselasky#define cma_src_ip6 src_addr[0] 109321936Shselasky#define cma_dst_ip4 dst_addr[3] 110321936Shselasky#define cma_dst_ip6 dst_addr[0] 111321936Shselasky}; 112321936Shselasky 113321936Shselasky#endif /* CMA_H */ 114