1 /**
2 * Copyright (C) Mellanox Technologies Ltd. 2001-2019.  ALL RIGHTS RESERVED.
3 *
4 * See file LICENSE for terms.
5 */
6 
7 #ifndef UCT_TL_H_
8 #define UCT_TL_H_
9 
10 #if !defined(UCT_H_)
11 #  error "You should not include this header directly. Include uct.h instead."
12 #endif
13 
14 #include "uct_def.h"
15 
16 #include <ucs/type/status.h>
17 #include <ucs/datastruct/callbackq.h>
18 #include <ucs/config/types.h>
19 #include <sys/types.h>
20 #include <stddef.h>
21 
22 BEGIN_C_DECLS
23 
24 /** @file tl.h */
25 
26 /* endpoint - put */
27 
28 typedef ucs_status_t (*uct_ep_put_short_func_t)(uct_ep_h ep,
29                                                 const void *buffer,
30                                                 unsigned length,
31                                                 uint64_t remote_addr,
32                                                 uct_rkey_t rkey);
33 
34 typedef ssize_t      (*uct_ep_put_bcopy_func_t)(uct_ep_h ep,
35                                                 uct_pack_callback_t pack_cb,
36                                                 void *arg,
37                                                 uint64_t remote_addr,
38                                                 uct_rkey_t rkey);
39 
40 typedef ucs_status_t (*uct_ep_put_zcopy_func_t)(uct_ep_h ep,
41                                                 const uct_iov_t *iov,
42                                                 size_t iovcnt,
43                                                 uint64_t remote_addr,
44                                                 uct_rkey_t rkey,
45                                                 uct_completion_t *comp);
46 
47 /* endpoint - get */
48 
49 typedef ucs_status_t (*uct_ep_get_short_func_t)(uct_ep_h ep,
50                                                 void *buffer,
51                                                 unsigned length,
52                                                 uint64_t remote_addr,
53                                                 uct_rkey_t rkey);
54 
55 typedef ucs_status_t (*uct_ep_get_bcopy_func_t)(uct_ep_h ep,
56                                                 uct_unpack_callback_t unpack_cb,
57                                                 void *arg,
58                                                 size_t length,
59                                                 uint64_t remote_addr,
60                                                 uct_rkey_t rkey,
61                                                 uct_completion_t *comp);
62 
63 typedef ucs_status_t (*uct_ep_get_zcopy_func_t)(uct_ep_h ep,
64                                                 const uct_iov_t *iov,
65                                                 size_t iovcnt,
66                                                 uint64_t remote_addr,
67                                                 uct_rkey_t rkey,
68                                                 uct_completion_t *comp);
69 
70 /* endpoint - active message */
71 
72 typedef ucs_status_t (*uct_ep_am_short_func_t)(uct_ep_h ep,
73                                                uint8_t id,
74                                                uint64_t header,
75                                                const void *payload,
76                                                unsigned length);
77 
78 typedef ssize_t      (*uct_ep_am_bcopy_func_t)(uct_ep_h ep,
79                                                uint8_t id,
80                                                uct_pack_callback_t pack_cb,
81                                                void *arg,
82                                                unsigned flags);
83 
84 typedef ucs_status_t (*uct_ep_am_zcopy_func_t)(uct_ep_h ep,
85                                                uint8_t id,
86                                                const void *header,
87                                                unsigned header_length,
88                                                const uct_iov_t *iov,
89                                                size_t iovcnt,
90                                                unsigned flags,
91                                                uct_completion_t *comp);
92 
93 /* endpoint - atomics */
94 
95 typedef ucs_status_t (*uct_ep_atomic_cswap64_func_t)(uct_ep_h ep,
96                                                      uint64_t compare,
97                                                      uint64_t swap,
98                                                      uint64_t remote_addr,
99                                                      uct_rkey_t rkey,
100                                                      uint64_t *result,
101                                                      uct_completion_t *comp);
102 
103 typedef ucs_status_t (*uct_ep_atomic_cswap32_func_t)(uct_ep_h ep,
104                                                      uint32_t compare,
105                                                      uint32_t swap,
106                                                      uint64_t remote_addr,
107                                                      uct_rkey_t rkey,
108                                                      uint32_t *result,
109                                                      uct_completion_t *comp);
110 
111 typedef ucs_status_t (*uct_ep_atomic32_post_func_t)(uct_ep_h ep,
112                                                     unsigned opcode,
113                                                     uint32_t value,
114                                                     uint64_t remote_addr,
115                                                     uct_rkey_t rkey);
116 
117 typedef ucs_status_t (*uct_ep_atomic64_post_func_t)(uct_ep_h ep,
118                                                     unsigned opcode,
119                                                     uint64_t value,
120                                                     uint64_t remote_addr,
121                                                     uct_rkey_t rkey);
122 
123 typedef ucs_status_t (*uct_ep_atomic32_fetch_func_t)(uct_ep_h ep,
124                                                      unsigned opcode,
125                                                      uint32_t value,
126                                                      uint32_t *result,
127                                                      uint64_t remote_addr,
128                                                      uct_rkey_t rkey,
129                                                      uct_completion_t *comp);
130 
131 typedef ucs_status_t (*uct_ep_atomic64_fetch_func_t)(uct_ep_h ep,
132                                                      unsigned opcode,
133                                                      uint64_t value,
134                                                      uint64_t *result,
135                                                      uint64_t remote_addr,
136                                                      uct_rkey_t rkey,
137                                                      uct_completion_t *comp);
138 
139 /* endpoint - tagged operations */
140 
141 typedef ucs_status_t (*uct_ep_tag_eager_short_func_t)(uct_ep_h ep,
142                                                       uct_tag_t tag,
143                                                       const void *data,
144                                                       size_t length);
145 
146 typedef ssize_t      (*uct_ep_tag_eager_bcopy_func_t)(uct_ep_h ep,
147                                                       uct_tag_t tag,
148                                                       uint64_t imm,
149                                                       uct_pack_callback_t pack_cb,
150                                                       void *arg,
151                                                       unsigned flags);
152 
153 typedef ucs_status_t (*uct_ep_tag_eager_zcopy_func_t)(uct_ep_h ep,
154                                                       uct_tag_t tag,
155                                                       uint64_t imm,
156                                                       const uct_iov_t *iov,
157                                                       size_t iovcnt,
158                                                       unsigned flags,
159                                                       uct_completion_t *comp);
160 
161 typedef ucs_status_ptr_t (*uct_ep_tag_rndv_zcopy_func_t)(uct_ep_h ep,
162                                                          uct_tag_t tag,
163                                                          const void *header,
164                                                          unsigned header_length,
165                                                          const uct_iov_t *iov,
166                                                          size_t iovcnt,
167                                                          unsigned flags,
168                                                          uct_completion_t *comp);
169 
170 typedef ucs_status_t (*uct_ep_tag_rndv_cancel_func_t)(uct_ep_h ep, void *op);
171 
172 typedef ucs_status_t (*uct_ep_tag_rndv_request_func_t)(uct_ep_h ep,
173                                                        uct_tag_t tag,
174                                                        const void* header,
175                                                        unsigned header_length,
176                                                        unsigned flags);
177 
178 /* interface - tagged operations */
179 
180 typedef ucs_status_t (*uct_iface_tag_recv_zcopy_func_t)(uct_iface_h iface,
181                                                         uct_tag_t tag,
182                                                         uct_tag_t tag_mask,
183                                                         const uct_iov_t *iov,
184                                                         size_t iovcnt,
185                                                         uct_tag_context_t *ctx);
186 
187 typedef ucs_status_t (*uct_iface_tag_recv_cancel_func_t)(uct_iface_h iface,
188                                                          uct_tag_context_t *ctx,
189                                                          int force);
190 
191 /* endpoint - pending queue */
192 
193 typedef ucs_status_t (*uct_ep_pending_add_func_t)(uct_ep_h ep,
194                                                   uct_pending_req_t *n,
195                                                   unsigned flags);
196 
197 typedef void         (*uct_ep_pending_purge_func_t)(uct_ep_h ep,
198                                                     uct_pending_purge_callback_t cb,
199                                                     void *arg);
200 
201 /* endpoint - synchronization */
202 
203 typedef ucs_status_t (*uct_ep_flush_func_t)(uct_ep_h ep,
204                                             unsigned flags,
205                                             uct_completion_t *comp);
206 
207 typedef ucs_status_t (*uct_ep_fence_func_t)(uct_ep_h ep, unsigned flags);
208 
209 typedef ucs_status_t (*uct_ep_check_func_t)(uct_ep_h ep,
210                                             unsigned flags,
211                                             uct_completion_t *comp);
212 
213 /* endpoint - connection establishment */
214 
215 typedef ucs_status_t (*uct_ep_create_func_t)(const uct_ep_params_t *params,
216                                              uct_ep_h *ep_p);
217 
218 typedef ucs_status_t (*uct_ep_disconnect_func_t)(uct_ep_h ep, unsigned flags);
219 
220 typedef ucs_status_t (*uct_cm_ep_conn_notify_func_t)(uct_ep_h ep);
221 
222 typedef void         (*uct_ep_destroy_func_t)(uct_ep_h ep);
223 
224 typedef ucs_status_t (*uct_ep_get_address_func_t)(uct_ep_h ep,
225                                                   uct_ep_addr_t *addr);
226 
227 typedef ucs_status_t (*uct_ep_connect_to_ep_func_t)(uct_ep_h ep,
228                                                     const uct_device_addr_t *dev_addr,
229                                                     const uct_ep_addr_t *ep_addr);
230 
231 typedef ucs_status_t (*uct_iface_accept_func_t)(uct_iface_h iface,
232                                                 uct_conn_request_h conn_request);
233 
234 typedef ucs_status_t (*uct_iface_reject_func_t)(uct_iface_h iface,
235                                                 uct_conn_request_h conn_request);
236 
237 /* interface - synchronization */
238 
239 typedef ucs_status_t (*uct_iface_flush_func_t)(uct_iface_h iface,
240                                                unsigned flags,
241                                                uct_completion_t *comp);
242 
243 typedef ucs_status_t (*uct_iface_fence_func_t)(uct_iface_h iface, unsigned flags);
244 
245 /* interface - progress control */
246 
247 typedef void         (*uct_iface_progress_enable_func_t)(uct_iface_h iface,
248                                                          unsigned flags);
249 
250 typedef void         (*uct_iface_progress_disable_func_t)(uct_iface_h iface,
251                                                           unsigned flags);
252 
253 typedef unsigned     (*uct_iface_progress_func_t)(uct_iface_h iface);
254 
255 /* interface - events */
256 
257 typedef ucs_status_t (*uct_iface_event_fd_get_func_t)(uct_iface_h iface,
258                                                       int *fd_p);
259 
260 typedef ucs_status_t (*uct_iface_event_arm_func_t)(uct_iface_h iface,
261                                                    unsigned events);
262 
263 /* interface - management */
264 
265 typedef void         (*uct_iface_close_func_t)(uct_iface_h iface);
266 
267 typedef ucs_status_t (*uct_iface_query_func_t)(uct_iface_h iface,
268                                                uct_iface_attr_t *iface_attr);
269 
270 /* interface - connection establishment */
271 
272 typedef ucs_status_t (*uct_iface_get_device_address_func_t)(uct_iface_h iface,
273                                                             uct_device_addr_t *addr);
274 
275 typedef ucs_status_t (*uct_iface_get_address_func_t)(uct_iface_h iface,
276                                                      uct_iface_addr_t *addr);
277 
278 typedef int          (*uct_iface_is_reachable_func_t)(const uct_iface_h iface,
279                                                       const uct_device_addr_t *dev_addr,
280                                                       const uct_iface_addr_t *iface_addr);
281 
282 
283 /**
284  * Transport interface operations.
285  * Every operation exposed in the API must appear in the table below, to allow
286  * creating interface/endpoint with custom operations.
287  */
288 typedef struct uct_iface_ops {
289 
290     /* endpoint - put */
291     uct_ep_put_short_func_t             ep_put_short;
292     uct_ep_put_bcopy_func_t             ep_put_bcopy;
293     uct_ep_put_zcopy_func_t             ep_put_zcopy;
294 
295     /* endpoint - get */
296     uct_ep_get_short_func_t             ep_get_short;
297     uct_ep_get_bcopy_func_t             ep_get_bcopy;
298     uct_ep_get_zcopy_func_t             ep_get_zcopy;
299 
300     /* endpoint - active message */
301     uct_ep_am_short_func_t              ep_am_short;
302     uct_ep_am_bcopy_func_t              ep_am_bcopy;
303     uct_ep_am_zcopy_func_t              ep_am_zcopy;
304 
305     /* endpoint - atomics */
306     uct_ep_atomic_cswap64_func_t        ep_atomic_cswap64;
307     uct_ep_atomic_cswap32_func_t        ep_atomic_cswap32;
308     uct_ep_atomic32_post_func_t         ep_atomic32_post;
309     uct_ep_atomic64_post_func_t         ep_atomic64_post;
310     uct_ep_atomic32_fetch_func_t        ep_atomic32_fetch;
311     uct_ep_atomic64_fetch_func_t        ep_atomic64_fetch;
312 
313     /* endpoint - tagged operations */
314     uct_ep_tag_eager_short_func_t       ep_tag_eager_short;
315     uct_ep_tag_eager_bcopy_func_t       ep_tag_eager_bcopy;
316     uct_ep_tag_eager_zcopy_func_t       ep_tag_eager_zcopy;
317     uct_ep_tag_rndv_zcopy_func_t        ep_tag_rndv_zcopy;
318     uct_ep_tag_rndv_cancel_func_t       ep_tag_rndv_cancel;
319     uct_ep_tag_rndv_request_func_t      ep_tag_rndv_request;
320 
321     /* interface - tagged operations */
322     uct_iface_tag_recv_zcopy_func_t     iface_tag_recv_zcopy;
323     uct_iface_tag_recv_cancel_func_t    iface_tag_recv_cancel;
324 
325     /* endpoint - pending queue */
326     uct_ep_pending_add_func_t           ep_pending_add;
327     uct_ep_pending_purge_func_t         ep_pending_purge;
328 
329     /* endpoint - synchronization */
330     uct_ep_flush_func_t                 ep_flush;
331     uct_ep_fence_func_t                 ep_fence;
332     uct_ep_check_func_t                 ep_check;
333 
334     /* endpoint - connection establishment */
335     uct_ep_create_func_t                ep_create;
336     uct_ep_disconnect_func_t            ep_disconnect;
337     uct_cm_ep_conn_notify_func_t        cm_ep_conn_notify;
338     uct_ep_destroy_func_t               ep_destroy;
339     uct_ep_get_address_func_t           ep_get_address;
340     uct_ep_connect_to_ep_func_t         ep_connect_to_ep;
341     uct_iface_accept_func_t             iface_accept;
342     uct_iface_reject_func_t             iface_reject;
343 
344     /* interface - synchronization */
345     uct_iface_flush_func_t              iface_flush;
346     uct_iface_fence_func_t              iface_fence;
347 
348     /* interface - progress control */
349     uct_iface_progress_enable_func_t    iface_progress_enable;
350     uct_iface_progress_disable_func_t   iface_progress_disable;
351     uct_iface_progress_func_t           iface_progress;
352 
353     /* interface - events */
354     uct_iface_event_fd_get_func_t       iface_event_fd_get;
355     uct_iface_event_arm_func_t          iface_event_arm;
356 
357     /* interface - management */
358     uct_iface_close_func_t              iface_close;
359     uct_iface_query_func_t              iface_query;
360 
361     /* interface - connection establishment */
362     uct_iface_get_device_address_func_t iface_get_device_address;
363     uct_iface_get_address_func_t        iface_get_address;
364     uct_iface_is_reachable_func_t       iface_is_reachable;
365 
366 } uct_iface_ops_t;
367 
368 
369 /**
370  *  A progress engine and a domain for allocating communication resources.
371  *  Different workers are progressed independently.
372  */
373 typedef struct uct_worker {
374     ucs_callbackq_t        progress_q;
375 } uct_worker_t;
376 
377 
378 /**
379  * Communication interface context
380  */
381 typedef struct uct_iface {
382     uct_iface_ops_t          ops;
383 } uct_iface_t;
384 
385 
386 /**
387  * Remote endpoint
388  */
389 typedef struct uct_ep {
390     uct_iface_h              iface;
391 } uct_ep_t;
392 
393 
394 /**
395  * Listener for incoming connections
396  */
397 typedef struct uct_listener {
398     uct_cm_h                 cm;
399 } uct_listener_t;
400 
401 
402 typedef struct uct_recv_desc uct_recv_desc_t;
403 typedef void (*uct_desc_release_callback_t)(uct_recv_desc_t *self, void * desc);
404 
405 
406 /**
407  * Receive descriptor
408  */
409 struct uct_recv_desc {
410     uct_desc_release_callback_t cb;
411 };
412 
413 
414 #define uct_recv_desc(_desc) \
415     ( *( ( (uct_recv_desc_t**)(_desc) ) - 1) )
416 
417 END_C_DECLS
418 
419 #endif
420