NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
pcc_core.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-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 <stdlib.h>
27 #include <string.h>
28 #include <stdbool.h>
29 #include <stdio.h>
30 #include <stdint.h>
31 #include <ctype.h>
32 
33 #include <doca_argp.h>
34 
35 #include "pcc_core.h"
36 
37 #include "libflexio/flexio_ver.h"
38 #define PCC_FLEXIO_MAJOR_VERSION (25)
39 #define PCC_FLEXIO_MINOR_VERSION (4)
40 #define PCC_FLEXIO_PATCH_VERSION (0)
41 #define FLEXIO_VER_USED FLEXIO_VER(PCC_FLEXIO_MAJOR_VERSION, PCC_FLEXIO_MINOR_VERSION, PCC_FLEXIO_PATCH_VERSION)
42 #include "libflexio/flexio.h"
43 
44 /*
45  * Formats of the trace message to be printed from the device
46  */
47 static char *trace_message_formats[] = {
48  "format 0 - user init: port num = %#lx, algo index = %#lx, algo slot = %#lx, algo enable = %#lx, disable event bitmask = %#lx\n",
49  "format 1 - user algo: algo slot = %#lx, result rate = %#lx, result rtt req = %#lx, port num = %#lx, timestamp = %#lx\n",
50  "format 2 - pcc_np dev: thread_idx = %#lx, debug_init = %#lx, cnt_enter = %#lx, cnt_arm = %#lx. end %u\n",
51  "format 3 - pcc_np dev: thread_idx = %#lx, cnt_recv_packet = %#lx, cnt_sent_packet = %#lx, cnt_user_func_err = %#lx. end %u\n",
52  "format 4 - pcc_np dev: thread_idx = %#lx, rq = %#lx, rq_pi = %#lx, rqcq = %#lx, rqcq_ci = %#lx\n",
53  "format 5 - pcc_np dev: thread_idx = %#lx, sq = %#lx, sq_pi = %#lx, sqcq = %#lx. end %u\n",
54  NULL};
55 
56 /* Default PCC RP threads */
58  176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 192, 193, 194, 195, 196,
59  197, 198, 199, 200, 201, 202, 203, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
60  218, 219, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 240};
61 /* Default PCC NP threads */
63  {16, 17, 18, 19, 20, 21, 22, 23, 32, 33, 34, 35, 36, 37, 38, 39};
64 
65 /*
66  * Declare threads list flag
67  */
68 static bool use_threads_list = false;
69 
70 /*
71  * Declare DPA resources flag
72  */
73 static bool use_dpa_resources = false;
74 
75 /*
76  * Declare user set application flag
77  */
78 static bool user_set_app = false;
79 
87 static doca_error_t get_file_size(const char *path, size_t *file_size)
88 {
89  FILE *file;
90  long nb_file_bytes;
91 
92  file = fopen(path, "rb");
93  if (file == NULL)
94  return DOCA_ERROR_NOT_FOUND;
95 
96  if (fseek(file, 0, SEEK_END) != 0) {
97  fclose(file);
98  return DOCA_ERROR_IO_FAILED;
99  }
100 
101  nb_file_bytes = ftell(file);
102  fclose(file);
103 
104  if (nb_file_bytes == -1)
105  return DOCA_ERROR_IO_FAILED;
106 
107  if (nb_file_bytes == 0)
109 
110  *file_size = (size_t)nb_file_bytes;
111  return DOCA_SUCCESS;
112 }
113 
122 static doca_error_t read_file_into_buffer(const char *path, char *buffer, size_t *bytes_read)
123 {
124  FILE *file;
125  size_t read_byte_count;
126 
127  file = fopen(path, "rb");
128  if (file == NULL)
129  return DOCA_ERROR_NOT_FOUND;
130 
131  read_byte_count = fread(buffer, 1, *bytes_read, file);
132  fclose(file);
133 
134  if (read_byte_count != *bytes_read)
135  return DOCA_ERROR_IO_FAILED;
136 
137  *bytes_read = read_byte_count;
138  return DOCA_SUCCESS;
139 }
140 
141 /*
142  * Check if the provided device name is a name of a valid IB device
143  *
144  * @device_name [in]: The wanted IB device name
145  * @role [in]: Role of the PCC context
146  * @return: True if device_name is an IB device, false otherwise.
147  */
148 static bool pcc_device_exists_check(const char *device_name)
149 {
150  struct doca_devinfo **dev_list;
151  uint32_t nb_devs = 0;
153  bool exists = false;
154  char ibdev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE] = {0};
155  uint32_t i = 0;
156 
157  result = doca_devinfo_create_list(&dev_list, &nb_devs);
158  if (result != DOCA_SUCCESS) {
159  PRINT_ERROR("Error: Failed to load DOCA devices list: %s\n", doca_error_get_descr(result));
160  return false;
161  }
162 
163  /* Search device with same device name */
164  for (i = 0; i < nb_devs; i++) {
165  result = doca_devinfo_get_ibdev_name(dev_list[i], ibdev_name, sizeof(ibdev_name));
166  if (result != DOCA_SUCCESS)
167  continue;
168 
169  /* Check if we found the device with the wanted name */
170  if (strncmp(device_name, ibdev_name, DOCA_DEVINFO_IBDEV_NAME_SIZE) == 0) {
171  exists = true;
172  break;
173  }
174  }
175 
176  doca_devinfo_destroy_list(dev_list);
177 
178  return exists;
179 }
180 
181 /*
182  * Open DOCA device that supports PCC
183  *
184  * @device_name [in]: Requested IB device name
185  * @role [in]: Role of the PCC context
186  * @doca_device [out]: An allocated DOCA device that supports PCC on success and NULL otherwise
187  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
188  */
189 static doca_error_t open_pcc_device(const char *device_name, pcc_role_t role, struct doca_dev **doca_device)
190 {
191  struct doca_devinfo **dev_list;
192  uint32_t nb_devs = 0;
194  char ibdev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE] = {0};
195  uint32_t i = 0;
196 
197  result = doca_devinfo_create_list(&dev_list, &nb_devs);
198  if (result != DOCA_SUCCESS) {
199  PRINT_ERROR("Error: Failed to load DOCA devices list: %s\n", doca_error_get_descr(result));
200  return result;
201  }
202 
203  /* Search device with same device name and PCC capabilities supported */
204  for (i = 0; i < nb_devs; i++) {
205  result = doca_devinfo_get_ibdev_name(dev_list[i], ibdev_name, sizeof(ibdev_name));
206  if (result != DOCA_SUCCESS) {
207  PRINT_ERROR("Error: could not get DOCA device name\n");
208  continue;
209  }
210 
211  /* Check if the device has the requested device name */
212  if (strncmp(device_name, ibdev_name, DOCA_DEVINFO_IBDEV_NAME_SIZE) != 0)
213  continue;
214 
215  if (role == PCC_ROLE_RP)
217  else if (role == PCC_ROLE_NP)
218  result = doca_pcc_np_cap_is_supported(dev_list[i]);
219  if (result != DOCA_SUCCESS) {
220  doca_devinfo_destroy_list(dev_list);
221  PRINT_ERROR("Error: DOCA device %s does not support PCC %s role\n",
222  device_name,
223  (role == PCC_ROLE_RP ? "RP" : "NP"));
224  return result;
225  }
226 
227  result = doca_dev_open(dev_list[i], doca_device);
228  if (result != DOCA_SUCCESS) {
229  doca_devinfo_destroy_list(dev_list);
230  PRINT_ERROR("Error: Failed to open DOCA device: %s\n", doca_error_get_descr(result));
231  return result;
232  }
233  break;
234  }
235 
236  doca_devinfo_destroy_list(dev_list);
237 
238  if (*doca_device == NULL) {
239  PRINT_ERROR("Error: Couldn't get DOCA device %s\n", device_name);
240  return DOCA_ERROR_NOT_FOUND;
241  }
242 
243  return result;
244 }
245 
247 {
248  doca_error_t result, tmp_result;
249  uint32_t min_num_threads, max_num_threads;
250 
251  /* Check if both threads list and DPA resources are specified */
253  PRINT_ERROR(
254  "Error: Cannot specify both threads list and DPA resources. Use either threads list or DPA resources (with application key).\n");
255  return DOCA_ERROR_BAD_CONFIG;
256  }
257 
258  /* If DPA resources are specified, read the DPA resources file */
259  if (use_dpa_resources) {
260  char *file_buffer;
261  size_t bytes_read;
262  struct flexio_resource *res;
263 
264  /* Get the file size first */
265  result = get_file_size(cfg->dpa_resources_file, &bytes_read);
266  if (result != DOCA_SUCCESS) {
267  PRINT_ERROR("Error: Failed to get DPA resources file size: %s\n", doca_error_get_descr(result));
268  return result;
269  }
270 
271  /* Allocate buffer based on file size */
272  file_buffer = (char *)malloc(bytes_read);
273  if (file_buffer == NULL) {
274  PRINT_ERROR("Error: Failed to allocate memory for DPA resources file\n");
275  return DOCA_ERROR_NO_MEMORY;
276  }
277 
278  /* Read the DPA resources file */
279  result = read_file_into_buffer(cfg->dpa_resources_file, file_buffer, &bytes_read);
280  if (result != DOCA_SUCCESS) {
281  PRINT_ERROR("Error: Failed to open DPA resources file: %s\n", doca_error_get_descr(result));
282  free(file_buffer);
283  return result;
284  }
285 
286  // if app_key is not set, we will default to the pcc_app name
287  const char *app_key = cfg->dpa_application_key;
288  if (app_key == NULL || strlen(app_key) == 0) {
289  struct flexio_app *pcc_app = (struct flexio_app *)(cfg->app);
290  const char *app_name = flexio_app_get_name(pcc_app);
291  app_key = app_name;
292  }
293 
294  /* Create the DPA resources object */
295  flexio_status res_created = flexio_resources_create(app_key, file_buffer, bytes_read, &res);
296  if (res_created != FLEXIO_STATUS_SUCCESS) {
297  PRINT_ERROR("Error: Failed creating DPA resources object!\n");
298  free(file_buffer);
300  }
301 
302  /* No support for eu groups yet */
303  int num_eu_groups = flexio_resources_get_eugs_num(res);
304  if (num_eu_groups > 0) {
305  PRINT_ERROR("Error: Execution unit groups are currently unsupported!\n");
306  free(file_buffer);
307  flexio_resources_destroy(res);
309  }
310 
311  /* Get the number of execution units */
312  uint32_t num_eus = flexio_resources_get_eus_num(res);
313  uint32_t *eus = flexio_resources_get_eus(res);
314 
315  /* Print information about the execution units */
316  PRINT_DEBUG("Debug: Found %d execution units in DPA resources file\n", num_eus);
317 
318  for (uint32_t i = 0; i < num_eus; i++) {
319  cfg->threads_list[i] = eus[i];
320  }
321  cfg->threads_num = num_eus;
322 
323  flexio_resources_destroy(res);
324  free(file_buffer);
325  }
326 
327  /* Open DOCA device that supports PCC */
328  result = open_pcc_device(cfg->device_name, cfg->role, &(resources->doca_device));
329  if (result != DOCA_SUCCESS) {
330  PRINT_ERROR("Error: Failed to open DOCA device that supports PCC\n");
331  return result;
332  }
333 
334  /* Create DOCA PCC context */
335  bool use_default_threads = !use_threads_list && !use_dpa_resources;
336  if (cfg->role == PCC_ROLE_RP)
338  else if (cfg->role == PCC_ROLE_NP)
340  if (result != DOCA_SUCCESS) {
341  PRINT_ERROR("Error: Failed to create DOCA PCC context\n");
342  goto close_doca_dev;
343  }
344 
345  /* Define default threads if not set according to role */
346  if (use_default_threads) {
347  if (cfg->role == PCC_ROLE_RP) {
348  memcpy(cfg->threads_list, default_pcc_rp_threads_list, sizeof(default_pcc_rp_threads_list));
349  cfg->threads_num = PCC_RP_THREADS_NUM_DEFAULT_VALUE;
350  } else if (cfg->role == PCC_ROLE_NP) {
351  memcpy(cfg->threads_list, default_pcc_np_threads_list, sizeof(default_pcc_np_threads_list));
352  cfg->threads_num = PCC_NP_THREADS_NUM_DEFAULT_VALUE;
353  }
354  }
355 
356  result = doca_pcc_get_min_num_threads(resources->doca_pcc, &min_num_threads);
357  if (result != DOCA_SUCCESS) {
358  PRINT_ERROR("Failed to get minimum DOCA PCC number of threads\n");
359  goto destroy_pcc;
360  }
361 
362  result = doca_pcc_get_max_num_threads(resources->doca_pcc, &max_num_threads);
363  if (result != DOCA_SUCCESS) {
364  PRINT_ERROR("Failed to get maximum DOCA PCC number of threads\n");
365  goto destroy_pcc;
366  }
367 
368  if (cfg->threads_num < min_num_threads || cfg->threads_num > max_num_threads) {
369  PRINT_ERROR(
370  "Invalid number of PCC threads: %u. The Minimum number of PCC threads is %d and the maximum number of PCC threads is %d\n",
371  cfg->threads_num,
372  min_num_threads,
373  max_num_threads);
375  goto destroy_pcc;
376  }
377 
378  result = doca_pcc_set_app(resources->doca_pcc, cfg->app);
379  if (result != DOCA_SUCCESS) {
380  PRINT_ERROR("Error: Failed to set DOCA PCC app\n");
381  goto destroy_pcc;
382  }
383 
384  /* Set DOCA PCC thread affinity */
385  result = doca_pcc_set_thread_affinity(resources->doca_pcc, cfg->threads_num, cfg->threads_list);
386  if (result != DOCA_SUCCESS) {
387  PRINT_ERROR("Error: Failed to set thread affinity for DOCA PCC\n");
388  goto destroy_pcc;
389  }
390 
391  /* Set DOCA PCC probe packet format */
392  switch (cfg->probe_packet_format) {
395  if (result != DOCA_SUCCESS) {
396  PRINT_ERROR("Error: Failed to set CCMAD probe packet format for DOCA PCC\n");
397  goto destroy_pcc;
398  }
399  if (cfg->role == PCC_ROLE_RP) {
400  result =
401  doca_pcc_rp_set_ccmad_remote_sw_handler(resources->doca_pcc, 0, cfg->remote_sw_handler);
402  if (result != DOCA_SUCCESS) {
403  PRINT_ERROR("Error: Failed to set CCMAD remote SW handler for DOCA PCC\n");
404  goto destroy_pcc;
405  }
406  }
407  break;
410  if (result != DOCA_SUCCESS) {
411  PRINT_ERROR("Error: Failed to set IFA1 probe packet format for DOCA PCC\n");
412  goto destroy_pcc;
413  }
414  break;
417  if (result != DOCA_SUCCESS) {
418  PRINT_ERROR("Error: Failed to set IFA2 probe packet format for DOCA PCC\n");
419  goto destroy_pcc;
420  }
421  if (cfg->role == PCC_ROLE_RP) {
422  result = doca_pcc_rp_set_ifa2_gns(resources->doca_pcc, 0, cfg->gns);
423  if (result != DOCA_SUCCESS) {
424  PRINT_ERROR("Error: Failed to set IFA2 GNS for DOCA PCC\n");
425  goto destroy_pcc;
426  }
427  result = doca_pcc_rp_set_ifa2_hop_limit(resources->doca_pcc, 0, cfg->hop_limit);
428  if (result != DOCA_SUCCESS) {
429  PRINT_ERROR("Error: Failed to set IFA2 hop limit for DOCA PCC\n");
430  goto destroy_pcc;
431  }
432  } else if (cfg->role == PCC_ROLE_NP) {
434  0,
435  cfg->gns_ignore_mask,
436  cfg->gns_ignore_value);
437  if (result != DOCA_SUCCESS) {
438  PRINT_ERROR("Error: Failed to set IFA2 GNS ignore for DOCA PCC\n");
439  goto destroy_pcc;
440  }
441  }
442  break;
443  }
444 
445  /* Set DOCA PCC print buffer size */
447  if (result != DOCA_SUCCESS) {
448  PRINT_ERROR("Error: Failed to set print buffer size for DOCA PCC\n");
449  goto destroy_pcc;
450  }
451 
452  /* Set DOCA PCC trace message formats */
454  if (result != DOCA_SUCCESS) {
455  PRINT_ERROR("Error: Failed to set trace message for DOCA PCC\n");
456  goto destroy_pcc;
457  }
458 
459  /* Set DOCA PCC coredump file pathname */
460  result = doca_pcc_set_dev_coredump_file(resources->doca_pcc, cfg->coredump_file);
461  if (result != DOCA_SUCCESS) {
462  PRINT_ERROR("Error: Failed to set coredump file for DOCA PCC\n");
463  goto destroy_pcc;
464  }
465 
466  /* Set DOCA PCC mailbox */
468  if (result != DOCA_SUCCESS) {
469  PRINT_ERROR("Error: Failed to set mailbox for DOCA PCC\n");
470  goto destroy_pcc;
471  }
472 
473  return result;
474 
475 destroy_pcc:
476  tmp_result = doca_pcc_destroy(resources->doca_pcc);
477  if (tmp_result != DOCA_SUCCESS) {
478  PRINT_ERROR("Error: Failed to destroy DOCA PCC context: %s\n", doca_error_get_descr(result));
479  DOCA_ERROR_PROPAGATE(result, tmp_result);
480  }
481 close_doca_dev:
482  tmp_result = doca_dev_close(resources->doca_device);
483  if (tmp_result != DOCA_SUCCESS) {
484  PRINT_ERROR("Error: Failed to close DOCA device: %s\n", doca_error_get_descr(result));
485  DOCA_ERROR_PROPAGATE(result, tmp_result);
486  }
487 
488  return result;
489 }
490 
492 {
494  uint32_t *request_buf;
495  uint32_t response_size, cb_ret_val;
496 
497  if (!(cfg->app == pcc_np_switch_telemetry_app))
498  return DOCA_SUCCESS;
499 
500  /* Get the request buffer of the mailbox */
501  result = doca_pcc_mailbox_get_request_buffer(resources->doca_pcc, (void **)&request_buf);
502  if (result != DOCA_SUCCESS) {
503  PRINT_ERROR("Error: Failed to get the request buffer of the PCC mailbox\n");
504  return result;
505  }
506 
507  /* send hop limit to device */
508  *request_buf = cfg->hop_limit;
509 
510  /* Send the request buffer that holds the hop limit */
511  result = doca_pcc_mailbox_send(resources->doca_pcc, PCC_MAILBOX_REQUEST_SIZE, &response_size, &cb_ret_val);
512  if (result != DOCA_SUCCESS) {
513  PRINT_ERROR("Error: Failed to send the PCC mailbox request buffer\n");
514  return result;
515  }
516 
517  if (cb_ret_val != 0) {
518  PRINT_ERROR("Error: Mailbox callback returned error status\n");
519  return DOCA_ERROR_UNEXPECTED;
520  }
521 
522  return DOCA_SUCCESS;
523 }
524 
526 {
527  doca_error_t result, tmp_result;
528 
529  result = doca_pcc_destroy(resources->doca_pcc);
530  if (result != DOCA_SUCCESS)
531  PRINT_ERROR("Error: Failed to destroy DOCA PCC context: %s\n", doca_error_get_descr(result));
532 
533  tmp_result = doca_dev_close(resources->doca_device);
534  if (tmp_result != DOCA_SUCCESS) {
535  PRINT_ERROR("Error: Failed to close DOCA device: %s\n", doca_error_get_descr(result));
536  DOCA_ERROR_PROPAGATE(result, tmp_result);
537  }
538 
539  return result;
540 }
541 
542 /*
543  * ARGP Callback - Handle IB device name parameter
544  *
545  * @param [in]: Input parameter
546  * @config [in/out]: Program configuration context
547  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
548  */
549 static doca_error_t device_name_callback(void *param, void *config)
550 {
551  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
552  char *device_name = (char *)param;
553  int len;
554 
557  PRINT_ERROR("Error: Entered IB device name exceeding the maximum size of %d\n",
560  }
561  strncpy(pcc_cfg->device_name, device_name, len + 1);
562 
563  if (!pcc_device_exists_check(pcc_cfg->device_name)) {
564  PRINT_ERROR("Error: Entered IB device name: %s doesn't exist\n", pcc_cfg->device_name);
566  }
567 
568  return DOCA_SUCCESS;
569 }
570 
571 /*
572  * ARGP Callback - Handle PCC NP NIC Telemetry parameter
573  *
574  * @param [in]: Input parameter
575  * @config [in/out]: Program configuration context
576  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
577  */
578 static doca_error_t np_nic_telemetry_callback(void *param, void *config)
579 {
580  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
581  bool np_nic_telemetry = *((bool *)param);
582 
583  if (user_set_app) {
584  PRINT_ERROR("Error: Can not set multiple runtime application.\n");
586  }
587 
588  if (np_nic_telemetry) {
589  pcc_cfg->app = pcc_np_nic_telemetry_app;
590  pcc_cfg->role = PCC_ROLE_NP;
591  }
592  user_set_app = true;
593  PRINT_INFO("Info: Set DOCA PCC NP NIC Telemetry application\n");
594 
595  return DOCA_SUCCESS;
596 }
597 
598 /*
599  * ARGP Callback - Handle PCC RP Switch Telemetry parameter
600  *
601  * @param [in]: Input parameter
602  * @config [in/out]: Program configuration context
603  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
604  */
605 static doca_error_t rp_switch_telemetry_callback(void *param, void *config)
606 {
607  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
608  bool rp_switch_telemetry = *((bool *)param);
609 
610  if (user_set_app) {
611  PRINT_ERROR("Error: Can not set multiple runtime application.\n");
613  }
614 
615  if (rp_switch_telemetry) {
616  pcc_cfg->app = pcc_rp_switch_telemetry_app;
618  }
619  user_set_app = true;
620  PRINT_INFO("Info: Set DOCA PCC RP Switch Telemetry application\n");
621 
622  return DOCA_SUCCESS;
623 }
624 
625 /*
626  * ARGP Callback - Handle PCC NP Switch Telemetry parameter
627  *
628  * @param [in]: Input parameter
629  * @config [in/out]: Program configuration context
630  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
631  */
632 static doca_error_t np_switch_telemetry_callback(void *param, void *config)
633 {
634  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
635  bool np_switch_telemetry = *((bool *)param);
636 
637  if (user_set_app) {
638  PRINT_ERROR("Error: Can not set multiple runtime application.\n");
640  }
641 
642  if (np_switch_telemetry) {
643  pcc_cfg->app = pcc_np_switch_telemetry_app;
644  pcc_cfg->role = PCC_ROLE_NP;
646  }
647  user_set_app = true;
648  PRINT_INFO("Info: Set DOCA PCC RP Switch Telemetry application\n");
649 
650  return DOCA_SUCCESS;
651 }
652 
653 /*
654  * ARGP Callback - Handle PCC threads list parameter
655  *
656  * @param [in]: Input parameter
657  * @config [in/out]: Program configuration context
658  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
659  */
660 static doca_error_t threads_list_callback(void *param, void *config)
661 {
662  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
663  char *threads_list_string = (char *)param;
664  static const char delim[2] = " ";
665  char *curr_pcc_string;
666  int curr_pcc_check, i, len;
667  uint32_t curr_pcc;
668 
669  len = strnlen(threads_list_string, MAX_ARG_SIZE);
670  if (len == MAX_ARG_SIZE) {
671  PRINT_ERROR("Error: Entered PCC threads list exceeded buffer size: %d\n", MAX_USER_ARG_SIZE);
673  }
674 
675  use_threads_list = true;
676  pcc_cfg->threads_num = 0;
677 
678  /* Check and fill out the PCC threads list */
679  /* Get the first PCC thread number */
680  curr_pcc_string = strtok(threads_list_string, delim);
681  if (curr_pcc_string == NULL) {
682  PRINT_ERROR("Error: Invalid PCC threads list: %s\n", threads_list_string);
684  }
685 
686  /* Walk through rest of the PCC threads numbers */
687  while (curr_pcc_string != NULL) {
688  /* Check if it's a number by checking its digits */
689  len = strnlen(threads_list_string, MAX_ARG_SIZE);
690  for (i = 0; i < len; i++) {
691  if (!isdigit(curr_pcc_string[i])) {
692  PRINT_ERROR("Error: Invalid PCC thread number: %s\n", curr_pcc_string);
694  }
695  }
696 
697  /* Convert to integer to check if it is non-negative */
698  curr_pcc_check = (int)atoi(curr_pcc_string);
699  if (curr_pcc_check < 0) {
700  PRINT_ERROR("Error: Invalid PCC thread number %d. PCC threads numbers must be non-negative\n",
701  curr_pcc_check);
703  }
704 
705  curr_pcc = (uint32_t)atoi(curr_pcc_string);
706  pcc_cfg->threads_list[pcc_cfg->threads_num++] = curr_pcc;
707  curr_pcc_string = strtok(NULL, delim);
708  }
709 
710  return DOCA_SUCCESS;
711 }
712 
713 /*
714  * ARGP Callback - Handle PCC wait time parameter
715  *
716  * @param [in]: Input parameter
717  * @config [in/out]: Program configuration context
718  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
719  */
720 static doca_error_t wait_time_callback(void *param, void *config)
721 {
722  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
723  int wait_time = *((int *)param);
724 
725  /* Wait time must be either positive or infinity (meaning -1 )*/
726  if (wait_time == 0) {
727  PRINT_ERROR(
728  "Error: Entered wait time can't be zero. Must be either positive or infinity (meaning negative value)\n");
730  }
731 
732  pcc_cfg->wait_time = wait_time;
733 
734  return DOCA_SUCCESS;
735 }
736 
737 /*
738  * ARGP Callback - Handle PCC remote SW handler parameter
739  *
740  * @param [in]: Input parameter
741  * @config [in/out]: Program configuration context
742  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
743  */
744 static doca_error_t ccmad_remote_sw_handler_callback(void *param, void *config)
745 {
746  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
747 
748  pcc_cfg->remote_sw_handler = *((bool *)param);
749 
750  return DOCA_SUCCESS;
751 }
752 
753 /*
754  * ARGP Callback - Handle PCC hop limit parameter
755  *
756  * @param [in]: Input parameter
757  * @config [in/out]: Program configuration context
758  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
759  */
760 static doca_error_t ifa2_hop_limit_callback(void *param, void *config)
761 {
762  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
763 
764  pcc_cfg->hop_limit = *((uint8_t *)param);
765 
766  return DOCA_SUCCESS;
767 }
768 
769 /*
770  * ARGP Callback - Handle PCC gns parameter
771  *
772  * @param [in]: Input parameter
773  * @config [in/out]: Program configuration context
774  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
775  */
776 static doca_error_t ifa2_gns_callback(void *param, void *config)
777 {
778  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
779 
780  pcc_cfg->gns = *((uint8_t *)param);
781 
782  return DOCA_SUCCESS;
783 }
784 
785 /*
786  * ARGP Callback - Handle PCC gns ignore mask parameter
787  *
788  * @param [in]: Input parameter
789  * @config [in/out]: Program configuration context
790  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
791  */
792 static doca_error_t ifa2_gns_ignore_mask_callback(void *param, void *config)
793 {
794  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
795 
796  pcc_cfg->gns_ignore_mask = *((uint8_t *)param);
797 
798  return DOCA_SUCCESS;
799 }
800 
801 /*
802  * ARGP Callback - Handle PCC gns ignore value parameter
803  *
804  * @param [in]: Input parameter
805  * @config [in/out]: Program configuration context
806  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
807  */
808 static doca_error_t ifa2_gns_ignore_value_callback(void *param, void *config)
809 {
810  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
811 
812  pcc_cfg->gns_ignore_value = *((uint8_t *)param);
813 
814  return DOCA_SUCCESS;
815 }
816 
817 /*
818  * ARGP Callback - Handle PCC device coredump file parameter
819  *
820  * @param [in]: Input parameter
821  * @config [in/out]: Program configuration context
822  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
823  */
824 static doca_error_t coredump_file_callback(void *param, void *config)
825 {
826  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
827  const char *path = (char *)param;
828 
829  int path_len = strnlen(path, MAX_ARG_SIZE);
830  if (path_len == MAX_ARG_SIZE) {
831  PRINT_ERROR("Entered path exceeded buffer size: %d\n", MAX_USER_ARG_SIZE);
833  }
834 
835  /* The string will be '\0' terminated due to the strnlen check above */
836  strncpy(pcc_cfg->coredump_file, path, path_len + 1);
837 
838  return DOCA_SUCCESS;
839 }
840 
841 /*
842  * ARGP Callback - Handles DPA resources file path parameter
843  *
844  * @param [in]: Input parameter
845  * @config [in/out]: Program configuration context
846  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
847  */
848 static doca_error_t dpa_resources_file_callback(void *param, void *config)
849 {
850  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
851  const char *path = (char *)param;
852 
853  int path_len = strnlen(path, MAX_ARG_SIZE);
854  if (path_len == MAX_ARG_SIZE) {
855  PRINT_ERROR("Error: Entered path exceeded buffer size: %d\n", MAX_USER_ARG_SIZE);
857  }
858 
859  strncpy(pcc_cfg->dpa_resources_file, path, path_len + 1);
860 
861  /* Check if the DPA resources file exists */
862  if (path_len > 0) {
863  FILE *file = fopen(path, "r");
864  if (file == NULL) {
865  PRINT_ERROR("Error: DPA resources file '%s' does not exist or cannot be accessed\n", path);
866  return DOCA_ERROR_NOT_FOUND;
867  }
868  fclose(file);
869  use_dpa_resources = true;
870  }
871 
872  return DOCA_SUCCESS;
873 }
874 
875 /*
876  * ARGP Callback - Handles DPA application key parameter
877  *
878  * @param [in]: Input parameter
879  * @config [in/out]: Program configuration context
880  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
881  */
882 static doca_error_t dpa_application_key_callback(void *param, void *config)
883 {
884  struct pcc_config *pcc_cfg = (struct pcc_config *)config;
885  const char *app_key = (char *)param;
886 
887  int dpa_app_key_len = strnlen(app_key, MAX_ARG_SIZE);
888  if (dpa_app_key_len == MAX_ARG_SIZE) {
889  PRINT_ERROR("Entered path exceeded buffer size: %d\n", MAX_USER_ARG_SIZE);
891  }
892 
893  strncpy(pcc_cfg->dpa_application_key, app_key, dpa_app_key_len + 1);
894 
895  return DOCA_SUCCESS;
896 }
897 
899 {
900  struct doca_argp_param *device_param;
901  struct doca_argp_param *np_nic_telemetry_param;
902  struct doca_argp_param *rp_switch_telemetry_param;
903  struct doca_argp_param *np_switch_telemetry_param;
904  struct doca_argp_param *threads_list_param;
905  struct doca_argp_param *wait_time_param;
906  struct doca_argp_param *remote_sw_handler_param;
907  struct doca_argp_param *hop_limit_param;
908  struct doca_argp_param *gns_param;
909  struct doca_argp_param *gns_ignore_mask_param;
910  struct doca_argp_param *gns_ignore_value_param;
911  struct doca_argp_param *coredump_file_param;
912  struct doca_argp_param *dpa_resources_file;
913  struct doca_argp_param *dpa_application_key;
914 
915  /* Create and register DOCA device name parameter */
916  doca_error_t result = doca_argp_param_create(&device_param);
917  if (result != DOCA_SUCCESS) {
918  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
919  return result;
920  }
921  doca_argp_param_set_short_name(device_param, "d");
922  doca_argp_param_set_long_name(device_param, "device");
923  doca_argp_param_set_arguments(device_param, "<IB device names>");
924  doca_argp_param_set_description(device_param, "IB device name that supports PCC (mandatory).");
927  doca_argp_param_set_mandatory(device_param);
928  result = doca_argp_register_param(device_param);
929  if (result != DOCA_SUCCESS) {
930  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
931  return result;
932  }
933 
934  /* Create and register PCC NP NIC Telemetry parameter */
935  result = doca_argp_param_create(&np_nic_telemetry_param);
936  if (result != DOCA_SUCCESS) {
937  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
938  return result;
939  }
940  doca_argp_param_set_short_name(np_nic_telemetry_param, "np-nt");
941  doca_argp_param_set_long_name(np_nic_telemetry_param, "np-nic-telemetry");
942  doca_argp_param_set_arguments(np_nic_telemetry_param, "<PCC Notification Point NIC Telemetry>");
944  np_nic_telemetry_param,
945  "Flag to indicate running as a Notification Point NIC Telemetry (optional). The application will generate CCMAD probe packets. By default the flag is set to false.");
947  doca_argp_param_set_type(np_nic_telemetry_param, DOCA_ARGP_TYPE_BOOLEAN);
948  result = doca_argp_register_param(np_nic_telemetry_param);
949  if (result != DOCA_SUCCESS) {
950  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
951  return result;
952  }
953 
954  /* Create and register PCC RP Switch Telemetry parameter */
955  result = doca_argp_param_create(&rp_switch_telemetry_param);
956  if (result != DOCA_SUCCESS) {
957  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
958  return result;
959  }
960  doca_argp_param_set_short_name(rp_switch_telemetry_param, "rp-st");
961  doca_argp_param_set_long_name(rp_switch_telemetry_param, "rp-switch-telemetry");
962  doca_argp_param_set_arguments(rp_switch_telemetry_param, "<PCC Reaction Point Switch Telemetry>");
964  rp_switch_telemetry_param,
965  "Flag to indicate running as a Reaction Point Switch Telemetry (optional). The application will generate IFA2 probe packets. By default the flag is set to false.");
967  doca_argp_param_set_type(rp_switch_telemetry_param, DOCA_ARGP_TYPE_BOOLEAN);
968  result = doca_argp_register_param(rp_switch_telemetry_param);
969  if (result != DOCA_SUCCESS) {
970  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
971  return result;
972  }
973 
974  /* Create and register PCC NP Switch Telemetry parameter */
975  result = doca_argp_param_create(&np_switch_telemetry_param);
976  if (result != DOCA_SUCCESS) {
977  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
978  return result;
979  }
980  doca_argp_param_set_short_name(np_switch_telemetry_param, "np-st");
981  doca_argp_param_set_long_name(np_switch_telemetry_param, "np-switch-telemetry");
982  doca_argp_param_set_arguments(np_switch_telemetry_param, "<PCC Notification Point Switch Telemetry>");
984  np_switch_telemetry_param,
985  "Flag to indicate running as a Notification Point Switch Telemetry (optional). The application will generate IFA2 probe packets. By default the flag is set to false.");
987  doca_argp_param_set_type(np_switch_telemetry_param, DOCA_ARGP_TYPE_BOOLEAN);
988  result = doca_argp_register_param(np_switch_telemetry_param);
989  if (result != DOCA_SUCCESS) {
990  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
991  return result;
992  }
993 
994  /* Create and register PCC threads list parameter */
995  result = doca_argp_param_create(&threads_list_param);
996  if (result != DOCA_SUCCESS) {
997  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
998  return result;
999  }
1000  doca_argp_param_set_short_name(threads_list_param, "t");
1001  doca_argp_param_set_long_name(threads_list_param, "threads");
1002  doca_argp_param_set_arguments(threads_list_param, "<PCC threads list>");
1004  threads_list_param,
1005  "A list of the PCC threads numbers to be chosen for the DOCA PCC context to run on (optional). Must be provided as a string, such that the number are separated by a space.");
1007  doca_argp_param_set_type(threads_list_param, DOCA_ARGP_TYPE_STRING);
1008  result = doca_argp_register_param(threads_list_param);
1009  if (result != DOCA_SUCCESS) {
1010  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
1011  return result;
1012  }
1013 
1014  /* Create and register PCC wait time parameter */
1015  result = doca_argp_param_create(&wait_time_param);
1016  if (result != DOCA_SUCCESS) {
1017  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
1018  return result;
1019  }
1020  doca_argp_param_set_short_name(wait_time_param, "w");
1021  doca_argp_param_set_long_name(wait_time_param, "wait-time");
1022  doca_argp_param_set_arguments(wait_time_param, "<PCC wait time>");
1024  wait_time_param,
1025  "The duration of the DOCA PCC wait (optional), can provide negative values which means infinity. If not provided then -1 will be chosen.");
1027  doca_argp_param_set_type(wait_time_param, DOCA_ARGP_TYPE_INT);
1028  result = doca_argp_register_param(wait_time_param);
1029  if (result != DOCA_SUCCESS) {
1030  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
1031  return result;
1032  }
1033 
1034  /* Create and register PCC remote SW handler */
1035  result = doca_argp_param_create(&remote_sw_handler_param);
1036  if (result != DOCA_SUCCESS) {
1037  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
1038  return result;
1039  }
1040  doca_argp_param_set_short_name(remote_sw_handler_param, "r-handler");
1041  doca_argp_param_set_long_name(remote_sw_handler_param, "remote-sw-handler");
1042  doca_argp_param_set_arguments(remote_sw_handler_param, "<CCMAD remote SW handler>");
1044  remote_sw_handler_param,
1045  "CCMAD remote SW handler flag (optional). If not provided then false will be chosen.");
1047  doca_argp_param_set_type(remote_sw_handler_param, DOCA_ARGP_TYPE_BOOLEAN);
1048  result = doca_argp_register_param(remote_sw_handler_param);
1049  if (result != DOCA_SUCCESS) {
1050  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
1051  return result;
1052  }
1053 
1054  /* Create and register PCC hop limit parameter */
1055  result = doca_argp_param_create(&hop_limit_param);
1056  if (result != DOCA_SUCCESS) {
1057  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
1058  return result;
1059  }
1060  doca_argp_param_set_short_name(hop_limit_param, "hl");
1061  doca_argp_param_set_long_name(hop_limit_param, "hop-limit");
1062  doca_argp_param_set_arguments(hop_limit_param, "<IFA2 hop limit>");
1064  hop_limit_param,
1065  "The IFA2 probe packet hop limit (optional). If not provided then 0XFE will be chosen.");
1067  doca_argp_param_set_type(hop_limit_param, DOCA_ARGP_TYPE_INT);
1068  result = doca_argp_register_param(hop_limit_param);
1069  if (result != DOCA_SUCCESS) {
1070  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
1071  return result;
1072  }
1073 
1074  /* Create and register PCC gns parameter */
1075  result = doca_argp_param_create(&gns_param);
1076  if (result != DOCA_SUCCESS) {
1077  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
1078  return result;
1079  }
1080  doca_argp_param_set_short_name(gns_param, "gns");
1081  doca_argp_param_set_long_name(gns_param, "global-namespace");
1082  doca_argp_param_set_arguments(gns_param, "<IFA2 global namespace>");
1084  gns_param,
1085  "The IFA2 probe packet global namespace (optional). If not provided then 0XF will be chosen.");
1088  result = doca_argp_register_param(gns_param);
1089  if (result != DOCA_SUCCESS) {
1090  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
1091  return result;
1092  }
1093 
1094  /* Create and register PCC gns ignore mask parameter */
1095  result = doca_argp_param_create(&gns_ignore_mask_param);
1096  if (result != DOCA_SUCCESS) {
1097  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
1098  return result;
1099  }
1100  doca_argp_param_set_short_name(gns_ignore_mask_param, "gns-ignore-mask");
1101  doca_argp_param_set_long_name(gns_ignore_mask_param, "global-namespace-ignore-mask");
1102  doca_argp_param_set_arguments(gns_ignore_mask_param, "<IFA2 global namespace ignore mask>");
1104  gns_ignore_mask_param,
1105  "The IFA2 probe packet global namespace ignore mask (optional). If not provided then 0 will be chosen.");
1107  doca_argp_param_set_type(gns_ignore_mask_param, DOCA_ARGP_TYPE_INT);
1108  result = doca_argp_register_param(gns_ignore_mask_param);
1109  if (result != DOCA_SUCCESS) {
1110  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
1111  return result;
1112  }
1113 
1114  /* Create and register PCC gns ignore value parameter */
1115  result = doca_argp_param_create(&gns_ignore_value_param);
1116  if (result != DOCA_SUCCESS) {
1117  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
1118  return result;
1119  }
1120  doca_argp_param_set_short_name(gns_ignore_value_param, "gns-ignore-val");
1121  doca_argp_param_set_long_name(gns_ignore_value_param, "global-namespace-ignore-value");
1122  doca_argp_param_set_arguments(gns_ignore_value_param, "<IFA2 global namespace ignore value>");
1124  gns_ignore_value_param,
1125  "The IFA2 probe packet global namespace ignore value (optional). If not provided then 0 will be chosen.");
1127  doca_argp_param_set_type(gns_ignore_value_param, DOCA_ARGP_TYPE_INT);
1128  result = doca_argp_register_param(gns_ignore_value_param);
1129  if (result != DOCA_SUCCESS) {
1130  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
1131  return result;
1132  }
1133 
1134  /* Create and register PCC device coredump file parameter */
1135  result = doca_argp_param_create(&coredump_file_param);
1136  if (result != DOCA_SUCCESS) {
1137  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
1138  return result;
1139  }
1140  doca_argp_param_set_short_name(coredump_file_param, "f");
1141  doca_argp_param_set_long_name(coredump_file_param, "coredump-file");
1142  doca_argp_param_set_arguments(coredump_file_param, "<PCC coredump file>");
1144  coredump_file_param,
1145  "A pathname to the file to write coredump data in case of unrecoverable error on the device (optional). Must be provided as a string.");
1147  doca_argp_param_set_type(coredump_file_param, DOCA_ARGP_TYPE_STRING);
1148  result = doca_argp_register_param(coredump_file_param);
1149  if (result != DOCA_SUCCESS) {
1150  PRINT_ERROR("Error: Failed to register program param: %s\n", doca_error_get_descr(result));
1151  return result;
1152  }
1153 
1154  /* Create and register DPA application name parameter */
1155  result = doca_argp_param_create(&dpa_application_key);
1156  if (result != DOCA_SUCCESS) {
1157  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
1158  return result;
1159  }
1160  doca_argp_param_set_long_name(dpa_application_key, "dpa-app-key");
1161  doca_argp_param_set_arguments(dpa_application_key, "<DPA application key>");
1162  doca_argp_param_set_description(dpa_application_key, "Application key in specified DPA resources .yaml file");
1164  doca_argp_param_set_type(dpa_application_key, DOCA_ARGP_TYPE_STRING);
1165  result = doca_argp_register_param(dpa_application_key);
1166  if (result != DOCA_SUCCESS) {
1167  PRINT_ERROR("Error: failed to register program param: %s\n", doca_error_get_descr(result));
1168  return result;
1169  }
1170 
1171  /* Create and register DPA resources file parameter */
1172  result = doca_argp_param_create(&dpa_resources_file);
1173  if (result != DOCA_SUCCESS) {
1174  PRINT_ERROR("Error: Failed to create ARGP param: %s\n", doca_error_get_descr(result));
1175  return result;
1176  }
1177  doca_argp_param_set_long_name(dpa_resources_file, "dpa-resources");
1178  doca_argp_param_set_arguments(dpa_resources_file, "<DPA resources file>");
1179  doca_argp_param_set_description(dpa_resources_file, "Path to a DPA resources .yaml file");
1181  doca_argp_param_set_type(dpa_resources_file, DOCA_ARGP_TYPE_STRING);
1182  result = doca_argp_register_param(dpa_resources_file);
1183  if (result != DOCA_SUCCESS) {
1184  PRINT_ERROR("Error: failed to register program param: %s\n", doca_error_get_descr(result));
1185  return result;
1186  }
1187 
1188  return DOCA_SUCCESS;
1189 }
#define NULL
Definition: __stddef_null.h:26
__SIZE_TYPE__ size_t
char path[MAX_PATH_LEN+1]
int32_t result
#define MAX_ARG_SIZE
Definition: dma_copy_core.h:39
uint64_t len
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_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
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_INITIALIZATION
Definition: doca_error.h:46
@ DOCA_ERROR_UNEXPECTED
Definition: doca_error.h:60
@ 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
DOCA_STABLE doca_error_t doca_pcc_create(struct doca_dev *doca_dev, struct doca_pcc **pcc)
Create programmable CC Reaction Point context.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_set_ifa1_probe_packet_format(struct doca_pcc *pcc, uint32_t probe_format_slot)
Set ifa1 probe packet format for the pcc process.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_mailbox_send(struct doca_pcc *pcc, uint32_t request_size, uint32_t *response_size, uint32_t *cb_ret_val)
Send mailbox request data to device.
DOCA_STABLE doca_error_t doca_pcc_set_trace_message(struct doca_pcc *pcc, char **trace_message)
Set message for trace printing.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_rp_set_ccmad_remote_sw_handler(struct doca_pcc *pcc, uint32_t probe_format_slot, bool sw_handler)
Set sw remote handler for CCMAD probe type.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_mailbox_get_request_buffer(struct doca_pcc *pcc, void **request_buffer)
Get mailbox request data buffer address to fill and transfer to device.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_set_mailbox(struct doca_pcc *pcc, uint32_t max_request_size, uint32_t max_response_size)
Set mailbox attributes to obtain and pass data from and to the device.
DOCA_STABLE doca_error_t doca_pcc_destroy(struct doca_pcc *pcc)
Destroy a DOCA PCC context.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_set_ccmad_probe_packet_format(struct doca_pcc *pcc, uint32_t probe_format_slot)
Set CCMAD probe packet format for the pcc process.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_set_ifa2_probe_packet_format(struct doca_pcc *pcc, uint32_t probe_format_slot)
Set ifa2 probe packet format for the pcc process.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_rp_set_ifa2_hop_limit(struct doca_pcc *pcc, uint32_t probe_format_slot, uint8_t hop_limit)
Set hop_limit field in the metadata header for IFA2 packets.
DOCA_STABLE doca_error_t doca_pcc_set_app(struct doca_pcc *pcc, struct doca_pcc_app *app)
Set program app for PCC context.
DOCA_STABLE doca_error_t doca_pcc_get_min_num_threads(struct doca_pcc *pcc, uint32_t *min_num_threads)
Get a minimal required number of threads handling CC events.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_np_create(struct doca_dev *doca_dev, struct doca_pcc **pcc)
Create programmable CC Notification Point context.
DOCA_STABLE doca_error_t doca_devinfo_get_is_pcc_supported(const struct doca_devinfo *devinfo)
Get whether the DOCA device supports PCC reaction point.
DOCA_STABLE doca_error_t doca_pcc_get_max_num_threads(struct doca_pcc *pcc, uint32_t *max_num_threads)
Get a maximal allowed number of threads handling CC events.
DOCA_STABLE doca_error_t doca_pcc_set_thread_affinity(struct doca_pcc *pcc, uint32_t num_threads, uint32_t *affinity_configs)
Configure affinity of threads handling CC events.
DOCA_STABLE doca_error_t doca_pcc_set_print_buffer_size(struct doca_pcc *pcc, size_t buffer_size)
Set buffer size of DPA print message.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_rp_set_ifa2_gns(struct doca_pcc *pcc, uint32_t probe_format_slot, uint8_t gns)
Set GNS value for IFA2 packets.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_np_cap_is_supported(const struct doca_devinfo *devinfo)
Get whether the DOCA device supports PCC notification point.
DOCA_STABLE doca_error_t doca_pcc_set_dev_coredump_file(struct doca_pcc *pcc, const char *file_name)
Set output file to write crash data and coredump in case of unrecoverable error on the device.
DOCA_EXPERIMENTAL doca_error_t doca_pcc_np_set_ifa2_gns_ignore(struct doca_pcc *pcc, uint32_t probe_format_slot, uint8_t ignore_mask, uint8_t ignore_value)
Set GNS ignore for IFA2 packets.
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
const uint32_t default_pcc_rp_threads_list[PCC_RP_THREADS_NUM_DEFAULT_VALUE]
Definition: pcc_core.c:57
static doca_error_t open_pcc_device(const char *device_name, pcc_role_t role, struct doca_dev **doca_device)
Definition: pcc_core.c:189
static doca_error_t rp_switch_telemetry_callback(void *param, void *config)
Definition: pcc_core.c:605
doca_error_t pcc_init(struct pcc_config *cfg, struct pcc_resources *resources)
Definition: pcc_core.c:246
static doca_error_t np_switch_telemetry_callback(void *param, void *config)
Definition: pcc_core.c:632
static doca_error_t ifa2_hop_limit_callback(void *param, void *config)
Definition: pcc_core.c:760
static doca_error_t coredump_file_callback(void *param, void *config)
Definition: pcc_core.c:824
static doca_error_t device_name_callback(void *param, void *config)
Definition: pcc_core.c:549
static bool use_threads_list
Definition: pcc_core.c:68
static doca_error_t dpa_application_key_callback(void *param, void *config)
Definition: pcc_core.c:882
static doca_error_t dpa_resources_file_callback(void *param, void *config)
Definition: pcc_core.c:848
static doca_error_t ccmad_remote_sw_handler_callback(void *param, void *config)
Definition: pcc_core.c:744
static doca_error_t threads_list_callback(void *param, void *config)
Definition: pcc_core.c:660
const uint32_t default_pcc_np_threads_list[PCC_NP_THREADS_NUM_DEFAULT_VALUE]
Definition: pcc_core.c:62
static doca_error_t np_nic_telemetry_callback(void *param, void *config)
Definition: pcc_core.c:578
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: pcc_core.c:122
static doca_error_t ifa2_gns_callback(void *param, void *config)
Definition: pcc_core.c:776
static doca_error_t ifa2_gns_ignore_mask_callback(void *param, void *config)
Definition: pcc_core.c:792
static doca_error_t ifa2_gns_ignore_value_callback(void *param, void *config)
Definition: pcc_core.c:808
static bool pcc_device_exists_check(const char *device_name)
Definition: pcc_core.c:148
static doca_error_t get_file_size(const char *path, size_t *file_size)
Get the size of a file.
Definition: pcc_core.c:87
static doca_error_t wait_time_callback(void *param, void *config)
Definition: pcc_core.c:720
doca_error_t register_pcc_params(void)
Definition: pcc_core.c:898
static bool user_set_app
Definition: pcc_core.c:78
static bool use_dpa_resources
Definition: pcc_core.c:73
doca_error_t pcc_mailbox_send(struct pcc_config *cfg, struct pcc_resources *resources)
Definition: pcc_core.c:491
doca_error_t pcc_destroy(struct pcc_resources *resources)
Definition: pcc_core.c:525
static char * trace_message_formats[]
Definition: pcc_core.c:47
#define PCC_MAILBOX_RESPONSE_SIZE
Definition: pcc_core.h:44
struct doca_pcc_app * pcc_np_nic_telemetry_app
pcc_role_t
intelemetry request packet format
Definition: pcc_core.h:124
@ PCC_ROLE_NP
Definition: pcc_core.h:126
@ PCC_ROLE_RP
Definition: pcc_core.h:125
#define PCC_PRINT_BUFFER_SIZE_DEFAULT_VALUE
Definition: pcc_core.h:42
#define PCC_RP_THREADS_NUM_DEFAULT_VALUE
Definition: pcc_core.h:33
struct doca_pcc_app * pcc_rp_switch_telemetry_app
struct doca_pcc_app * pcc_np_switch_telemetry_app
#define PCC_NP_THREADS_NUM_DEFAULT_VALUE
Definition: pcc_core.h:35
@ PCC_DEV_PROBE_PACKET_IFA1
Definition: pcc_core.h:117
@ PCC_DEV_PROBE_PACKET_IFA2
Definition: pcc_core.h:118
@ PCC_DEV_PROBE_PACKET_CCMAD
Definition: pcc_core.h:116
#define PRINT_DEBUG(...)
Definition: pcc_core.h:86
#define MAX_USER_ARG_SIZE
Definition: pcc_core.h:45
#define PRINT_ERROR(...)
Definition: pcc_core.h:68
#define PRINT_INFO(...)
Definition: pcc_core.h:80
#define PCC_MAILBOX_REQUEST_SIZE
Definition: pcc_core.h:43
uint8_t gns
Definition: pcc_core.h:139
char coredump_file[MAX_ARG_SIZE]
Definition: pcc_core.h:142
int wait_time
Definition: pcc_core.h:135
uint8_t gns_ignore_value
Definition: pcc_core.h:140
uint32_t threads_list[MAX_ARG_SIZE]
Definition: pcc_core.h:134
struct doca_pcc_app * app
Definition: pcc_core.h:132
uint32_t threads_num
Definition: pcc_core.h:133
pcc_role_t role
Definition: pcc_core.h:131
char dpa_application_key[MAX_ARG_SIZE]
Definition: pcc_core.h:144
char device_name[DOCA_DEVINFO_IBDEV_NAME_SIZE]
Definition: pcc_core.h:130
uint8_t hop_limit
Definition: pcc_core.h:138
uint8_t gns_ignore_mask
Definition: pcc_core.h:141
char dpa_resources_file[MAX_ARG_SIZE]
Definition: pcc_core.h:143
pcc_dev_probe_packet_type_t probe_packet_format
Definition: pcc_core.h:136
bool remote_sw_handler
Definition: pcc_core.h:137
struct doca_dev * doca_device
Definition: rdma_common.h:81