NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
dma_copy.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 
29 #include <doca_buf.h>
30 #include <doca_buf_inventory.h>
31 #include <doca_log.h>
32 
33 #include "dma_copy_core.h"
34 
36 
37 /*
38  * DMA copy application main function
39  *
40  * @argc [in]: command line arguments size
41  * @argv [in]: array of command line arguments
42  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
43  */
44 int main(int argc, char **argv)
45 {
47  struct comch_cfg *comch_cfg;
48  struct dma_copy_cfg dma_cfg = {0};
49  struct doca_log_backend *sdk_log;
50  int exit_status = EXIT_FAILURE;
51 
52 #ifdef DOCA_ARCH_DPU
53  dma_cfg.mode = DMA_COPY_MODE_DPU;
54 #endif
55 
56  /* Register a logger backend */
58  if (result != DOCA_SUCCESS)
59  return EXIT_FAILURE;
60 
61  /* Register a logger backend for internal SDK errors and warnings */
63  if (result != DOCA_SUCCESS)
64  return EXIT_FAILURE;
66  if (result != DOCA_SUCCESS)
67  return EXIT_FAILURE;
68 
69  result = doca_argp_init(NULL, &dma_cfg);
70  if (result != DOCA_SUCCESS) {
71  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
72  return EXIT_FAILURE;
73  }
74 
76  if (result != DOCA_SUCCESS) {
77  DOCA_LOG_ERR("Failed to register the program parameters: %s", doca_error_get_descr(result));
78  goto destroy_argp;
79  }
80 
81  result = doca_argp_start(argc, argv);
82  if (result != DOCA_SUCCESS) {
83  DOCA_LOG_ERR("Failed to parse application input: %s", doca_error_get_descr(result));
84  goto destroy_argp;
85  }
86 
88  dma_cfg.cc_dev_pci_addr,
89  dma_cfg.cc_dev_rep_pci_addr,
90  &dma_cfg,
93  &comch_cfg);
94  if (result != DOCA_SUCCESS) {
95  DOCA_LOG_ERR("Failed to initialize a comch: %s", doca_error_get_descr(result));
96  goto destroy_argp;
97  }
98 
99  if (dma_cfg.mode == DMA_COPY_MODE_HOST)
100  result = host_start_dma_copy(&dma_cfg, comch_cfg);
101  else
102  result = dpu_start_dma_copy(&dma_cfg, comch_cfg);
103 
104  if (result == DOCA_SUCCESS)
105  exit_status = EXIT_SUCCESS;
106 
107  /* Destroy Comm Channel */
109  if (result != DOCA_SUCCESS) {
110  DOCA_LOG_ERR("Failed to destroy DOCA Comch");
111  exit_status = EXIT_FAILURE;
112  }
113 
114 destroy_argp:
115  /* ARGP destroy_resources */
117 
118  return exit_status;
119 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
doca_error_t comch_utils_destroy(struct comch_cfg *comch_cfg)
Definition: comch_utils.c:592
doca_error_t comch_utils_init(const char *server_name, const char *pci_addr, const char *rep_pci_addr, void *user_data, doca_comch_event_msg_recv_cb_t client_recv_event_cb, doca_comch_event_msg_recv_cb_t server_recv_event_cb, struct comch_cfg **comch_cfg)
Definition: comch_utils.c:573
int main(int argc, char **argv)
Definition: dma_copy.c:44
DOCA_LOG_REGISTER(DMA_COPY)
void host_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
void dpu_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
doca_error_t register_dma_copy_params(void)
doca_error_t dpu_start_dma_copy(struct dma_copy_cfg *dma_cfg, struct comch_cfg *comch_cfg)
doca_error_t host_start_dma_copy(struct dma_copy_cfg *dma_cfg, struct comch_cfg *comch_cfg)
#define SERVER_NAME
Definition: dma_copy_core.h:40
@ DMA_COPY_MODE_HOST
Definition: dma_copy_core.h:44
@ DMA_COPY_MODE_DPU
Definition: dma_copy_core.h:45
DOCA_EXPERIMENTAL doca_error_t doca_argp_start(int argc, char **argv)
Parse incoming arguments (cmd line/json).
DOCA_EXPERIMENTAL doca_error_t doca_argp_init(const char *program_name, void *program_config)
Initialize the parser interface.
DOCA_EXPERIMENTAL doca_error_t doca_argp_destroy(void)
ARG Parser destroy.
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_SUCCESS
Definition: doca_error.h:38
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_standard(void)
Create default, non configurable backend for application messages.
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_with_file_sdk(FILE *fptr, struct doca_log_backend **backend)
Create a logging backend with a FILE* stream for SDK messages.
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_set_sdk_level(struct doca_log_backend *backend, uint32_t level)
Set the log level limit for SDK logging backends.
@ DOCA_LOG_LEVEL_WARNING
Definition: doca_log.h:47
char cc_dev_rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]
Definition: dma_copy_core.h:91
char cc_dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
Definition: dma_copy_core.h:90
enum dma_copy_mode mode
Definition: dma_copy_core.h:88