NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
common_common.h
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 #ifndef COMMON_COMMON_H
27 #define COMMON_COMMON_H
28 
29 #include <stdbool.h>
30 
31 #include <doca_comch.h>
32 #include <doca_ctx.h>
33 #include <doca_dev.h>
34 #include <doca_pe.h>
35 #include <doca_sync_event.h>
36 
37 #define SYNC_EVENT_CC_MAX_MSG_SIZE 1024 /* DOCA comch maximum message size */
38 #define SYNC_EVENT_CC_MAX_QUEUE_SIZE 8 /* DOCA comch maximum queue size */
39 #define SYNC_EVENT_CC_MAX_TASKS 8 /* DOCA comch maximum send tasks to allocate */
40 #define SYNC_EVENT_CC_SERVICE_NAME "sync_event_cc" /* DOCA comch service name */
41 #define SYNC_EVENT_CC_TIMEOUT_SEC 30 /* DOCA comch timeout in seconds */
42 #define SYNC_EVENT_CC_ACK_SIZE 1 /* DOCA comch acknowledge size in bytes */
43 #define SYNC_EVENT_CC_ACK_VALUE 1 /* DOCA comch acknowledge value */
44 
45 /* user input */
47  char dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* Device PCI address */
48  char rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]; /* DPU representor PCI address */
49  bool is_async_mode; /* Start DOCA Sync Event in asynchronous or synchronous mode */
50  bool is_update_atomic; /* Update DOCA Sync Event using Set or atomic Add operation */
51  uint32_t async_num_tasks; /* Num tasks for asynchronous mode */
52 };
53 
54 /* runtime objects */
56  struct doca_dev *dev; /* DOCA device */
57  struct doca_dev_rep *rep; /* DOCA representor */
58  struct doca_sync_event *se; /* DOCA Sync Event */
59  struct doca_ctx *se_ctx; /* DOCA Sync Event Context */
60  struct doca_pe *se_pe; /* DOCA Progress Engine */
61  doca_error_t se_task_result; /* Last completed Sync Event Tasks's status */
62 
63  /* Comch objects */
64  struct doca_pe *comch_pe; /* DOCA Progress Engine for comch */
65  union {
66  struct doca_comch_server *server; /* Server context (DPU only) */
67  struct doca_comch_client *client; /* Client context (x86 host only) */
68  };
69  struct doca_comch_connection *comch_connection; /* Established comch connection */
70  doca_comch_event_msg_recv_cb_t comch_recv_event_cb; /* Comch event callback on recv messages */
71  void *user_data; /* Sample user data - recv events return struct sync_event_runtime_objects */
72 };
73 
74 /*
75  * Register command line parameters for DOCA Sync Event sample
76  *
77  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
78  */
80 
81 /*
82  * DOCA device with export-to-dpu capability filter callback
83  *
84  * @devinfo [in]: doca_devinfo
85  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
86  */
87 doca_error_t sync_event_get_export_to_dpu_supported(struct doca_devinfo *devinfo);
88 
89 /*
90  * Validate configured flow by user input
91  *
92  * @se_cfg [in]: user configuration represents command line arguments
93  * @se_rt_objs [in]: sample's runtime resources
94  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
95  */
97  const struct sync_event_runtime_objects *se_rt_objs);
98 
99 /*
100  * Start Sample's DOCA Sync Event in asynchronous operation mode
101  *
102  * @se_cfg [in]: user configuration represents command line arguments
103  * @se_rt_objs [in]: sample's runtime resources
104  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
105  */
107  struct sync_event_runtime_objects *se_rt_objs);
108 
109 /*
110  * Establish Sample's DOCA comch connection
111  *
112  * @se_rt_objs [in/out]: sample's runtime resources
113  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
114  */
116 
117 /*
118  * Submit asynchronous DOCA Task on Sample's DOCA Sync Event Context
119  *
120  * @se_rt_objs [in]: sample's runtime resources
121  * @se_task [in]: DOCA Task to submit
122  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
123  */
124 doca_error_t sync_event_async_task_submit(struct sync_event_runtime_objects *se_rt_objs, struct doca_task *se_task);
125 
126 /*
127  * Sample's tear down flow
128  *
129  * @se_rt_objs [in]: sample's runtime resources
130  */
131 void sync_event_tear_down(struct sync_event_runtime_objects *se_rt_objs);
132 
133 #endif /* COMMON_COMMON_H */
void sync_event_tear_down(struct sync_event_runtime_objects *se_rt_objs)
doca_error_t sync_event_async_task_submit(struct sync_event_runtime_objects *se_rt_objs, struct doca_task *se_task)
doca_error_t sync_event_params_register(void)
doca_error_t sync_event_start_async(const struct sync_event_config *se_cfg, struct sync_event_runtime_objects *se_rt_objs)
doca_error_t sync_event_cc_handshake(struct sync_event_runtime_objects *se_rt_objs)
doca_error_t sync_event_config_validate(const struct sync_event_config *se_cfg, const struct sync_event_runtime_objects *se_rt_objs)
doca_error_t sync_event_get_export_to_dpu_supported(struct doca_devinfo *devinfo)
void(* doca_comch_event_msg_recv_cb_t)(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
Definition: doca_comch.h:718
#define DOCA_DEVINFO_REP_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:665
#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.
char rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]
Definition: common_common.h:48
char dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
Definition: common_common.h:47
uint32_t async_num_tasks
Definition: common_common.h:51
struct doca_dev * dev
Definition: common_common.h:56
struct doca_comch_connection * comch_connection
Definition: common_common.h:69
struct doca_pe * se_pe
Definition: common_common.h:60
struct doca_comch_server * server
Definition: common_common.h:66
struct doca_pe * comch_pe
Definition: common_common.h:64
struct doca_ctx * se_ctx
Definition: common_common.h:59
doca_comch_event_msg_recv_cb_t comch_recv_event_cb
Definition: common_common.h:70
struct doca_comch_client * client
Definition: common_common.h:67
struct doca_sync_event * se
Definition: common_common.h:58
struct doca_dev_rep * rep
Definition: common_common.h:57