NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
dpa_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-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 #ifndef DPA_COMMON_H_
27 #define DPA_COMMON_H_
28 
29 #include <stdlib.h>
30 #include <unistd.h>
31 
32 #include <doca_dev.h>
33 #include <doca_dpa.h>
34 #include <doca_error.h>
35 #include <doca_log.h>
36 #include <doca_types.h>
37 #include <doca_argp.h>
38 #include <doca_sync_event.h>
39 #include <doca_mmap.h>
40 #include <doca_rdma.h>
41 #include <doca_ctx.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
50 #define SLEEP(SECONDS) for (int i = 0; i < 1 + SECONDS * 30000; i++)
51 
55 #define DEVICE_DEFAULT_NAME "NOT_SET"
56 
60 #define SYNC_EVENT_MASK_FFS (0xFFFFFFFFFFFFFFFF)
61 
65 #define RDMA_DEVICE_DEFAULT_GID_INDEX (1)
66 
70 #define RDMA_DEFAULT_BUF_LIST_LEN (1)
71 
75 #define DPA_RESOURCES_PATH_MAX_SIZE 1024
76 
80 #define DPA_APP_KEY_MAX_SIZE 1024
81 
85 struct dpa_resources {
86  struct doca_dev *pf_doca_device;
87  struct doca_dpa *pf_dpa_ctx;
88  struct doca_dev *rdma_doca_device;
90  struct doca_dpa *rdma_dpa_ctx;
93  struct doca_dpa_eu_affinity **affinities;
94  uint32_t num_affinities;
95 };
96 
100 struct dpa_config {
106 };
107 
112  struct doca_dpa *doca_dpa;
114  uint64_t arg;
116  struct doca_dpa_thread *thread;
117  struct doca_dpa_eu_affinity *affinity;
118 };
119 
124  struct doca_dpa *doca_dpa;
125  unsigned int queue_size;
126  struct doca_dpa_thread *thread;
127  struct doca_dpa_completion *dpa_comp;
129 };
130 
135  struct doca_dpa *doca_dpa;
136  struct doca_dpa_thread *thread;
137  struct doca_dpa_notification_completion *notification_comp;
139 };
140 
144 struct dpa_rdma_obj {
145  struct doca_dev *doca_device;
146  struct doca_dpa *doca_dpa;
147  uint32_t permissions;
148  uint32_t buf_list_len;
149  uint32_t recv_queue_size;
151  uint32_t gid_index;
152  struct doca_dpa_completion *dpa_comp;
153  struct doca_rdma *rdma;
154  struct doca_ctx *rdma_as_ctx;
156  const void *connection_details;
157  size_t conn_det_len;
158  struct doca_rdma_connection *connection;
159  uint32_t connection_id;
161  const void *connection2_details;
162  size_t conn2_det_len;
163  struct doca_rdma_connection *connection2;
164  uint32_t connection2_id;
165 };
166 
170 enum mmap_type {
173 };
174 
179  enum mmap_type mmap_type;
180  struct doca_dev *doca_device;
181  struct doca_dpa *doca_dpa;
182  uint32_t permissions;
184  size_t memrange_len;
185  struct doca_mmap *mmap;
187  const void *rdma_export;
188  size_t export_len;
189 };
190 
197 
206 doca_error_t create_doca_dpa_wait_sync_event(struct doca_dpa *doca_dpa,
207  struct doca_dev *doca_device,
208  struct doca_sync_event **wait_event);
209 
219 doca_error_t create_doca_dpa_completion_sync_event(struct doca_dpa *doca_dpa,
220  struct doca_dev *doca_device,
221  struct doca_sync_event **comp_event,
222  doca_dpa_dev_sync_event_t *handle);
223 
231 doca_error_t create_doca_dpa_kernel_sync_event(struct doca_dpa *doca_dpa, struct doca_sync_event **kernel_event);
232 
240 doca_error_t create_doca_remote_net_sync_event(struct doca_dev *doca_device, struct doca_sync_event **remote_net_event);
241 
252 doca_error_t export_doca_remote_net_sync_event_to_dpa(struct doca_dev *doca_device,
253  struct doca_dpa *doca_dpa,
254  struct doca_sync_event *remote_net_event,
255  struct doca_sync_event_remote_net **remote_net_exported_event,
256  doca_dpa_dev_sync_event_remote_net_t *remote_net_event_dpa_handle);
257 
266 
274 
282 
290 
298 
306 
314 
322  struct dpa_notification_completion_obj *notification_completion_obj);
323 
335 
343 
351 
359 
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 
372 #endif /* DPA_COMMON_H_ */
doca_error_t dpa_rdma_obj_destroy(struct dpa_rdma_obj *dpa_rdma_obj)
Destroy DPA RDMA.
Definition: dpa_common.c:1107
doca_error_t export_doca_remote_net_sync_event_to_dpa(struct doca_dev *doca_device, struct doca_dpa *doca_dpa, struct doca_sync_event *remote_net_event, struct doca_sync_event_remote_net **remote_net_exported_event, doca_dpa_dev_sync_event_remote_net_t *remote_net_event_dpa_handle)
Create DOCA sync event to be published by a remote net and subscribed by the CPU.
Definition: dpa_common.c:483
doca_error_t dpa_notification_completion_obj_init(struct dpa_notification_completion_obj *notification_completion_obj)
Initialize DPA notification completion.
Definition: dpa_common.c:929
doca_error_t destroy_dpa_resources(struct dpa_resources *resources)
Destroy DOCA DPA resources.
Definition: dpa_common.c:769
doca_error_t dpa_rdma_obj_start(struct dpa_rdma_obj *dpa_rdma_obj)
Start DPA RDMA.
Definition: dpa_common.c:1058
doca_error_t register_dpa_params(void)
Register the command line parameters for the sample.
Definition: dpa_common.c:126
doca_error_t dpa_thread_obj_init(struct dpa_thread_obj *dpa_thread_obj)
Initialize DPA thread.
Definition: dpa_common.c:817
doca_error_t dpa_notification_completion_obj_destroy(struct dpa_notification_completion_obj *notification_completion_obj)
Destroy DPA notification completion.
Definition: dpa_common.c:962
doca_error_t create_doca_dpa_wait_sync_event(struct doca_dpa *doca_dpa, struct doca_dev *doca_device, struct doca_sync_event **wait_event)
Create DOCA sync event to be published by the CPU and subscribed by the DPA.
Definition: dpa_common.c:313
doca_error_t doca_mmap_obj_destroy(struct doca_mmap_obj *doca_mmap_obj)
Destroy DOCA Mmap.
Definition: dpa_common.c:1209
doca_error_t dpa_completion_obj_init(struct dpa_completion_obj *dpa_completion_obj)
Initialize DPA completion.
Definition: dpa_common.c:877
mmap_type
DOCA Mmap type definition.
Definition: dpa_common.h:170
@ MMAP_TYPE_DPA
Definition: dpa_common.h:172
@ MMAP_TYPE_CPU
Definition: dpa_common.h:171
doca_error_t allocate_dpa_resources(struct dpa_config *cfg, struct dpa_resources *resources)
Allocate DOCA DPA resources.
Definition: dpa_common.c:660
#define DPA_APP_KEY_MAX_SIZE
DPA application key size.
Definition: dpa_common.h:80
doca_error_t create_doca_remote_net_sync_event(struct doca_dev *doca_device, struct doca_sync_event **remote_net_event)
Create DOCA sync event to be published by a remote net and subscribed by the CPU.
Definition: dpa_common.c:443
doca_error_t dpa_rdma_obj_init(struct dpa_rdma_obj *dpa_rdma_obj)
Initialize DPA RDMA without starting it.
Definition: dpa_common.c:976
doca_error_t create_doca_dpa_completion_sync_event(struct doca_dpa *doca_dpa, struct doca_dev *doca_device, struct doca_sync_event **comp_event, doca_dpa_dev_sync_event_t *handle)
Create DOCA sync event to be published by the DPA and subscribed by the CPU.
Definition: dpa_common.c:354
doca_error_t doca_mmap_obj_init(struct doca_mmap_obj *doca_mmap_obj)
Initialize DOCA Mmap.
Definition: dpa_common.c:1126
doca_error_t dpa_completion_obj_destroy(struct dpa_completion_obj *dpa_completion_obj)
Destroy DPA completion.
Definition: dpa_common.c:916
#define DPA_RESOURCES_PATH_MAX_SIZE
DPA resources file path size.
Definition: dpa_common.h:75
doca_error_t dpa_thread_obj_destroy(struct dpa_thread_obj *dpa_thread_obj)
Destroy DPA thread.
Definition: dpa_common.c:864
doca_error_t create_doca_dpa_kernel_sync_event(struct doca_dpa *doca_dpa, struct doca_sync_event **kernel_event)
Create DOCA sync event to be published and subscribed by the DPA.
Definition: dpa_common.c:404
struct rdma_resources resources
#define DOCA_DEVINFO_IBDEV_NAME_SIZE
Buffer size to hold Infiniband/RoCE device name. Including a null terminator.
Definition: doca_dev.h:309
uint64_t doca_dpa_dev_t
DPA context handle type definition.
Definition: doca_dpa.h:73
void() doca_dpa_func_t(void)
Generic function pointer type.
Definition: doca_dpa.h:118
uint64_t doca_dpa_dev_completion_t
DPA completion handle type definition.
Definition: doca_dpa.h:88
uint64_t doca_dpa_dev_uintptr_t
DPA pointer type definition.
Definition: doca_dpa.h:78
uint64_t doca_dpa_dev_notification_completion_t
DPA notification completion handle type definition.
Definition: doca_dpa.h:98
enum doca_error doca_error_t
DOCA API return codes.
uint32_t doca_dpa_dev_mmap_t
Handle on the DPA for a doca_mmap instance.
Definition: doca_mmap.h:74
uint64_t doca_dpa_dev_rdma_t
Definition: doca_rdma.h:79
uint64_t doca_dpa_dev_sync_event_t
DOCA Sync Event DPA handle.
uint64_t doca_dpa_dev_sync_event_remote_net_t
DOCA Sync Event remote DPA handle.
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
A struct that includes all the resources needed for DOCA Mmap.
Definition: dpa_common.h:178
size_t export_len
Definition: dpa_common.h:188
const void * rdma_export
Definition: dpa_common.h:187
size_t memrange_len
Definition: dpa_common.h:184
enum mmap_type mmap_type
Definition: dpa_common.h:179
uint32_t permissions
Definition: dpa_common.h:182
struct doca_dev * doca_device
Definition: dpa_common.h:180
struct doca_mmap * mmap
Definition: dpa_common.h:185
struct doca_dpa * doca_dpa
Definition: dpa_common.h:181
doca_dpa_dev_mmap_t dpa_mmap_handle
Definition: dpa_common.h:186
void * memrange_addr
Definition: dpa_common.h:183
A struct that includes all the resources needed for DPA completion.
Definition: dpa_common.h:123
struct doca_dpa_thread * thread
Definition: dpa_common.h:126
doca_dpa_dev_completion_t handle
Definition: dpa_common.h:128
struct doca_dpa_completion * dpa_comp
Definition: dpa_common.h:127
struct doca_dpa * doca_dpa
Definition: dpa_common.h:124
unsigned int queue_size
Definition: dpa_common.h:125
Configuration struct.
Definition: dpa_common.h:100
char rdma_device_name[DOCA_DEVINFO_IBDEV_NAME_SIZE]
Definition: dpa_common.h:102
char dpa_resources_file[DPA_RESOURCES_PATH_MAX_SIZE]
Definition: dpa_common.h:104
char pf_device_name[DOCA_DEVINFO_IBDEV_NAME_SIZE]
Definition: dpa_common.h:101
char dpa_app_key[DPA_APP_KEY_MAX_SIZE]
Definition: dpa_common.h:105
A struct that includes all the resources needed for DPA notification completion.
Definition: dpa_common.h:134
struct doca_dpa_thread * thread
Definition: dpa_common.h:136
doca_dpa_dev_notification_completion_t handle
Definition: dpa_common.h:138
struct doca_dpa * doca_dpa
Definition: dpa_common.h:135
struct doca_dpa_notification_completion * notification_comp
Definition: dpa_common.h:137
A struct that includes all the resources needed for DPA RDMA.
Definition: dpa_common.h:144
struct doca_ctx * rdma_as_ctx
Definition: dpa_common.h:154
doca_dpa_dev_rdma_t dpa_rdma
Definition: dpa_common.h:155
struct doca_rdma_connection * connection
Definition: dpa_common.h:158
uint32_t connection_id
Definition: dpa_common.h:159
uint32_t permissions
Definition: dpa_common.h:147
bool second_connection_needed
Definition: dpa_common.h:160
uint32_t max_connections_count
Definition: dpa_common.h:150
size_t conn2_det_len
Definition: dpa_common.h:162
uint32_t connection2_id
Definition: dpa_common.h:164
const void * connection2_details
Definition: dpa_common.h:161
uint32_t gid_index
Definition: dpa_common.h:151
struct doca_rdma_connection * connection2
Definition: dpa_common.h:163
size_t conn_det_len
Definition: dpa_common.h:157
uint32_t recv_queue_size
Definition: dpa_common.h:149
struct doca_dev * doca_device
Definition: dpa_common.h:145
uint32_t buf_list_len
Definition: dpa_common.h:148
struct doca_dpa_completion * dpa_comp
Definition: dpa_common.h:152
struct doca_rdma * rdma
Definition: dpa_common.h:153
struct doca_dpa * doca_dpa
Definition: dpa_common.h:146
const void * connection_details
Definition: dpa_common.h:156
A struct that includes all the resources needed for DPA.
Definition: dpa_common.h:85
struct doca_dpa * pf_dpa_ctx
Definition: dpa_common.h:87
struct doca_dpa_eu_affinity ** affinities
Definition: dpa_common.h:93
struct doca_dev * rdma_doca_device
Definition: dpa_common.h:88
struct doca_dev * pf_doca_device
Definition: dpa_common.h:86
uint32_t num_affinities
Definition: dpa_common.h:94
struct doca_dpa * rdma_dpa_ctx
Definition: dpa_common.h:90
doca_dpa_dev_t rdma_dpa_ctx_handle
Definition: dpa_common.h:92
A struct that includes all the resources needed for DPA thread.
Definition: dpa_common.h:111
struct doca_dpa_thread * thread
Definition: dpa_common.h:116
uint64_t arg
Definition: dpa_common.h:114
doca_dpa_dev_uintptr_t tls_dev_ptr
Definition: dpa_common.h:115
struct doca_dpa * doca_dpa
Definition: dpa_common.h:112
doca_dpa_func_t * func
Definition: dpa_common.h:113
struct doca_dpa_eu_affinity * affinity
Definition: dpa_common.h:117