1 /*
2 * Copyright (c) 2015-2016 Intel Corporation, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33 #ifndef _FI_NETDIR_H_
34 #define _FI_NETDIR_H_
35
36 #if HAVE_CONFIG_H
37 # include <config.h>
38 #endif /* HAVE_CONFIG_H */
39
40 #include <ws2tcpip.h>
41 #include <winsock2.h>
42 #include <assert.h>
43
44 #include <ndspi.h>
45 #include "ofi_osd.h"
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif /* __cplusplus */
50
51
52 #define ND_MSG_IOV_LIMIT (256)
53 #define ND_MSG_INTERNAL_IOV_LIMIT (512)
54 #define ND_EP_MAX_CM_DATA_SIZE (256)
55 #define OFI_ND_MAX_MR_CNT (1 << 16)
56
57 #define OFI_ND_DOMAIN_CAPS (FI_LOCAL_COMM | FI_REMOTE_COMM)
58
59 #define OFI_ND_EP_CAPS (FI_MSG | FI_RMA | \
60 FI_SEND | FI_RECV | \
61 FI_READ | FI_WRITE | \
62 FI_REMOTE_READ | FI_REMOTE_WRITE)
63
64 #define OFI_ND_TX_OP_FLAGS (FI_INJECT | FI_COMPLETION | FI_TRANSMIT_COMPLETE | \
65 FI_INJECT_COMPLETE | FI_DELIVERY_COMPLETE | \
66 FI_SELECTIVE_COMPLETION)
67
68 #define OFI_ND_MSG_ORDER (OFI_ORDER_RAR_SET | OFI_ORDER_RAW_SET | FI_ORDER_RAS | \
69 OFI_ORDER_WAW_SET | FI_ORDER_WAS | FI_ORDER_SAW | FI_ORDER_SAS )
70
71 extern struct gl_data {
72 int inline_thr;
73 int prepost_cnt;
74 int prepost_buf_cnt;
75 int flow_control_cnt;
76 int total_avail;
77 } gl_data;
78
79 extern struct fi_provider ofi_nd_prov;
80 extern struct util_prov ofi_nd_util_prov;
81 extern struct fi_info ofi_nd_info;
82
83 extern const char ofi_nd_prov_name[];
84
85 int ofi_nd_cq_open(struct fid_domain *domain, struct fi_cq_attr *attr,
86 struct fid_cq **cq_fid, void *context);
87 int ofi_nd_eq_open(struct fid_fabric *fabric, struct fi_eq_attr *attr,
88 struct fid_eq **peq, void *context);
89 int ofi_nd_endpoint(struct fid_domain *domain, struct fi_info *info,
90 struct fid_ep **ep_fid, void *context);
91 int ofi_nd_passive_endpoint(struct fid_fabric *fabric, struct fi_info *info,
92 struct fid_pep **pep, void *context);
93 int ofi_nd_domain_open(struct fid_fabric *fabric, struct fi_info *info,
94 struct fid_domain **domain, void *context);
95 int ofi_nd_srx_ctx(struct fid_domain *domain,
96 struct fi_rx_attr *attr, struct fid_ep **rx_ep,
97 void *context);
98 int ofi_nd_fabric(struct fi_fabric_attr *attr, struct fid_fabric **fabric,
99 void *context);
100
101 int ofi_nd_getinfo(uint32_t version, const char *node, const char *service,
102 uint64_t flags, const struct fi_info *hints, struct fi_info **info);
103 void ofi_nd_fini(void);
104
105 int ofi_nd_mr_reg(struct fid *fid, const void *buf, size_t len,
106 uint64_t access, uint64_t offset, uint64_t requested_key,
107 uint64_t flags, struct fid_mr **mr, void *context);
108 int ofi_nd_mr_regv(struct fid *fid, const struct iovec *iov,
109 size_t count, uint64_t access,
110 uint64_t offset, uint64_t requested_key,
111 uint64_t flags, struct fid_mr **mr, void *context);
112 int ofi_nd_mr_regattr(struct fid *fid, const struct fi_mr_attr *attr,
113 uint64_t flags, struct fid_mr **mr);
114 int ofi_nd_cntr_open(struct fid_domain *pdomain, struct fi_cntr_attr *attr,
115 struct fid_cntr **pcntr, void *context);
116
117 typedef int(*ofi_nd_adapter_cb_t)(const ND2_ADAPTER_INFO* info, const char *name);
118
119 void ofi_nd_send_event(ND2_RESULT *result);
120 void ofi_nd_read_event(ND2_RESULT *result);
121 void ofi_nd_write_event(ND2_RESULT *result);
122
123 HRESULT ofi_nd_startup(ofi_nd_adapter_cb_t cb);
124 HRESULT ofi_nd_shutdown();
125
126 int ofi_nd_lookup_adapter(const char *name, IND2Adapter **adapter, struct sockaddr** addr);
127
128 int ofi_nd_is_valid_addr(const SOCKADDR *addr);
129 int ofi_nd_addr_cmp(const void* vaddr1, const void* vaddr2);
130
131 int ofi_nd_is_same_file(const wchar_t* path1, const wchar_t* path2);
132 int ofi_nd_file_exists(const wchar_t* path);
133 int ofi_nd_is_directory(const wchar_t* path);
134 const wchar_t *ofi_nd_filename(const wchar_t *path);
135
unique(void * base,size_t num,size_t width,int (* cmp)(const void *,const void *))136 static inline size_t unique(void *base, size_t num, size_t width,
137 int(*cmp)(const void *, const void *))
138 {
139 char *dst = (char*)base;
140 char *src = (char*)base + width;
141
142 size_t i;
143 size_t n = 1;
144
145 if (num < 2)
146 return num;
147
148 for (i = 1; i < num; i++) {
149 if (cmp(dst, src)) {
150 dst += width;
151 if (dst != src)
152 memcpy(dst, src, width);
153 n++;
154 }
155 src += width;
156 }
157
158 return n;
159 }
160
161 #define H2F(x) ofi_nd_hresult_2_fierror(x)
162
ofi_nd_hresult_2_fierror(HRESULT hr)163 static inline int ofi_nd_hresult_2_fierror(HRESULT hr)
164 {
165 switch (hr) {
166 case S_OK:
167 case ND_PENDING:
168 return FI_SUCCESS;
169 case ND_BUFFER_OVERFLOW:
170 return -FI_EOVERFLOW;
171 case ND_CONNECTION_REFUSED:
172 return -FI_ECONNREFUSED;
173 case ND_TIMEOUT:
174 return -FI_ETIMEDOUT;
175 default:
176 return -FI_EOTHER;
177 }
178 }
179
180 #define OFI_ND_TIMEOUT_INIT(timeout) \
181 uint64_t sfinish = ((timeout) >= 0) ? \
182 (ofi_gettime_ms() + (timeout) * 10000) : -1;
183
184 #define OFI_ND_TIMEDOUT() ((sfinish > 0) ? ofi_gettime_ms() >= sfinish : 0)
185
186 #ifdef ENABLE_DEBUG
187 # define NODEFAULT assert(0)
188 #else
189 # define NODEFAULT __assume(0)
190 #endif
191
192
193 #ifdef __cplusplus
194 }
195 #endif /* __cplusplus */
196
197 #endif /* _FI_NETDIR_H_ */
198
199