NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
dpa_basic_initiator_target_main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 
28 DOCA_LOG_REGISTER(DPA_BASIC_INITIATOR_TARGET::MAIN);
29 
34 
42 int main(int argc, char **argv)
43 {
44  struct dpa_config cfg = {0};
45  struct dpa_resources resources = {0};
47  struct doca_log_backend *sdk_log = NULL;
48  int exit_status = EXIT_FAILURE;
49 
50  strcpy(cfg.pf_device_name, DEVICE_DEFAULT_NAME);
51  strcpy(cfg.rdma_device_name, DEVICE_DEFAULT_NAME);
52 
54  if (result != DOCA_SUCCESS)
55  goto sample_exit;
56 
58  if (result != DOCA_SUCCESS)
59  goto sample_exit;
61  if (result != DOCA_SUCCESS)
62  goto sample_exit;
63 
64  DOCA_LOG_INFO("Starting the sample");
65 
67  if (result != DOCA_SUCCESS) {
68  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
69  goto sample_exit;
70  }
71 
73  if (result != DOCA_SUCCESS) {
74  DOCA_LOG_ERR("Failed to register sample parameters: %s", doca_error_get_descr(result));
75  goto argp_cleanup;
76  }
77 
78  result = doca_argp_start(argc, argv);
79  if (result != DOCA_SUCCESS) {
80  DOCA_LOG_ERR("Failed to parse sample input: %s", doca_error_get_descr(result));
81  goto argp_cleanup;
82  }
83 
85  if (result != DOCA_SUCCESS) {
86  DOCA_LOG_ERR("Failed to Allocate DPA Resources: %s", doca_error_get_descr(result));
87  goto argp_cleanup;
88  }
89 
91  if (result != DOCA_SUCCESS) {
92  DOCA_LOG_ERR("dpa_basic_initiator_target() encountered an error: %s", doca_error_get_descr(result));
93  goto dpa_cleanup;
94  }
95 
96  exit_status = EXIT_SUCCESS;
97 
98 dpa_cleanup:
100  if (result != DOCA_SUCCESS) {
101  DOCA_LOG_ERR("Failed to destroy DOCA DPA resources: %s", doca_error_get_descr(result));
102  exit_status = EXIT_FAILURE;
103  }
104 
105 argp_cleanup:
107 
108 sample_exit:
109  if (exit_status == EXIT_SUCCESS)
110  DOCA_LOG_INFO("Sample finished successfully");
111  else
112  DOCA_LOG_INFO("Sample finished with errors");
113  return exit_status;
114 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
int main(int argc, char **argv)
Sample's main function.
doca_error_t dpa_basic_initiator_target(struct dpa_resources *resources)
Sample's logic.
DOCA_LOG_REGISTER(DPA_BASIC_INITIATOR_TARGET::MAIN)
doca_error_t destroy_dpa_resources(struct dpa_resources *resources)
Destroy DOCA DPA resources.
Definition: dpa_common.c:769
doca_error_t register_dpa_params(void)
Register the command line parameters for the sample.
Definition: dpa_common.c:126
doca_error_t allocate_dpa_resources(struct dpa_config *cfg, struct dpa_resources *resources)
Allocate DOCA DPA resources.
Definition: dpa_common.c:660
#define DEVICE_DEFAULT_NAME
device default name
Definition: dpa_common.h:55
struct rdma_resources resources
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
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
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
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
Configuration struct.
Definition: dpa_common.h:100
A struct that includes all the resources needed for DPA.
Definition: dpa_common.h:85