forked from linux-rdma/rdma-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcma.h
117 lines (102 loc) · 3.14 KB
/
cma.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright (c) 2005-2014 Intel Corporation. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#if !defined(CMA_H)
#define CMA_H
#include <config.h>
#include <stdlib.h>
#include <errno.h>
#include <endian.h>
#include <semaphore.h>
#include <stdatomic.h>
#include <rdma/rdma_cma.h>
#include <infiniband/ib.h>
#include <ccan/minmax.h>
#include <valgrind/memcheck.h>
#define PFX "librdmacm: "
/*
* Fast synchronization for low contention locking.
*/
typedef struct {
sem_t sem;
_Atomic(int) cnt;
} fastlock_t;
static inline void fastlock_init(fastlock_t *lock)
{
sem_init(&lock->sem, 0, 0);
atomic_store(&lock->cnt, 0);
}
static inline void fastlock_destroy(fastlock_t *lock)
{
sem_destroy(&lock->sem);
}
static inline void fastlock_acquire(fastlock_t *lock)
{
if (atomic_fetch_add(&lock->cnt, 1) > 0)
sem_wait(&lock->sem);
}
static inline void fastlock_release(fastlock_t *lock)
{
if (atomic_fetch_sub(&lock->cnt, 1) > 1)
sem_post(&lock->sem);
}
__be16 ucma_get_port(struct sockaddr *addr);
int ucma_addrlen(struct sockaddr *addr);
void ucma_set_sid(enum rdma_port_space ps, struct sockaddr *addr,
struct sockaddr_ib *sib);
int ucma_max_qpsize(struct rdma_cm_id *id);
int ucma_complete(struct rdma_cm_id *id);
int ucma_shutdown(struct rdma_cm_id *id);
static inline int ERR(int err)
{
errno = err;
return -1;
}
int ucma_init(void);
extern int af_ib_support;
#define RAI_ROUTEONLY 0x01000000
void ucma_ib_init(void);
void ucma_ib_cleanup(void);
void ucma_ib_resolve(struct rdma_addrinfo **rai,
const struct rdma_addrinfo *hints);
struct ib_connect_hdr {
uint8_t cma_version;
uint8_t ip_version; /* IP version: 7:4 */
uint16_t port;
uint32_t src_addr[4];
uint32_t dst_addr[4];
#define cma_src_ip4 src_addr[3]
#define cma_src_ip6 src_addr[0]
#define cma_dst_ip4 dst_addr[3]
#define cma_dst_ip6 dst_addr[0]
};
#endif /* CMA_H */