NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
rdma_common.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 
31 #include <doca_argp.h>
32 #include <doca_ctx.h>
33 #include <doca_error.h>
34 #include <doca_log.h>
35 
36 #include "rdma_common.h"
37 
38 DOCA_LOG_REGISTER(RDMA::COMMON);
39 
40 /*
41  * ARGP Callback - Handle IB device name parameter
42  *
43  * @param [in]: Input parameter
44  * @config [in/out]: Program configuration context
45  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
46  */
47 static doca_error_t device_address_callback(void *param, void *config)
48 {
49  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
50  char *device_name = (char *)param;
51  int len;
52 
55  DOCA_LOG_ERR("Entered IB device name exceeding the maximum size of %d",
58  }
59  strncpy(rdma_cfg->device_name, device_name, len + 1);
60 
61  return DOCA_SUCCESS;
62 }
63 
64 /*
65  * ARGP Callback - Handle send string parameter
66  *
67  * @param [in]: Input parameter
68  * @config [in/out]: Program configuration context
69  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
70  */
71 static doca_error_t send_string_callback(void *param, void *config)
72 {
73  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
74  char *send_string = (char *)param;
75  int len;
76 
77  len = strnlen(send_string, MAX_ARG_SIZE);
78  if (len == MAX_ARG_SIZE) {
79  DOCA_LOG_ERR("Entered send string exceeded buffer size: %d", MAX_USER_ARG_SIZE);
81  }
82  /* The string will be '\0' terminated due to the strnlen check above */
83  strncpy(rdma_cfg->send_string, send_string, len + 1);
84 
85  return DOCA_SUCCESS;
86 }
87 
88 /*
89  * ARGP Callback - Handle read string parameter
90  *
91  * @param [in]: Input parameter
92  * @config [in/out]: Program configuration context
93  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
94  */
95 static doca_error_t read_string_callback(void *param, void *config)
96 {
97  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
98  char *read_string = (char *)param;
99  int len;
100 
101  len = strnlen(read_string, MAX_ARG_SIZE);
102  if (len == MAX_ARG_SIZE) {
103  DOCA_LOG_ERR("Entered read string exceeded buffer size: %d", MAX_USER_ARG_SIZE);
105  }
106  /* The string will be '\0' terminated due to the strnlen check above */
107  strncpy(rdma_cfg->read_string, read_string, len + 1);
108 
109  return DOCA_SUCCESS;
110 }
111 
112 /*
113  * ARGP Callback - Handle write string parameter
114  *
115  * @param [in]: Input parameter
116  * @config [in/out]: Program configuration context
117  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
118  */
119 static doca_error_t write_string_callback(void *param, void *config)
120 {
121  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
122  char *write_string = (char *)param;
123  int len;
124 
125  len = strnlen(write_string, MAX_ARG_SIZE);
126  if (len == MAX_ARG_SIZE) {
127  DOCA_LOG_ERR("Entered send string exceeded buffer size: %d", MAX_USER_ARG_SIZE);
129  }
130  /* The string will be '\0' terminated due to the strnlen check above */
131  strncpy(rdma_cfg->write_string, write_string, len + 1);
132 
133  return DOCA_SUCCESS;
134 }
135 
136 /*
137  * ARGP Callback - Handle exported descriptor file path parameter
138  *
139  * @param [in]: Input parameter
140  * @config [in/out]: Program configuration context
141  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
142  */
143 static doca_error_t local_descriptor_path_callback(void *param, void *config)
144 {
145  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
146  const char *path = (char *)param;
147  int path_len;
148 
149  path_len = strnlen(path, MAX_ARG_SIZE);
150  if (path_len == MAX_ARG_SIZE) {
151  DOCA_LOG_ERR("Entered path exceeded buffer size: %d", MAX_USER_ARG_SIZE);
153  }
154 
155  /* The string will be '\0' terminated due to the strnlen check above */
156  strncpy(rdma_cfg->local_connection_desc_path, path, path_len + 1);
157 
158  return DOCA_SUCCESS;
159 }
160 
161 /*
162  * ARGP Callback - Handle exported descriptor file path parameter
163  *
164  * @param [in]: Input parameter
165  * @config [in/out]: Program configuration context
166  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
167  */
168 static doca_error_t remote_descriptor_path_callback(void *param, void *config)
169 {
170  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
171  const char *path = (char *)param;
172  int path_len = strnlen(path, MAX_ARG_SIZE);
173 
174  if (path_len == MAX_ARG_SIZE) {
175  DOCA_LOG_ERR("Entered path exceeded buffer size: %d", MAX_USER_ARG_SIZE);
177  }
178 
179  /* The string will be '\0' terminated due to the strnlen check above */
180  strncpy(rdma_cfg->remote_connection_desc_path, path, path_len + 1);
181 
182  return DOCA_SUCCESS;
183 }
184 
185 /*
186  * ARGP Callback - Handle exported descriptor file path parameter
187  *
188  * @param [in]: Input parameter
189  * @config [in/out]: Program configuration context
190  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
191  */
192 static doca_error_t mmap_descriptor_path_callback(void *param, void *config)
193 {
194  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
195  const char *path = (char *)param;
196  int path_len = strnlen(path, MAX_ARG_SIZE);
197 
198  if (path_len == MAX_ARG_SIZE) {
199  DOCA_LOG_ERR("Entered path exceeded buffer size: %d", MAX_USER_ARG_SIZE);
201  }
202 
203  /* The string will be '\0' terminated due to the strnlen check above */
204  strncpy(rdma_cfg->remote_resource_desc_path, path, path_len + 1);
205 
206  return DOCA_SUCCESS;
207 }
208 
209 /*
210  * ARGP Callback - Handle gid_index parameter
211  *
212  * @param [in]: Input parameter
213  * @config [in/out]: Program configuration context
214  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
215  */
216 static doca_error_t gid_index_param_callback(void *param, void *config)
217 {
218  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
219  const int gid_index = *(uint32_t *)param;
220 
221  if (gid_index < 0) {
222  DOCA_LOG_ERR("GID index for DOCA RDMA must be non-negative");
224  }
225 
226  rdma_cfg->is_gid_index_set = true;
227  rdma_cfg->gid_index = (uint32_t)gid_index;
228 
229  return DOCA_SUCCESS;
230 }
231 
233 {
234  struct doca_argp_param *send_string_param;
236 
237  /* Create and register send_string param */
238  result = doca_argp_param_create(&send_string_param);
239  if (result != DOCA_SUCCESS) {
240  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
241  return result;
242  }
243  doca_argp_param_set_short_name(send_string_param, "s");
244  doca_argp_param_set_long_name(send_string_param, "send-string");
245  doca_argp_param_set_arguments(send_string_param, "<Send string>");
246  doca_argp_param_set_description(send_string_param,
247  "String to send (optional). If not provided then \"" DEFAULT_STRING
248  "\" will be chosen");
251  result = doca_argp_register_param(send_string_param);
252  if (result != DOCA_SUCCESS) {
253  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
254  return result;
255  }
256 
257  return result;
258 }
259 
261 {
262  struct doca_argp_param *read_string_param;
264 
265  /* Create and register read_string param */
266  result = doca_argp_param_create(&read_string_param);
267  if (result != DOCA_SUCCESS) {
268  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
269  return result;
270  }
271  doca_argp_param_set_short_name(read_string_param, "r");
272  doca_argp_param_set_long_name(read_string_param, "read-string");
273  doca_argp_param_set_arguments(read_string_param, "<Read string>");
274  doca_argp_param_set_description(read_string_param,
275  "String to read (optional). If not provided then \"" DEFAULT_STRING
276  "\" will be chosen");
279  result = doca_argp_register_param(read_string_param);
280  if (result != DOCA_SUCCESS) {
281  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
282  return result;
283  }
284 
285  return result;
286 }
287 
289 {
290  struct doca_argp_param *write_string_param;
292 
293  /* Create and register write_string param */
294  result = doca_argp_param_create(&write_string_param);
295  if (result != DOCA_SUCCESS) {
296  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
297  return result;
298  }
299  doca_argp_param_set_short_name(write_string_param, "w");
300  doca_argp_param_set_long_name(write_string_param, "write-string");
301  doca_argp_param_set_arguments(write_string_param, "<Write string>");
302  doca_argp_param_set_description(write_string_param,
303  "String to write (optional). If not provided then \"" DEFAULT_STRING
304  "\" will be chosen");
306  doca_argp_param_set_type(write_string_param, DOCA_ARGP_TYPE_STRING);
307  result = doca_argp_register_param(write_string_param);
308  if (result != DOCA_SUCCESS) {
309  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
310  return result;
311  }
312 
313  return result;
314 }
315 
316 /*
317  * ARGP Callback - Handle num_connections parameter
318  *
319  * @param [in]: Input parameter
320  * @config [in/out]: Program configuration context
321  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
322  */
323 static doca_error_t num_connections_param_callback(void *param, void *config)
324 {
325  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
326  const uint32_t num_connections = *(uint32_t *)param;
327 
329  DOCA_LOG_ERR("Max number of connections must be <= [%d]", MAX_NUM_CONNECTIONS);
331  }
332 
333  rdma_cfg->num_connections = num_connections;
334 
335  return DOCA_SUCCESS;
336 }
337 
339 {
340  struct doca_argp_param *num_connections_param;
342  static char param_desc[MAX_ARG_SIZE];
343 
344  /* Create and register num_connections param */
345  result = doca_argp_param_create(&num_connections_param);
346  if (result != DOCA_SUCCESS) {
347  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
348  return result;
349  }
350  doca_argp_param_set_short_name(num_connections_param, "nc");
351  doca_argp_param_set_long_name(num_connections_param, "num-connections");
352  snprintf(param_desc,
353  MAX_ARG_SIZE,
354  "%s%d%s",
355  "num_connections for DOCA RDMA (optional), max connections number must be <= ",
357  " in this sample");
358  doca_argp_param_set_description(num_connections_param, param_desc);
360  doca_argp_param_set_type(num_connections_param, DOCA_ARGP_TYPE_INT);
361  result = doca_argp_register_param(num_connections_param);
362  if (result != DOCA_SUCCESS) {
363  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
364  return result;
365  }
366  return result;
367 }
368 
369 /*
370  * ARGP Callback - Handle transport_type parameter
371  *
372  * @param [in]: Input parameter
373  * @config [in/out]: Program configuration context
374  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
375  */
376 static doca_error_t transport_type_param_callback(void *param, void *config)
377 {
378  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
379  const char *type = (char *)param;
380 
381  if (strcasecmp(type, "RC") == 0)
383  else if (strcasecmp(type, "DC") == 0)
385  else {
386  DOCA_LOG_ERR("Entered wrong RDMA transport_type, the accepted RDMA transport_type are: "
387  "RC, rc, "
388  "DC, dc");
390  }
391 
392  return DOCA_SUCCESS;
393 }
394 
395 /*
396  * ARGP Callback - Handle use_rdma_cm parameter
397  *
398  * @param [in]: Input parameter
399  * @config [in/out]: Program configuration context
400  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
401  */
402 static doca_error_t use_rdma_cm_param_callback(void *param, void *config)
403 {
404  (void)param;
405  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
406 
407  rdma_cfg->use_rdma_cm = true;
408 
409  return DOCA_SUCCESS;
410 }
411 
412 /*
413  * ARGP Callback - Handle cm_port parameter
414  *
415  * @param [in]: Input parameter
416  * @config [in/out]: Program configuration context
417  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
418  */
419 static doca_error_t cm_port_param_callback(void *param, void *config)
420 {
421  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
422  const int cm_port = *(uint32_t *)param;
423 
424  if (cm_port < 0) {
425  DOCA_LOG_ERR("Server listening port number for DOCA RDMA-CM must be non-negative");
427  }
428 
429  rdma_cfg->cm_port = (uint32_t)cm_port;
430 
431  return DOCA_SUCCESS;
432 }
433 
434 /*
435  * ARGP Callback - Handle cm server addr parameter
436  *
437  * @param [in]: Input parameter
438  * @config [in/out]: Program configuration context
439  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
440  */
441 static doca_error_t cm_addr_param_callback(void *param, void *config)
442 {
443  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
444  const char *addr = (char *)param;
445  int addr_len = strnlen(addr, SERVER_ADDR_LEN + 1);
446 
447  if (addr_len == SERVER_ADDR_LEN) {
448  DOCA_LOG_ERR("Entered server address exceeded buffer size: %d", SERVER_ADDR_LEN);
450  }
451 
452  /* The string will be '\0' terminated due to the strnlen check above */
453  strncpy(rdma_cfg->cm_addr, addr, addr_len + 1);
454 
455  return DOCA_SUCCESS;
456 }
457 
458 /*
459  * ARGP Callback - Handle cm server addr type parameter
460  *
461  * @param [in]: Input parameter
462  * @config [in/out]: Program configuration context
463  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
464  */
465 static doca_error_t cm_addr_type_param_callback(void *param, void *config)
466 {
467  struct rdma_config *rdma_cfg = (struct rdma_config *)config;
468  const char *type = (char *)param;
469  int type_len = strnlen(type, SERVER_ADDR_TYPE_LEN + 1);
470 
471  if (type_len == SERVER_ADDR_TYPE_LEN) {
472  DOCA_LOG_ERR("Entered server address type exceeded buffer size: %d", SERVER_ADDR_TYPE_LEN);
474  }
475 
476  if (strcasecmp(type, "ip4") == 0 || strcasecmp(type, "ipv4") == 0)
478  else if (strcasecmp(type, "ip6") == 0 || strcasecmp(type, "ipv6") == 0)
480  else if (strcasecmp(type, "gid") == 0)
482  else {
483  DOCA_LOG_ERR("Entered wrong server address type, the accepted server address type are: "
484  "ip4, ipv4, IP4, IPv4, IPV4, "
485  "ip6, ipv6, IP6, IPv6, IPV6, "
486  "gid, GID");
488  }
489 
490  return DOCA_SUCCESS;
491 }
492 
493 /*
494  * A wrapper for handling rdma_cm related cmdline parameters
495  *
496  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
497  */
499 {
501  struct doca_argp_param *use_rdma_cm_param;
502  struct doca_argp_param *cm_port_param;
503  struct doca_argp_param *cm_addr_param;
504  struct doca_argp_param *cm_addr_type_param;
505 
506  /* Create and register user_rdma_cm param */
507  result = doca_argp_param_create(&use_rdma_cm_param);
508  if (result != DOCA_SUCCESS) {
509  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
510  return result;
511  }
512  doca_argp_param_set_short_name(use_rdma_cm_param, "cm");
513  doca_argp_param_set_long_name(use_rdma_cm_param, "use-rdma-cm");
514  doca_argp_param_set_description(use_rdma_cm_param, "Whether to use rdma-cm or oob to setup connection");
517  result = doca_argp_register_param(use_rdma_cm_param);
518  if (result != DOCA_SUCCESS) {
519  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
520  return result;
521  }
522 
523  /* Create and register cm_port_param */
524  result = doca_argp_param_create(&cm_port_param);
525  if (result != DOCA_SUCCESS) {
526  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
527  return result;
528  }
529  doca_argp_param_set_short_name(cm_port_param, "lp");
530  doca_argp_param_set_long_name(cm_port_param, "listen-port");
531  doca_argp_param_set_arguments(cm_port_param, "<listen-port-num>");
532  doca_argp_param_set_description(cm_port_param, "server listen port number");
535  result = doca_argp_register_param(cm_port_param);
536  if (result != DOCA_SUCCESS) {
537  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
538  return result;
539  }
540 
541  /* Create and register cm_addr_param */
542  result = doca_argp_param_create(&cm_addr_param);
543  if (result != DOCA_SUCCESS) {
544  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
545  return result;
546  }
547  doca_argp_param_set_short_name(cm_addr_param, "sa");
548  doca_argp_param_set_long_name(cm_addr_param, "server-addr");
549  doca_argp_param_set_arguments(cm_addr_param, "<server address>");
550  doca_argp_param_set_description(cm_addr_param, "Rdma cm server device address");
553  result = doca_argp_register_param(cm_addr_param);
554  if (result != DOCA_SUCCESS) {
555  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
556  return result;
557  }
558 
559  /* Create and register cm_addr_type_param */
560  result = doca_argp_param_create(&cm_addr_type_param);
561  if (result != DOCA_SUCCESS) {
562  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
563  return result;
564  }
565  doca_argp_param_set_short_name(cm_addr_type_param, "sat");
566  doca_argp_param_set_long_name(cm_addr_type_param, "server-addr-type");
567  doca_argp_param_set_arguments(cm_addr_type_param, "<server address type>");
568  doca_argp_param_set_description(cm_addr_type_param, "Rdma cm server device address type: IPv4, IPv6 or GID");
570  doca_argp_param_set_type(cm_addr_type_param, DOCA_ARGP_TYPE_STRING);
571  result = doca_argp_register_param(cm_addr_type_param);
572  if (result != DOCA_SUCCESS) {
573  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
574  return result;
575  }
576 
577  return DOCA_SUCCESS;
578 }
579 
581 {
583  struct doca_argp_param *device_param;
584  struct doca_argp_param *local_desc_path_param;
585  struct doca_argp_param *remote_desc_path_param;
586  struct doca_argp_param *remote_resource_desc_path;
587  struct doca_argp_param *gid_index_param;
588  struct doca_argp_param *transport_type_param;
589 
590  /* Create and register device param */
591  result = doca_argp_param_create(&device_param);
592  if (result != DOCA_SUCCESS) {
593  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
594  return result;
595  }
596  doca_argp_param_set_short_name(device_param, "d");
597  doca_argp_param_set_long_name(device_param, "device");
598  doca_argp_param_set_arguments(device_param, "<IB device name>");
599  doca_argp_param_set_description(device_param, "IB device name");
602  doca_argp_param_set_mandatory(device_param);
603  result = doca_argp_register_param(device_param);
604  if (result != DOCA_SUCCESS) {
605  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
606  return result;
607  }
608 
609  /* Create and register local descriptor file path param */
610  result = doca_argp_param_create(&local_desc_path_param);
611  if (result != DOCA_SUCCESS) {
612  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
613  return result;
614  }
615  doca_argp_param_set_short_name(local_desc_path_param, "ld");
616  doca_argp_param_set_long_name(local_desc_path_param, "local-descriptor-path");
618  local_desc_path_param,
619  "Local descriptor file path that includes the local connection descriptor, to be copied to the remote program, "
620  "used only when not using the use-rdma-cm flag");
622  doca_argp_param_set_type(local_desc_path_param, DOCA_ARGP_TYPE_STRING);
623  result = doca_argp_register_param(local_desc_path_param);
624  if (result != DOCA_SUCCESS) {
625  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
626  return result;
627  }
628 
629  /* Create and register remote descriptor file path param */
630  result = doca_argp_param_create(&remote_desc_path_param);
631  if (result != DOCA_SUCCESS) {
632  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
633  return result;
634  }
635  doca_argp_param_set_short_name(remote_desc_path_param, "re");
636  doca_argp_param_set_long_name(remote_desc_path_param, "remote-descriptor-path");
638  remote_desc_path_param,
639  "Remote descriptor file path that includes the remote connection descriptor, to be copied from the remote program, "
640  "used only when not using the use-rdma-cm flag");
642  doca_argp_param_set_type(remote_desc_path_param, DOCA_ARGP_TYPE_STRING);
643  result = doca_argp_register_param(remote_desc_path_param);
644  if (result != DOCA_SUCCESS) {
645  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
646  return result;
647  }
648 
649  /* Create and register mmap descriptor file path param */
650  result = doca_argp_param_create(&remote_resource_desc_path);
651  if (result != DOCA_SUCCESS) {
652  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
653  return result;
654  }
655  doca_argp_param_set_short_name(remote_resource_desc_path, "m");
656  doca_argp_param_set_long_name(remote_resource_desc_path, "remote-resource-descriptor-path");
658  remote_resource_desc_path,
659  "Remote descriptor file path that includes the remote mmap connection descriptor, to be copied from the remote program, "
660  "used only when not using the use-rdma-cm flag");
662  doca_argp_param_set_type(remote_resource_desc_path, DOCA_ARGP_TYPE_STRING);
663  result = doca_argp_register_param(remote_resource_desc_path);
664  if (result != DOCA_SUCCESS) {
665  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
666  return result;
667  }
668 
669  /* Create and register gid_index param */
670  result = doca_argp_param_create(&gid_index_param);
671  if (result != DOCA_SUCCESS) {
672  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
673  return result;
674  }
675  doca_argp_param_set_short_name(gid_index_param, "g");
676  doca_argp_param_set_long_name(gid_index_param, "gid-index");
677  doca_argp_param_set_description(gid_index_param, "GID index for DOCA RDMA (optional)");
680  result = doca_argp_register_param(gid_index_param);
681  if (result != DOCA_SUCCESS) {
682  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
683  return result;
684  }
685 
686  /* Create and register transport_type param */
687  result = doca_argp_param_create(&transport_type_param);
688  if (result != DOCA_SUCCESS) {
689  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
690  return result;
691  }
692  doca_argp_param_set_short_name(transport_type_param, "tt");
693  doca_argp_param_set_long_name(transport_type_param, "transport-type");
695  transport_type_param,
696  "transport_type for DOCA RDMA (RC or DC, optional), only useful for single connection out-of-band RDMA for now");
698  doca_argp_param_set_type(transport_type_param, DOCA_ARGP_TYPE_STRING);
699  result = doca_argp_register_param(transport_type_param);
700  if (result != DOCA_SUCCESS) {
701  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
702  return result;
703  }
704 
705  return register_rdma_cm_params();
706 }
707 
708 /*
709  * Open DOCA device
710  *
711  * @device_name [in]: The name of the wanted IB device (could be empty string)
712  * @func [in]: Function to check if a given device is capable of executing some task
713  * @doca_device [out]: An allocated DOCA device on success and NULL otherwise
714  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
715  */
716 static doca_error_t open_doca_device(const char *device_name, task_check func, struct doca_dev **doca_device)
717 {
718  struct doca_devinfo **dev_list;
719  uint32_t nb_devs = 0;
721  char ibdev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE] = {0};
722  uint32_t i = 0;
723 
724  result = doca_devinfo_create_list(&dev_list, &nb_devs);
725  if (result != DOCA_SUCCESS) {
726  DOCA_LOG_ERR("Failed to load DOCA devices list: %s", doca_error_get_descr(result));
727  return result;
728  }
729 
730  /* Search device with same dev name*/
731  for (i = 0; i < nb_devs; i++) {
732  result = doca_devinfo_get_ibdev_name(dev_list[i], ibdev_name, sizeof(ibdev_name));
733  if (result != DOCA_SUCCESS ||
734  (strlen(device_name) != 0 && strncmp(device_name, ibdev_name, DOCA_DEVINFO_IBDEV_NAME_SIZE) != 0))
735  continue;
736  /* If any special capabilities are needed */
737  if (func != NULL && func(dev_list[i]) != DOCA_SUCCESS)
738  continue;
739  result = doca_dev_open(dev_list[i], doca_device);
740  if (result != DOCA_SUCCESS) {
741  DOCA_LOG_ERR("Failed to open DOCA device: %s", doca_error_get_descr(result));
742  goto out;
743  }
744  break;
745  }
746 
747 out:
748  doca_devinfo_destroy_list(dev_list);
749 
750  if (*doca_device == NULL) {
751  DOCA_LOG_ERR("Couldn't get DOCA device");
752  return DOCA_ERROR_NOT_FOUND;
753  }
754 
755  return result;
756 }
757 
759  const uint32_t mmap_permissions,
760  const uint32_t rdma_permissions,
761  task_check func,
762  struct rdma_resources *resources)
763 {
764  doca_error_t result, tmp_result;
765 
766  resources->cfg = cfg;
768  resources->run_pe_progress = true;
770 
771  /* Check configuration correctness, for now, DC is only supported for out-of-band single connection sample */
772  if (((cfg->num_connections > 1) || (cfg->use_rdma_cm == true)) &&
773  (cfg->transport_type == DOCA_RDMA_TRANSPORT_TYPE_DC)) {
774  DOCA_LOG_ERR(
775  "Failed to allocate RDMA resources: due to DOCA_RDMA_TRANSPORT_TYPE_DC is only supported for out-of-band single connection case for now");
777  }
778 
779  /* Open DOCA device */
780  result = open_doca_device(cfg->device_name, func, &(resources->doca_device));
781  if (result != DOCA_SUCCESS) {
782  DOCA_LOG_ERR("Failed to open DOCA device: %s", doca_error_get_descr(result));
783  return result;
784  }
785 
786  /* Allocate memory for memory range */
788  if (resources->mmap_memrange == NULL) {
789  DOCA_LOG_ERR("Failed to allocate memory for mmap_memrange: %s", doca_error_get_descr(result));
791  goto close_doca_dev;
792  }
793 
794  /* Create mmap with allocated memory */
796  mmap_permissions,
797  (void *)resources->mmap_memrange,
800  if (result != DOCA_SUCCESS) {
801  DOCA_LOG_ERR("Failed to create DOCA mmap: %s", doca_error_get_descr(result));
802  goto free_memrange;
803  }
804 
806  if (result != DOCA_SUCCESS) {
807  DOCA_LOG_ERR("Failed to set permissions to DOCA RDMA: %s", doca_error_get_descr(result));
808  goto destroy_doca_mmap;
809  }
810 
811  /* Create DOCA RDMA instance */
813  if (result != DOCA_SUCCESS) {
814  DOCA_LOG_ERR("Failed to create DOCA RDMA: %s", doca_error_get_descr(result));
815  goto destroy_pe;
816  }
817 
818  /* Convert DOCA RDMA to general DOCA context */
820  if (resources->rdma_ctx == NULL) {
822  DOCA_LOG_ERR("Failed to convert DOCA RDMA to DOCA context: %s", doca_error_get_descr(result));
823  goto destroy_doca_rdma;
824  }
825 
826  /* Set permissions to DOCA RDMA */
827  result = doca_rdma_set_permissions(resources->rdma, rdma_permissions);
828  if (result != DOCA_SUCCESS) {
829  DOCA_LOG_ERR("Failed to set permissions to DOCA RDMA: %s", doca_error_get_descr(result));
830  goto destroy_doca_rdma;
831  }
832 
833  /* Set gid_index to DOCA RDMA if it's provided */
834  if (cfg->is_gid_index_set) {
835  /* Set gid_index to DOCA RDMA */
837  if (result != DOCA_SUCCESS) {
838  DOCA_LOG_ERR("Failed to set gid_index to DOCA RDMA: %s", doca_error_get_descr(result));
839  goto destroy_doca_rdma;
840  }
841  }
842 
843  /* Set num_connections to DOCA RDMA */
845  if (result != DOCA_SUCCESS) {
846  DOCA_LOG_ERR("Failed to set max_num_connections to DOCA RDMA: %s", doca_error_get_descr(result));
847  goto destroy_doca_rdma;
848  }
849 
850  /* Set transport type */
852  if (result != DOCA_SUCCESS) {
853  DOCA_LOG_ERR("Failed to set RDMA transport type: %s", doca_error_get_descr(result));
854  goto destroy_doca_rdma;
855  }
856 
858  if (result != DOCA_SUCCESS) {
859  DOCA_LOG_ERR("Unable to set progress engine for RDMA: %s", doca_error_get_descr(result));
860  goto destroy_doca_rdma;
861  }
862 
863  return result;
864 
865 destroy_doca_rdma:
866  /* Destroy DOCA RDMA */
867  tmp_result = doca_rdma_destroy(resources->rdma);
868  if (tmp_result != DOCA_SUCCESS) {
869  DOCA_LOG_ERR("Failed to destroy DOCA RDMA: %s", doca_error_get_descr(tmp_result));
870  DOCA_ERROR_PROPAGATE(result, tmp_result);
871  }
872 destroy_pe:
873  /* Destroy DOCA progress engine */
874  tmp_result = doca_pe_destroy(resources->pe);
875  if (tmp_result != DOCA_SUCCESS) {
876  DOCA_LOG_ERR("Failed to destroy DOCA progress engine: %s", doca_error_get_descr(tmp_result));
877  DOCA_ERROR_PROPAGATE(result, tmp_result);
878  }
879 destroy_doca_mmap:
880  /* Destroy DOCA mmap */
881  tmp_result = doca_mmap_destroy(resources->mmap);
882  if (tmp_result != DOCA_SUCCESS) {
883  DOCA_LOG_ERR("Failed to destroy DOCA mmap: %s", doca_error_get_descr(tmp_result));
884  DOCA_ERROR_PROPAGATE(result, tmp_result);
885  }
886 free_memrange:
887  /* Free DOCA mmap memory range */
888  free(resources->mmap_memrange);
889 close_doca_dev:
890  /* Close DOCA device */
891  tmp_result = doca_dev_close(resources->doca_device);
892  if (tmp_result != DOCA_SUCCESS) {
893  DOCA_LOG_ERR("Failed to close DOCA device: %s", doca_error_get_descr(tmp_result));
894  DOCA_ERROR_PROPAGATE(result, tmp_result);
895  }
896  return result;
897 }
898 
899 doca_error_t delete_file(const char *file_path)
900 {
901  FILE *fp;
902  int res;
904 
905  /* Check if file exists before deleting it */
906  fp = fopen(file_path, "r");
907  if (fp) {
908  /* Delete file by using unlink */
909  res = unlink(file_path);
910  if (res != 0) {
912  DOCA_LOG_ERR("Failed to delete file %s: %s", file_path, doca_error_get_descr(result));
913  }
914  fclose(fp);
915  }
916 
917  return result;
918 }
919 
920 /*
921  * Delete the description files that we created
922  *
923  * @cfg [in]: Configuration parameters
924  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
925  */
927 {
929 
930  result = delete_file(cfg->local_connection_desc_path);
931  if (result != DOCA_SUCCESS) {
932  DOCA_LOG_ERR("Deleting file %s failed: %s",
933  cfg->local_connection_desc_path,
935  return result;
936  }
937 
938  result = delete_file(cfg->remote_connection_desc_path);
939  if (result != DOCA_SUCCESS) {
940  DOCA_LOG_ERR("Deleting file %s failed: %s",
941  cfg->remote_connection_desc_path,
943  return result;
944  }
945 
946  result = delete_file(cfg->remote_resource_desc_path);
947  if (result != DOCA_SUCCESS) {
948  DOCA_LOG_ERR("Deleting file %s failed: %s",
949  cfg->remote_resource_desc_path,
951  return result;
952  }
953 
954  return result;
955 }
956 
957 /*
958  * Destroy DOCA RDMA-CM related resources
959  *
960  * @resources [in]: DOCA RDMA-CM related resources to destroy
961  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
962  */
964 {
965  doca_error_t result = DOCA_SUCCESS, tmp_result;
966 
967  if (resources->cm_addr != NULL) {
969  if (result != DOCA_SUCCESS) {
970  DOCA_LOG_ERR("Failed to destroy DOCA rdma cm address: %s", doca_error_get_descr(result));
971  return result;
972  }
973  }
976  if (tmp_result != DOCA_SUCCESS) {
977  DOCA_LOG_ERR("Failed to destroy DOCA local mmap descriptor mmap: %s",
978  doca_error_get_descr(tmp_result));
979  DOCA_ERROR_PROPAGATE(result, tmp_result);
980  }
981  }
984  if (tmp_result != DOCA_SUCCESS) {
985  DOCA_LOG_ERR("Failed to destroy DOCA remote mmap descriptor mmap: %s",
986  doca_error_get_descr(tmp_result));
987  DOCA_ERROR_PROPAGATE(result, tmp_result);
988  }
989  }
992  if (tmp_result != DOCA_SUCCESS) {
993  DOCA_LOG_ERR("Failed to destroy DOCA local sync_event descriptor mmap: %s",
994  doca_error_get_descr(tmp_result));
995  DOCA_ERROR_PROPAGATE(result, tmp_result);
996  }
997  }
998 
999  return result;
1000 }
1001 
1003 {
1004  doca_error_t result = DOCA_SUCCESS, tmp_result;
1005 
1006  /* Stop and destroy remote mmap if exists */
1007  if (resources->remote_mmap != NULL) {
1009  if (result != DOCA_SUCCESS)
1010  DOCA_LOG_ERR("Failed to stop DOCA remote mmap: %s", doca_error_get_descr(result));
1011 
1012  tmp_result = doca_mmap_destroy(resources->remote_mmap);
1013  if (tmp_result != DOCA_SUCCESS) {
1014  DOCA_LOG_ERR("Failed to destroy DOCA remote mmap: %s", doca_error_get_descr(tmp_result));
1015  DOCA_ERROR_PROPAGATE(result, tmp_result);
1016  }
1017  }
1018 
1019  if (resources->cfg->use_rdma_cm == true) {
1020  tmp_result = destroy_rdma_cm_resources(resources);
1021  if (tmp_result != DOCA_SUCCESS) {
1022  DOCA_LOG_ERR("Failed to destroy rdma cm resources: %s", doca_error_get_descr(tmp_result));
1023  DOCA_ERROR_PROPAGATE(result, tmp_result);
1024  }
1025  }
1026 
1027  /* Destroy DOCA RDMA */
1028  tmp_result = doca_rdma_destroy(resources->rdma);
1029  if (tmp_result != DOCA_SUCCESS) {
1030  DOCA_LOG_ERR("Failed to destroy DOCA RDMA: %s", doca_error_get_descr(tmp_result));
1031  DOCA_ERROR_PROPAGATE(result, tmp_result);
1032  }
1033 
1034  /* Destroy DOCA progress engine */
1035  tmp_result = doca_pe_destroy(resources->pe);
1036  if (tmp_result != DOCA_SUCCESS) {
1037  DOCA_LOG_ERR("Failed to destroy DOCA progress engine: %s", doca_error_get_descr(tmp_result));
1038  DOCA_ERROR_PROPAGATE(result, tmp_result);
1039  }
1040 
1041  /* Stop DOCA mmap */
1042  tmp_result = doca_mmap_stop(resources->mmap);
1043  if (tmp_result != DOCA_SUCCESS) {
1044  DOCA_LOG_ERR("Failed to stop DOCA mmap: %s", doca_error_get_descr(tmp_result));
1045  DOCA_ERROR_PROPAGATE(result, tmp_result);
1046  }
1047 
1048  /* Free DOCA mmap memory range */
1049  free(resources->mmap_memrange);
1050 
1051  /* Destroy DOCA mmap */
1052  tmp_result = doca_mmap_destroy(resources->mmap);
1053  if (tmp_result != DOCA_SUCCESS) {
1054  DOCA_LOG_ERR("Failed to destroy DOCA mmap: %s", doca_error_get_descr(tmp_result));
1055  DOCA_ERROR_PROPAGATE(result, tmp_result);
1056  }
1057 
1058  /* Free remote connection descriptor */
1061 
1062  /* Free remote mmap descriptor */
1065 
1066  /* Free remote mmap descriptor */
1069 
1070  /* Close DOCA device */
1071  tmp_result = doca_dev_close(resources->doca_device);
1072  if (tmp_result != DOCA_SUCCESS) {
1073  DOCA_LOG_ERR("Failed to close DOCA device: %s", doca_error_get_descr(tmp_result));
1074  DOCA_ERROR_PROPAGATE(result, tmp_result);
1075  }
1076 
1077  /* Delete description files that we created */
1078  tmp_result = clean_up_files(cfg);
1079  if (tmp_result != DOCA_SUCCESS) {
1080  DOCA_LOG_ERR("Failed to clean up files: %s", doca_error_get_descr(tmp_result));
1081  DOCA_ERROR_PROPAGATE(result, tmp_result);
1082  }
1083 
1084  return result;
1085 }
1086 
1087 doca_error_t write_file(const char *file_path, const char *string, size_t string_len)
1088 {
1089  FILE *fp;
1091 
1092  /* Check if the file exists by opening it to read */
1093  fp = fopen(file_path, "r");
1094  if (fp) {
1095  DOCA_LOG_ERR("File %s already exists. Please delete it prior to running the sample", file_path);
1096  fclose(fp);
1097  return DOCA_ERROR_IO_FAILED;
1098  }
1099 
1100  fp = fopen(file_path, "wb");
1101  if (fp == NULL) {
1102  DOCA_LOG_ERR("Failed to create file %s", file_path);
1103  return DOCA_ERROR_IO_FAILED;
1104  }
1105 
1106  /* Write the string */
1107  if (fwrite(string, 1, string_len, fp) != string_len) {
1108  DOCA_LOG_ERR("Failed to write on file %s", file_path);
1109  fclose(fp);
1110  return DOCA_ERROR_IO_FAILED;
1111  }
1112 
1113  /* Close the file */
1114  fclose(fp);
1115 
1116  return result;
1117 }
1118 
1119 doca_error_t read_file(const char *file_path, char **string, size_t *string_len)
1120 {
1121  FILE *fp;
1122  long file_size;
1124 
1125  /* Open the file for reading */
1126  fp = fopen(file_path, "r");
1127  if (fp == NULL) {
1128  DOCA_LOG_ERR("Failed to open the file %s for reading", file_path);
1129  return DOCA_ERROR_IO_FAILED;
1130  }
1131 
1132  /* Calculate the size of the file */
1133  if (fseek(fp, 0, SEEK_END) != 0) {
1134  DOCA_LOG_ERR("Failed to calculate file size");
1135  fclose(fp);
1136  return DOCA_ERROR_IO_FAILED;
1137  }
1138 
1139  file_size = ftell(fp);
1140  if (file_size == -1) {
1141  DOCA_LOG_ERR("Failed to calculate file size");
1142  fclose(fp);
1143  return DOCA_ERROR_IO_FAILED;
1144  }
1145 
1146  /* Rewind file to the start */
1147  if (fseek(fp, 0, SEEK_SET) != 0) {
1148  DOCA_LOG_ERR("Failed to rewind file");
1149  fclose(fp);
1150  return DOCA_ERROR_IO_FAILED;
1151  }
1152 
1153  *string_len = file_size;
1154  *string = malloc(file_size);
1155  if (*string == NULL) {
1156  DOCA_LOG_ERR("Failed to allocate memory of size %lu", file_size);
1157  fclose(fp);
1158  return DOCA_ERROR_NO_MEMORY;
1159  }
1160 
1161  /* Read the file to the string */
1162  if (fread(*string, 1, file_size, fp) != (size_t)file_size) {
1163  DOCA_LOG_ERR("Failed read from file %s", file_path);
1165  free(*string);
1166  }
1167 
1168  fclose(fp);
1169  return result;
1170 }
1171 
1173 {
1174  union doca_data connection_data;
1176  struct rdma_config *cfg = resources->cfg;
1177 
1179  resources->is_client = false;
1180  if (cfg->use_rdma_cm == true) {
1181  DOCA_LOG_INFO("Using RDMA_CM to setup RDMA connection");
1182  /* If cmdline option has a cm_addr param, the test object is used as a client; otherwise it is a server
1183  */
1184  if (cfg->cm_addr[0] != '\0') {
1186  resources->is_client = true;
1187  }
1188  if ((resources->is_client == true) && (cfg->num_connections > 1)) {
1189  DOCA_LOG_ERR("Client only support single connection, but input num_connections is [%u]",
1190  cfg->num_connections);
1191  return DOCA_ERROR_INVALID_VALUE;
1192  }
1193  } else
1194  DOCA_LOG_INFO("Using Out-Of-Band to setup RDMA connection");
1195 
1196  DOCA_LOG_INFO("-----------------------------------------------");
1197  DOCA_LOG_INFO("RDMA_CM connection params:");
1198  DOCA_LOG_INFO("-- Connection Role: %s", (resources->is_client == true) ? CLIENT_NAME : SERVER_NAME);
1199  DOCA_LOG_INFO("-- Addr_type : %d", cfg->cm_addr_type);
1200  DOCA_LOG_INFO("-- Addr: %s", (cfg->cm_addr[0] == '\0') ? "NULL" : cfg->cm_addr);
1201  DOCA_LOG_INFO("-- Port: %u", cfg->cm_port);
1202  DOCA_LOG_INFO("-- Num_connections: %u", cfg->num_connections);
1203  DOCA_LOG_INFO("-----------------------------------------------");
1204 
1205  resources->cm_addr = NULL;
1207 
1208  if (resources->is_client == false) {
1209  DOCA_LOG_INFO("Server calling doca_rdma_start_listen_to_port");
1211  if (DOCA_IS_ERROR(result)) {
1212  DOCA_LOG_ERR("Server failed to call doca_rdma_start_listen_to_port");
1213  return result;
1214  }
1215  } else {
1216  result = doca_rdma_addr_create(cfg->cm_addr_type, cfg->cm_addr, cfg->cm_port, &resources->cm_addr);
1217  if (DOCA_IS_ERROR(result)) {
1218  DOCA_LOG_ERR("Failed to create rdma cm connection address");
1219  return result;
1220  }
1221  if (resources->cm_addr == NULL) {
1222  DOCA_LOG_ERR("RDMA_CM client must be given a valid server address (ipv4, ipv6 or gid)");
1223  return DOCA_ERROR_INVALID_VALUE;
1224  }
1225  DOCA_LOG_INFO("Client calling doca_rdma_connect_to_addr");
1226  connection_data.ptr = (void *)resources;
1228  if (DOCA_IS_ERROR(result)) {
1230  resources->cm_addr = NULL;
1231  DOCA_LOG_ERR("Client failed to call doca_rdma_connect_to_addr");
1232  return result;
1233  }
1234  }
1235 
1236  if (result != DOCA_SUCCESS)
1237  DOCA_LOG_ERR("[%s] failed to start connection: %s", resources->self_name, doca_error_get_descr(result));
1238  else
1239  DOCA_LOG_INFO("[%s] started connection successfully", resources->self_name);
1240 
1241  return result;
1242 }
1243 
1245 {
1247  uint32_t i = 0;
1248 
1249  for (i = 0; i < resources->num_connection_established; i++) {
1251  if (result != DOCA_SUCCESS) {
1252  DOCA_LOG_ERR("[%s] cannot disconnect rdma-cm connection: %s",
1255  break;
1256  } else
1257  DOCA_LOG_INFO("[%s] successfully disconnect rdma-cm connection", resources->self_name);
1258  }
1259  return result;
1260 }
1261 
1262 doca_error_t send_msg(struct doca_rdma *rdma,
1263  struct doca_rdma_connection *rdma_connection,
1264  struct doca_mmap *mmap,
1265  struct doca_buf_inventory *buf_inv,
1266  void *msg,
1267  uint32_t msg_len,
1268  void *user_data)
1269 {
1271  struct doca_buf *src_buf;
1272  struct doca_rdma_task_send *rdma_send_task;
1273  union doca_data task_user_data;
1274  task_user_data.ptr = user_data;
1275 
1276  result = doca_buf_inventory_buf_get_by_data(buf_inv, mmap, msg, msg_len, &src_buf);
1277  if (DOCA_IS_ERROR(result)) {
1278  DOCA_LOG_ERR("Failed to get a doca_buf, with error: %s", doca_error_get_descr(result));
1279  return result;
1280  }
1281 
1282  result = doca_rdma_task_send_allocate_init(rdma, rdma_connection, src_buf, task_user_data, &rdma_send_task);
1283  if (DOCA_IS_ERROR(result)) {
1284  DOCA_LOG_ERR("Failed to allocate send task, with error: %s", doca_error_get_descr(result));
1285  return result;
1286  }
1287 
1289  if (DOCA_IS_ERROR(result)) {
1290  DOCA_LOG_ERR("Failed to submit a send task, with error: %s", doca_error_get_descr(result));
1291  return result;
1292  }
1293 
1294  return result;
1295 }
1296 
1297 doca_error_t recv_msg(struct doca_rdma *rdma,
1298  struct doca_mmap *mmap,
1299  struct doca_buf_inventory *buf_inv,
1300  void *msg,
1301  uint32_t msg_len,
1302  void *user_data)
1303 {
1305  struct doca_buf *dst_buf;
1306  struct doca_rdma_task_receive *rdma_recv_task;
1307  union doca_data task_user_data;
1308  task_user_data.ptr = user_data;
1309 
1310  result = doca_buf_inventory_buf_get_by_addr(buf_inv, mmap, msg, msg_len, &dst_buf);
1311  if (DOCA_IS_ERROR(result)) {
1312  DOCA_LOG_ERR("Failed to get a doca_buf, with error: %s", doca_error_get_descr(result));
1313  return result;
1314  }
1315 
1316  result = doca_rdma_task_receive_allocate_init(rdma, dst_buf, task_user_data, &rdma_recv_task);
1317  if (DOCA_IS_ERROR(result)) {
1318  DOCA_LOG_ERR("Failed to allocate receive task, with error: %s", doca_error_get_descr(result));
1319  return result;
1320  }
1321 
1323  if (DOCA_IS_ERROR(result)) {
1324  DOCA_LOG_ERR("Failed to submit a receive task, with error: %s", doca_error_get_descr(result));
1325  return result;
1326  }
1327  DOCA_LOG_INFO("Negotiation receive task submission completed\n");
1328 
1329  return result;
1330 }
1331 
1333 {
1335  struct doca_mmap *recv_descriptor_mmap = NULL;
1336  void *recv_descriptor = NULL;
1337  size_t recv_descriptor_size = MEM_RANGE_LEN;
1338 
1339  DOCA_LOG_INFO("Start to exchange data resource between client and server");
1340 
1341  /* Create receive descriptor buffer */
1342  recv_descriptor = malloc(sizeof(uint8_t) * recv_descriptor_size);
1343  if (recv_descriptor == NULL) {
1344  DOCA_LOG_ERR("Failed to allocate buffer for receive descriptor: %s", doca_error_get_descr(result));
1345  return DOCA_ERROR_NO_MEMORY;
1346  }
1347 
1348  /* Create receive descriptor's mmap */
1349  result = create_local_mmap(&recv_descriptor_mmap,
1351  recv_descriptor,
1352  recv_descriptor_size,
1354  if (result != DOCA_SUCCESS) {
1355  DOCA_LOG_ERR("Failed to create receive descriptor's mmap: %s", doca_error_get_descr(result));
1356  goto free_recv_descriptor;
1357  }
1358 
1360  recv_descriptor_mmap,
1362  recv_descriptor,
1363  recv_descriptor_size,
1364  resources);
1365  if (result != DOCA_SUCCESS) {
1366  DOCA_LOG_ERR("Failed to recvd responder's data to requester: %s", doca_error_get_descr(result));
1367  goto destroy_recv_descriptor_mmap;
1368  }
1369 
1370  if (resources->recv_sync_event_desc == true) {
1371  resources->sync_event_descriptor_mmap = recv_descriptor_mmap;
1372  resources->sync_event_descriptor = recv_descriptor;
1373  } else {
1374  resources->remote_mmap_descriptor_mmap = recv_descriptor_mmap;
1375  resources->remote_mmap_descriptor = recv_descriptor;
1376  }
1377 
1378  return DOCA_SUCCESS;
1379 
1380 destroy_recv_descriptor_mmap:
1381  doca_mmap_destroy(recv_descriptor_mmap);
1382 free_recv_descriptor:
1383  free(recv_descriptor);
1384  return result;
1385 }
1386 
1388 {
1390  struct doca_mmap *send_descriptor_mmap = NULL;
1391  void *send_descriptor = NULL;
1392  size_t send_descriptor_size = 0;
1393 
1394  DOCA_LOG_INFO("Start to exchange data resource between client and server");
1395 
1396  if (resources->recv_sync_event_desc == true) {
1397  /* Export RDMA sync event */
1399  (const uint8_t **)&(resources->sync_event_descriptor),
1401  if (result != DOCA_SUCCESS) {
1402  DOCA_LOG_ERR("Failed to export DOCA sync event for RDMA: %s", doca_error_get_descr(result));
1403  return result;
1404  }
1405  send_descriptor = (void *)(resources->sync_event_descriptor);
1406  send_descriptor_size = resources->sync_event_descriptor_size;
1407  } else {
1408  /* Export RDMA mmap */
1411  (const void **)&(resources->mmap_descriptor),
1413  if (result != DOCA_SUCCESS) {
1414  DOCA_LOG_ERR("Failed to export DOCA mmap for RDMA: %s", doca_error_get_descr(result));
1415  return result;
1416  }
1417  send_descriptor = (void *)(resources->mmap_descriptor);
1418  send_descriptor_size = resources->mmap_descriptor_size;
1419  }
1420 
1421  /* Create DOCA buffer inventory */
1423  if (result != DOCA_SUCCESS) {
1424  DOCA_LOG_ERR("Failed to create DOCA buffer inventory: %s", doca_error_get_descr(result));
1425  return result;
1426  }
1427 
1428  /* Start DOCA buffer inventory */
1430  if (result != DOCA_SUCCESS) {
1431  DOCA_LOG_ERR("Failed to start DOCA buffer inventory: %s", doca_error_get_descr(result));
1432  goto destroy_buf_inv;
1433  }
1434 
1435  /* Create local data descriptor's mmap */
1436  result = create_local_mmap(&send_descriptor_mmap,
1438  send_descriptor,
1439  send_descriptor_size,
1441  if (result != DOCA_SUCCESS) {
1442  DOCA_LOG_ERR("Failed to create send mmap for local descriptor: %s", doca_error_get_descr(result));
1443  goto destroy_buf_inv;
1444  }
1445  if (resources->recv_sync_event_desc == true)
1446  resources->sync_event_descriptor_mmap = send_descriptor_mmap;
1447  else
1448  resources->mmap_descriptor_mmap = send_descriptor_mmap;
1449 
1450  /* Wait for enter which means that the requester has finished posting receive */
1451  DOCA_LOG_INFO(
1452  "Wait till the requester has finished the submission of the receive task for negotiation and press enter");
1453  wait_for_enter();
1454 
1456  resources->connections[0],
1457  send_descriptor_mmap,
1459  send_descriptor,
1460  send_descriptor_size,
1461  resources);
1462  if (result != DOCA_SUCCESS) {
1463  DOCA_LOG_ERR("Failed to send responder's data to requester: %s", doca_error_get_descr(result));
1464  goto destroy_send_descriptor_mmap;
1465  }
1466 
1467  return DOCA_SUCCESS;
1468 
1469 destroy_send_descriptor_mmap:
1470  doca_mmap_destroy(send_descriptor_mmap);
1471 destroy_buf_inv:
1474  return result;
1475 }
1476 
1477 void receive_task_completion_cb(struct doca_rdma_task_receive *task,
1478  union doca_data task_user_data,
1479  union doca_data ctx_user_data)
1480 {
1481  (void)task_user_data;
1482  unsigned long int dst_buf_data_len = 0;
1484  struct doca_buf *dst_buf = doca_rdma_task_receive_get_dst_buf(task);
1485  struct rdma_resources *resource = (struct rdma_resources *)ctx_user_data.ptr;
1486  bool cm_error_occur = false;
1487 
1488  result = doca_buf_get_data_len(dst_buf, &dst_buf_data_len);
1489  if (result != DOCA_SUCCESS) {
1490  DOCA_LOG_ERR("Failed to get data length from doca_buf with error: %s", doca_error_get_name(result));
1491  cm_error_occur = true;
1492  }
1493 
1496  if (cm_error_occur == false) {
1497  if (resource->recv_sync_event_desc == false)
1498  resource->remote_mmap_descriptor_size = dst_buf_data_len;
1499  else
1500  resource->sync_event_descriptor_size = dst_buf_data_len;
1501 
1502  result = resource->task_fn(resource);
1503  if (result != DOCA_SUCCESS)
1504  cm_error_occur = true;
1505  }
1506  if (cm_error_occur == true)
1507  (void)doca_ctx_stop(resource->rdma_ctx);
1508 }
1509 
1510 void receive_task_error_cb(struct doca_rdma_task_receive *rdma_recv_task,
1511  union doca_data task_user_data,
1512  union doca_data ctx_user_data)
1513 {
1514  (void)task_user_data;
1515  struct rdma_resources *resource = (struct rdma_resources *)ctx_user_data.ptr;
1516  struct doca_task *task = doca_rdma_task_receive_as_task(rdma_recv_task);
1517 
1518  /* Get the result of the task */
1519  DOCA_LOG_ERR("RDMA negotiation receive task failed: %s", doca_error_get_descr(doca_task_get_status(task)));
1520  doca_task_free(task);
1522  (void)doca_ctx_stop(resource->rdma_ctx);
1523 }
1524 
1525 void send_task_completion_cb(struct doca_rdma_task_send *task,
1526  union doca_data task_user_data,
1527  union doca_data ctx_user_data)
1528 {
1529  (void)task_user_data;
1530  struct rdma_resources *resource = (struct rdma_resources *)ctx_user_data.ptr;
1532 
1534  doca_buf_dec_refcount((struct doca_buf *)(doca_rdma_task_send_get_src_buf(task)), NULL);
1535 
1536  result = resource->task_fn(resource);
1537  if (result != DOCA_SUCCESS)
1538  (void)doca_ctx_stop(resource->rdma_ctx);
1539 }
1540 
1541 void send_task_error_cb(struct doca_rdma_task_send *rdma_send_task,
1542  union doca_data task_user_data,
1543  union doca_data ctx_user_data)
1544 {
1545  (void)task_user_data;
1546  struct rdma_resources *resource = (struct rdma_resources *)ctx_user_data.ptr;
1547  struct doca_task *task = doca_rdma_task_send_as_task(rdma_send_task);
1548 
1549  /* Get the result of the task */
1550  DOCA_LOG_ERR("RDMA negotiation send task failed: %s", doca_error_get_descr(doca_task_get_status(task)));
1551  doca_task_free(task);
1552  doca_buf_dec_refcount((struct doca_buf *)(doca_rdma_task_send_get_src_buf(rdma_send_task)), NULL);
1553  (void)doca_ctx_stop(resource->rdma_ctx);
1554 }
1555 
1556 void rdma_cm_connect_request_cb(struct doca_rdma_connection *connection, union doca_data ctx_user_data)
1557 {
1558  struct rdma_resources *resource = (struct rdma_resources *)ctx_user_data.ptr;
1560  union doca_data connection_user_data;
1561 
1563  if (result != DOCA_SUCCESS) {
1564  DOCA_LOG_ERR("Failed to accept rdma cm connection: %s", doca_error_get_descr(result));
1565  (void)doca_ctx_stop(resource->rdma_ctx);
1566  return;
1567  }
1568 
1569  connection_user_data.ptr = ctx_user_data.ptr;
1570  result = doca_rdma_connection_set_user_data(connection, connection_user_data);
1571  if (result != DOCA_SUCCESS) {
1572  DOCA_LOG_ERR("Failed to set server connection user data: %s", doca_error_get_descr(result));
1573  (void)doca_ctx_stop(resource->rdma_ctx);
1574  }
1575 }
1576 
1577 void rdma_cm_connect_established_cb(struct doca_rdma_connection *connection,
1578  union doca_data connection_user_data,
1579  union doca_data ctx_user_data)
1580 {
1581  (void)connection_user_data;
1582  union doca_data connection_data;
1583  struct rdma_resources *resource = (struct rdma_resources *)ctx_user_data.ptr;
1584 
1585  connection_data.u64 = resource->num_connection_established;
1586  (void)doca_rdma_connection_set_user_data(connection, connection_data);
1587  resource->connections[resource->num_connection_established] = connection;
1588  resource->connection_established[resource->num_connection_established++] = true;
1589 
1590  if (resource->require_remote_mmap == false) {
1591  if (resource->num_connection_established >= resource->cfg->num_connections) {
1592  if (resource->task_fn(resource) != DOCA_SUCCESS)
1593  (void)doca_ctx_stop(resource->rdma_ctx);
1594  }
1595  return;
1596  }
1597 
1598  if (resource->is_requester == true)
1600  else
1602 }
1603 
1604 void rdma_cm_connect_failure_cb(struct doca_rdma_connection *connection,
1605  union doca_data connection_user_data,
1606  union doca_data ctx_user_data)
1607 {
1608  uint16_t connection_index = (uint16_t)(connection_user_data.u64);
1609  struct rdma_resources *resource = (struct rdma_resources *)ctx_user_data.ptr;
1610 
1611  if (resource->num_connection_established > 0) {
1612  if ((resource->connections[connection_index] == connection) &&
1613  (resource->connection_established[connection_index] == true)) {
1614  resource->connection_established[connection_index] = false;
1615  --resource->num_connection_established;
1616  }
1617  }
1619  (void)doca_ctx_stop(resource->rdma_ctx);
1620 }
1621 
1622 void rdma_cm_disconnect_cb(struct doca_rdma_connection *connection,
1623  union doca_data connection_user_data,
1624  union doca_data ctx_user_data)
1625 {
1626  (void)connection_user_data;
1627  struct rdma_resources *resource = (struct rdma_resources *)ctx_user_data.ptr;
1629 
1631  if (result != DOCA_SUCCESS) {
1632  DOCA_LOG_ERR("Failed to disconnect rdma cm connection: %s", doca_error_get_descr(result));
1633  (void)doca_ctx_stop(resource->rdma_ctx);
1634  return;
1635  }
1636 
1637  resource->connections[--resource->num_connection_established] = NULL;
1638 }
1639 
1641 {
1642  if (cfg == NULL)
1643  return DOCA_ERROR_INVALID_VALUE;
1644 
1645  /* Set the default configuration values (Example values) */
1646  strcpy(cfg->send_string, DEFAULT_STRING);
1647  strcpy(cfg->read_string, DEFAULT_STRING);
1648  strcpy(cfg->write_string, DEFAULT_STRING);
1649  strcpy(cfg->local_connection_desc_path, DEFAULT_LOCAL_CONNECTION_DESC_PATH);
1650  strcpy(cfg->remote_connection_desc_path, DEFAULT_REMOTE_CONNECTION_DESC_PATH);
1651  strcpy(cfg->remote_resource_desc_path, DEFAULT_REMOTE_RESOURCE_CONNECTION_DESC_PATH);
1652  cfg->is_gid_index_set = false;
1653  cfg->num_connections = 1;
1654  cfg->transport_type = DOCA_RDMA_TRANSPORT_TYPE_RC;
1655 
1656  /* Only related rdma cm */
1657  cfg->use_rdma_cm = false;
1658  cfg->cm_port = DEFAULT_RDMA_CM_PORT;
1659  cfg->cm_addr_type = DOCA_RDMA_ADDR_TYPE_IPv4;
1660  memset(cfg->cm_addr, 0, SERVER_ADDR_LEN);
1661 
1662  return DOCA_SUCCESS;
1663 }
1664 
1666  const uint32_t mmap_permissions,
1667  void *data_buffer,
1668  size_t data_buffer_size,
1669  struct doca_dev *dev)
1670 {
1671  doca_error_t result, tmp_result;
1672 
1673  /* Create mmap with no user data */
1675  if (result != DOCA_SUCCESS) {
1676  DOCA_LOG_ERR("Failed to create mmap for source buffer, error: %s", doca_error_get_descr(result));
1677  return result;
1678  }
1679 
1680  /* Set permissions for DOCA mmap */
1681  result = doca_mmap_set_permissions(*mmap, mmap_permissions);
1682  if (result != DOCA_SUCCESS) {
1683  DOCA_LOG_ERR("Failed to set mmap source buffer permissions, error: %s", doca_error_get_descr(result));
1684  goto destroy_mmap;
1685  }
1686 
1687  /* Set memory range for DOCA mmap */
1688  result = doca_mmap_set_memrange(*mmap, data_buffer, data_buffer_size);
1689  if (result != DOCA_SUCCESS) {
1690  DOCA_LOG_ERR("Failed to set memory range, error: %s", doca_error_get_descr(result));
1691  goto destroy_mmap;
1692  }
1693 
1694  /* Add device to mmap */
1695  result = doca_mmap_add_dev(*mmap, dev);
1696  if (result != DOCA_SUCCESS) {
1697  DOCA_LOG_ERR("Failed to add device to mmap, error: %s", doca_error_get_descr(result));
1698  goto destroy_mmap;
1699  }
1700 
1701  /* Start DOCA mmap */
1703  if (result != DOCA_SUCCESS) {
1704  DOCA_LOG_ERR("Failed to start mmap, error: %s", doca_error_get_descr(result));
1705  goto destroy_mmap;
1706  }
1707 
1708  return DOCA_SUCCESS;
1709 
1710 destroy_mmap:
1711  tmp_result = doca_mmap_destroy(*mmap);
1712  if (tmp_result != DOCA_SUCCESS) {
1713  DOCA_LOG_ERR("Failed to destroy DOCA mmap: %s", doca_error_get_descr(tmp_result));
1714  DOCA_ERROR_PROPAGATE(result, tmp_result);
1715  }
1716  *mmap = NULL;
1717  return result;
1718 }
1719 
1721  bool need_send_task,
1722  bool need_recv_task)
1723 {
1725 
1726  if (resources == NULL) {
1728  DOCA_LOG_ERR("Invalid resource pointer found, error: %s", doca_error_get_descr(result));
1729  return result;
1730  }
1731 
1737  if (need_recv_task == true) {
1742  if (result != DOCA_SUCCESS) {
1743  DOCA_LOG_ERR("Failed to set task recv configuration, error: %s", doca_error_get_descr(result));
1744  return result;
1745  }
1746  }
1747  if (need_send_task == true) {
1752  if (result != DOCA_SUCCESS) {
1753  DOCA_LOG_ERR("Failed to set task send configuration, error: %s", doca_error_get_descr(result));
1754  return result;
1755  }
1756  }
1757  /* Set rdma cm connection configuration callbacks */
1763  if (result != DOCA_SUCCESS) {
1764  DOCA_LOG_ERR("Failed to set rdma cm callback configuration, error: %s", doca_error_get_descr(result));
1765  return result;
1766  }
1767 
1768  return DOCA_SUCCESS;
1769 }
1770 
1771 void wait_for_enter(void)
1772 {
1773  int enter = 0;
1774 
1775  /* Wait for enter */
1776  while (enter != '\r' && enter != '\n')
1777  enter = getchar();
1778 }
#define NULL
Definition: __stddef_null.h:26
char path[MAX_PATH_LEN+1]
int32_t result
#define MAX_ARG_SIZE
Definition: dma_copy_core.h:39
#define SERVER_NAME
Definition: dma_copy_core.h:40
uintptr_t addr
doca_dpa_dev_mmap_t mmap
uint64_t len
doca_error_t destroy_rdma_resources(struct rdma_resources *resources)
Definition: rdma_common.c:470
void rdma_cm_connect_established_cb(struct doca_rdma_connection *connection, union doca_data connection_user_data, union doca_data ctx_user_data)
Definition: rdma_common.c:75
void rdma_cm_disconnect_cb(struct doca_rdma_connection *connection, union doca_data connection_user_data, union doca_data ctx_user_data)
Definition: rdma_common.c:128
void rdma_cm_connect_failure_cb(struct doca_rdma_connection *connection, union doca_data connection_user_data, union doca_data ctx_user_data)
Definition: rdma_common.c:101
void rdma_cm_connect_request_cb(struct doca_rdma_connection *connection, union doca_data ctx_user_data)
Definition: rdma_common.c:47
DOCA_LOG_REGISTER(GPURDMA::COMMON)
#define SERVER_ADDR_TYPE_LEN
Definition: rdma_common.h:61
#define SERVER_ADDR_LEN
Definition: rdma_common.h:60
static doca_error_t destroy_rdma_cm_resources(struct rdma_resources *resources)
Definition: rdma_common.c:963
void send_task_error_cb(struct doca_rdma_task_send *rdma_send_task, union doca_data task_user_data, union doca_data ctx_user_data)
Definition: rdma_common.c:1541
static doca_error_t read_string_callback(void *param, void *config)
Definition: rdma_common.c:95
static doca_error_t num_connections_param_callback(void *param, void *config)
Definition: rdma_common.c:323
void receive_task_error_cb(struct doca_rdma_task_receive *rdma_recv_task, union doca_data task_user_data, union doca_data ctx_user_data)
Definition: rdma_common.c:1510
void wait_for_enter(void)
Definition: rdma_common.c:1771
doca_error_t register_rdma_num_connections_param(void)
Definition: rdma_common.c:338
static doca_error_t remote_descriptor_path_callback(void *param, void *config)
Definition: rdma_common.c:168
static doca_error_t transport_type_param_callback(void *param, void *config)
Definition: rdma_common.c:376
doca_error_t rdma_responder_send_data_to_rdma_requester(struct rdma_resources *resources)
Definition: rdma_common.c:1387
doca_error_t delete_file(const char *file_path)
Definition: rdma_common.c:899
doca_error_t write_file(const char *file_path, const char *string, size_t string_len)
Definition: rdma_common.c:1087
static doca_error_t register_rdma_cm_params(void)
Definition: rdma_common.c:498
doca_error_t rdma_cm_connect(struct rdma_resources *resources)
Definition: rdma_common.c:1172
doca_error_t allocate_rdma_resources(struct rdma_config *cfg, const uint32_t mmap_permissions, const uint32_t rdma_permissions, task_check func, struct rdma_resources *resources)
Definition: rdma_common.c:758
static doca_error_t mmap_descriptor_path_callback(void *param, void *config)
Definition: rdma_common.c:192
void receive_task_completion_cb(struct doca_rdma_task_receive *task, union doca_data task_user_data, union doca_data ctx_user_data)
Definition: rdma_common.c:1477
doca_error_t send_msg(struct doca_rdma *rdma, struct doca_rdma_connection *rdma_connection, struct doca_mmap *mmap, struct doca_buf_inventory *buf_inv, void *msg, uint32_t msg_len, void *user_data)
Definition: rdma_common.c:1262
static doca_error_t write_string_callback(void *param, void *config)
Definition: rdma_common.c:119
doca_error_t config_rdma_cm_callback_and_negotiation_task(struct rdma_resources *resources, bool need_send_task, bool need_recv_task)
Definition: rdma_common.c:1720
static doca_error_t cm_addr_type_param_callback(void *param, void *config)
Definition: rdma_common.c:465
static doca_error_t local_descriptor_path_callback(void *param, void *config)
Definition: rdma_common.c:143
doca_error_t register_rdma_write_string_param(void)
Definition: rdma_common.c:288
doca_error_t recv_msg(struct doca_rdma *rdma, struct doca_mmap *mmap, struct doca_buf_inventory *buf_inv, void *msg, uint32_t msg_len, void *user_data)
Definition: rdma_common.c:1297
static doca_error_t device_address_callback(void *param, void *config)
Definition: rdma_common.c:47
doca_error_t register_rdma_read_string_param(void)
Definition: rdma_common.c:260
doca_error_t rdma_cm_disconnect(struct rdma_resources *resources)
Definition: rdma_common.c:1244
static doca_error_t gid_index_param_callback(void *param, void *config)
Definition: rdma_common.c:216
static doca_error_t use_rdma_cm_param_callback(void *param, void *config)
Definition: rdma_common.c:402
static doca_error_t send_string_callback(void *param, void *config)
Definition: rdma_common.c:71
doca_error_t rdma_requester_recv_data_from_rdma_responder(struct rdma_resources *resources)
Definition: rdma_common.c:1332
static doca_error_t cm_addr_param_callback(void *param, void *config)
Definition: rdma_common.c:441
static doca_error_t clean_up_files(struct rdma_config *cfg)
Definition: rdma_common.c:926
void send_task_completion_cb(struct doca_rdma_task_send *task, union doca_data task_user_data, union doca_data ctx_user_data)
Definition: rdma_common.c:1525
doca_error_t register_rdma_send_string_param(void)
Definition: rdma_common.c:232
static doca_error_t cm_port_param_callback(void *param, void *config)
Definition: rdma_common.c:419
doca_error_t read_file(const char *file_path, char **string, size_t *string_len)
Definition: rdma_common.c:1119
doca_error_t set_default_config_value(struct rdma_config *cfg)
Definition: rdma_common.c:1640
doca_error_t create_local_mmap(struct doca_mmap **mmap, const uint32_t mmap_permissions, void *data_buffer, size_t data_buffer_size, struct doca_dev *dev)
Definition: rdma_common.c:1665
static doca_error_t open_doca_device(const char *device_name, task_check func, struct doca_dev **doca_device)
Definition: rdma_common.c:716
doca_error_t register_rdma_common_params(void)
Definition: rdma_common.c:580
#define DEFAULT_LOCAL_CONNECTION_DESC_PATH
Definition: rdma_common.h:52
#define MAX_NUM_CONNECTIONS
Definition: rdma_common.h:67
#define DEFAULT_STRING
Definition: rdma_common.h:50
#define MEM_RANGE_LEN
Definition: rdma_common.h:46
#define DEFAULT_RDMA_CM_PORT
Definition: rdma_common.h:66
#define CLIENT_NAME
Definition: rdma_common.h:65
doca_error_t(* task_check)(const struct doca_devinfo *)
Definition: rdma_common.h:70
#define INVENTORY_NUM_INITIAL_ELEMENTS
Definition: rdma_common.h:47
#define NUM_NEGOTIATION_RDMA_TASKS
Definition: rdma_common.h:63
#define DEFAULT_REMOTE_CONNECTION_DESC_PATH
Definition: rdma_common.h:54
#define DEFAULT_REMOTE_RESOURCE_CONNECTION_DESC_PATH
Definition: rdma_common.h:56
if(bitoffset % 64+bitlength > 64) result|
struct rdma_resources resources
DOCA_EXPERIMENTAL void doca_argp_param_set_description(struct doca_argp_param *param, const char *description)
Set the description of the program param, used during program usage.
DOCA_EXPERIMENTAL void doca_argp_param_set_long_name(struct doca_argp_param *param, const char *name)
Set the long name of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_arguments(struct doca_argp_param *param, const char *arguments)
Set the description of the expected arguments of the program param, used during program usage.
DOCA_EXPERIMENTAL void doca_argp_param_set_callback(struct doca_argp_param *param, doca_argp_param_cb_t callback)
Set the callback function of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_mandatory(struct doca_argp_param *param)
Mark the program param as mandatory.
DOCA_EXPERIMENTAL doca_error_t doca_argp_param_create(struct doca_argp_param **param)
Create new program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_type(struct doca_argp_param *param, enum doca_argp_type type)
Set the type of the param arguments.
DOCA_EXPERIMENTAL void doca_argp_param_set_short_name(struct doca_argp_param *param, const char *name)
Set the short name of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_param(struct doca_argp_param *input_param)
Register a program flag.
@ DOCA_ARGP_TYPE_STRING
Definition: doca_argp.h:56
@ DOCA_ARGP_TYPE_BOOLEAN
Definition: doca_argp.h:58
@ DOCA_ARGP_TYPE_INT
Definition: doca_argp.h:57
DOCA_STABLE doca_error_t doca_buf_inventory_destroy(struct doca_buf_inventory *inventory)
Destroy buffer inventory structure.
static doca_error_t doca_buf_inventory_buf_get_by_addr(struct doca_buf_inventory *inventory, struct doca_mmap *mmap, void *addr, size_t len, struct doca_buf **buf)
Allocate single element from buffer inventory and point it to the buffer defined by addr & len argume...
static doca_error_t doca_buf_inventory_buf_get_by_data(struct doca_buf_inventory *inventory, struct doca_mmap *mmap, void *data, size_t data_len, struct doca_buf **buf)
Allocate single element from buffer inventory and point it to the buffer defined by data & data_len a...
DOCA_STABLE doca_error_t doca_buf_inventory_start(struct doca_buf_inventory *inventory)
Start element retrieval from inventory.
DOCA_STABLE doca_error_t doca_buf_inventory_create(size_t num_elements, struct doca_buf_inventory **inventory)
Allocates buffer inventory with default/unset attributes.
DOCA_STABLE doca_error_t doca_buf_dec_refcount(struct doca_buf *buf, uint16_t *refcount)
Decrease the object reference count by 1, if 0 reached, return the element back to the inventory.
DOCA_STABLE doca_error_t doca_buf_get_data_len(const struct doca_buf *buf, size_t *data_len)
Get buffer's data length.
DOCA_STABLE doca_error_t doca_ctx_stop(struct doca_ctx *ctx)
Stops the context allowing reconfiguration.
DOCA_STABLE doca_error_t doca_devinfo_create_list(struct doca_devinfo ***dev_list, uint32_t *nb_devs)
Creates list of all available local devices.
DOCA_STABLE doca_error_t doca_devinfo_get_ibdev_name(const struct doca_devinfo *devinfo, char *ibdev_name, uint32_t size)
Get the name of the IB device represented by a DOCA devinfo.
#define DOCA_DEVINFO_IBDEV_NAME_SIZE
Buffer size to hold Infiniband/RoCE device name. Including a null terminator.
Definition: doca_dev.h:309
DOCA_STABLE doca_error_t doca_devinfo_destroy_list(struct doca_devinfo **dev_list)
Destroy list of local device info structures.
DOCA_STABLE doca_error_t doca_dev_open(struct doca_devinfo *devinfo, struct doca_dev **dev)
Initialize local device for use.
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
Definition: doca_error.h:83
#define DOCA_IS_ERROR(r)
Compiler optimized macro to check if we have an error.
Definition: doca_error.h:76
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_name(doca_error_t error)
Returns the string representation of an error code name.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_CONNECTION_ABORTED
Definition: doca_error.h:50
@ DOCA_ERROR_INVALID_VALUE
Definition: doca_error.h:44
@ DOCA_ERROR_UNEXPECTED
Definition: doca_error.h:60
@ DOCA_ERROR_NOT_FOUND
Definition: doca_error.h:54
@ DOCA_ERROR_IO_FAILED
Definition: doca_error.h:55
@ DOCA_SUCCESS
Definition: doca_error.h:38
@ DOCA_ERROR_NO_MEMORY
Definition: doca_error.h:45
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
DOCA_STABLE doca_error_t doca_mmap_set_memrange(struct doca_mmap *mmap, void *addr, size_t len)
Set the memory range of DOCA memory map.
DOCA_STABLE doca_error_t doca_mmap_destroy(struct doca_mmap *mmap)
Destroy DOCA Memory Map structure.
DOCA_STABLE doca_error_t doca_mmap_create(struct doca_mmap **mmap)
Allocates zero size memory map object with default/unset attributes.
DOCA_STABLE doca_error_t doca_mmap_set_permissions(struct doca_mmap *mmap, uint32_t access_mask)
Set access flags of the registered memory.
DOCA_STABLE doca_error_t doca_mmap_start(struct doca_mmap *mmap)
Start DOCA Memory Map.
DOCA_STABLE doca_error_t doca_mmap_stop(struct doca_mmap *mmap)
Stop DOCA Memory Map.
DOCA_STABLE doca_error_t doca_mmap_add_dev(struct doca_mmap *mmap, struct doca_dev *dev)
Register DOCA memory map on a given device.
DOCA_STABLE doca_error_t doca_mmap_export_rdma(struct doca_mmap *mmap, const struct doca_dev *dev, const void **export_desc, size_t *export_desc_len)
Compose memory map representation for later import with doca_mmap_create_from_export() for one of the...
DOCA_STABLE doca_error_t doca_pe_destroy(struct doca_pe *pe)
Destroy doca progress engine.
DOCA_STABLE doca_error_t doca_task_get_status(const struct doca_task *task)
Get task status.
DOCA_STABLE doca_error_t doca_pe_connect_ctx(struct doca_pe *pe, struct doca_ctx *ctx)
This method connects a context to a progress engine.
DOCA_STABLE doca_error_t doca_task_submit(struct doca_task *task)
Submit a task to a progress engine.
DOCA_STABLE doca_error_t doca_pe_create(struct doca_pe **pe)
Creates DOCA progress engine.
DOCA_STABLE void doca_task_free(struct doca_task *task)
Free a task back to where it was allocated from.
DOCA_EXPERIMENTAL struct doca_buf * doca_rdma_task_receive_get_dst_buf(const struct doca_rdma_task_receive *task)
This method gets the destination buffer of a receive task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_set_transport_type(struct doca_rdma *rdma, enum doca_rdma_transport_type transport_type)
Set transport type for doca_rdma. The value can be queried using doca_rdma_get_transport_type()....
DOCA_EXPERIMENTAL doca_error_t doca_rdma_task_send_set_conf(struct doca_rdma *rdma, doca_rdma_task_send_completion_cb_t successful_task_completion_cb, doca_rdma_task_send_completion_cb_t error_task_completion_cb, uint32_t num_tasks)
This method sets the send tasks configuration.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_destroy(struct doca_rdma *rdma)
Destroy a DOCA RDMA instance.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_connect_to_addr(struct doca_rdma *rdma, struct doca_rdma_addr *addr, union doca_data connection_user_data)
Connect to a remote doca_rdma peer listening for a connection. Can be called when the ctx is in DOCA_...
DOCA_EXPERIMENTAL doca_error_t doca_rdma_addr_destroy(struct doca_rdma_addr *addr)
Destroy connection address object for doca_rdma.
DOCA_EXPERIMENTAL const struct doca_buf * doca_rdma_task_send_get_src_buf(const struct doca_rdma_task_send *task)
This method gets the source buffer of a send task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_set_connection_state_callbacks(struct doca_rdma *rdma, doca_rdma_connection_request_cb_t doca_rdma_connect_request_cb, doca_rdma_connection_established_cb_t doca_rdma_connect_established_cb, doca_rdma_connection_failure_cb_t doca_rdma_connect_failure_cb, doca_rdma_connection_disconnection_cb_t doca_rdma_disconnect_cb)
This method set the function executed on RDMA connection events.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_set_permissions(struct doca_rdma *rdma, uint32_t permissions)
Set rdma permissions for doca_rdma. The value can be queried using doca_rdma_get_permissions()....
DOCA_EXPERIMENTAL struct doca_task * doca_rdma_task_receive_as_task(struct doca_rdma_task_receive *task)
This method converts a receive task to a doca_task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_task_receive_set_conf(struct doca_rdma *rdma, doca_rdma_task_receive_completion_cb_t successful_task_completion_cb, doca_rdma_task_receive_completion_cb_t error_task_completion_cb, uint32_t num_tasks)
This method sets the receive tasks configuration.
DOCA_EXPERIMENTAL struct doca_task * doca_rdma_task_send_as_task(struct doca_rdma_task_send *task)
This method converts a send task to a doca_task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_task_receive_allocate_init(struct doca_rdma *rdma, struct doca_buf *dst_buf, union doca_data user_data, struct doca_rdma_task_receive **task)
This method allocates and initializes a receive task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_addr_create(enum doca_rdma_addr_type addr_type, const char *address, uint16_t port, struct doca_rdma_addr **addr)
Set connection address object for doca_rdma. The object can be queried using doca_rdma_connection_get...
DOCA_EXPERIMENTAL doca_error_t doca_rdma_set_max_num_connections(struct doca_rdma *rdma, uint16_t max_num_connections)
Set the maximum number of connections property for a context. The value can be queried using doca_rdm...
DOCA_EXPERIMENTAL doca_error_t doca_rdma_start_listen_to_port(struct doca_rdma *rdma, uint16_t port)
Start listening for a connection from a remote doca_rdma peer. Can be called when the ctx is in DOCA_...
DOCA_EXPERIMENTAL doca_error_t doca_rdma_connection_disconnect(struct doca_rdma_connection *rdma_connection)
Finalize a connection with a remote doca_rdma peer. Can be called when the ctx is in DOCA_CTX_STATE_R...
DOCA_EXPERIMENTAL doca_error_t doca_rdma_set_gid_index(struct doca_rdma *rdma, uint32_t gid_index)
Set GID index for doca_rdma. The value can be queried using doca_rdma_get_gid_index()....
DOCA_EXPERIMENTAL doca_error_t doca_rdma_task_send_allocate_init(struct doca_rdma *rdma, struct doca_rdma_connection *rdma_connection, const struct doca_buf *src_buf, union doca_data user_data, struct doca_rdma_task_send **task)
This method allocates and initializes a send task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_connection_accept(struct doca_rdma_connection *rdma_connection, void *private_data, uint8_t private_data_len)
Accept an incoming connection request from remote doca_rdma peer. Can be called when the ctx is in DO...
DOCA_EXPERIMENTAL struct doca_ctx * doca_rdma_as_ctx(struct doca_rdma *rdma)
Convert doca_rdma instance into a generalized context for use with doca core objects.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_create(struct doca_dev *dev, struct doca_rdma **rdma)
Create a DOCA RDMA instance.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_connection_set_user_data(struct doca_rdma_connection *rdma_connection, union doca_data connection_user_data)
Set user data to include in each connection.
@ DOCA_RDMA_ADDR_TYPE_IPv6
Definition: doca_rdma.h:58
@ DOCA_RDMA_ADDR_TYPE_IPv4
Definition: doca_rdma.h:57
@ DOCA_RDMA_ADDR_TYPE_GID
Definition: doca_rdma.h:59
@ DOCA_RDMA_TRANSPORT_TYPE_RC
Definition: doca_rdma.h:46
@ DOCA_RDMA_TRANSPORT_TYPE_DC
Definition: doca_rdma.h:47
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_export_to_remote_net(struct doca_sync_event *event, const uint8_t **data, size_t *sz)
Export Sync Event to be shared with a remote peer.
@ DOCA_ACCESS_FLAG_LOCAL_READ_WRITE
Definition: doca_types.h:83
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
uint8_t type
Definition: packets.h:0
#define MAX_USER_ARG_SIZE
Definition: pcc_core.h:45
enum doca_rdma_addr_type cm_addr_type
Definition: rdma_common.h:74
uint32_t num_connections
Definition: rdma_common.h:88
enum doca_rdma_transport_type transport_type
Definition: rdma_common.h:90
char device_name[DOCA_DEVINFO_IBDEV_NAME_SIZE]
Definition: rdma_common.h:65
char send_string[MAX_ARG_SIZE]
Definition: rdma_common.h:80
char cm_addr[SERVER_ADDR_LEN+1]
Definition: rdma_common.h:73
uint32_t gid_index
Definition: rdma_common.h:70
char remote_resource_desc_path[MAX_ARG_SIZE]
Definition: rdma_common.h:85
bool use_rdma_cm
Definition: rdma_common.h:71
char local_connection_desc_path[MAX_ARG_SIZE]
Definition: rdma_common.h:83
char read_string[MAX_ARG_SIZE]
Definition: rdma_common.h:81
uint32_t cm_port
Definition: rdma_common.h:72
char remote_connection_desc_path[MAX_ARG_SIZE]
Definition: rdma_common.h:84
bool is_gid_index_set
Definition: rdma_common.h:69
char write_string[MAX_ARG_SIZE]
Definition: rdma_common.h:82
struct doca_sync_event * sync_event
Definition: rdma_common.h:114
doca_error_t first_encountered_error
Definition: rdma_common.h:132
struct doca_rdma_connection * connection
Definition: rdma_common.h:92
bool require_remote_mmap
Definition: rdma_common.h:152
struct doca_ctx * rdma_ctx
Definition: rdma_common.h:85
struct doca_mmap * remote_mmap
Definition: rdma_common.h:113
uint32_t num_connection_established
Definition: rdma_common.h:141
size_t sync_event_descriptor_size
Definition: rdma_common.h:131
const void * mmap_descriptor
Definition: rdma_common.h:118
size_t num_remaining_tasks
Definition: rdma_common.h:134
prepare_and_submit_task_fn task_fn
Definition: rdma_common.h:150
bool recv_sync_event_desc
Definition: rdma_common.h:145
struct doca_mmap * mmap_descriptor_mmap
Definition: rdma_common.h:142
size_t remote_mmap_descriptor_size
Definition: rdma_common.h:129
void * remote_mmap_descriptor
Definition: rdma_common.h:128
void * remote_rdma_conn_descriptor
Definition: rdma_common.h:126
struct doca_rdma_connection * connections[MAX_NUM_CONNECTIONS]
Definition: rdma_common.h:138
struct doca_buf * dst_buf
Definition: rdma_common.h:123
struct rdma_config * cfg
Definition: rdma_common.h:80
struct doca_rdma_addr * cm_addr
Definition: rdma_common.h:91
struct doca_rdma * rdma
Definition: rdma_common.h:83
size_t mmap_descriptor_size
Definition: rdma_common.h:119
struct doca_pe * pe
Definition: rdma_common.h:86
struct doca_mmap * sync_event_descriptor_mmap
Definition: rdma_common.h:144
struct doca_mmap * mmap
Definition: rdma_common.h:112
bool run_pe_progress
Definition: rdma_common.h:133
struct doca_mmap * remote_mmap_descriptor_mmap
Definition: rdma_common.h:143
const char * self_name
Definition: rdma_common.h:147
struct doca_dev * doca_device
Definition: rdma_common.h:81
struct doca_buf_inventory * buf_inventory
Definition: rdma_common.h:117
void * sync_event_descriptor
Definition: rdma_common.h:130
char * mmap_memrange
Definition: rdma_common.h:116
bool connection_established
Definition: rdma_common.h:93
Convenience type for representing opaque data.
Definition: doca_types.h:56
uint64_t u64
Definition: doca_types.h:58
void * ptr
Definition: doca_types.h:57