1 /*
2 * Copyright (c) 2013-2014 Intel Corporation. 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_ENDPOINT_H
34 #define FI_ENDPOINT_H
35
36 #include <rdma/fabric.h>
37 #include <rdma/fi_domain.h>
38
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44
45 struct fi_msg {
46 const struct iovec *msg_iov;
47 void **desc;
48 size_t iov_count;
49 fi_addr_t addr;
50 void *context;
51 uint64_t data;
52 };
53
54 /* Endpoint option levels */
55 enum {
56 FI_OPT_ENDPOINT
57 };
58
59 /* FI_OPT_ENDPOINT option names */
60 enum {
61 FI_OPT_MIN_MULTI_RECV, /* size_t */
62 FI_OPT_CM_DATA_SIZE, /* size_t */
63 FI_OPT_BUFFERED_MIN, /* size_t */
64 FI_OPT_BUFFERED_LIMIT, /* size_t */
65 FI_OPT_SEND_BUF_SIZE,
66 FI_OPT_RECV_BUF_SIZE,
67 FI_OPT_TX_SIZE,
68 FI_OPT_RX_SIZE,
69 };
70
71 struct fi_ops_ep {
72 size_t size;
73 ssize_t (*cancel)(fid_t fid, void *context);
74 int (*getopt)(fid_t fid, int level, int optname,
75 void *optval, size_t *optlen);
76 int (*setopt)(fid_t fid, int level, int optname,
77 const void *optval, size_t optlen);
78 int (*tx_ctx)(struct fid_ep *sep, int index,
79 struct fi_tx_attr *attr, struct fid_ep **tx_ep,
80 void *context);
81 int (*rx_ctx)(struct fid_ep *sep, int index,
82 struct fi_rx_attr *attr, struct fid_ep **rx_ep,
83 void *context);
84 ssize_t (*rx_size_left)(struct fid_ep *ep);
85 ssize_t (*tx_size_left)(struct fid_ep *ep);
86 };
87
88 struct fi_ops_msg {
89 size_t size;
90 ssize_t (*recv)(struct fid_ep *ep, void *buf, size_t len, void *desc,
91 fi_addr_t src_addr, void *context);
92 ssize_t (*recvv)(struct fid_ep *ep, const struct iovec *iov, void **desc,
93 size_t count, fi_addr_t src_addr, void *context);
94 ssize_t (*recvmsg)(struct fid_ep *ep, const struct fi_msg *msg,
95 uint64_t flags);
96 ssize_t (*send)(struct fid_ep *ep, const void *buf, size_t len, void *desc,
97 fi_addr_t dest_addr, void *context);
98 ssize_t (*sendv)(struct fid_ep *ep, const struct iovec *iov, void **desc,
99 size_t count, fi_addr_t dest_addr, void *context);
100 ssize_t (*sendmsg)(struct fid_ep *ep, const struct fi_msg *msg,
101 uint64_t flags);
102 ssize_t (*inject)(struct fid_ep *ep, const void *buf, size_t len,
103 fi_addr_t dest_addr);
104 ssize_t (*senddata)(struct fid_ep *ep, const void *buf, size_t len, void *desc,
105 uint64_t data, fi_addr_t dest_addr, void *context);
106 ssize_t (*injectdata)(struct fid_ep *ep, const void *buf, size_t len,
107 uint64_t data, fi_addr_t dest_addr);
108 };
109
110 struct fi_ops_cm;
111 struct fi_ops_rma;
112 struct fi_ops_tagged;
113 struct fi_ops_atomic;
114 struct fi_ops_collective;
115
116 /*
117 * Calls which modify the properties of a endpoint (control, setopt, bind, ...)
118 * must be serialized against all other operations. Those calls may modify the
119 * operations referenced by a endpoint in order to optimize the data transfer code
120 * paths.
121 *
122 * A provider may allocate the minimal size structure needed to support the
123 * ops requested by the user.
124 */
125 struct fid_ep {
126 struct fid fid;
127 struct fi_ops_ep *ops;
128 struct fi_ops_cm *cm;
129 struct fi_ops_msg *msg;
130 struct fi_ops_rma *rma;
131 struct fi_ops_tagged *tagged;
132 struct fi_ops_atomic *atomic;
133 struct fi_ops_collective *collective;
134 };
135
136 struct fid_pep {
137 struct fid fid;
138 struct fi_ops_ep *ops;
139 struct fi_ops_cm *cm;
140 };
141
142 struct fid_stx {
143 struct fid fid;
144 struct fi_ops_ep *ops;
145 };
146
147 #ifdef FABRIC_DIRECT
148 #include <rdma/fi_direct_endpoint.h>
149 #endif /* FABRIC_DIRECT */
150
151 #ifndef FABRIC_DIRECT_ENDPOINT
152
153 static inline int
fi_passive_ep(struct fid_fabric * fabric,struct fi_info * info,struct fid_pep ** pep,void * context)154 fi_passive_ep(struct fid_fabric *fabric, struct fi_info *info,
155 struct fid_pep **pep, void *context)
156 {
157 return fabric->ops->passive_ep(fabric, info, pep, context);
158 }
159
160 static inline int
fi_endpoint(struct fid_domain * domain,struct fi_info * info,struct fid_ep ** ep,void * context)161 fi_endpoint(struct fid_domain *domain, struct fi_info *info,
162 struct fid_ep **ep, void *context)
163 {
164 return domain->ops->endpoint(domain, info, ep, context);
165 }
166
167 static inline int
fi_scalable_ep(struct fid_domain * domain,struct fi_info * info,struct fid_ep ** sep,void * context)168 fi_scalable_ep(struct fid_domain *domain, struct fi_info *info,
169 struct fid_ep **sep, void *context)
170 {
171 return domain->ops->scalable_ep(domain, info, sep, context);
172 }
173
fi_ep_bind(struct fid_ep * ep,struct fid * bfid,uint64_t flags)174 static inline int fi_ep_bind(struct fid_ep *ep, struct fid *bfid, uint64_t flags)
175 {
176 return ep->fid.ops->bind(&ep->fid, bfid, flags);
177 }
178
fi_pep_bind(struct fid_pep * pep,struct fid * bfid,uint64_t flags)179 static inline int fi_pep_bind(struct fid_pep *pep, struct fid *bfid, uint64_t flags)
180 {
181 return pep->fid.ops->bind(&pep->fid, bfid, flags);
182 }
183
fi_scalable_ep_bind(struct fid_ep * sep,struct fid * bfid,uint64_t flags)184 static inline int fi_scalable_ep_bind(struct fid_ep *sep, struct fid *bfid, uint64_t flags)
185 {
186 return sep->fid.ops->bind(&sep->fid, bfid, flags);
187 }
188
fi_enable(struct fid_ep * ep)189 static inline int fi_enable(struct fid_ep *ep)
190 {
191 return ep->fid.ops->control(&ep->fid, FI_ENABLE, NULL);
192 }
193
fi_cancel(fid_t fid,void * context)194 static inline ssize_t fi_cancel(fid_t fid, void *context)
195 {
196 struct fid_ep *ep = container_of(fid, struct fid_ep, fid);
197 return ep->ops->cancel(fid, context);
198 }
199
200 static inline int
fi_setopt(fid_t fid,int level,int optname,const void * optval,size_t optlen)201 fi_setopt(fid_t fid, int level, int optname,
202 const void *optval, size_t optlen)
203 {
204 struct fid_ep *ep = container_of(fid, struct fid_ep, fid);
205 return ep->ops->setopt(fid, level, optname, optval, optlen);
206 }
207
208 static inline int
fi_getopt(fid_t fid,int level,int optname,void * optval,size_t * optlen)209 fi_getopt(fid_t fid, int level, int optname,
210 void *optval, size_t *optlen)
211 {
212 struct fid_ep *ep = container_of(fid, struct fid_ep, fid);
213 return ep->ops->getopt(fid, level, optname, optval, optlen);
214 }
215
fi_ep_alias(struct fid_ep * ep,struct fid_ep ** alias_ep,uint64_t flags)216 static inline int fi_ep_alias(struct fid_ep *ep, struct fid_ep **alias_ep,
217 uint64_t flags)
218 {
219 int ret;
220 struct fid *fid;
221 ret = fi_alias(&ep->fid, &fid, flags);
222 if (!ret)
223 *alias_ep = container_of(fid, struct fid_ep, fid);
224 return ret;
225 }
226
227 static inline int
fi_tx_context(struct fid_ep * ep,int idx,struct fi_tx_attr * attr,struct fid_ep ** tx_ep,void * context)228 fi_tx_context(struct fid_ep *ep, int idx, struct fi_tx_attr *attr,
229 struct fid_ep **tx_ep, void *context)
230 {
231 return ep->ops->tx_ctx(ep, idx, attr, tx_ep, context);
232 }
233
234 static inline int
fi_rx_context(struct fid_ep * ep,int idx,struct fi_rx_attr * attr,struct fid_ep ** rx_ep,void * context)235 fi_rx_context(struct fid_ep *ep, int idx, struct fi_rx_attr *attr,
236 struct fid_ep **rx_ep, void *context)
237 {
238 return ep->ops->rx_ctx(ep, idx, attr, rx_ep, context);
239 }
240
241 static inline FI_DEPRECATED_FUNC ssize_t
fi_rx_size_left(struct fid_ep * ep)242 fi_rx_size_left(struct fid_ep *ep)
243 {
244 return ep->ops->rx_size_left(ep);
245 }
246
247 static inline FI_DEPRECATED_FUNC ssize_t
fi_tx_size_left(struct fid_ep * ep)248 fi_tx_size_left(struct fid_ep *ep)
249 {
250 return ep->ops->tx_size_left(ep);
251 }
252
253 static inline int
fi_stx_context(struct fid_domain * domain,struct fi_tx_attr * attr,struct fid_stx ** stx,void * context)254 fi_stx_context(struct fid_domain *domain, struct fi_tx_attr *attr,
255 struct fid_stx **stx, void *context)
256 {
257 return domain->ops->stx_ctx(domain, attr, stx, context);
258 }
259
260 static inline int
fi_srx_context(struct fid_domain * domain,struct fi_rx_attr * attr,struct fid_ep ** rx_ep,void * context)261 fi_srx_context(struct fid_domain *domain, struct fi_rx_attr *attr,
262 struct fid_ep **rx_ep, void *context)
263 {
264 return domain->ops->srx_ctx(domain, attr, rx_ep, context);
265 }
266
267 static inline ssize_t
fi_recv(struct fid_ep * ep,void * buf,size_t len,void * desc,fi_addr_t src_addr,void * context)268 fi_recv(struct fid_ep *ep, void *buf, size_t len, void *desc, fi_addr_t src_addr,
269 void *context)
270 {
271 return ep->msg->recv(ep, buf, len, desc, src_addr, context);
272 }
273
274 static inline ssize_t
fi_recvv(struct fid_ep * ep,const struct iovec * iov,void ** desc,size_t count,fi_addr_t src_addr,void * context)275 fi_recvv(struct fid_ep *ep, const struct iovec *iov, void **desc,
276 size_t count, fi_addr_t src_addr, void *context)
277 {
278 return ep->msg->recvv(ep, iov, desc, count, src_addr, context);
279 }
280
281 static inline ssize_t
fi_recvmsg(struct fid_ep * ep,const struct fi_msg * msg,uint64_t flags)282 fi_recvmsg(struct fid_ep *ep, const struct fi_msg *msg, uint64_t flags)
283 {
284 return ep->msg->recvmsg(ep, msg, flags);
285 }
286
287 static inline ssize_t
fi_send(struct fid_ep * ep,const void * buf,size_t len,void * desc,fi_addr_t dest_addr,void * context)288 fi_send(struct fid_ep *ep, const void *buf, size_t len, void *desc,
289 fi_addr_t dest_addr, void *context)
290 {
291 return ep->msg->send(ep, buf, len, desc, dest_addr, context);
292 }
293
294 static inline ssize_t
fi_sendv(struct fid_ep * ep,const struct iovec * iov,void ** desc,size_t count,fi_addr_t dest_addr,void * context)295 fi_sendv(struct fid_ep *ep, const struct iovec *iov, void **desc,
296 size_t count, fi_addr_t dest_addr, void *context)
297 {
298 return ep->msg->sendv(ep, iov, desc, count, dest_addr, context);
299 }
300
301 static inline ssize_t
fi_sendmsg(struct fid_ep * ep,const struct fi_msg * msg,uint64_t flags)302 fi_sendmsg(struct fid_ep *ep, const struct fi_msg *msg, uint64_t flags)
303 {
304 return ep->msg->sendmsg(ep, msg, flags);
305 }
306
307 static inline ssize_t
fi_inject(struct fid_ep * ep,const void * buf,size_t len,fi_addr_t dest_addr)308 fi_inject(struct fid_ep *ep, const void *buf, size_t len, fi_addr_t dest_addr)
309 {
310 return ep->msg->inject(ep, buf, len, dest_addr);
311 }
312
313 static inline ssize_t
fi_senddata(struct fid_ep * ep,const void * buf,size_t len,void * desc,uint64_t data,fi_addr_t dest_addr,void * context)314 fi_senddata(struct fid_ep *ep, const void *buf, size_t len, void *desc,
315 uint64_t data, fi_addr_t dest_addr, void *context)
316 {
317 return ep->msg->senddata(ep, buf, len, desc, data, dest_addr, context);
318 }
319
320 static inline ssize_t
fi_injectdata(struct fid_ep * ep,const void * buf,size_t len,uint64_t data,fi_addr_t dest_addr)321 fi_injectdata(struct fid_ep *ep, const void *buf, size_t len,
322 uint64_t data, fi_addr_t dest_addr)
323 {
324 return ep->msg->injectdata(ep, buf, len, data, dest_addr);
325 }
326
327 #endif
328
329 #ifdef __cplusplus
330 }
331 #endif
332
333 #endif /* FI_ENDPOINT_H */
334