NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
secure_channel_core.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-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 SECURE_CHANNEL_CORE_H_
27 #define SECURE_CHANNEL_CORE_H_
28 
29 #include <pthread.h>
30 #include <stdatomic.h>
31 
32 #include <doca_dev.h>
33 
34 #include "comch_utils.h"
35 
36 enum sc_mode {
37  SC_MODE_HOST, /* Run endpoint in Host */
38  SC_MODE_DPU /* Run endpoint in DPU */
39 };
40 
41 struct sc_config {
42  enum sc_mode mode; /* Mode of operation */
43  int send_msg_size; /* Message size in bytes */
44  int send_msg_nb; /* Number of messages to send */
45  char cc_dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* Comm Channel DOCA device PCI address */
46  char cc_dev_rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]; /* Comm Channel DOCA device representor PCI address */
47 };
48 
49 struct t_results {
50  doca_error_t result; /* Send thread result */
51  struct timespec start_time; /* Timestamp when thread starts to send */
52  struct timespec end_time; /* Timestamp when thread stops sending */
53  uint32_t processed_msgs; /* Number of messages sent/received */
54 };
55 
61 };
62 
63 /* Producer and consumer context */
64 struct fast_path_ctx {
65  struct timespec start_time; /* Start time of send/recv */
66  struct timespec end_time; /* End time of send/recv */
67  uint32_t total_msgs; /* Total messages to send/recv before completing */
68  uint32_t completed_msgs; /* Current number of messages verified as send/received */
69  uint32_t submitted_msgs; /* Total messages submitted but not verified complete (producer only) */
70  enum transfer_state state; /* State the producer/consumer is in */
71 };
72 
73 struct cc_ctx {
74  struct sc_config *cfg; /* Secure Channel configuration */
75  pthread_t *sendto_t; /* Send thread ptr */
76  pthread_t *recvfrom_t; /* Receive thread ptr */
77  struct t_results *send_result; /* Final send thread result */
78  struct t_results *recv_result; /* Final recv thread result */
79 
80  struct doca_comch_connection *comch_connection; /* Comm channel for fast path control */
81  int expected_msgs; /* Total messages consumer expects to receive */
82  int expected_msg_size; /* Size of messages consumer expects to receive */
83  uint32_t consumer_id; /* ID of consumer created at the opposite end on comch_connection */
84 
85  atomic_int active_threads; /* Thread safe counter for detached threads */
86 };
87 
88 enum msg_type {
89  START_MSG, /* Metadata contains information on number of messages */
90  END_MSG, /* Opposite side has completed processing */
91 };
92 
93 /* Initial message sent from both sides to configure the opposite end */
94 struct metadata_msg {
95  enum msg_type type; /* Indicates the type of message sent */
96  uint32_t num_msgs; /* Number of messages producer intends to send */
97  uint32_t msg_size; /* Size of producer messages */
98 };
99 
100 /*
101  * Starts Secure Channel flow
102  *
103  * @comch_cfg [in]: Comch configuration structure
104  * @cfg [in]: App configuration structure
105  * @ctx [in]: Threads context structure
106  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
107  */
108 doca_error_t sc_start(struct comch_cfg *comch_cfg, struct sc_config *cfg, struct cc_ctx *ctx);
109 
110 /*
111  * Registers Secure Channel parameters
112  *
113  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
114  */
116 
117 /*
118  * Callback event for messages on the comch
119  *
120  * In this app the same callback is used for both client and server
121  *
122  * @event [in]: message receive event
123  * @recv_buffer [in]: array of bytes containing the message data
124  * @msg_len [in]: number of bytes in the recv_buffer
125  * @comch_connection [in]: comm channel connection over which the event occurred
126  */
127 void comch_recv_event_cb(struct doca_comch_event_msg_recv *event,
128  uint8_t *recv_buffer,
129  uint32_t msg_len,
130  struct doca_comch_connection *comch_connection);
131 
132 /*
133  * Callback event for new consumers on the comch
134  *
135  * @event [in]: consumer event
136  * @comch_connection [in]: control channel connection associated with the new consumer
137  * @id [in]: id of the consumer (unique to the comch_connection)
138  */
139 void new_consumer_callback(struct doca_comch_event_consumer *event,
140  struct doca_comch_connection *comch_connection,
141  uint32_t id);
142 
143 /*
144  * Callback event for expired consumers on the comch
145  *
146  * @event [in]: consumer event
147  * @comch_connection [in]: control channel connection associated with the expired consumer
148  * @id [in]: id of the consumer (unique to the comch_connection)
149  */
150 void expired_consumer_callback(struct doca_comch_event_consumer *event,
151  struct doca_comch_connection *comch_connection,
152  uint32_t id);
153 
154 #endif /* SECURE_CHANNEL_CORE_H_ */
#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.
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
void comch_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
@ START_MSG
@ END_MSG
void expired_consumer_callback(struct doca_comch_event_consumer *event, struct doca_comch_connection *comch_connection, uint32_t id)
doca_error_t sc_start(struct comch_cfg *comch_cfg, struct sc_config *cfg, struct cc_ctx *ctx)
@ SC_MODE_DPU
@ SC_MODE_HOST
@ FASTPATH_IN_PROGRESS
@ FASTPATH_COMPLETE
@ FASTPATH_ERROR
@ FASTPATH_IDLE
void new_consumer_callback(struct doca_comch_event_consumer *event, struct doca_comch_connection *comch_connection, uint32_t id)
doca_error_t register_secure_channel_params(void)
struct sc_config * cfg
struct t_results * recv_result
int expected_msg_size
struct doca_comch_connection * comch_connection
pthread_t * sendto_t
uint32_t consumer_id
struct t_results * send_result
pthread_t * recvfrom_t
atomic_int active_threads
struct timespec start_time
struct timespec end_time
enum transfer_state state
enum msg_type type
char cc_dev_rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]
enum sc_mode mode
char cc_dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
doca_error_t result
uint32_t processed_msgs
struct timespec start_time
struct timespec end_time
struct upf_accel_ctx * ctx