NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
comch_data_path_high_speed_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 COMCH_DATA_PATH_HIGH_SPEED_COMMON_H_
27 #define COMCH_DATA_PATH_HIGH_SPEED_COMMON_H_
28 
29 #include <doca_buf_inventory.h>
30 #include <doca_comch.h>
31 #include <doca_comch_consumer.h>
32 #include <doca_comch_producer.h>
33 #include <doca_dev.h>
34 #include <doca_error.h>
35 #include <doca_mmap.h>
36 #include <doca_pe.h>
37 
38 #define CC_DATA_PATH_TASK_NUM 2 /* Maximum amount of CC consumer and producer task number */
39 #define CC_DATA_PATH_MAX_MSG_SIZE (1024 * 1024) /* CC DATA PATH maximum message size */
40 
41 #define STR_START_DATA_PATH_TEST "start_data_path_test" /* The negotiation message between client and server */
42 #define STR_STOP_DATA_PATH_TEST "stop_data_path_test" /* The negotiation message between client and server */
43 
44 #define INVALID_CONSUMER_ID 0xffff
45 
47  void *mem; /* Memory address for DOCA buf mmap */
48  struct doca_mmap *mmap; /* DOCA mmap object */
49  struct doca_buf_inventory *buf_inv; /* DOCA buf inventory object */
50  bool need_alloc_mem; /* Whether need to allocate memory */
51 };
52 
54  /* User specified callback when task completed successfully */
56  /* User specified callback when task completed with error */
58  /* User specified context data */
60  /* User specified PE context state changed event callback */
62 };
63 
65  /* User specified callback when task completed successfully */
67  /* User specified callback when task completed with error */
69  /* User specified context data */
71  /* User specified PE context state changed event callback */
73 };
74 
76  struct doca_dev *hw_dev; /* Device used in the data path */
77  struct doca_pe *pe; /* Connection PE object used in the sample */
78  struct doca_comch_connection *connection; /* CC connection object used in the sample */
79  struct doca_comch_consumer *consumer; /* CC consumer object used in the sample */
80  struct doca_pe *consumer_pe; /* CC consumer's PE object used in the sample */
81  struct local_mem_bufs consumer_mem; /* Mmap and DOCA buf objects for consumer */
82  struct doca_comch_producer *producer; /* CC producer object used in the sample */
83  struct doca_pe *producer_pe; /* CC producer's PE object used in the sample */
84  struct local_mem_bufs producer_mem; /* Mmap and DOCA buf objects for producer */
85  uint32_t remote_consumer_id; /* Consumer ID on the peer side */
86  const char *text; /* Message to send to the server */
87  doca_error_t producer_result; /* Holds result will be updated in producer callbacks */
88  bool producer_finish; /* Controls whether producer progress loop should be run */
89  doca_error_t consumer_result; /* Holds result will be updated in consumer callbacks */
90  bool consumer_finish; /* Controls whether consumer progress loop should be run */
91 };
92 
98 void clean_local_mem_bufs(struct local_mem_bufs *local);
99 
109 doca_error_t init_local_mem_bufs(struct local_mem_bufs *local, struct doca_dev *dev, size_t buf_len, size_t max_bufs);
110 
117 void clean_comch_producer(struct doca_comch_producer *producer, struct doca_pe *pe);
118 
128 doca_error_t init_comch_producer(struct doca_comch_connection *connection,
129  struct comch_producer_cb_config *cb_cfg,
130  struct doca_comch_producer **producer,
131  struct doca_pe **pe);
132 
139 void clean_comch_consumer(struct doca_comch_consumer *consumer, struct doca_pe *pe);
140 
151 doca_error_t init_comch_consumer(struct doca_comch_connection *connection,
152  struct doca_mmap *user_mmap,
153  struct comch_consumer_cb_config *cb_cfg,
154  struct doca_comch_consumer **consumer,
155  struct doca_pe **pe);
156 
164 
172 
173 #endif // COMCH_DATA_PATH_HIGH_SPEED_COMMON_H_
void clean_comch_producer(struct doca_comch_producer *producer, struct doca_pe *pe)
doca_error_t init_local_mem_bufs(struct local_mem_bufs *local, struct doca_dev *dev, size_t buf_len, size_t max_bufs)
doca_error_t init_comch_producer(struct doca_comch_connection *connection, struct comch_producer_cb_config *cb_cfg, struct doca_comch_producer **producer, struct doca_pe **pe)
doca_error_t init_comch_consumer(struct doca_comch_connection *connection, struct doca_mmap *user_mmap, struct comch_consumer_cb_config *cb_cfg, struct doca_comch_consumer **consumer, struct doca_pe **pe)
void clean_comch_consumer(struct doca_comch_consumer *consumer, struct doca_pe *pe)
void clean_local_mem_bufs(struct local_mem_bufs *local)
doca_error_t comch_data_path_send_msg(struct comch_data_path_objects *data_path)
doca_error_t comch_data_path_recv_msg(struct comch_data_path_objects *data_path)
static struct doca_pe * pe
void(* doca_comch_consumer_task_post_recv_completion_cb_t)(struct doca_comch_consumer_task_post_recv *task, union doca_data task_user_data, union doca_data ctx_user_data)
void(* doca_comch_producer_task_send_completion_cb_t)(struct doca_comch_producer_task_send *task, union doca_data task_user_data, union doca_data ctx_user_data)
void(* doca_ctx_state_changed_callback_t)(const union doca_data user_data, struct doca_ctx *ctx, enum doca_ctx_states prev_state, enum doca_ctx_states next_state)
Function to execute on context state change.
Definition: doca_ctx.h:123
enum doca_error doca_error_t
DOCA API return codes.
doca_comch_consumer_task_post_recv_completion_cb_t recv_task_comp_cb
doca_comch_consumer_task_post_recv_completion_cb_t recv_task_comp_err_cb
doca_ctx_state_changed_callback_t ctx_state_changed_cb
struct doca_comch_consumer * consumer
struct doca_comch_producer * producer
struct doca_comch_connection * connection
doca_ctx_state_changed_callback_t ctx_state_changed_cb
doca_comch_producer_task_send_completion_cb_t send_task_comp_err_cb
doca_comch_producer_task_send_completion_cb_t send_task_comp_cb
struct doca_buf_inventory * buf_inv