NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
gpunetio_simple_send_sample.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <arpa/inet.h>
27 #include <doca_flow.h>
28 #include <doca_log.h>
29 
30 #include "gpunetio_common.h"
31 
32 #include "common.h"
33 
34 #define FLOW_NB_COUNTERS 524228 /* 1024 x 512 */
35 #define MBUF_NUM 8192
36 #define MBUF_SIZE 2048
37 #define CPU_TO_BE16(val) __builtin_bswap16(val)
38 
39 struct doca_flow_port *df_port;
41 
42 DOCA_LOG_REGISTER(SIMPLE_SEND : SAMPLE);
43 
44 /*
45  * Signal handler to quit application gracefully
46  *
47  * @signum [in]: signal received
48  */
49 static void signal_handler(int signum)
50 {
51  if (signum == SIGINT || signum == SIGTERM) {
52  DOCA_LOG_INFO("Signal %d received, preparing to exit!", signum);
53  DOCA_GPUNETIO_VOLATILE(force_quit) = true;
54  }
55 }
56 
57 /*
58  * Initialize a DOCA network device.
59  *
60  * @nic_pcie_addr [in]: Network card PCIe address
61  * @ddev [out]: DOCA device
62  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
63  */
64 static doca_error_t init_doca_device(char *nic_pcie_addr, struct doca_dev **ddev)
65 {
67 
68  if (nic_pcie_addr == NULL || ddev == NULL)
70 
71  if (strnlen(nic_pcie_addr, DOCA_DEVINFO_PCI_ADDR_SIZE) >= DOCA_DEVINFO_PCI_ADDR_SIZE)
73 
74  result = open_doca_device_with_pci(nic_pcie_addr, NULL, ddev);
75  if (result != DOCA_SUCCESS) {
76  DOCA_LOG_ERR("Failed to open NIC device based on PCI address");
77  return result;
78  }
79 
80  return DOCA_SUCCESS;
81 }
82 
83 /*
84  * Init doca flow.
85  *
86  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
87  */
89 {
90  struct doca_flow_cfg *queue_flow_cfg;
92 
93  /* Initialize doca flow framework */
94  result = doca_flow_cfg_create(&queue_flow_cfg);
95  if (result != DOCA_SUCCESS) {
96  DOCA_LOG_ERR("Failed to create doca_flow_cfg: %s", doca_error_get_descr(result));
97  return result;
98  }
99 
100  result = doca_flow_cfg_set_pipe_queues(queue_flow_cfg, 1);
101  if (result != DOCA_SUCCESS) {
102  DOCA_LOG_ERR("Failed to set doca_flow_cfg pipe_queues: %s", doca_error_get_descr(result));
103  doca_flow_cfg_destroy(queue_flow_cfg);
104  return result;
105  }
106 
107  result = doca_flow_cfg_set_mode_args(queue_flow_cfg, "vnf,isolated");
108  if (result != DOCA_SUCCESS) {
109  DOCA_LOG_ERR("Failed to set doca_flow_cfg mode_args: %s", doca_error_get_descr(result));
110  doca_flow_cfg_destroy(queue_flow_cfg);
111  return result;
112  }
113 
115  if (result != DOCA_SUCCESS) {
116  DOCA_LOG_ERR("Failed to set doca_flow_cfg nr_counters: %s", doca_error_get_descr(result));
117  doca_flow_cfg_destroy(queue_flow_cfg);
118  return result;
119  }
120 
121  result = doca_flow_init(queue_flow_cfg);
122  if (result != DOCA_SUCCESS) {
123  DOCA_LOG_ERR("Failed to init doca flow with: %s", doca_error_get_descr(result));
124  doca_flow_cfg_destroy(queue_flow_cfg);
125  return result;
126  }
127  doca_flow_cfg_destroy(queue_flow_cfg);
128 
129  return DOCA_SUCCESS;
130 }
131 
132 /*
133  * Start doca flow.
134  *
135  * @dev [in]: DOCA device
136  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
137  */
138 static doca_error_t start_doca_flow(struct doca_dev *dev)
139 {
140  struct doca_flow_port_cfg *port_cfg;
142 
143  /* Start doca flow port */
144  result = doca_flow_port_cfg_create(&port_cfg);
145  if (result != DOCA_SUCCESS) {
146  DOCA_LOG_ERR("Failed to create doca_flow_port_cfg: %s", doca_error_get_descr(result));
147  return result;
148  }
149 
150  result = doca_flow_port_cfg_set_port_id(port_cfg, 0);
151  if (result != DOCA_SUCCESS) {
152  DOCA_LOG_ERR("Failed to set doca_flow_port_cfg port ID: %s", doca_error_get_descr(result));
153  doca_flow_port_cfg_destroy(port_cfg);
154  return result;
155  }
156 
157  result = doca_flow_port_cfg_set_dev(port_cfg, dev);
158  if (result != DOCA_SUCCESS) {
159  DOCA_LOG_ERR("Failed to set doca_flow_port_cfg dev: %s", doca_error_get_descr(result));
160  doca_flow_port_cfg_destroy(port_cfg);
161  return result;
162  }
163 
164  result = doca_flow_port_start(port_cfg, &df_port);
165  if (result != DOCA_SUCCESS) {
166  DOCA_LOG_ERR("Failed to start doca flow port with: %s", doca_error_get_descr(result));
167  doca_flow_port_cfg_destroy(port_cfg);
168  return result;
169  }
170 
171  return DOCA_SUCCESS;
172 }
173 
174 /*
175  * Destroy DOCA Ethernet Tx queue for GPU
176  *
177  * @txq [in]: DOCA Eth Rx queue handler
178  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
179  */
180 static doca_error_t destroy_txq(struct txq_queue *txq)
181 {
183 
184  if (txq == NULL) {
185  DOCA_LOG_ERR("Can't destroy UDP queues, invalid input");
187  }
188 
189  DOCA_LOG_INFO("Destroying Txq");
190 
191  if (txq->eth_txq_ctx != NULL) {
193  if (result != DOCA_SUCCESS) {
194  DOCA_LOG_ERR("Failed doca_ctx_stop: %s", doca_error_get_descr(result));
195  return DOCA_ERROR_BAD_STATE;
196  }
197  }
198 
199  if (txq->gpu_pkt_addr != NULL) {
200  result = doca_gpu_mem_free(txq->gpu_dev, txq->gpu_pkt_addr);
201  if (result != DOCA_SUCCESS) {
202  DOCA_LOG_ERR("Failed to free gpu memory: %s", doca_error_get_descr(result));
203  return DOCA_ERROR_BAD_STATE;
204  }
205  }
206 
207  if (txq->eth_txq_cpu != NULL) {
209  if (result != DOCA_SUCCESS) {
210  DOCA_LOG_ERR("Failed doca_eth_txq_destroy: %s", doca_error_get_descr(result));
211  return DOCA_ERROR_BAD_STATE;
212  }
213  }
214 
215  if (df_port != NULL) {
217  if (result != DOCA_SUCCESS) {
218  DOCA_LOG_ERR("Failed to stop DOCA flow port, err: %s", doca_error_get_name(result));
219  return DOCA_ERROR_BAD_STATE;
220  }
221  }
222 
223  if (txq->pkt_buff_mmap != NULL) {
225  if (result != DOCA_SUCCESS) {
226  DOCA_LOG_ERR("Failed to destroy mmap: %s", doca_error_get_descr(result));
227  return DOCA_ERROR_BAD_STATE;
228  }
229  }
230 
231  result = doca_dev_close(txq->ddev);
232  if (result != DOCA_SUCCESS) {
233  DOCA_LOG_ERR("Failed to destroy Eth dev: %s", doca_error_get_descr(result));
234  return DOCA_ERROR_BAD_STATE;
235  }
236 
237  return DOCA_SUCCESS;
238 }
239 
240 /*
241  * Create DOCA Ethernet Tx queue for GPU
242  *
243  * @txq [in]: DOCA Eth Tx queue handler
244  * @gpu_dev [in]: DOCA GPUNetIO device
245  * @ddev [in]: DOCA device
246  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
247  */
248 static doca_error_t create_txq(struct txq_queue *txq,
249  struct doca_gpu *gpu_dev,
250  struct doca_dev *ddev,
251  uint32_t pkt_size,
252  uint32_t pkt_num)
253 {
255  cudaError_t res_cuda;
256 
257  uint32_t buffer_size = 0;
258  uint8_t *cpu_pkt_addr;
259 
260  if (txq == NULL || gpu_dev == NULL || ddev == NULL) {
261  DOCA_LOG_ERR("Can't create UDP queues, invalid input");
263  }
264 
265  txq->gpu_dev = gpu_dev;
266  txq->ddev = ddev;
267  txq->port = df_port;
268  txq->pkt_size = pkt_size;
269  txq->cuda_threads = pkt_num;
270  txq->inflight_sends = MAX_SQ_DESCR_NUM / 2;
271  buffer_size = txq->cuda_threads * pkt_size;
272 
273  DOCA_LOG_INFO("Creating Sample Eth Txq");
274 
276  if (result != DOCA_SUCCESS) {
277  DOCA_LOG_ERR("Failed doca_eth_txq_create: %s", doca_error_get_descr(result));
278  return DOCA_ERROR_BAD_STATE;
279  }
280 
282  if (result != DOCA_SUCCESS) {
283  DOCA_LOG_ERR("Failed to set eth_txq l3 offloads: %s", doca_error_get_descr(result));
284  goto exit_error;
285  }
286 
288  if (result != DOCA_SUCCESS) {
289  DOCA_LOG_ERR("Failed to set eth_txq l3 offloads: %s", doca_error_get_descr(result));
290  goto exit_error;
291  }
292 
293  /* Application can check Txq completions on the GPU. By default, it can be done by CPU. */
295  if (result != DOCA_SUCCESS) {
296  DOCA_LOG_ERR("Failed doca_eth_txq_gpu_set_completion_on_gpu: %s", doca_error_get_descr(result));
297  goto exit_error;
298  }
299 
301  if (txq->eth_txq_ctx == NULL) {
302  DOCA_LOG_ERR("Failed doca_eth_txq_as_doca_ctx: %s", doca_error_get_descr(result));
303  goto exit_error;
304  }
305 
307  if (result != DOCA_SUCCESS) {
308  DOCA_LOG_ERR("Failed doca_ctx_set_datapath_on_gpu: %s", doca_error_get_descr(result));
309  goto exit_error;
310  }
311 
313  if (result != DOCA_SUCCESS) {
314  DOCA_LOG_ERR("Failed doca_ctx_start: %s", doca_error_get_descr(result));
315  goto exit_error;
316  }
317 
319  if (result != DOCA_SUCCESS) {
320  DOCA_LOG_ERR("Failed doca_eth_txq_get_gpu_handle: %s", doca_error_get_descr(result));
321  goto exit_error;
322  }
323 
325  if (result != DOCA_SUCCESS) {
326  DOCA_LOG_ERR("Failed to create mmap: %s", doca_error_get_descr(result));
327  goto exit_error;
328  }
329 
331  if (result != DOCA_SUCCESS) {
332  DOCA_LOG_ERR("Failed to add dev to mmap: %s", doca_error_get_descr(result));
333  goto exit_error;
334  }
335 
336  result = doca_gpu_mem_alloc(txq->gpu_dev,
337  buffer_size,
340  &txq->gpu_pkt_addr,
341  NULL);
342  if (result != DOCA_SUCCESS || txq->gpu_pkt_addr == NULL) {
343  DOCA_LOG_ERR("Failed to allocate gpu memory %s", doca_error_get_descr(result));
344  goto exit_error;
345  }
346 
347  cpu_pkt_addr = (uint8_t *)calloc(txq->cuda_threads * pkt_size, sizeof(uint8_t));
348  if (cpu_pkt_addr == NULL) {
349  DOCA_LOG_ERR("Error in tx buf preparation, failed to allocate memory");
350  goto exit_error;
351  }
352 
353  struct ether_hdr *eth;
354 
355  for (uint32_t idx = 0; idx < txq->cuda_threads; idx++) {
356  eth = (struct ether_hdr *)(cpu_pkt_addr + (idx * pkt_size));
357  eth->d_addr_bytes[0] = 0x10;
358  eth->d_addr_bytes[1] = 0x11;
359  eth->d_addr_bytes[2] = 0x12;
360  eth->d_addr_bytes[3] = 0x13;
361  eth->d_addr_bytes[4] = 0x14;
362  eth->d_addr_bytes[5] = 0x15;
363 
364  eth->s_addr_bytes[0] = 0x20;
365  eth->s_addr_bytes[1] = 0x21;
366  eth->s_addr_bytes[2] = 0x22;
367  eth->s_addr_bytes[3] = 0x23;
368  eth->s_addr_bytes[4] = 0x24;
369  eth->s_addr_bytes[5] = 0x25;
370 
371  eth->ether_type = CPU_TO_BE16(0x0800);
372  }
373 
374  res_cuda = cudaMemcpy(txq->gpu_pkt_addr, cpu_pkt_addr, buffer_size, cudaMemcpyDefault);
375  free(cpu_pkt_addr);
376  if (res_cuda != cudaSuccess) {
377  DOCA_LOG_ERR("Function CUDA Memcpy cqe_addr failed with %s", cudaGetErrorString(res_cuda));
378  return DOCA_ERROR_DRIVER;
379  }
380 
381  /* Map GPU memory buffer used to receive packets with DMABuf */
382  result = doca_gpu_dmabuf_fd(txq->gpu_dev, txq->gpu_pkt_addr, buffer_size, &(txq->dmabuf_fd));
383  if (result != DOCA_SUCCESS) {
384  DOCA_LOG_INFO("Mapping receive queue buffer (0x%p size %dB) with nvidia-peermem mode",
385  txq->gpu_pkt_addr,
386  buffer_size);
387 
388  /* If failed, use nvidia-peermem legacy method */
389  result = doca_mmap_set_memrange(txq->pkt_buff_mmap, txq->gpu_pkt_addr, buffer_size);
390  if (result != DOCA_SUCCESS) {
391  DOCA_LOG_ERR("Failed to set memrange for mmap %s", doca_error_get_descr(result));
392  goto exit_error;
393  }
394  } else {
395  DOCA_LOG_INFO("Mapping receive queue buffer (0x%p size %dB dmabuf fd %d) with dmabuf mode",
396  txq->gpu_pkt_addr,
397  buffer_size,
398  txq->dmabuf_fd);
399 
401  txq->dmabuf_fd,
402  txq->gpu_pkt_addr,
403  0,
404  buffer_size);
405  if (result != DOCA_SUCCESS) {
406  DOCA_LOG_ERR("Failed to set dmabuf memrange for mmap %s", doca_error_get_descr(result));
407  goto exit_error;
408  }
409  }
410 
412  if (result != DOCA_SUCCESS) {
413  DOCA_LOG_ERR("Failed to set permissions for mmap %s", doca_error_get_descr(result));
414  goto exit_error;
415  }
416 
418  if (result != DOCA_SUCCESS) {
419  DOCA_LOG_ERR("Failed to start mmap %s", doca_error_get_descr(result));
420  goto exit_error;
421  }
422 
424  if (result != DOCA_SUCCESS) {
425  DOCA_LOG_ERR("Unable to start buf: doca buf_arr internal error");
426  goto exit_error;
427  }
428 
430  if (result != DOCA_SUCCESS) {
431  DOCA_LOG_ERR("Unable to start buf: doca buf_arr internal error");
432  goto exit_error;
433  }
434 
436  if (result != DOCA_SUCCESS) {
437  DOCA_LOG_ERR("Unable to start buf: doca buf_arr internal error");
438  goto exit_error;
439  }
440 
442  if (result != DOCA_SUCCESS) {
443  DOCA_LOG_ERR("Unable to start buf: doca buf_arr internal error");
444  goto exit_error;
445  }
446 
448  if (result != DOCA_SUCCESS) {
449  DOCA_LOG_ERR("Unable to get buff_arr GPU handle: %s", doca_error_get_descr(result));
450  goto exit_error;
451  }
452 
453  return DOCA_SUCCESS;
454 
455 exit_error:
456  destroy_txq(txq);
457  return DOCA_ERROR_BAD_STATE;
458 }
459 
460 /*
461  * Launch GPUNetIO simple receive sample
462  *
463  * @sample_cfg [in]: Sample config parameters
464  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
465  */
467 {
469  struct doca_gpu *gpu_dev = NULL;
470  struct doca_dev *ddev = NULL;
471  struct txq_queue txq = {0};
472  cudaStream_t stream;
473  cudaError_t res_rt = cudaSuccess;
474  uint32_t *cpu_exit_condition;
475  uint32_t *gpu_exit_condition;
476 
477  result = init_doca_device(sample_cfg->nic_pcie_addr, &ddev);
478  if (result != DOCA_SUCCESS) {
479  DOCA_LOG_ERR("Function init_doca_device returned %s", doca_error_get_descr(result));
480  return EXIT_FAILURE;
481  }
482 
484  if (result != DOCA_SUCCESS) {
485  DOCA_LOG_ERR("Function init_doca_flow returned %s", doca_error_get_descr(result));
486  goto exit;
487  }
488 
490  if (result != DOCA_SUCCESS) {
491  DOCA_LOG_ERR("Function start_doca_flow returned %s", doca_error_get_descr(result));
492  goto exit;
493  }
494 
495  /* Gracefully terminate sample if ctrlc */
496  DOCA_GPUNETIO_VOLATILE(force_quit) = false;
497  signal(SIGINT, signal_handler);
498  signal(SIGTERM, signal_handler);
499 
500  result = doca_gpu_create(sample_cfg->gpu_pcie_addr, &gpu_dev);
501  if (result != DOCA_SUCCESS) {
502  DOCA_LOG_ERR("Function doca_gpu_create returned %s", doca_error_get_descr(result));
503  goto exit;
504  }
505 
506  result = create_txq(&txq, gpu_dev, ddev, sample_cfg->pkt_size, sample_cfg->cuda_threads);
507  if (result != DOCA_SUCCESS) {
508  DOCA_LOG_ERR("Function create_txq returned %s", doca_error_get_descr(result));
509  goto exit;
510  }
511 
512  res_rt = cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking);
513  if (res_rt != cudaSuccess) {
514  DOCA_LOG_ERR("Function cudaStreamCreateWithFlags error %d", res_rt);
515  return DOCA_ERROR_DRIVER;
516  }
517 
518  result = doca_gpu_mem_alloc(gpu_dev,
519  sizeof(uint32_t),
522  (void **)&gpu_exit_condition,
523  (void **)&cpu_exit_condition);
524  if (result != DOCA_SUCCESS || gpu_exit_condition == NULL || cpu_exit_condition == NULL) {
525  DOCA_LOG_ERR("Function doca_gpu_mem_alloc returned %s", doca_error_get_descr(result));
526  return EXIT_FAILURE;
527  }
528  cpu_exit_condition[0] = 0;
529 
530  DOCA_LOG_INFO("Launching CUDA kernel to receive packets");
531 
532  kernel_send_packets(stream, &txq, gpu_exit_condition);
533 
534  DOCA_LOG_INFO("Waiting for termination");
535  /* This loop keeps busy main thread until force_quit is set to 1 (e.g. typing ctrl+c) */
536  while (DOCA_GPUNETIO_VOLATILE(force_quit) == false)
537  ;
538  DOCA_GPUNETIO_VOLATILE(*cpu_exit_condition) = 1;
539 
540  DOCA_LOG_INFO("Exiting from sample");
541 
542  cudaStreamSynchronize(stream);
543 exit:
544 
545  result = destroy_txq(&txq);
546  if (result != DOCA_SUCCESS) {
547  DOCA_LOG_ERR("Function destroy_txq returned %s", doca_error_get_descr(result));
548  return DOCA_ERROR_BAD_STATE;
549  }
550 
551  DOCA_LOG_INFO("Sample finished successfully");
552 
553  return DOCA_SUCCESS;
554 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
#define GPU_PAGE_SIZE
Definition: defines.h:58
#define MAX_SQ_DESCR_NUM
Definition: defines.h:74
static doca_error_t open_doca_device_with_pci(const char *pcie_value, struct doca_dev **retval)
Definition: device.c:43
static struct doca_gpu * gpu_dev
static struct doca_dev * ddev
doca_error_t kernel_send_packets(cudaStream_t stream, struct txq_queue *txq, uint32_t *gpu_exit_condition)
static doca_error_t destroy_txq(struct txq_queue *txq)
static doca_error_t init_doca_flow(void)
static doca_error_t init_doca_device(char *nic_pcie_addr, struct doca_dev **ddev)
#define FLOW_NB_COUNTERS
DOCA_LOG_REGISTER(SIMPLE_SEND :SAMPLE)
struct doca_flow_port * df_port
#define CPU_TO_BE16(val)
static doca_error_t start_doca_flow(struct doca_dev *dev)
static doca_error_t create_txq(struct txq_queue *txq, struct doca_gpu *gpu_dev, struct doca_dev *ddev, uint32_t pkt_size, uint32_t pkt_num)
doca_error_t gpunetio_simple_send(struct sample_simple_send_cfg *sample_cfg)
static void signal_handler(int signum)
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_set_params(struct doca_buf_arr *buf_arr, struct doca_mmap *mmap, size_t elem_size, uint64_t start_offset)
Sets the buf array params.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_set_target_gpu(struct doca_buf_arr *buf_arr, struct doca_gpu *gpu_handler)
Configures the buf array to be created on the gpu device.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_get_gpu_handle(const struct doca_buf_arr *buf_arr, struct doca_gpu_buf_arr **gpu_buf_arr)
Retrieves the handle in the gpu memory space of a doca_buf_arr.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_create(size_t num_elem, struct doca_buf_arr **buf_arr)
Allocates a doca_buf_arr.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_start(struct doca_buf_arr *buf_arr)
This method enables the allocation of doca_bufs.
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_gpu(struct doca_ctx *ctx, struct doca_gpu *gpu_dev)
This function binds the DOCA context to a gpu device.
DOCA_STABLE doca_error_t doca_ctx_stop(struct doca_ctx *ctx)
Stops the context allowing reconfiguration.
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:313
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_name(doca_error_t error)
Returns the string representation of an error code name.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_INVALID_VALUE
Definition: doca_error.h:44
@ DOCA_ERROR_BAD_STATE
Definition: doca_error.h:56
@ DOCA_SUCCESS
Definition: doca_error.h:38
@ DOCA_ERROR_DRIVER
Definition: doca_error.h:59
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_gpu_set_completion_on_gpu(struct doca_eth_txq *eth_txq)
By default, the Eth Txq completion can be checked on th CPU. With this method set the Eth Txq complet...
DOCA_EXPERIMENTAL struct doca_ctx * doca_eth_txq_as_doca_ctx(struct doca_eth_txq *eth_txq)
Convert doca_eth_txq instance into a generalized context for use with doca core objects.
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_get_gpu_handle(const struct doca_eth_txq *eth_txq, struct doca_gpu_eth_txq **eth_txq_ext)
Get a gpu handle of a doca_eth_txq.
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_create(struct doca_dev *dev, uint32_t max_burst_size, struct doca_eth_txq **eth_txq)
Create a DOCA ETH TXQ instance.
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_set_l3_chksum_offload(struct doca_eth_txq *eth_txq, uint8_t enable_l3_chksum)
Set offload for the calculation of IPv4 checksum (L3) on transmitted packets. If the users enables L3...
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_destroy(struct doca_eth_txq *eth_txq)
Destroy a DOCA ETH TXQ instance.
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_set_l4_chksum_offload(struct doca_eth_txq *eth_txq, uint8_t enable_l4_chksum)
Set offload for the calculation of TCP/UDP checksum (L4) on transmitted packets. If the users enables...
DOCA_STABLE doca_error_t doca_flow_cfg_set_mode_args(struct doca_flow_cfg *cfg, const char *mode_args)
Set DOCA mode args.
DOCA_EXPERIMENTAL doca_error_t doca_flow_port_start(const struct doca_flow_port_cfg *cfg, struct doca_flow_port **port)
Start a doca port.
DOCA_STABLE doca_error_t doca_flow_cfg_create(struct doca_flow_cfg **cfg)
Create DOCA Flow configuration struct.
DOCA_EXPERIMENTAL doca_error_t doca_flow_init(struct doca_flow_cfg *cfg)
Initialize the doca flow.
DOCA_EXPERIMENTAL doca_error_t doca_flow_port_cfg_set_dev(struct doca_flow_port_cfg *cfg, struct doca_dev *dev)
Set port's device.
DOCA_STABLE doca_error_t doca_flow_cfg_set_nr_counters(struct doca_flow_cfg *cfg, uint32_t nr_counters)
Set number of counters to configure.
DOCA_STABLE doca_error_t doca_flow_port_stop(struct doca_flow_port *port)
Stop a doca port.
DOCA_EXPERIMENTAL doca_error_t doca_flow_port_cfg_set_port_id(struct doca_flow_port_cfg *cfg, uint16_t port_id)
Set the logical port ID.
DOCA_STABLE doca_error_t doca_flow_port_cfg_create(struct doca_flow_port_cfg **cfg)
Create DOCA Flow port configuration struct.
DOCA_STABLE doca_error_t doca_flow_port_cfg_destroy(struct doca_flow_port_cfg *cfg)
Destroy DOCA Flow port configuration struct.
DOCA_STABLE doca_error_t doca_flow_cfg_set_pipe_queues(struct doca_flow_cfg *cfg, uint16_t pipe_queues)
Set pipe queues.
DOCA_STABLE doca_error_t doca_flow_cfg_destroy(struct doca_flow_cfg *cfg)
Destroy DOCA Flow configuration struct.
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
DOCA_STABLE doca_error_t doca_mmap_set_memrange(struct doca_mmap *mmap, void *addr, size_t len)
Set the memory range of DOCA memory map.
DOCA_STABLE doca_error_t doca_mmap_destroy(struct doca_mmap *mmap)
Destroy DOCA Memory Map structure.
DOCA_STABLE doca_error_t doca_mmap_create(struct doca_mmap **mmap)
Allocates zero size memory map object with default/unset attributes.
DOCA_STABLE doca_error_t doca_mmap_set_permissions(struct doca_mmap *mmap, uint32_t access_mask)
Set access flags of the registered memory.
DOCA_STABLE doca_error_t doca_mmap_start(struct doca_mmap *mmap)
Start DOCA Memory Map.
DOCA_STABLE doca_error_t doca_mmap_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_set_dmabuf_memrange(struct doca_mmap *mmap, int dmabuf_fd, void *addr, size_t dmabuf_offset, size_t len)
Set the memory range of DOCA memory map using dmabuf.
@ DOCA_GPU_MEM_TYPE_GPU_CPU
Definition: doca_types.h:133
@ DOCA_GPU_MEM_TYPE_GPU
Definition: doca_types.h:131
@ DOCA_ACCESS_FLAG_LOCAL_READ_WRITE
Definition: doca_types.h:83
rte_ether_hdr eth
Definition: psp_gw_flows.cpp:1
char nic_pcie_addr[MAX_PCI_ADDRESS_LEN]
char gpu_pcie_addr[MAX_PCI_ADDRESS_LEN]
void * gpu_pkt_addr
struct doca_buf_arr * buf_arr
struct doca_dev * ddev
uint32_t pkt_size
uint32_t inflight_sends
struct doca_gpu_eth_txq * eth_txq_gpu
uint32_t cuda_threads
struct doca_flow_port * port
struct doca_mmap * pkt_buff_mmap
struct doca_ctx * eth_txq_ctx
struct doca_gpu_buf_arr * buf_arr_gpu
struct doca_eth_txq * eth_txq_cpu
struct doca_gpu * gpu_dev