forked from ofiwg/libfabric
/
gnix.h
379 lines (332 loc) · 9.42 KB
/
gnix.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
* Copyright (c) 2015 Cray Inc. All rights reserved.
* Copyright (c) 2015 Los Alamos National Security, LLC. 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
* 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.
*/
#ifndef _GNIX_H_
#define _GNIX_H_
#ifdef __cplusplus
extern "C" {
#endif
#if HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#include <rdma/fabric.h>
#include <rdma/fi_atomic.h>
#include <rdma/fi_cm.h>
#include <rdma/fi_domain.h>
#include <rdma/fi_endpoint.h>
#include <rdma/fi_eq.h>
#include <rdma/fi_errno.h>
#include <rdma/fi_prov.h>
#include <rdma/fi_rma.h>
#include <rdma/fi_tagged.h>
#include <rdma/fi_trigger.h>
#include <fi.h>
#include <fi_enosys.h>
#include <fi_indexer.h>
#include <fi_rbuf.h>
#include <fi_list.h>
#include "gni_pub.h"
#include "ccan/list.h"
#include "gnix_util.h"
#define GNI_MAJOR_VERSION 0
#define GNI_MINOR_VERSION 5
/*
* useful macros
*/
#define PFX "libfabric:gni"
#ifndef likely
#define likely(x) __builtin_expect((x), 1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect((x), 0)
#endif
#ifndef FLOOR
#define FLOOR(a, b) ((long long)(a) - (((long long)(a)) % (b)))
#endif
#ifndef CEILING
#define CEILING(a, b) ((long long)(a) <= 0LL ? 0 : (FLOOR((a)-1, b) + (b)))
#endif
#ifndef IN
#define IN
#endif
#ifndef OUT
#define OUT
#endif
#ifndef INOUT
#define INOUT
#endif
/*
* Cray gni provider supported flags for fi_getinfo argument for now, needs
* refining (see fi_getinfo.3 man page)
*/
#define GNIX_SUPPORTED_FLAGS (FI_NUMERICHOST | FI_SOURCE)
#define GNIX_DEFAULT_FLAGS (0)
/*
* Cray gni provider will try to support the fabric interface capabilities (see
* fi_getinfo.3 man page)
* for RDM and MSG (future) endpoint types.
*/
/*
* see capabilities section in fi_getinfo.3
*/
#define GNIX_EP_RDM_CAPS \
(FI_MSG | FI_RMA | FI_TAGGED | FI_ATOMICS | FI_BUFFERED_RECV | \
FI_DIRECTED_RECV | FI_MULTI_RECV | FI_INJECT | FI_SOURCE | FI_READ | \
FI_WRITE | FI_SEND | FI_RECV | FI_REMOTE_READ | FI_REMOTE_WRITE | \
FI_REMOTE_COMPLETE | FI_CANCEL | FI_FENCE)
/*
* see Operations flags in fi_endpoint.3
*/
#define GNIX_EP_OP_FLAGS \
(FI_MULTI_RECV | FI_BUFFERED_RECV | FI_COMPLETION | \
FI_REMOTE_COMPLETE | FI_READ | FI_WRITE | FI_SEND | FI_RECV | \
FI_REMOTE_READ | FI_REMOTE_WRITE)
/*
* if this has to be changed, check gnix_getinfo, etc.
*/
#define GNIX_EP_MSG_CAPS GNIX_EP_RDM_CAPS
#define GNIX_MAX_MSG_SIZE ((0x1ULL << 32) - 1)
#define GNIX_INJECT_SIZE 64
/*
* Cray gni provider will require the following fabric interface modes (see
* fi_getinfo.3 man page)
*/
#define GNIX_FAB_MODES (FI_CONTEXT | FI_LOCAL_MR | FI_PROV_MR_ATTR)
/*
* fabric modes that GNI provider doesn't need
*/
#define GNIX_FAB_MODES_CLEAR (FI_MSG_PREFIX | FI_ASYNC_IOV)
/*
* gnix address format - used for fi_send/fi_recv, etc.
*/
struct gnix_address {
uint32_t device_addr;
uint32_t cdm_id;
};
/*
* info returned by fi_getname/fi_getpeer - has enough
* side band info for RDM ep's to be able to connect, etc.
*/
struct gnix_ep_name {
struct gnix_address gnix_addr;
struct {
uint32_t name_type : 8;
uint32_t unused : 24;
uint32_t cookie;
};
uint64_t reserved[4];
};
/*
* enum for blocking/non-blocking progress
*/
enum gnix_progress_type {
GNIX_PRG_BLOCKING,
GNIX_PRG_NON_BLOCKING
};
/*
* simple struct for gnix fabric, may add more stuff here later
*/
struct gnix_fabric {
struct fid_fabric fab_fid;
/* llist of domains's opened from fabric */
struct list_head domain_list;
};
/*
* a gnix_domain is associated with one cdm and one nic
* since a single cdm with a given cookie/cdm_id can only
* be bound once to a given physical aries nic
*/
struct gnix_domain {
struct fid_domain domain_fid;
/* used for fabric object llist of domains*/
struct list_node list;
/* list nics this domain is attached to, TODO: thread safety */
struct list_head nic_list;
/* cm nic bound to this domain */
struct gnix_cm_nic *cm_nic;
uint8_t ptag;
uint32_t cookie;
/* work queue for domain */
struct list_head domain_wq;
atomic_t ref_cnt;
};
/*
* gnix cm nic struct - to be used only for GNI_EpPostData, etc.
*/
struct gnix_cm_nic {
struct list_node list;
gni_cdm_handle_t gni_cdm_hndl;
gni_nic_handle_t gni_nic_hndl;
/* free list of datagrams */
struct list_head datagram_free_list;
/* list of active wc datagrams */
struct list_head wc_datagram_active_list;
/* free list of wc datagrams */
struct list_head wc_datagram_free_list;
/* pointer to domain this nic is attached to */
struct gnix_domain *domain;
struct gnix_datagram *datagram_base;
uint32_t inst_id;
uint8_t ptag;
uint32_t cookie;
uint32_t device_id;
uint32_t device_addr;
atomic_t ref_cnt;
};
struct gnix_nic {
struct list_node list;
gni_cdm_handle_t gni_cdm_hndl;
gni_nic_handle_t gni_nic_hndl;
/* receive completion queue for hndl */
gni_cq_handle_t rx_cq;
/* receive completion queue for hndl (blocking) */
gni_cq_handle_t rx_cq_blk;
/* local(tx) completion queue for hndl */
gni_cq_handle_t tx_cq;
/* local(tx) completion queue for hndl (blocking) */
gni_cq_handle_t tx_cq_blk;
/* list of wqe's */
struct list_head wqe_active_list;
/* list for managing wqe's */
struct gnix_wqe_list *wqe_list;
/* pointer to domain this nic is attached to */
struct gnix_domain *domain;
struct list_head smsg_active_req_list;
/* list for managing smsg req's */
struct gnix_smsg_req_list *smsg_req_list;
/* list of active datagrams */
struct list_head datagram_active_list;
/* free list of datagrams */
struct list_head datagram_free_list;
/* list of active wc datagrams */
struct list_head wc_datagram_active_list;
/* free list of wc datagrams */
struct list_head wc_datagram_free_list;
struct gnix_datagram *datagram_base;
uint32_t device_id;
uint32_t device_addr;
atomic_t ref_cnt;
};
/*
* CQE struct definitions
*/
struct gnix_cq_entry {
struct list_node list;
struct fi_cq_entry the_entry;
};
struct gnix_cq_msg_entry {
struct list_node list;
struct fi_cq_msg_entry the_entry;
};
struct gnix_cq_tagged_entry {
struct list_node list;
struct fi_cq_tagged_entry the_entry;
};
struct gnix_cq {
struct fid_cq cq_fid;
uint64_t flags;
struct gnix_domain *domain;
void *free_list_base;
struct list_head entry;
struct list_head err_entry;
struct list_head entry_free_list;
int (*progress_fn)(struct gnix_cq *);
enum fi_cq_format format;
};
struct gnix_mem_desc {
struct fid_mr mr_fid;
struct gnix_domain *domain;
gni_mem_handle_t mem_hndl;
};
/*
* TODO: need a lot more fields for AV support
*/
struct gnix_av {
struct fid_av av_fid;
struct gnix_domain *domain;
};
/*
* gnix endpoint structure
*/
struct gnix_ep {
struct fid_ep ep_fid;
enum fi_ep_type type;
struct gnix_domain *domain;
struct gnix_cq *send_cq;
struct gnix_cq *recv_cq;
struct gnix_av *av;
void *vc_hash_hndl;
void *vc;
int (*progress_fn)(struct gnix_ep *, enum gnix_progress_type);
/* RX specific progress fn */
int (*rx_progress_fn)(struct gnix_ep *, gni_return_t *rc);
int enabled;
int no_want_cqes;
/* num. active post descs associated with this ep */
uint32_t active_post_descs;
};
/*
* globals
*/
extern const char gnix_fab_name[];
extern const char gnix_dom_name[];
extern uint32_t gnix_cdm_modes;
/*
* linked list helpers
*/
static inline void gnix_list_node_init(struct list_node *node)
{
node->prev = node->next = NULL;
}
static inline void gnix_list_del_init(struct list_node *node)
{
list_del(node);
node->prev = node->next = node;
}
/*
* prototypes
*/
int gnix_domain_open(struct fid_fabric *fabric, struct fi_info *info,
struct fid_domain **domain, void *context);
int gnix_av_open(struct fid_domain *domain, struct fi_av_attr *attr,
struct fid_av **av, void *context);
int gnix_cq_open(struct fid_domain *domain, struct fi_cq_attr *attr,
struct fid_cq **cq, void *context);
int gnix_ep_open(struct fid_domain *domain, struct fi_info *info,
struct fid_ep **ep, void *context);
int gnix_mr_reg(struct fid_domain *domain, const void *buf, size_t len,
uint64_t access, uint64_t offset, uint64_t requested_key,
uint64_t flags, struct fid_mr **mr, void *context);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _GNIX_H_ */