NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
args.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 <doca_argp.h>
27 #include <utils.h>
28 
29 #include "common.h"
30 
32 
33 /*
34  * Get GPU PCIe address input.
35  *
36  * @param [in]: Command line parameter
37  * @config [in]: Application configuration structure
38  * @return: DOCA_SUCCESS on success and DOCA_ERROR_INVALID_VALUE otherwise
39  */
40 static doca_error_t gpu_pci_address_callback(void *param, void *config)
41 {
42  struct app_gpu_cfg *app_cfg = (struct app_gpu_cfg *)config;
43  char *pci_address = (char *)param;
44  int len;
45 
46  len = strnlen(pci_address, DOCA_DEVINFO_PCI_ADDR_SIZE);
48  DOCA_LOG_ERR("PCI file name too long. Max %d", DOCA_DEVINFO_PCI_ADDR_SIZE - 1);
50  }
51 
53 
54  return DOCA_SUCCESS;
55 }
56 
57 /*
58  * Enable GPU HTTP server mode.
59  *
60  * @param [in]: Command line parameter
61  * @config [in]: Application configuration structure
62  * @return: DOCA_SUCCESS on success and DOCA_ERROR_INVALID_VALUE otherwise
63  */
64 static doca_error_t http_server_callback(void *param, void *config)
65 {
66  struct app_gpu_cfg *app_cfg = (struct app_gpu_cfg *)config;
67  bool http_server = *((bool *)param);
68 
70 
71  return DOCA_SUCCESS;
72 }
73 
74 /*
75  * Get NIC PCIe address input.
76  *
77  * @param [in]: Command line parameter
78  * @config [in]: Application configuration structure
79  * @return: DOCA_SUCCESS on success and DOCA_ERROR_INVALID_VALUE otherwise
80  */
81 static doca_error_t nic_pci_address_callback(void *param, void *config)
82 {
83  struct app_gpu_cfg *app_cfg = (struct app_gpu_cfg *)config;
84  char *pci_address = (char *)param;
85  int len;
86 
87  len = strnlen(pci_address, DOCA_DEVINFO_PCI_ADDR_SIZE);
89  DOCA_LOG_ERR("PCI file name too long. Max %d", DOCA_DEVINFO_PCI_ADDR_SIZE - 1);
91  }
92 
94 
95  return DOCA_SUCCESS;
96 }
97 
98 /*
99  * Get GPU receive queue number.
100  *
101  * @param [in]: Command line parameter
102  * @config [in]: Application configuration structure
103  * @return: DOCA_SUCCESS on success and DOCA_ERROR_INVALID_VALUE otherwise
104  */
105 static doca_error_t queue_num_callback(void *param, void *config)
106 {
107  struct app_gpu_cfg *app_cfg = (struct app_gpu_cfg *)config;
108  int queue_num = *((int *)param);
109 
110  if (queue_num == 0 || queue_num > MAX_QUEUES) {
111  DOCA_LOG_ERR("GPU receive queue number is wrong 0 < %d < %d", queue_num, MAX_QUEUES);
113  }
114 
116 
117  return DOCA_SUCCESS;
118 }
119 
121 {
123  struct doca_argp_param *gpu_param, *nic_param, *queue_param, *server_param;
124 
125  result = doca_argp_param_create(&gpu_param);
126  if (result != DOCA_SUCCESS) {
127  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
128  return result;
129  }
130 
131  doca_argp_param_set_short_name(gpu_param, "g");
132  doca_argp_param_set_long_name(gpu_param, "gpu");
133  doca_argp_param_set_arguments(gpu_param, "<GPU PCIe address>");
134  doca_argp_param_set_description(gpu_param, "GPU PCIe address to be used by the app");
138  result = doca_argp_register_param(gpu_param);
139  if (result != DOCA_SUCCESS) {
140  DOCA_LOG_ERR("Failed to register ARGP param: %s", doca_error_get_descr(result));
141  return result;
142  }
143 
144  result = doca_argp_param_create(&nic_param);
145  if (result != DOCA_SUCCESS) {
146  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
147  return result;
148  }
149 
150  doca_argp_param_set_short_name(nic_param, "n");
151  doca_argp_param_set_long_name(nic_param, "nic");
152  doca_argp_param_set_arguments(nic_param, "<NIC PCIe address>");
153  doca_argp_param_set_description(nic_param, "DOCA device PCIe address used by the app");
157  result = doca_argp_register_param(nic_param);
158  if (result != DOCA_SUCCESS) {
159  DOCA_LOG_ERR("Failed to register ARGP param: %s", doca_error_get_descr(result));
160  return result;
161  }
162 
163  result = doca_argp_param_create(&queue_param);
164  if (result != DOCA_SUCCESS) {
165  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
166  return result;
167  }
168 
169  doca_argp_param_set_short_name(queue_param, "q");
170  doca_argp_param_set_long_name(queue_param, "queue");
171  doca_argp_param_set_arguments(queue_param, "<GPU receive queues>");
172  doca_argp_param_set_description(queue_param, "DOCA GPUNetIO receive queue per flow");
175  doca_argp_param_set_mandatory(queue_param);
176  result = doca_argp_register_param(queue_param);
177  if (result != DOCA_SUCCESS) {
178  DOCA_LOG_ERR("Failed to register ARGP param: %s", doca_error_get_descr(result));
179  return result;
180  }
181 
182  result = doca_argp_param_create(&server_param);
183  if (result != DOCA_SUCCESS) {
184  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
185  return result;
186  }
187 
188  doca_argp_param_set_short_name(server_param, "s");
189  doca_argp_param_set_long_name(server_param, "httpserver");
190  doca_argp_param_set_arguments(server_param, "<Enable GPU HTTP server>");
191  doca_argp_param_set_description(server_param, "Enable GPU HTTP server mode");
194  result = doca_argp_register_param(server_param);
195  if (result != DOCA_SUCCESS) {
196  DOCA_LOG_ERR("Failed to register ARGP param: %s", doca_error_get_descr(result));
197  return result;
198  }
199 
200  /* Register version callback for DOCA SDK & RUNTIME */
202  if (result != DOCA_SUCCESS) {
203  DOCA_LOG_ERR("Failed to register ARGP param: %s", doca_error_get_descr(result));
204  return result;
205  }
206 
207  return DOCA_SUCCESS;
208 }
int32_t result
static doca_error_t queue_num_callback(void *param, void *config)
Definition: args.c:105
doca_error_t register_application_params(void)
Definition: args.c:120
DOCA_LOG_REGISTER(GPU_ARGS)
static doca_error_t nic_pci_address_callback(void *param, void *config)
Definition: args.c:81
static doca_error_t http_server_callback(void *param, void *config)
Definition: args.c:64
static doca_error_t gpu_pci_address_callback(void *param, void *config)
Definition: args.c:40
#define MAX_QUEUES
Definition: defines.h:62
uint64_t len
static struct app_gpu_cfg app_cfg
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 doca_error_t doca_argp_register_version_callback(doca_argp_param_cb_t callback)
Register an alternative version callback.
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
#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
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_SUCCESS
Definition: doca_error.h:38
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
uint8_t queue_num
Definition: common.h:38
bool http_server
Definition: common.h:39
char nic_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
Definition: common.h:37
char gpu_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
Definition: common.h:36
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: utils.c:123
noreturn doca_error_t sdk_version_callback(void *param, void *doca_config)
Definition: utils.c:41