NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
comch_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 COMCH_UTILS_H_
27 #define COMCH_UTILS_H_
28 
29 #include <stdio.h>
30 #include <stdint.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 
34 #include <doca_comch.h>
35 
36 struct comch_cfg;
37 
38 /*
39  * Set up a new comch channel for control messages
40  *
41  * This should only be used when a single client is connecting to a single server
42  * Attempts to handle multiple connections to a server will fail or have undefined behavior
43  * Success occurs when a server has a client connected, or a client is successfully connected to a server
44  *
45  * @server_name [in]: name for server to use or client to connect to
46  * @pci_addr [in]: PCI address of device to use
47  * @rep_pci_addr [in]: Repr address to use (server/DPU side only)
48  * @user_data [in]: app user data that can be returned from a connection event
49  * @client_recv_event_cb [in]: callback for new messages on client (client side only)
50  * @server_recv_event_cb [in]: callback for new messages on server (server side only)
51  * @comch_cfg [out]: comch utils configuration object
52  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
53  */
54 doca_error_t comch_utils_init(const char *server_name,
55  const char *pci_addr,
56  const char *rep_pci_addr,
57  void *user_data,
60  struct comch_cfg **comch_cfg);
61 
62 /*
63  * Set up a new comch channel for control messages and fast path
64  *
65  * This should only be used when a single client is connecting to a single server
66  * Attempts to handle multiple connections to a server will fail or have undefined behavior
67  * Success occurs when a server has a client connected, or a client is successfully connected to a server
68  *
69  * This function extends comch_utils_init() to add callbacks for new consumers generated on the opposite end of the
70  * single doca_comch_connection that is created.
71  *
72  * @server_name [in]: name for server to use or client to connect to
73  * @pci_addr [in]: PCI address of device to use
74  * @rep_pci_addr [in]: Repr address to use (server/DPU side only)
75  * @user_data [in]: app user data that can be returned from a connection event
76  * @client_recv_event_cb [in]: callback for new messages on client (client side only)
77  * @server_recv_event_cb [in]: callback for new messages on server (server side only)
78  * @new_consumer_event_cb [in]: callback for new consumers created across the connection (client and server side)
79  * @expired_consumer_event_cb [in]: callback for expired consumers on the connection (client and server side)
80  * @comch_cfg [out]: comch utils configuration object
81  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
82  */
83 doca_error_t comch_utils_fast_path_init(const char *server_name,
84  const char *pci_addr,
85  const char *rep_pci_addr,
86  void *user_data,
89  doca_comch_event_consumer_cb_t new_consumer_event_cb,
90  doca_comch_event_consumer_cb_t expired_consumer_event_cb,
91  struct comch_cfg **comch_cfg);
92 
93 /*
94  * Tear down the comch created with init_comch
95  *
96  * The server side waits until the client has complete before exiting
97  *
98  * @comch_cfg [in]: pointer to comch utils configuration object to destroy
99  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
100  */
102 
103 /*
104  * Send a message across a given connection
105  *
106  * The connection must have been created via comch_utils_init.
107  * Connection is returned with the receive event callback.
108  * Connection can be extracted from configuration object using comch_util_get_connection().
109  * Caller must ensure there is a free task for success.
110  *
111  * @connection [in]: connection to send message across
112  * @msg [in]: message to send on connection channel
113  * @len [in]: length of message to send
114  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
115  */
116 doca_error_t comch_utils_send(struct doca_comch_connection *connection, const void *msg, uint32_t len);
117 
118 /*
119  * Return the user_data passed to comch_utils_init from a connection object
120  *
121  * @connection [in]: pointer to connection object
122  * @return: pointer to the user_data
123  */
124 void *comch_utils_get_user_data(struct doca_comch_connection *connection);
125 
126 /*
127  * Call progress on the client/server associated with a given connection
128  *
129  * @connection [in]: pointer to connection object
130  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
131  */
132 doca_error_t comch_utils_progress_connection(struct doca_comch_connection *connection);
133 
134 /*
135  * Get the connection associated with a comch utils configuration object
136  *
137  * Comch utils only supports one connection per server
138  *
139  * @comch_cfg [in]: pointer to comch utils configuration object
140  * @return: pointer to associated connection
141  */
142 struct doca_comch_connection *comch_util_get_connection(struct comch_cfg *comch_cfg);
143 
144 /*
145  * Get the maximum buffer size the configured comch client/server supports
146  *
147  * This max size is configured to the max supported.
148  *
149  * @comch_cfg [in]: pointer to comch utils configuration object
150  * @return: maximum buffer size supported
151  */
153 
154 #endif /* COMCH_UTILS_H_ */
void * comch_utils_get_user_data(struct doca_comch_connection *connection)
Definition: comch_utils.c:254
doca_error_t comch_utils_fast_path_init(const char *server_name, const char *pci_addr, const char *rep_pci_addr, void *user_data, doca_comch_event_msg_recv_cb_t client_recv_event_cb, doca_comch_event_msg_recv_cb_t server_recv_event_cb, doca_comch_event_consumer_cb_t new_consumer_event_cb, doca_comch_event_consumer_cb_t expired_consumer_event_cb, struct comch_cfg **comch_cfg)
Definition: comch_utils.c:296
doca_error_t comch_utils_progress_connection(struct doca_comch_connection *connection)
Definition: comch_utils.c:264
doca_error_t comch_utils_destroy(struct comch_cfg *comch_cfg)
Definition: comch_utils.c:592
struct doca_comch_connection * comch_util_get_connection(struct comch_cfg *comch_cfg)
Definition: comch_utils.c:276
doca_error_t comch_utils_init(const char *server_name, const char *pci_addr, const char *rep_pci_addr, void *user_data, doca_comch_event_msg_recv_cb_t client_recv_event_cb, doca_comch_event_msg_recv_cb_t server_recv_event_cb, struct comch_cfg **comch_cfg)
Definition: comch_utils.c:573
doca_error_t comch_utils_send(struct doca_comch_connection *connection, const void *msg, uint32_t len)
Definition: comch_utils.c:212
uint32_t comch_utils_get_max_buffer_size(struct comch_cfg *comch_cfg)
Definition: comch_utils.c:286
uint64_t len
void server_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
void client_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
void(* doca_comch_event_consumer_cb_t)(struct doca_comch_event_consumer *event, struct doca_comch_connection *comch_connection, uint32_t id)
Definition: doca_comch.h:874
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
enum doca_error doca_error_t
DOCA API return codes.