NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
apsh_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 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 #ifndef APSH_COMMON_H_
26 #define APSH_COMMON_H_
27 
28 #include <doca_apsh.h>
29 #include <doca_apsh_attr.h>
30 #include <doca_dev.h>
31 
32 #define MAX_PATH_LEN 260
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* Configuration struct */
39 struct apsh_config {
40  DOCA_APSH_PROCESS_PID_TYPE pid; /* Process Identifier */
41  char system_vuid[DOCA_DEVINFO_VUID_SIZE + 1]; /* Virtual Unique Identifier */
42  char dma_dev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE + 1]; /* DMA device name */
43  enum doca_apsh_system_os os_type; /* System OS type - windows/linux */
44  char system_mem_region_path[MAX_PATH_LEN]; /* Path to APSH's mem_regions.json file */
45  char system_os_symbol_map_path[MAX_PATH_LEN]; /* Path to APSH's os_symbols.json file */
46 };
47 
48 /*
49  * Register the command line parameters for the DOCA APSH samples.
50  *
51  * @add_os_arg [in]: true/false - need OS type from argv
52  * @add_pid_arg [in]: true/false - need process PID from argv
53  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
54  */
55 doca_error_t register_apsh_params(bool add_os_arg, bool add_pid_arg);
56 
57 /*
58  * Creates and starts a DOCA Apsh context, in order to make the library usable.
59  *
60  * @dma_device_name [in]: String representing a DMA capable device
61  * @ctx [out]: Memory storage for the context pointer
62  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
63  *
64  * @NOTE: On failure all lib Apsh resources are freed
65  */
66 doca_error_t init_doca_apsh(const char *dma_device_name, struct doca_apsh_ctx **ctx);
67 
68 /*
69  * Creates and starts a DOCA Apsh System context, in order to apply the library on a specific host system.
70  *
71  * @ctx [in]: App shield initiated context
72  * @os_type [in]: Target OS type
73  * @os_symbols [in]: Path to the symbols JSON created by doca_apsh_config tool
74  * @mem_region [in]: Path to the mem_regions JSON created by doca_apsh_config tool
75  * @pci_vuid [in]: VUID of the VF/PF exposed to the target
76  * @system [out]: Memory storage for the context pointer
77  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
78  *
79  * @NOTE: On failure all lib Apsh resources are freed
80  */
81 doca_error_t init_doca_apsh_system(struct doca_apsh_ctx *ctx,
82  enum doca_apsh_system_os os_type,
83  const char *os_symbols,
84  const char *mem_region,
85  const char *pci_vuid,
86  struct doca_apsh_system **system);
87 
88 /*
89  * Destroys the system and context handler and free inner resources.
90  *
91  * @ctx [in]: App shield created context
92  * @system [in]: App shield System created context (or NULL to ignore)
93  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
94  */
95 doca_error_t cleanup_doca_apsh(struct doca_apsh_ctx *ctx, struct doca_apsh_system *system);
96 
97 /*
98  * Searches for a process on the "sys" with a specific PID.
99  *
100  * @pid [in]: PID of a process to be searched for
101  * @sys [in]: App shield System initiated context
102  * @nb_procs [out]: Length of processes list
103  * @processes [out]: List of all processes in the target system
104  * @process [out]: Pointer to the specific process
105  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
106  *
107  * @NOTE: If process pid is not found, the processes list is not returned
108  */
110  struct doca_apsh_system *sys,
111  int *nb_procs,
112  struct doca_apsh_process ***processes,
113  struct doca_apsh_process **process);
114 
115 #ifdef __cplusplus
116 } /* extern "C" */
117 #endif
118 
119 #endif /* APSH_COMMON_H_ */
int32_t pid
doca_error_t register_apsh_params(bool add_os_arg, bool add_pid_arg)
Definition: apsh_common.c:169
doca_error_t process_get(DOCA_APSH_PROCESS_PID_TYPE pid, struct doca_apsh_system *sys, int *nb_procs, struct doca_apsh_process ***processes, struct doca_apsh_process **process)
Definition: apsh_common.c:397
doca_error_t cleanup_doca_apsh(struct doca_apsh_ctx *ctx, struct doca_apsh_system *system)
Definition: apsh_common.c:384
#define MAX_PATH_LEN
Definition: apsh_common.h:32
doca_error_t init_doca_apsh_system(struct doca_apsh_ctx *ctx, enum doca_apsh_system_os os_type, const char *os_symbols, const char *mem_region, const char *pci_vuid, struct doca_apsh_system **system)
Definition: apsh_common.c:325
doca_error_t init_doca_apsh(const char *dma_device_name, struct doca_apsh_ctx **ctx)
Definition: apsh_common.c:287
uint32_t DOCA_APSH_PROCESS_PID_TYPE
process pid type
doca_apsh_system_os
system os types
#define DOCA_DEVINFO_IBDEV_NAME_SIZE
Buffer size to hold Infiniband/RoCE device name. Including a null terminator.
Definition: doca_dev.h:309
#define DOCA_DEVINFO_VUID_SIZE
Buffer size to hold VUID. Including a null terminator.
Definition: doca_dev.h:289
enum doca_error doca_error_t
DOCA API return codes.
char system_vuid[DOCA_DEVINFO_VUID_SIZE+1]
DOCA_APSH_PROCESS_PID_TYPE pid
char dma_dev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE+1]
char system_mem_region_path[MAX_PATH_LEN]
char system_os_symbol_map_path[MAX_PATH_LEN]
enum doca_apsh_system_os os_type
struct upf_accel_ctx * ctx