NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
dpa_common.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2024 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 "dpa_common.h"
27 #include "doca_dpa.h"
28 #include "libflexio/flexio_ver.h"
29 
30 #define DPA_BASIC_INITIATOR_TARGET_FLEXIO_MAJOR_VERSION (25)
31 #define DPA_BASIC_INITIATOR_TARGET_FLEXIO_MINOR_VERSION (4)
32 #define DPA_BASIC_INITIATOR_TARGET_FLEXIO_PATCH_VERSION (0)
33 
34 #define FLEXIO_VER_USED \
35  FLEXIO_VER(DPA_BASIC_INITIATOR_TARGET_FLEXIO_MAJOR_VERSION, \
36  DPA_BASIC_INITIATOR_TARGET_FLEXIO_MINOR_VERSION, \
37  DPA_BASIC_INITIATOR_TARGET_FLEXIO_PATCH_VERSION)
38 #include "libflexio/flexio.h"
39 
40 DOCA_LOG_REGISTER(DPA_COMMON);
41 
42 #define DPA_THREADS_MAX 256
43 
44 /*
45  * A struct that includes all needed info on registered kernels and is initialized during linkage by DPACC.
46  * Variable name should be the token passed to DPACC with --app-name parameter.
47  */
48 extern struct doca_dpa_app *dpa_sample_app;
49 
50 /*
51  * ARGP Callback - Handle PF device name parameter
52  *
53  * @param [in]: Input parameter
54  * @config [in/out]: Program configuration context
55  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
56  */
57 static doca_error_t pf_device_name_param_callback(void *param, void *config)
58 {
59  struct dpa_config *dpa_cfg = (struct dpa_config *)config;
60  char *device_name = (char *)param;
61 
62  int len = strnlen(device_name, DOCA_DEVINFO_IBDEV_NAME_SIZE);
64  DOCA_LOG_ERR("Entered device name exceeding the maximum size of %d", DOCA_DEVINFO_IBDEV_NAME_SIZE - 1);
66  }
67  strncpy(dpa_cfg->pf_device_name, device_name, len + 1);
68 
69  return DOCA_SUCCESS;
70 }
71 
72 static doca_error_t dpa_resources_file_param_callback(void *param, void *config)
73 {
74  struct dpa_config *dpa_cfg = (struct dpa_config *)config;
75  char *dpa_resources_file = (char *)param;
76 
77  int path_len = strnlen(dpa_resources_file, DPA_RESOURCES_PATH_MAX_SIZE);
78  if (path_len >= DPA_RESOURCES_PATH_MAX_SIZE) {
79  DOCA_LOG_ERR("Entered DPA resources file path exceeding the maximum size of %d",
82  }
83  strncpy(dpa_cfg->dpa_resources_file, dpa_resources_file, path_len + 1);
84 
85  return DOCA_SUCCESS;
86 }
87 
88 static doca_error_t dpa_app_key_param_callback(void *param, void *config)
89 {
90  struct dpa_config *dpa_cfg = (struct dpa_config *)config;
91  const char *path = (char *)param;
92  int dpa_app_key_len = strnlen(path, DPA_APP_KEY_MAX_SIZE);
93  if (dpa_app_key_len >= DPA_APP_KEY_MAX_SIZE) {
94  DOCA_LOG_ERR("Entered DPA application key exceeding the maximum size of %d", DPA_APP_KEY_MAX_SIZE - 1);
96  }
97  strncpy(dpa_cfg->dpa_app_key, path, dpa_app_key_len + 1);
98  return DOCA_SUCCESS;
99 }
100 
101 #ifdef DOCA_ARCH_DPU
102 /*
103  * ARGP Callback - Handle RDMA device name parameter
104  *
105  * @param [in]: Input parameter
106  * @config [in/out]: Program configuration context
107  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
108  */
109 static doca_error_t rdma_device_name_param_callback(void *param, void *config)
110 {
111  struct dpa_config *dpa_cfg = (struct dpa_config *)config;
112  char *device_name = (char *)param;
113  int len;
114 
115  len = strnlen(device_name, DOCA_DEVINFO_IBDEV_NAME_SIZE);
117  DOCA_LOG_ERR("Entered device name exceeding the maximum size of %d", DOCA_DEVINFO_IBDEV_NAME_SIZE - 1);
119  }
120  strncpy(dpa_cfg->rdma_device_name, device_name, len + 1);
121 
122  return DOCA_SUCCESS;
123 }
124 #endif
125 
127 {
129 
130  struct doca_argp_param *pf_device_param;
131  result = doca_argp_param_create(&pf_device_param);
132  if (result != DOCA_SUCCESS) {
133  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
134  return result;
135  }
136  doca_argp_param_set_short_name(pf_device_param, "pf_dev");
137  doca_argp_param_set_long_name(pf_device_param, "pf-device");
138  doca_argp_param_set_arguments(pf_device_param, "<PF DOCA device name>");
140  pf_device_param,
141  "PF device name that supports DPA (optional). If not provided then a random device will be chosen");
144  result = doca_argp_register_param(pf_device_param);
145  if (result != DOCA_SUCCESS) {
146  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
147  return result;
148  }
149 
150  struct doca_argp_param *dpa_resources_file_param;
151  result = doca_argp_param_create(&dpa_resources_file_param);
152  if (result != DOCA_SUCCESS) {
153  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
154  return result;
155  }
156  doca_argp_param_set_long_name(dpa_resources_file_param, "dpa-resources");
157  doca_argp_param_set_arguments(dpa_resources_file_param, "<DPA resources file>");
158  doca_argp_param_set_description(dpa_resources_file_param, "Path to a DPA resources .yaml file");
160  doca_argp_param_set_type(dpa_resources_file_param, DOCA_ARGP_TYPE_STRING);
161  result = doca_argp_register_param(dpa_resources_file_param);
162  if (result != DOCA_SUCCESS) {
163  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
164  return result;
165  }
166 
167  struct doca_argp_param *dpa_app_key_param;
168  result = doca_argp_param_create(&dpa_app_key_param);
169  if (result != DOCA_SUCCESS) {
170  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
171  return result;
172  }
173  doca_argp_param_set_long_name(dpa_app_key_param, "dpa-app-key");
174  doca_argp_param_set_arguments(dpa_app_key_param, "<DPA application key>");
175  doca_argp_param_set_description(dpa_app_key_param, "Application key in specified DPA resources .yaml file");
178  result = doca_argp_register_param(dpa_app_key_param);
179  if (result != DOCA_SUCCESS) {
180  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
181  return result;
182  }
183 
184 #ifdef DOCA_ARCH_DPU
185  struct doca_argp_param *rdma_device_param;
186  result = doca_argp_param_create(&rdma_device_param);
187  if (result != DOCA_SUCCESS) {
188  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
189  return result;
190  }
191  doca_argp_param_set_short_name(rdma_device_param, "rdma_dev");
192  doca_argp_param_set_long_name(rdma_device_param, "rdma-device");
193  doca_argp_param_set_arguments(rdma_device_param, "<RDMA DOCA device name>");
195  rdma_device_param,
196  "device name that supports RDMA (optional). If not provided then a random device will be chosen");
197  doca_argp_param_set_callback(rdma_device_param, rdma_device_name_param_callback);
199  result = doca_argp_register_param(rdma_device_param);
200  if (result != DOCA_SUCCESS) {
201  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
202  return result;
203  }
204 #endif
205 
206  return DOCA_SUCCESS;
207 }
208 
209 /*
210  * Open DPA DOCA devices
211  *
212  * When running from DPU, rdma_doca_device will be opened for SF DOCA device with RDMA capability.
213  * When running from Host, returned rdma_doca_device is equal to pf_doca_device.
214  *
215  * @pf_device_name [in]: Wanted PF device name, can be NOT_SET and then a random DPA supported device is chosen
216  * @rdma_device_name [in]: Relevant when running from DPU. Wanted RDMA device name, can be NOT_SET and then a random
217  * RDMA supported device is chosen
218  * @pf_doca_device [out]: An allocated PF DOCA device on success and NULL otherwise
219  * @rdma_doca_device [out]: An allocated RDMA DOCA device on success and NULL otherwise
220  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
221  */
222 static doca_error_t open_dpa_device(const char *pf_device_name,
223  const char *rdma_device_name,
224  struct doca_dev **pf_doca_device,
225  struct doca_dev **rdma_doca_device)
226 {
227  struct doca_devinfo **dev_list;
228  uint32_t nb_devs = 0;
229  doca_error_t result, dpa_cap;
230  char ibdev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE] = {0};
231  char actual_base_ibdev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE] = {0};
232  uint32_t i = 0;
233 
234  if (strcmp(pf_device_name, DEVICE_DEFAULT_NAME) != 0 && strcmp(rdma_device_name, DEVICE_DEFAULT_NAME) != 0 &&
235  strcmp(pf_device_name, rdma_device_name) == 0) {
236  DOCA_LOG_ERR("RDMA DOCA device must be different than PF DOCA device (%s)", pf_device_name);
238  }
239 
240  result = doca_devinfo_create_list(&dev_list, &nb_devs);
241  if (result != DOCA_SUCCESS) {
242  DOCA_LOG_ERR("Failed to load DOCA devices list: %s", doca_error_get_descr(result));
243  return result;
244  }
245 
246  for (i = 0; i < nb_devs; i++) {
247  dpa_cap = doca_dpa_cap_is_supported(dev_list[i]);
248  if (dpa_cap != DOCA_SUCCESS) {
249  continue;
250  }
251 
252  result = doca_devinfo_get_ibdev_name(dev_list[i], ibdev_name, sizeof(ibdev_name));
253  if (result != DOCA_SUCCESS) {
254  continue;
255  }
256 
257 #ifdef DOCA_ARCH_DPU
258  doca_error_t rdma_cap = doca_rdma_cap_task_send_is_supported(dev_list[i]);
259  if (*rdma_doca_device == NULL && rdma_cap == DOCA_SUCCESS) {
260  /* to be able to extend rdma device later on (if needed), it must be a different device */
261  if (strcmp(ibdev_name, actual_base_ibdev_name) == 0) {
262  continue;
263  }
264  if (strcmp(rdma_device_name, DEVICE_DEFAULT_NAME) == 0 ||
265  strcmp(rdma_device_name, ibdev_name) == 0) {
266  result = doca_dev_open(dev_list[i], rdma_doca_device);
267  if (result != DOCA_SUCCESS) {
268  doca_devinfo_destroy_list(dev_list);
269  DOCA_LOG_ERR("Failed to open DOCA device %s: %s",
270  ibdev_name,
272  return result;
273  }
274  }
275  }
276 #endif
277 
278  if (*pf_doca_device == NULL) {
279  if (strcmp(pf_device_name, DEVICE_DEFAULT_NAME) == 0 ||
280  strcmp(pf_device_name, ibdev_name) == 0) {
281  result = doca_dev_open(dev_list[i], pf_doca_device);
282  if (result != DOCA_SUCCESS) {
283  doca_devinfo_destroy_list(dev_list);
284  DOCA_LOG_ERR("Failed to open DOCA device %s: %s",
285  ibdev_name,
287  return result;
288  }
289  strncpy(actual_base_ibdev_name, ibdev_name, DOCA_DEVINFO_IBDEV_NAME_SIZE);
290  }
291  }
292  }
293 
294  doca_devinfo_destroy_list(dev_list);
295 
296  if (*pf_doca_device == NULL) {
297  DOCA_LOG_ERR("Couldn't open PF DOCA device");
298  return DOCA_ERROR_NOT_FOUND;
299  }
300 
301 #ifdef DOCA_ARCH_DPU
302  if (*rdma_doca_device == NULL) {
303  DOCA_LOG_ERR("Couldn't open RDMA DOCA device");
304  return DOCA_ERROR_NOT_FOUND;
305  }
306 #else
307  *rdma_doca_device = *pf_doca_device;
308 #endif
309 
310  return result;
311 }
312 
314  struct doca_dev *doca_device,
315  struct doca_sync_event **wait_event)
316 {
317  doca_error_t result, tmp_result;
318 
319  result = doca_sync_event_create(wait_event);
320  if (result != DOCA_SUCCESS) {
321  DOCA_LOG_ERR("Failed to create DOCA sync event: %s", doca_error_get_descr(result));
322  return result;
323  }
324 
325  result = doca_sync_event_add_publisher_location_cpu(*wait_event, doca_device);
326  if (result != DOCA_SUCCESS) {
327  DOCA_LOG_ERR("Failed to set CPU as publisher for DOCA sync event: %s", doca_error_get_descr(result));
328  goto destroy_wait_event;
329  }
330 
331  result = doca_sync_event_add_subscriber_location_dpa(*wait_event, doca_dpa);
332  if (result != DOCA_SUCCESS) {
333  DOCA_LOG_ERR("Failed to set DPA as subscriber for DOCA sync event: %s", doca_error_get_descr(result));
334  goto destroy_wait_event;
335  }
336 
337  result = doca_sync_event_start(*wait_event);
338  if (result != DOCA_SUCCESS) {
339  DOCA_LOG_ERR("Failed to start DOCA sync event: %s", doca_error_get_descr(result));
340  goto destroy_wait_event;
341  }
342 
343  return result;
344 
345 destroy_wait_event:
346  tmp_result = doca_sync_event_destroy(*wait_event);
347  if (tmp_result != DOCA_SUCCESS) {
348  DOCA_LOG_ERR("Failed to destroy DOCA sync event: %s", doca_error_get_descr(tmp_result));
349  DOCA_ERROR_PROPAGATE(result, tmp_result);
350  }
351  return result;
352 }
353 
355  struct doca_dev *doca_device,
356  struct doca_sync_event **comp_event,
358 {
359  doca_error_t result, tmp_result;
360 
361  result = doca_sync_event_create(comp_event);
362  if (result != DOCA_SUCCESS) {
363  DOCA_LOG_ERR("Failed to create DOCA sync event: %s", doca_error_get_descr(result));
364  return result;
365  }
366 
367  result = doca_sync_event_add_publisher_location_dpa(*comp_event, doca_dpa);
368  if (result != DOCA_SUCCESS) {
369  DOCA_LOG_ERR("Failed to set DPA as publisher for DOCA sync event: %s", doca_error_get_descr(result));
370  goto destroy_comp_event;
371  }
372 
373  result = doca_sync_event_add_subscriber_location_cpu(*comp_event, doca_device);
374  if (result != DOCA_SUCCESS) {
375  DOCA_LOG_ERR("Failed to set CPU as subscriber for DOCA sync event: %s", doca_error_get_descr(result));
376  goto destroy_comp_event;
377  }
378 
379  result = doca_sync_event_start(*comp_event);
380  if (result != DOCA_SUCCESS) {
381  DOCA_LOG_ERR("Failed to start DOCA sync event: %s", doca_error_get_descr(result));
382  goto destroy_comp_event;
383  }
384 
385  if (handle != NULL) {
386  result = doca_sync_event_get_dpa_handle(*comp_event, doca_dpa, handle);
387  if (result != DOCA_SUCCESS) {
388  DOCA_LOG_ERR("Function doca_sync_event_get_dpa_handle failed (%d)", result);
389  goto destroy_comp_event;
390  }
391  }
392 
393  return result;
394 
395 destroy_comp_event:
396  tmp_result = doca_sync_event_destroy(*comp_event);
397  if (tmp_result != DOCA_SUCCESS) {
398  DOCA_LOG_ERR("Failed to destroy DOCA sync event: %s", doca_error_get_descr(tmp_result));
399  DOCA_ERROR_PROPAGATE(result, tmp_result);
400  }
401  return result;
402 }
403 
404 doca_error_t create_doca_dpa_kernel_sync_event(struct doca_dpa *doca_dpa, struct doca_sync_event **kernel_event)
405 {
406  doca_error_t result, tmp_result;
407 
408  result = doca_sync_event_create(kernel_event);
409  if (result != DOCA_SUCCESS) {
410  DOCA_LOG_ERR("Failed to create DOCA sync event: %s", doca_error_get_descr(result));
411  return result;
412  }
413 
414  result = doca_sync_event_add_publisher_location_dpa(*kernel_event, doca_dpa);
415  if (result != DOCA_SUCCESS) {
416  DOCA_LOG_ERR("Failed to set DPA as publisher for DOCA sync event: %s", doca_error_get_descr(result));
417  goto destroy_kernel_event;
418  }
419 
420  result = doca_sync_event_add_subscriber_location_dpa(*kernel_event, doca_dpa);
421  if (result != DOCA_SUCCESS) {
422  DOCA_LOG_ERR("Failed to set DPA as subscriber for DOCA sync event: %s", doca_error_get_descr(result));
423  goto destroy_kernel_event;
424  }
425 
426  result = doca_sync_event_start(*kernel_event);
427  if (result != DOCA_SUCCESS) {
428  DOCA_LOG_ERR("Failed to start DOCA sync event: %s", doca_error_get_descr(result));
429  goto destroy_kernel_event;
430  }
431 
432  return result;
433 
434 destroy_kernel_event:
435  tmp_result = doca_sync_event_destroy(*kernel_event);
436  if (tmp_result != DOCA_SUCCESS) {
437  DOCA_LOG_ERR("Failed to destroy DOCA sync event: %s", doca_error_get_descr(tmp_result));
438  DOCA_ERROR_PROPAGATE(result, tmp_result);
439  }
440  return result;
441 }
442 
443 doca_error_t create_doca_remote_net_sync_event(struct doca_dev *doca_device, struct doca_sync_event **remote_net_event)
444 {
445  doca_error_t result, tmp_result;
446 
447  result = doca_sync_event_create(remote_net_event);
448  if (result != DOCA_SUCCESS) {
449  DOCA_LOG_ERR("Failed to create DOCA sync event: %s", doca_error_get_descr(result));
450  return result;
451  }
452 
454  if (result != DOCA_SUCCESS) {
455  DOCA_LOG_ERR("Failed to set remote net as publisher for DOCA sync event: %s",
457  goto destroy_remote_net_event;
458  }
459 
460  result = doca_sync_event_add_subscriber_location_cpu(*remote_net_event, doca_device);
461  if (result != DOCA_SUCCESS) {
462  DOCA_LOG_ERR("Failed to set CPU as subscriber for DOCA sync event: %s", doca_error_get_descr(result));
463  goto destroy_remote_net_event;
464  }
465 
466  result = doca_sync_event_start(*remote_net_event);
467  if (result != DOCA_SUCCESS) {
468  DOCA_LOG_ERR("Failed to start DOCA sync event: %s", doca_error_get_descr(result));
469  goto destroy_remote_net_event;
470  }
471 
472  return result;
473 
474 destroy_remote_net_event:
475  tmp_result = doca_sync_event_destroy(*remote_net_event);
476  if (tmp_result != DOCA_SUCCESS) {
477  DOCA_LOG_ERR("Failed to destroy DOCA sync event: %s", doca_error_get_descr(tmp_result));
478  DOCA_ERROR_PROPAGATE(result, tmp_result);
479  }
480  return result;
481 }
482 
484  struct doca_dpa *doca_dpa,
485  struct doca_sync_event *remote_net_event,
486  struct doca_sync_event_remote_net **remote_net_exported_event,
487  doca_dpa_dev_sync_event_remote_net_t *remote_net_event_dpa_handle)
488 {
489  doca_error_t result, tmp_result;
490  const uint8_t *remote_net_event_export_data;
491  size_t remote_net_event_export_size;
492 
493  result = doca_sync_event_export_to_remote_net(remote_net_event,
494  &remote_net_event_export_data,
495  &remote_net_event_export_size);
496  if (result != DOCA_SUCCESS) {
497  DOCA_LOG_ERR("Failed to export DOCA sync event to remote net: %s", doca_error_get_descr(result));
498  return result;
499  }
500 
502  remote_net_event_export_data,
503  remote_net_event_export_size,
504  remote_net_exported_event);
505  if (result != DOCA_SUCCESS) {
506  DOCA_LOG_ERR("Failed to create remote net DOCA sync event: %s", doca_error_get_descr(result));
507  return result;
508  }
509 
510  result = doca_sync_event_remote_net_get_dpa_handle(*remote_net_exported_event,
511  doca_dpa,
512  remote_net_event_dpa_handle);
513  if (result != DOCA_SUCCESS) {
514  DOCA_LOG_ERR("Failed to export remote net DOCA sync event to DPA: %s", doca_error_get_descr(result));
515  goto destroy_export_remote_net_event;
516  }
517 
518  return result;
519 
520 destroy_export_remote_net_event:
521  tmp_result = doca_sync_event_remote_net_destroy(*remote_net_exported_event);
522  if (tmp_result != DOCA_SUCCESS) {
523  DOCA_LOG_ERR("Failed to destroy remote net DOCA sync event: %s", doca_error_get_descr(tmp_result));
524  DOCA_ERROR_PROPAGATE(result, tmp_result);
525  }
526  return result;
527 }
528 
536 static doca_error_t get_file_size(const char *path, size_t *file_size)
537 {
538  FILE *file;
539  long nb_file_bytes;
540 
541  file = fopen(path, "rb");
542  if (file == NULL)
543  return DOCA_ERROR_NOT_FOUND;
544 
545  if (fseek(file, 0, SEEK_END) != 0) {
546  fclose(file);
547  return DOCA_ERROR_IO_FAILED;
548  }
549 
550  nb_file_bytes = ftell(file);
551  fclose(file);
552 
553  if (nb_file_bytes == -1)
554  return DOCA_ERROR_IO_FAILED;
555 
556  if (nb_file_bytes == 0)
558 
559  *file_size = (size_t)nb_file_bytes;
560  return DOCA_SUCCESS;
561 }
562 
571 static doca_error_t read_file_into_buffer(const char *path, char *buffer, size_t *bytes_read)
572 {
573  FILE *file;
574  size_t read_byte_count;
575 
576  file = fopen(path, "rb");
577  if (file == NULL)
578  return DOCA_ERROR_NOT_FOUND;
579 
580  read_byte_count = fread(buffer, 1, *bytes_read, file);
581  fclose(file);
582 
583  if (read_byte_count != *bytes_read)
584  return DOCA_ERROR_IO_FAILED;
585 
586  *bytes_read = read_byte_count;
587  return DOCA_SUCCESS;
588 }
589 
602  uint32_t *threads_list,
603  uint32_t *threads_num)
604 {
605  char *file_buffer;
606  size_t bytes_read;
607  struct flexio_resource *res;
608 
609  /* Get the file size first */
610  doca_error_t result = get_file_size(cfg->dpa_resources_file, &bytes_read);
611  if (result != DOCA_SUCCESS) {
612  DOCA_LOG_ERR("Error: Failed to get DPA resources file size: %s", doca_error_get_descr(result));
613  return result;
614  }
615 
616  /* Allocate buffer based on file size */
617  file_buffer = (char *)malloc(bytes_read);
618  if (file_buffer == NULL) {
619  DOCA_LOG_ERR("Error: Failed to allocate memory for DPA resources file");
620  return DOCA_ERROR_NO_MEMORY;
621  }
622 
623  /* Read the DPA resources file */
624  result = read_file_into_buffer(cfg->dpa_resources_file, file_buffer, &bytes_read);
625  if (result != DOCA_SUCCESS) {
626  DOCA_LOG_ERR("Error: Failed to open DPA resources file: %s", doca_error_get_descr(result));
627  free(file_buffer);
628  return result;
629  }
630 
631  const char *app_key = cfg->dpa_app_key;
632  flexio_status res_created = flexio_resources_create(app_key, file_buffer, bytes_read, &res);
633  if (res_created != FLEXIO_STATUS_SUCCESS) {
634  DOCA_LOG_ERR("Error: Failed creating DPA resources object!");
635  free(file_buffer);
636  return DOCA_ERROR_BAD_CONFIG;
637  }
638  /* No support for eu groups yet */
639  int num_eu_groups = flexio_resources_get_eugs_num(res);
640  if (num_eu_groups > 0) {
641  DOCA_LOG_ERR("Execution unit groups are currently unsupported!");
642  free(file_buffer);
643  flexio_resources_destroy(res);
644  return DOCA_ERROR_BAD_CONFIG;
645  }
646  /* Get the number of execution units */
647  uint32_t num_eus = flexio_resources_get_eus_num(res);
648  uint32_t *eus = flexio_resources_get_eus(res);
649  /* Print information about the execution units */
650  DOCA_LOG_INFO("Info: Found %d execution units in DPA resources file", num_eus);
651  for (uint32_t i = 0; i < num_eus; i++) {
652  threads_list[i] = eus[i];
653  }
654  *threads_num = num_eus;
655  flexio_resources_destroy(res);
656  free(file_buffer);
657  return DOCA_SUCCESS;
658 }
659 
661 {
663  uint32_t threads_list[DPA_THREADS_MAX] = {0};
664  uint32_t threads_num = 0;
665  doca_error_t get_execution_ids_status;
666 
667  result = open_dpa_device(cfg->pf_device_name,
668  cfg->rdma_device_name,
669  &resources->pf_doca_device,
670  &resources->rdma_doca_device);
671  if (result != DOCA_SUCCESS) {
672  DOCA_LOG_ERR("Function open_doca_device() failed");
673  goto exit_label;
674  }
675 
676  result = doca_dpa_create(resources->pf_doca_device, &(resources->pf_dpa_ctx));
677  if (result != DOCA_SUCCESS) {
678  DOCA_LOG_ERR("Failed to create DOCA DPA context: %s", doca_error_get_descr(result));
679  goto close_doca_dev;
680  }
681 
683  if (result != DOCA_SUCCESS) {
684  DOCA_LOG_ERR("Failed to set DOCA DPA app: %s", doca_error_get_descr(result));
685  goto destroy_doca_dpa;
686  }
687 
688  result = doca_dpa_start(resources->pf_dpa_ctx);
689  if (result != DOCA_SUCCESS) {
690  DOCA_LOG_ERR("Failed to start DOCA DPA context: %s", doca_error_get_descr(result));
691  goto destroy_doca_dpa;
692  }
693 
694 #ifdef DOCA_ARCH_DPU
695  if (resources->rdma_doca_device != resources->pf_doca_device) {
697  resources->rdma_doca_device,
698  &resources->rdma_dpa_ctx);
699  if (result != DOCA_SUCCESS) {
700  DOCA_LOG_ERR("Failed to extend DOCA DPA context: %s", doca_error_get_descr(result));
701  goto destroy_doca_dpa;
702  }
703 
704  result = doca_dpa_get_dpa_handle(resources->rdma_dpa_ctx, &resources->rdma_dpa_ctx_handle);
705  if (result != DOCA_SUCCESS) {
706  DOCA_LOG_ERR("Failed to get DOCA DPA context handle: %s", doca_error_get_descr(result));
707  goto destroy_rdma_doca_dpa;
708  }
709  } else {
710  resources->rdma_dpa_ctx = resources->pf_dpa_ctx;
711  }
712 #else
713  resources->rdma_dpa_ctx = resources->pf_dpa_ctx;
714 #endif
715 
716  get_execution_ids_status = get_eu_ids_from_resources_file(cfg, threads_list, &threads_num);
717 
718  if (get_execution_ids_status == DOCA_SUCCESS && threads_num > 0) {
719  resources->affinities = malloc(threads_num * sizeof(struct doca_dpa_eu_affinity *));
720  if (resources->affinities == NULL) {
721  DOCA_LOG_ERR("Failed to allocate memory for affinities");
722  goto destroy_doca_dpa;
723  }
724  resources->num_affinities = threads_num;
725 
726  for (uint32_t i = 0; i < threads_num; ++i) {
727  result = doca_dpa_eu_affinity_create(resources->rdma_dpa_ctx, &(resources->affinities[i]));
728  if (result != DOCA_SUCCESS) {
729  DOCA_LOG_ERR("Function doca_dpa_eu_affinity_create failed (%s)",
731  goto destroy_target_thread_affinity;
732  }
733 
734  result = doca_dpa_eu_affinity_set(resources->affinities[i], threads_list[i]);
735  if (result != DOCA_SUCCESS) {
736  DOCA_LOG_ERR("Function doca_dpa_eu_affinity_set failed (%s)",
738  goto destroy_target_thread_affinity;
739  }
740  }
741  }
742 
743  return result;
744 
745 #ifdef DOCA_ARCH_DPU
746 destroy_rdma_doca_dpa:
747  doca_dpa_destroy(resources->rdma_dpa_ctx);
748 #endif
749 
750 destroy_target_thread_affinity:
751  for (uint32_t i = 0; i < threads_num; ++i) {
752  if (resources->affinities[i] != NULL) {
753  doca_dpa_eu_affinity_destroy(resources->affinities[i]);
754  }
755  }
756  free(resources->affinities);
757 
758 destroy_doca_dpa:
759  doca_dpa_destroy(resources->pf_dpa_ctx);
760 close_doca_dev:
761  doca_dev_close(resources->pf_doca_device);
762 #ifdef DOCA_ARCH_DPU
763  doca_dev_close(resources->rdma_doca_device);
764 #endif
765 exit_label:
766  return result;
767 }
768 
770 {
772  doca_error_t tmp_result;
773 
774  for (uint32_t i = 0; i < resources->num_affinities; ++i) {
775  tmp_result = doca_dpa_eu_affinity_destroy(resources->affinities[i]);
776  if (tmp_result != DOCA_SUCCESS) {
777  DOCA_LOG_ERR("Function doca_dpa_eu_affinity_destroy failed: %s",
778  doca_error_get_descr(tmp_result));
779  DOCA_ERROR_PROPAGATE(result, tmp_result);
780  }
781  }
782  free(resources->affinities);
783 
784 #ifdef DOCA_ARCH_DPU
785  if (resources->rdma_dpa_ctx != resources->pf_dpa_ctx) {
786  tmp_result = doca_dpa_destroy(resources->rdma_dpa_ctx);
787  if (tmp_result != DOCA_SUCCESS) {
788  DOCA_LOG_ERR("Function doca_dpa_destroy() failed: %s", doca_error_get_descr(tmp_result));
789  DOCA_ERROR_PROPAGATE(result, tmp_result);
790  }
791  }
792 #endif
793 
794  tmp_result = doca_dpa_destroy(resources->pf_dpa_ctx);
795  if (tmp_result != DOCA_SUCCESS) {
796  DOCA_LOG_ERR("Function doca_dpa_destroy() failed: %s", doca_error_get_descr(tmp_result));
797  DOCA_ERROR_PROPAGATE(result, tmp_result);
798  }
799 
800 #ifdef DOCA_ARCH_DPU
801  tmp_result = doca_dev_close(resources->rdma_doca_device);
802  if (tmp_result != DOCA_SUCCESS) {
803  DOCA_LOG_ERR("Failed to close DOCA device: %s", doca_error_get_descr(tmp_result));
804  DOCA_ERROR_PROPAGATE(result, tmp_result);
805  }
806 #endif
807 
808  tmp_result = doca_dev_close(resources->pf_doca_device);
809  if (tmp_result != DOCA_SUCCESS) {
810  DOCA_LOG_ERR("Failed to close DOCA device: %s", doca_error_get_descr(tmp_result));
811  DOCA_ERROR_PROPAGATE(result, tmp_result);
812  }
813 
814  return result;
815 }
816 
818 {
819  doca_error_t doca_err = DOCA_SUCCESS;
820 
822  if (doca_err != DOCA_SUCCESS) {
823  DOCA_LOG_ERR("Function doca_dpa_thread_create failed (%s)", doca_error_get_descr(doca_err));
824  return doca_err;
825  }
826 
828  if (doca_err != DOCA_SUCCESS) {
829  DOCA_LOG_ERR("Function doca_dpa_thread_set_func_arg failed (%s)", doca_error_get_descr(doca_err));
831  return doca_err;
832  }
833 
836  if (doca_err != DOCA_SUCCESS) {
837  DOCA_LOG_ERR("Function doca_dpa_thread_set_local_storage failed (%s)",
838  doca_error_get_descr(doca_err));
840  return doca_err;
841  }
842  }
843 
844  if (dpa_thread_obj->affinity != NULL) {
846  if (doca_err != DOCA_SUCCESS) {
847  DOCA_LOG_ERR("Function doca_dpa_thread_set_affinity failed (%s)",
848  doca_error_get_descr(doca_err));
850  return doca_err;
851  }
852  }
853 
855  if (doca_err != DOCA_SUCCESS) {
856  DOCA_LOG_ERR("Function doca_dpa_thread_start failed (%s)", doca_error_get_descr(doca_err));
858  return doca_err;
859  }
860 
861  return doca_err;
862 }
863 
865 {
866  doca_error_t doca_err = DOCA_SUCCESS, ret_err = DOCA_SUCCESS;
867 
869  if (doca_err != DOCA_SUCCESS) {
870  DOCA_LOG_ERR("Function doca_dpa_thread_destroy failed (%s)", doca_error_get_descr(doca_err));
871  DOCA_ERROR_PROPAGATE(ret_err, doca_err);
872  }
873 
874  return ret_err;
875 }
876 
878 {
879  doca_error_t doca_err = DOCA_SUCCESS;
880 
884  if (doca_err != DOCA_SUCCESS) {
885  DOCA_LOG_ERR("Function doca_dpa_completion_create failed (%s)", doca_error_get_descr(doca_err));
886  return doca_err;
887  }
888 
889  if (dpa_completion_obj->thread) {
891  if (doca_err != DOCA_SUCCESS) {
892  DOCA_LOG_ERR("Function doca_dpa_completion_set_thread failed (%s)",
893  doca_error_get_descr(doca_err));
895  return doca_err;
896  }
897  }
898 
900  if (doca_err != DOCA_SUCCESS) {
901  DOCA_LOG_ERR("Function doca_dpa_completion_start failed (%s)", doca_error_get_descr(doca_err));
903  return doca_err;
904  }
905 
907  if (doca_err != DOCA_SUCCESS) {
908  DOCA_LOG_ERR("Function doca_dpa_completion_get_dpa_handle failed (%s)", doca_error_get_descr(doca_err));
910  return doca_err;
911  }
912 
913  return DOCA_SUCCESS;
914 }
915 
917 {
918  doca_error_t doca_err = DOCA_SUCCESS, ret_err = DOCA_SUCCESS;
919 
921  if (doca_err != DOCA_SUCCESS) {
922  DOCA_LOG_ERR("Function doca_dpa_completion_destroy failed (%s)", doca_error_get_descr(doca_err));
923  DOCA_ERROR_PROPAGATE(ret_err, doca_err);
924  }
925 
926  return ret_err;
927 }
928 
930 {
931  doca_error_t doca_err = DOCA_SUCCESS;
932 
933  doca_err = doca_dpa_notification_completion_create(notification_completion_obj->doca_dpa,
934  notification_completion_obj->thread,
935  &(notification_completion_obj->notification_comp));
936  if (doca_err != DOCA_SUCCESS) {
937  DOCA_LOG_ERR("Function doca_dpa_notification_completion_create failed (%s)",
938  doca_error_get_descr(doca_err));
939  return doca_err;
940  }
941 
942  doca_err = doca_dpa_notification_completion_start(notification_completion_obj->notification_comp);
943  if (doca_err != DOCA_SUCCESS) {
944  DOCA_LOG_ERR("Function doca_dpa_notification_completion_start failed (%s)",
945  doca_error_get_descr(doca_err));
946  dpa_notification_completion_obj_destroy(notification_completion_obj);
947  return doca_err;
948  }
949 
950  doca_err = doca_dpa_notification_completion_get_dpa_handle(notification_completion_obj->notification_comp,
951  &(notification_completion_obj->handle));
952  if (doca_err != DOCA_SUCCESS) {
953  DOCA_LOG_ERR("Function doca_dpa_notification_completion_get_dpa_handle failed (%s)",
954  doca_error_get_descr(doca_err));
955  dpa_notification_completion_obj_destroy(notification_completion_obj);
956  return doca_err;
957  }
958 
959  return DOCA_SUCCESS;
960 }
961 
963 {
964  doca_error_t doca_err = DOCA_SUCCESS, ret_err = DOCA_SUCCESS;
965 
966  doca_err = doca_dpa_notification_completion_destroy(notification_completion_obj->notification_comp);
967  if (doca_err != DOCA_SUCCESS) {
968  DOCA_LOG_ERR("Function doca_dpa_notification_completion_destroy failed (%s)",
969  doca_error_get_descr(doca_err));
970  DOCA_ERROR_PROPAGATE(ret_err, doca_err);
971  }
972 
973  return ret_err;
974 }
975 
977 {
978  doca_error_t doca_err = DOCA_SUCCESS;
979 
981  if (doca_err != DOCA_SUCCESS) {
982  DOCA_LOG_ERR("RDMA create failed (%s)", doca_error_get_descr(doca_err));
983  return doca_err;
984  }
985 
987 
989  if (doca_err != DOCA_SUCCESS) {
990  DOCA_LOG_ERR("Function doca_rdma_set_permissions failed (%s)", doca_error_get_descr(doca_err));
992  return doca_err;
993  }
994 
995  doca_err = doca_rdma_set_grh_enabled(dpa_rdma_obj->rdma, true);
996  if (doca_err != DOCA_SUCCESS) {
997  DOCA_LOG_ERR("Function doca_rdma_set_grh_enabled failed (%s)", doca_error_get_descr(doca_err));
999  return doca_err;
1000  }
1001 
1003  if (doca_err != DOCA_SUCCESS) {
1004  DOCA_LOG_ERR("Function doca_ctx_set_datapath_on_dpa failed (%s)", doca_error_get_descr(doca_err));
1006  return doca_err;
1007  }
1008 
1011  if (doca_err != DOCA_SUCCESS) {
1012  DOCA_LOG_ERR("Function doca_rdma_set_recv_queue_size failed (%s)\n",
1013  doca_error_get_descr(doca_err));
1015  return doca_err;
1016  }
1017  }
1018 
1019  if (dpa_rdma_obj->buf_list_len) {
1021  if (doca_err != DOCA_SUCCESS) {
1022  DOCA_LOG_ERR("Function doca_rdma_task_receive_set_dst_buf_list_len failed (%s)\n",
1023  doca_error_get_descr(doca_err));
1025  return doca_err;
1026  }
1027  }
1028 
1029  if (dpa_rdma_obj->gid_index) {
1031  if (doca_err != DOCA_SUCCESS) {
1032  DOCA_LOG_ERR("Function doca_rdma_set_gid_index failed (%s)\n", doca_error_get_descr(doca_err));
1034  return doca_err;
1035  }
1036  }
1037 
1040  if (doca_err != DOCA_SUCCESS) {
1041  DOCA_LOG_ERR("Function doca_rdma_set_max_num_connections failed (%s)\n",
1042  doca_error_get_descr(doca_err));
1044  return doca_err;
1045  }
1046  }
1047 
1049  if (doca_err != DOCA_SUCCESS) {
1050  DOCA_LOG_ERR("Function doca_rdma_dpa_completion_attach failed (%s)", doca_error_get_descr(doca_err));
1052  return doca_err;
1053  }
1054 
1055  return doca_err;
1056 }
1057 
1059 {
1061  if (doca_err != DOCA_SUCCESS) {
1063  return doca_err;
1064  }
1065 
1067  if (doca_err != DOCA_SUCCESS) {
1069  return doca_err;
1070  }
1071 
1072  doca_err = doca_rdma_export(dpa_rdma_obj->rdma,
1075  &(dpa_rdma_obj->connection));
1076  if (doca_err != DOCA_SUCCESS) {
1078  return doca_err;
1079  }
1080 
1082  if (doca_err != DOCA_SUCCESS) {
1084  return doca_err;
1085  }
1086 
1088  doca_err = doca_rdma_export(dpa_rdma_obj->rdma,
1092  if (doca_err != DOCA_SUCCESS) {
1094  return doca_err;
1095  }
1096 
1098  if (doca_err != DOCA_SUCCESS) {
1100  return doca_err;
1101  }
1102  }
1103 
1104  return doca_err;
1105 }
1106 
1108 {
1109  doca_error_t doca_err = DOCA_SUCCESS, ret_err = DOCA_SUCCESS;
1110 
1111  doca_err = doca_ctx_stop(dpa_rdma_obj->rdma_as_ctx);
1112  if (doca_err != DOCA_SUCCESS) {
1113  DOCA_LOG_ERR("Function doca_ctx_stop failed (%s)", doca_error_get_descr(doca_err));
1114  DOCA_ERROR_PROPAGATE(ret_err, doca_err);
1115  }
1116 
1117  doca_err = doca_rdma_destroy(dpa_rdma_obj->rdma);
1118  if (doca_err != DOCA_SUCCESS) {
1119  DOCA_LOG_ERR("Function doca_rdma_destroy failed (%s)", doca_error_get_descr(doca_err));
1120  DOCA_ERROR_PROPAGATE(ret_err, doca_err);
1121  }
1122 
1123  return ret_err;
1124 }
1125 
1127 {
1129  if (doca_err != DOCA_SUCCESS) {
1130  DOCA_LOG_ERR("Function doca_mmap_create failed (%s)", doca_error_get_descr(doca_err));
1131  return doca_err;
1132  }
1133 
1135  if (doca_err != DOCA_SUCCESS) {
1136  DOCA_LOG_ERR("Function doca_mmap_set_permissions failed (%s)", doca_error_get_descr(doca_err));
1138  return doca_err;
1139  }
1140 
1141  switch (doca_mmap_obj->mmap_type) {
1142  case MMAP_TYPE_CPU:
1146  if (doca_err != DOCA_SUCCESS) {
1147  DOCA_LOG_ERR("Function doca_mmap_set_memrange failed (%s)", doca_error_get_descr(doca_err));
1149  return doca_err;
1150  }
1151 
1153  if (doca_err != DOCA_SUCCESS) {
1154  DOCA_LOG_ERR("Function doca_mmap_add_dev failed (%s)", doca_error_get_descr(doca_err));
1156  return doca_err;
1157  }
1158 
1159  break;
1160 
1161  case MMAP_TYPE_DPA:
1164  (uint64_t)doca_mmap_obj->memrange_addr,
1166  if (doca_err != DOCA_SUCCESS) {
1167  DOCA_LOG_ERR("Function doca_mmap_set_dpa_memrange failed (%s)", doca_error_get_descr(doca_err));
1169  return doca_err;
1170  }
1171 
1172  break;
1173 
1174  default:
1175  DOCA_LOG_ERR("Unsupported mmap_type (%d)", doca_mmap_obj->mmap_type);
1177  return DOCA_ERROR_NOT_SUPPORTED;
1178  }
1179 
1180  doca_err = doca_mmap_start(doca_mmap_obj->mmap);
1181  if (doca_err != DOCA_SUCCESS) {
1182  DOCA_LOG_ERR("Function doca_mmap_start failed (%s)", doca_error_get_descr(doca_err));
1184  return doca_err;
1185  }
1186 
1190  if (doca_err != DOCA_SUCCESS) {
1191  DOCA_LOG_ERR("Function doca_mmap_dev_get_dpa_handle failed (%s)", doca_error_get_descr(doca_err));
1193  return doca_err;
1194  }
1195 
1200  if (doca_err != DOCA_SUCCESS) {
1201  DOCA_LOG_ERR("Function doca_mmap_export_rdma failed (%s)", doca_error_get_descr(doca_err));
1203  return doca_err;
1204  }
1205 
1206  return doca_err;
1207 }
1208 
1210 {
1211  doca_error_t doca_err = DOCA_SUCCESS, ret_err = DOCA_SUCCESS;
1212 
1213  doca_err = doca_mmap_destroy(doca_mmap_obj->mmap);
1214  if (doca_err != DOCA_SUCCESS) {
1215  DOCA_LOG_ERR("Function doca_mmap_destroy failed (%s)", doca_error_get_descr(doca_err));
1216  DOCA_ERROR_PROPAGATE(ret_err, doca_err);
1217  }
1218 
1219  return ret_err;
1220 }
#define NULL
Definition: __stddef_null.h:26
__SIZE_TYPE__ size_t
char path[MAX_PATH_LEN+1]
int32_t result
uint64_t len
doca_error_t dpa_rdma_obj_destroy(struct dpa_rdma_obj *dpa_rdma_obj)
Destroy DPA RDMA.
Definition: dpa_common.c:1107
doca_error_t export_doca_remote_net_sync_event_to_dpa(struct doca_dev *doca_device, struct doca_dpa *doca_dpa, struct doca_sync_event *remote_net_event, struct doca_sync_event_remote_net **remote_net_exported_event, doca_dpa_dev_sync_event_remote_net_t *remote_net_event_dpa_handle)
Create DOCA sync event to be published by a remote net and subscribed by the CPU.
Definition: dpa_common.c:483
doca_error_t dpa_notification_completion_obj_init(struct dpa_notification_completion_obj *notification_completion_obj)
Initialize DPA notification completion.
Definition: dpa_common.c:929
doca_error_t destroy_dpa_resources(struct dpa_resources *resources)
Destroy DOCA DPA resources.
Definition: dpa_common.c:769
static doca_error_t dpa_app_key_param_callback(void *param, void *config)
Definition: dpa_common.c:88
#define DPA_THREADS_MAX
Definition: dpa_common.c:42
doca_error_t dpa_rdma_obj_start(struct dpa_rdma_obj *dpa_rdma_obj)
Start DPA RDMA.
Definition: dpa_common.c:1058
doca_error_t register_dpa_params(void)
Register the command line parameters for the sample.
Definition: dpa_common.c:126
doca_error_t dpa_thread_obj_init(struct dpa_thread_obj *dpa_thread_obj)
Initialize DPA thread.
Definition: dpa_common.c:817
static doca_error_t get_eu_ids_from_resources_file(struct dpa_config *cfg, uint32_t *threads_list, uint32_t *threads_num)
Get execution unit IDs from FlexIO resources.
Definition: dpa_common.c:601
doca_error_t dpa_notification_completion_obj_destroy(struct dpa_notification_completion_obj *notification_completion_obj)
Destroy DPA notification completion.
Definition: dpa_common.c:962
doca_error_t create_doca_dpa_wait_sync_event(struct doca_dpa *doca_dpa, struct doca_dev *doca_device, struct doca_sync_event **wait_event)
Create DOCA sync event to be published by the CPU and subscribed by the DPA.
Definition: dpa_common.c:313
doca_error_t doca_mmap_obj_destroy(struct doca_mmap_obj *doca_mmap_obj)
Destroy DOCA Mmap.
Definition: dpa_common.c:1209
DOCA_LOG_REGISTER(DPA_COMMON)
doca_error_t dpa_completion_obj_init(struct dpa_completion_obj *dpa_completion_obj)
Initialize DPA completion.
Definition: dpa_common.c:877
struct doca_dpa_app * dpa_sample_app
static doca_error_t pf_device_name_param_callback(void *param, void *config)
Definition: dpa_common.c:57
doca_error_t allocate_dpa_resources(struct dpa_config *cfg, struct dpa_resources *resources)
Allocate DOCA DPA resources.
Definition: dpa_common.c:660
doca_error_t create_doca_remote_net_sync_event(struct doca_dev *doca_device, struct doca_sync_event **remote_net_event)
Create DOCA sync event to be published by a remote net and subscribed by the CPU.
Definition: dpa_common.c:443
static doca_error_t read_file_into_buffer(const char *path, char *buffer, size_t *bytes_read)
Read file content into a pre-allocated buffer.
Definition: dpa_common.c:571
doca_error_t dpa_rdma_obj_init(struct dpa_rdma_obj *dpa_rdma_obj)
Initialize DPA RDMA without starting it.
Definition: dpa_common.c:976
static doca_error_t open_dpa_device(const char *pf_device_name, const char *rdma_device_name, struct doca_dev **pf_doca_device, struct doca_dev **rdma_doca_device)
Definition: dpa_common.c:222
doca_error_t create_doca_dpa_completion_sync_event(struct doca_dpa *doca_dpa, struct doca_dev *doca_device, struct doca_sync_event **comp_event, doca_dpa_dev_sync_event_t *handle)
Create DOCA sync event to be published by the DPA and subscribed by the CPU.
Definition: dpa_common.c:354
doca_error_t doca_mmap_obj_init(struct doca_mmap_obj *doca_mmap_obj)
Initialize DOCA Mmap.
Definition: dpa_common.c:1126
doca_error_t dpa_completion_obj_destroy(struct dpa_completion_obj *dpa_completion_obj)
Destroy DPA completion.
Definition: dpa_common.c:916
static doca_error_t get_file_size(const char *path, size_t *file_size)
Get the size of a file.
Definition: dpa_common.c:536
doca_error_t dpa_thread_obj_destroy(struct dpa_thread_obj *dpa_thread_obj)
Destroy DPA thread.
Definition: dpa_common.c:864
static doca_error_t dpa_resources_file_param_callback(void *param, void *config)
Definition: dpa_common.c:72
doca_error_t create_doca_dpa_kernel_sync_event(struct doca_dpa *doca_dpa, struct doca_sync_event **kernel_event)
Create DOCA sync event to be published and subscribed by the DPA.
Definition: dpa_common.c:404
@ MMAP_TYPE_DPA
Definition: dpa_common.h:172
@ MMAP_TYPE_CPU
Definition: dpa_common.h:171
#define DEVICE_DEFAULT_NAME
device default name
Definition: dpa_common.h:55
#define DPA_APP_KEY_MAX_SIZE
DPA application key size.
Definition: dpa_common.h:80
#define DPA_RESOURCES_PATH_MAX_SIZE
DPA resources file path size.
Definition: dpa_common.h:75
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 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_STABLE doca_error_t doca_ctx_start(struct doca_ctx *ctx)
Finalizes all configurations, and starts the DOCA CTX.
DOCA_EXPERIMENTAL doca_error_t doca_ctx_set_datapath_on_dpa(struct doca_ctx *ctx, struct doca_dpa *dpa_dev)
This function binds the DOCA context to a dpa device.
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.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_notification_completion_start(struct doca_dpa_notification_completion *notify_comp)
Start DPA notification completion context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_thread_create(struct doca_dpa *dpa, struct doca_dpa_thread **dpa_thread)
Create DPA thread.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_completion_destroy(struct doca_dpa_completion *dpa_comp)
Destroy DPA completion context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_create(struct doca_dev *dev, struct doca_dpa **dpa)
Create a DOCA DPA Context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_notification_completion_destroy(struct doca_dpa_notification_completion *notify_comp)
Destroy DPA notification completion context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_get_dpa_handle(struct doca_dpa *dpa, doca_dpa_dev_t *handle)
Get DPA context handle.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_completion_set_thread(struct doca_dpa_completion *dpa_comp, struct doca_dpa_thread *dpa_thread)
Set DPA completion context thread.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_device_extend(struct doca_dpa *dpa, struct doca_dev *other_dev, struct doca_dpa **extended_dpa)
Create an extended DPA context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_notification_completion_create(struct doca_dpa *dpa, struct doca_dpa_thread *dpa_thread, struct doca_dpa_notification_completion **notify_comp)
Create DPA notification completion context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_completion_start(struct doca_dpa_completion *dpa_comp)
Start DPA completion context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_destroy(struct doca_dpa *dpa)
Destroy a DOCA DPA context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_thread_set_local_storage(struct doca_dpa_thread *dpa_thread, doca_dpa_dev_uintptr_t dev_ptr)
Set DPA thread local storage.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_completion_get_dpa_handle(struct doca_dpa_completion *dpa_comp, doca_dpa_dev_completion_t *handle)
Get DPA completion context handle.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_notification_completion_get_dpa_handle(struct doca_dpa_notification_completion *notify_comp, doca_dpa_dev_notification_completion_t *handle)
Get DPA notification completion context handle.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_completion_create(struct doca_dpa *dpa, unsigned int queue_size, struct doca_dpa_completion **dpa_comp)
Create DPA completion context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_eu_affinity_create(struct doca_dpa *dpa, struct doca_dpa_eu_affinity **affinity)
Create DPA EU affinity.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_start(struct doca_dpa *dpa)
Start a DPA context.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_thread_set_func_arg(struct doca_dpa_thread *dpa_thread, doca_dpa_func_t *func, uint64_t arg)
Set DPA thread entry point and its argument.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_cap_is_supported(const struct doca_devinfo *devinfo)
Get whether the DOCA device supports DPA.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_thread_set_affinity(struct doca_dpa_thread *dpa_thread, const struct doca_dpa_eu_affinity *affinity)
Set DPA thread affinity.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_eu_affinity_destroy(struct doca_dpa_eu_affinity *affinity)
Destroy DPA EU affinity.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_thread_start(struct doca_dpa_thread *dpa_thread)
Start DPA thread.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_eu_affinity_set(struct doca_dpa_eu_affinity *affinity, unsigned int eu_id)
Set EU ID in DPA EU affinity.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_thread_destroy(struct doca_dpa_thread *dpa_thread)
Destroy DPA thread.
DOCA_EXPERIMENTAL doca_error_t doca_dpa_set_app(struct doca_dpa *dpa, struct doca_dpa_app *app)
Set program app for DPA context.
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
Definition: doca_error.h:83
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_INVALID_VALUE
Definition: doca_error.h:44
@ DOCA_ERROR_NOT_FOUND
Definition: doca_error.h:54
@ DOCA_ERROR_NOT_SUPPORTED
Definition: doca_error.h:42
@ DOCA_ERROR_IO_FAILED
Definition: doca_error.h:55
@ DOCA_SUCCESS
Definition: doca_error.h:38
@ DOCA_ERROR_BAD_CONFIG
Definition: doca_error.h:67
@ 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_EXPERIMENTAL doca_error_t doca_mmap_dev_get_dpa_handle(struct doca_mmap *mmap, const struct doca_dev *dev, doca_dpa_dev_mmap_t *dpa_mmap_handle)
Extract mmap handle associated with the given DOCA device, for the DPA to operate on.
DOCA_EXPERIMENTAL doca_error_t doca_mmap_set_dpa_memrange(struct doca_mmap *mmap, struct doca_dpa *dpa, uint64_t dpa_addr, size_t len)
Set the memory range of DOCA memory map to be a DPA heap memory.
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_EXPERIMENTAL doca_error_t doca_rdma_destroy(struct doca_rdma *rdma)
Destroy a DOCA RDMA instance.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_dpa_completion_attach(struct doca_rdma *rdma, struct doca_dpa_completion *dpa_comp)
Attach DOCA RDMA to DPA completion context.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_set_grh_enabled(struct doca_rdma *rdma, uint8_t grh_enabled)
Set whether to use GRH in connection. The value can be queried using doca_rdma_get_grh_enabled()....
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 doca_error_t doca_rdma_get_dpa_handle(struct doca_rdma *rdma, doca_dpa_dev_rdma_t *dpa_rdma)
Retrieve the handle in the dpa memory space of a doca_rdma.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_connection_get_id(const struct doca_rdma_connection *rdma_connection, uint32_t *connection_id)
Get connection ID from an rdma connection.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_set_recv_queue_size(struct doca_rdma *rdma, uint32_t recv_queue_size)
Set recv queue size property for doca_rdma. The value can be queried using doca_rdma_get_recv_queue_s...
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_task_receive_set_dst_buf_list_len(struct doca_rdma *rdma, uint32_t buf_list_len)
Set the maximal destination buffer list length property for receive tasks. After starting the DOCA RD...
DOCA_EXPERIMENTAL doca_error_t doca_rdma_export(struct doca_rdma *rdma, const void **local_rdma_conn_details, size_t *local_rdma_conn_details_size, struct doca_rdma_connection **rdma_connection)
Export doca_rdma connection details object The doca_rdma_conn_details are used in doca_rdma_connect()...
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 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_cap_task_send_is_supported(const struct doca_devinfo *devinfo)
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_remote_net_create_from_export(struct doca_dev *dev, const uint8_t *data, size_t sz, struct doca_sync_event_remote_net **event)
Create a remote Sync Event handle from an export.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_remote_net_destroy(struct doca_sync_event_remote_net *event)
Destroy a Sync Event instance.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_start(struct doca_sync_event *event)
Start a Sync Event to be operate as stand-alone DOCA Core object only.
uint64_t doca_dpa_dev_sync_event_t
DOCA Sync Event DPA handle.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_create(struct doca_sync_event **event)
Create a Sync Event handle.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_add_subscriber_location_dpa(struct doca_sync_event *event, struct doca_dpa *dpa)
Associate a DOCA DPA context as the Sync Event subscriber.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_remote_net_get_dpa_handle(struct doca_sync_event_remote_net *event, struct doca_dpa *dpa, doca_dpa_dev_sync_event_remote_net_t *dpa_remote_event)
Export remote Sync Event to be shared with the DPA.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_get_dpa_handle(struct doca_sync_event *event, struct doca_dpa *dpa, doca_dpa_dev_sync_event_t *dpa_dev_se_handle)
Export Sync Event to be shared with the DPA.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_add_publisher_location_remote_net(struct doca_sync_event *event)
Declare Sync Event publisher as a remote peer.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_add_subscriber_location_cpu(struct doca_sync_event *event, struct doca_dev *dev)
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_destroy(struct doca_sync_event *event)
Destroy a Sync Event instance.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_add_publisher_location_dpa(struct doca_sync_event *event, struct doca_dpa *dpa)
Associate a DOCA DPA context as the Sync Event publisher.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_add_publisher_location_cpu(struct doca_sync_event *event, struct doca_dev *dev)
Associate a CPU device context as the Sync Event publisher.
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.
uint64_t doca_dpa_dev_sync_event_remote_net_t
DOCA Sync Event remote DPA handle.
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
A struct that includes all the resources needed for DOCA Mmap.
Definition: dpa_common.h:178
size_t export_len
Definition: dpa_common.h:188
const void * rdma_export
Definition: dpa_common.h:187
size_t memrange_len
Definition: dpa_common.h:184
enum mmap_type mmap_type
Definition: dpa_common.h:179
uint32_t permissions
Definition: dpa_common.h:182
struct doca_dev * doca_device
Definition: dpa_common.h:180
struct doca_mmap * mmap
Definition: dpa_common.h:185
struct doca_dpa * doca_dpa
Definition: dpa_common.h:181
doca_dpa_dev_mmap_t dpa_mmap_handle
Definition: dpa_common.h:186
void * memrange_addr
Definition: dpa_common.h:183
A struct that includes all the resources needed for DPA completion.
Definition: dpa_common.h:123
struct doca_dpa_thread * thread
Definition: dpa_common.h:126
doca_dpa_dev_completion_t handle
Definition: dpa_common.h:128
struct doca_dpa_completion * dpa_comp
Definition: dpa_common.h:127
struct doca_dpa * doca_dpa
Definition: dpa_common.h:124
unsigned int queue_size
Definition: dpa_common.h:125
Configuration struct.
Definition: dpa_common.h:100
char rdma_device_name[DOCA_DEVINFO_IBDEV_NAME_SIZE]
Definition: dpa_common.h:102
char dpa_resources_file[DPA_RESOURCES_PATH_MAX_SIZE]
Definition: dpa_common.h:104
char pf_device_name[DOCA_DEVINFO_IBDEV_NAME_SIZE]
Definition: dpa_common.h:101
char dpa_app_key[DPA_APP_KEY_MAX_SIZE]
Definition: dpa_common.h:105
A struct that includes all the resources needed for DPA notification completion.
Definition: dpa_common.h:134
struct doca_dpa_thread * thread
Definition: dpa_common.h:136
doca_dpa_dev_notification_completion_t handle
Definition: dpa_common.h:138
struct doca_dpa * doca_dpa
Definition: dpa_common.h:135
struct doca_dpa_notification_completion * notification_comp
Definition: dpa_common.h:137
A struct that includes all the resources needed for DPA RDMA.
Definition: dpa_common.h:144
struct doca_ctx * rdma_as_ctx
Definition: dpa_common.h:154
doca_dpa_dev_rdma_t dpa_rdma
Definition: dpa_common.h:155
struct doca_rdma_connection * connection
Definition: dpa_common.h:158
uint32_t connection_id
Definition: dpa_common.h:159
uint32_t permissions
Definition: dpa_common.h:147
bool second_connection_needed
Definition: dpa_common.h:160
uint32_t max_connections_count
Definition: dpa_common.h:150
size_t conn2_det_len
Definition: dpa_common.h:162
uint32_t connection2_id
Definition: dpa_common.h:164
const void * connection2_details
Definition: dpa_common.h:161
uint32_t gid_index
Definition: dpa_common.h:151
struct doca_rdma_connection * connection2
Definition: dpa_common.h:163
size_t conn_det_len
Definition: dpa_common.h:157
uint32_t recv_queue_size
Definition: dpa_common.h:149
struct doca_dev * doca_device
Definition: dpa_common.h:145
uint32_t buf_list_len
Definition: dpa_common.h:148
struct doca_dpa_completion * dpa_comp
Definition: dpa_common.h:152
struct doca_rdma * rdma
Definition: dpa_common.h:153
struct doca_dpa * doca_dpa
Definition: dpa_common.h:146
const void * connection_details
Definition: dpa_common.h:156
A struct that includes all the resources needed for DPA.
Definition: dpa_common.h:85
A struct that includes all the resources needed for DPA thread.
Definition: dpa_common.h:111
struct doca_dpa_thread * thread
Definition: dpa_common.h:116
uint64_t arg
Definition: dpa_common.h:114
doca_dpa_dev_uintptr_t tls_dev_ptr
Definition: dpa_common.h:115
struct doca_dpa * doca_dpa
Definition: dpa_common.h:112
doca_dpa_func_t * func
Definition: dpa_common.h:113
struct doca_dpa_eu_affinity * affinity
Definition: dpa_common.h:117