NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
comch_utils.c
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 #include <doca_ctx.h>
27 #include <doca_error.h>
28 #include <doca_log.h>
29 #include <doca_pe.h>
30 
31 #include <samples/common.h>
32 
33 #include <time.h>
34 
35 #include "comch_utils.h"
36 
37 DOCA_LOG_REGISTER(COMCH_UTILS);
38 
39 #define COMCH_NUM_TASKS 1024 /* Tasks for sending comch messages */
40 #define SLEEP_IN_NANOS (10 * 1000)
41 
42 struct comch_cfg {
43  void *app_user_data; /* User-data supplied by the app */
44  struct doca_pe *pe; /* Progress engine for comch */
45  struct doca_ctx *ctx; /* Doca context of the client/server */
46  union {
47  struct doca_comch_server *server; /* Server context (DPU only) */
48  struct doca_comch_client *client; /* Client context (x86 host only) */
49  };
50  struct doca_comch_connection *active_connection; /* Single connection active on the channel */
51  struct doca_dev *dev; /* Device in use */
52  struct doca_dev_rep *dev_rep; /* Representor in use (DPU only) */
53  uint32_t max_buf_size; /* Maximum size of message on channel */
54  uint8_t is_server; /* Indicator of client or server */
55 };
56 
57 /*
58  * Callback for send completions
59  *
60  * Frees the allocated task that was used for the send
61  *
62  * @task [in]: send task that has completed
63  * @task_user_data [in]: user data of task
64  * @ctx_user_data [in]: user data of doca context
65  */
66 static void comch_send_completion(struct doca_comch_task_send *task,
67  union doca_data task_user_data,
68  union doca_data ctx_user_data)
69 {
70  (void)task_user_data;
71  (void)ctx_user_data;
72 
74 }
75 
76 /*
77  * Callback for send completion error
78  *
79  * Frees the allocated task that was used for the send
80  * Unexpected code path so logs an error
81  *
82  * @task [in]: send task that has completed
83  * @task_user_data [in]: user data of task
84  * @ctx_user_data [in]: user data of doca context
85  */
86 static void comch_send_completion_err(struct doca_comch_task_send *task,
87  union doca_data task_user_data,
88  union doca_data ctx_user_data)
89 {
90  (void)task_user_data;
91  (void)ctx_user_data;
92 
94  DOCA_LOG_ERR("Send Task got a completion error");
95 }
96 
97 /*
98  * Callback for new server connection
99  *
100  * @event [in]: connection event
101  * @comch_connection [in]: doca connection that triggered the event
102  * @change_successful [in]: indicator of change success
103  */
104 static void server_connection_cb(struct doca_comch_event_connection_status_changed *event,
105  struct doca_comch_connection *comch_connection,
106  uint8_t change_successful)
107 {
108  struct doca_comch_server *server = doca_comch_server_get_server_ctx(comch_connection);
109  union doca_data ctx_user_data = {0};
110  struct comch_cfg *comch_cfg;
112 
113  (void)event;
114 
115  if (change_successful == 0) {
116  DOCA_LOG_ERR("Connection event unsuccessful");
117  return;
118  }
119 
121  if (result != DOCA_SUCCESS) {
122  DOCA_LOG_ERR("Failed to get user data from server context: %s", doca_error_get_descr(result));
123  return;
124  }
125 
126  comch_cfg = (struct comch_cfg *)ctx_user_data.ptr;
127  if (comch_cfg == NULL) {
128  DOCA_LOG_ERR("Failed to get configuration from server context");
129  return;
130  }
131 
132  if (comch_cfg->active_connection != NULL) {
133  DOCA_LOG_ERR("A connection already exists on the server - rejecting new attempt");
134  result = doca_comch_server_disconnect(server, comch_connection);
135  if (result != DOCA_SUCCESS)
136  DOCA_LOG_ERR("Failed to properly reject connection");
137  return;
138  }
139 
140  result = doca_comch_connection_set_user_data(comch_connection, ctx_user_data);
141  if (result != DOCA_SUCCESS) {
142  DOCA_LOG_ERR("Failed to set user data on connection: %s", doca_error_get_descr(result));
143  return;
144  }
145 
146  comch_cfg->active_connection = comch_connection;
147 
148  DOCA_LOG_TRC("Server received a new connection");
149 }
150 
151 /*
152  * Callback for server disconnection
153  *
154  * @event [in]: connection event
155  * @comch_connection [in]: doca connection that triggered the event
156  * @change_successful [in]: indicator of change success
157  */
158 static void server_disconnection_cb(struct doca_comch_event_connection_status_changed *event,
159  struct doca_comch_connection *comch_connection,
160  uint8_t change_successful)
161 {
162  struct doca_comch_server *server = doca_comch_server_get_server_ctx(comch_connection);
163  union doca_data ctx_user_data = {0};
164  struct comch_cfg *comch_cfg;
166 
167  (void)event;
168  (void)change_successful;
169 
171  if (result != DOCA_SUCCESS) {
172  DOCA_LOG_ERR("Failed to get user data from server context: %s", doca_error_get_descr(result));
173  return;
174  }
175 
176  comch_cfg = (struct comch_cfg *)ctx_user_data.ptr;
177  if (comch_cfg == NULL) {
178  DOCA_LOG_ERR("Failed to get configuration from server context: %s", doca_error_get_descr(result));
179  return;
180  }
181 
183 
184  DOCA_LOG_TRC("Server received a client disconnection");
185 }
186 
187 /*
188  * Extract the comch_cfg data from a connection
189  *
190  * @connection [in]: connection to extract comch_cfg from
191  * @return: pointer to the comch_cfg object
192  */
193 static inline struct comch_cfg *get_comch_cfg_from_connection(struct doca_comch_connection *connection)
194 {
195  union doca_data connection_user_data;
196  struct comch_cfg *comch_cfg;
197 
198  if (connection == NULL) {
199  DOCA_LOG_ERR("Connection is NULL");
200  return NULL;
201  }
202 
203  connection_user_data = doca_comch_connection_get_user_data(connection);
204  comch_cfg = connection_user_data.ptr;
205 
206  if (comch_cfg == NULL)
207  DOCA_LOG_ERR("Failed to get user data from connection");
208 
209  return comch_cfg;
210 }
211 
212 doca_error_t comch_utils_send(struct doca_comch_connection *connection, const void *msg, uint32_t len)
213 {
214  struct comch_cfg *comch_cfg = get_comch_cfg_from_connection(connection);
215  struct doca_comch_task_send *task;
217 
218  if (comch_cfg == NULL)
219  return DOCA_ERROR_NOT_FOUND;
220 
221  if (len > comch_cfg->max_buf_size) {
222  DOCA_LOG_ERR("Message length of %u larger than max comch length of %u", len, comch_cfg->max_buf_size);
224  }
225 
226  if (comch_cfg->is_server)
228  else
230 
231  /*
232  * QP depths match the number of tasks so if a task can be allocated then there must be a space to send.
233  * Return AGAIN if a task can not be allocated telling the application to progress and retry.
234  * Assuming a task can be allocated it will only fail to send if there is a more serious error.
235  */
237  return DOCA_ERROR_AGAIN;
238 
239  if (result != DOCA_SUCCESS) {
240  DOCA_LOG_ERR("Failed to allocate send task: %s", doca_error_get_descr(result));
241  return result;
242  }
243 
245  if (result != DOCA_SUCCESS) {
247  DOCA_LOG_ERR("Failed to submit send task: %s", doca_error_get_descr(result));
248  return result;
249  }
250 
251  return DOCA_SUCCESS;
252 }
253 
254 void *comch_utils_get_user_data(struct doca_comch_connection *connection)
255 {
256  struct comch_cfg *comch_cfg = get_comch_cfg_from_connection(connection);
257 
258  if (comch_cfg == NULL)
259  return NULL;
260 
261  return comch_cfg->app_user_data;
262 }
263 
264 doca_error_t comch_utils_progress_connection(struct doca_comch_connection *connection)
265 {
266  struct comch_cfg *comch_cfg = get_comch_cfg_from_connection(connection);
267 
268  if (comch_cfg == NULL)
270 
271  (void)doca_pe_progress(comch_cfg->pe);
272 
273  return DOCA_SUCCESS;
274 }
275 
276 struct doca_comch_connection *comch_util_get_connection(struct comch_cfg *comch_cfg)
277 {
278  if (comch_cfg == NULL) {
279  DOCA_LOG_ERR("Configuration object is NULL");
280  return NULL;
281  }
282 
284 }
285 
287 {
288  if (comch_cfg == NULL) {
289  DOCA_LOG_ERR("Configuration object is NULL");
290  return 0;
291  }
292 
293  return comch_cfg->max_buf_size;
294 }
295 
296 doca_error_t comch_utils_fast_path_init(const char *server_name,
297  const char *pci_addr,
298  const char *rep_pci_addr,
299  void *user_data,
302  doca_comch_event_consumer_cb_t new_consumer_event_cb,
303  doca_comch_event_consumer_cb_t expired_consumer_event_cb,
304  struct comch_cfg **comch_cfg)
305 {
306  enum doca_ctx_states state;
307  union doca_data comch_user_data = {0};
308  struct timespec ts = {
309  .tv_nsec = SLEEP_IN_NANOS,
310  };
311  struct comch_cfg *cfg;
313 
314  if (server_name == NULL) {
315  DOCA_LOG_ERR("Init: server name is NULL");
317  }
318 
319  if (pci_addr == NULL) {
320  DOCA_LOG_ERR("Init: PCIe address is NULL");
322  }
323 
324  if (comch_cfg == NULL) {
325  DOCA_LOG_ERR("Init: configuration object is NULL");
327  }
328 
329 #ifdef DOCA_ARCH_DPU
330  if (rep_pci_addr == NULL) {
331  DOCA_LOG_ERR("Init: repr PCIe is NULL");
333  }
334 
335  if (server_recv_event_cb == NULL) {
336  DOCA_LOG_ERR("Init: server recv event callback is NULL");
338  }
339 #else
340  if (client_recv_event_cb == NULL) {
341  DOCA_LOG_ERR("Init: server recv event callback is NULL");
343  }
344 #endif
345 
346  cfg = (struct comch_cfg *)calloc(1, sizeof(struct comch_cfg));
347  if (cfg == NULL) {
348  DOCA_LOG_ERR("Failed to comch configuration data");
349  return DOCA_ERROR_NO_MEMORY;
350  }
351 
352 #ifdef DOCA_ARCH_DPU
353  cfg->is_server = 1;
354 #endif
355 
356  cfg->app_user_data = user_data;
357  comch_user_data.ptr = cfg;
358 
359  result = doca_pe_create(&cfg->pe);
360  if (result != DOCA_SUCCESS) {
361  DOCA_LOG_ERR("Failed to create comch progress engine: %s", doca_error_get_descr(result));
362  goto destroy_comch_cfg;
363  }
364 
365  result = open_doca_device_with_pci(pci_addr, NULL, &cfg->dev);
366  if (result != DOCA_SUCCESS) {
367  DOCA_LOG_ERR("Failed to open Comm Channel DOCA device based on PCI address: %s",
369  goto destroy_pe;
370  }
371 
373  if (result != DOCA_SUCCESS) {
374  DOCA_LOG_ERR("Failed to get comch max buffer size: %s", doca_error_get_descr(result));
375  goto close_device;
376  }
377 
378  if (cfg->is_server) {
380  if (result != DOCA_SUCCESS) {
381  DOCA_LOG_ERR("Doca device does not support comch server: %s", doca_error_get_descr(result));
382  goto close_device;
383  }
384 
387  rep_pci_addr,
388  &cfg->dev_rep);
389  if (result != DOCA_SUCCESS) {
390  DOCA_LOG_ERR("Failed to open Comm Channel DOCA device representor based on PCI address: %s",
392  goto close_device;
393  }
394 
395  result = doca_comch_server_create(cfg->dev, cfg->dev_rep, server_name, &cfg->server);
396  if (result != DOCA_SUCCESS) {
397  DOCA_LOG_ERR("Failed to create comch server: %s", doca_error_get_descr(result));
398  goto close_rep_device;
399  }
400 
401  result = doca_comch_server_set_max_msg_size(cfg->server, cfg->max_buf_size);
402  if (result != DOCA_SUCCESS) {
403  DOCA_LOG_ERR("Failed set max message size of server: %s", doca_error_get_descr(result));
404  goto destroy_comch_ep;
405  }
406 
407  cfg->ctx = doca_comch_server_as_ctx(cfg->server);
408 
409  result = doca_pe_connect_ctx(cfg->pe, cfg->ctx);
410  if (result != DOCA_SUCCESS) {
411  DOCA_LOG_ERR("Failed to connect comch server context to progress engine: %s",
413  goto destroy_comch_ep;
414  }
415 
420  if (result != DOCA_SUCCESS) {
421  DOCA_LOG_ERR("Failed to configure server task pool: %s", doca_error_get_descr(result));
422  goto destroy_comch_ep;
423  }
424 
426  if (result != DOCA_SUCCESS) {
427  DOCA_LOG_ERR("Failed to register comch server receive event callback: %s",
429  goto destroy_comch_ep;
430  }
431 
435  if (result != DOCA_SUCCESS) {
436  DOCA_LOG_ERR("Failed to register comch server event callback: %s",
438  goto destroy_comch_ep;
439  }
440 
441  /* Only set consumer events if app is interesting in fast path */
442  if (new_consumer_event_cb != NULL || expired_consumer_event_cb != NULL) {
443  /* Both callbacks must be non NULL for function to succeed */
445  new_consumer_event_cb,
446  expired_consumer_event_cb);
447  if (result != DOCA_SUCCESS) {
448  DOCA_LOG_ERR("Failed to register comch server consumer callback: %s",
450  goto destroy_comch_ep;
451  }
452  }
453 
454  doca_ctx_set_user_data(cfg->ctx, comch_user_data);
455 
456  cfg->active_connection = NULL;
457 
458  result = doca_ctx_start(cfg->ctx);
459  if (result != DOCA_SUCCESS) {
460  DOCA_LOG_ERR("Failed to start comch server context: %s", doca_error_get_descr(result));
461  goto destroy_comch_ep;
462  }
463 
464  DOCA_LOG_INFO("Server waiting on a client to connect");
465 
466  /* Connection will be populated when a single client connects */
467  while (cfg->active_connection == NULL) {
468  (void)doca_pe_progress(cfg->pe);
469  nanosleep(&ts, &ts);
470  }
471 
472  DOCA_LOG_INFO("Server connection established");
473 
474  } else {
476  if (result != DOCA_SUCCESS) {
477  DOCA_LOG_ERR("Doca device does not support comch client: %s", doca_error_get_descr(result));
478  goto close_device;
479  }
480 
481  result = doca_comch_client_create(cfg->dev, server_name, &cfg->client);
482  if (result != DOCA_SUCCESS) {
483  DOCA_LOG_ERR("Failed to create comch client: %s", doca_error_get_descr(result));
484  goto close_device;
485  }
486 
487  result = doca_comch_client_set_max_msg_size(cfg->client, cfg->max_buf_size);
488  if (result != DOCA_SUCCESS) {
489  DOCA_LOG_ERR("Failed set max message size of client: %s", doca_error_get_descr(result));
490  goto destroy_comch_ep;
491  }
492 
493  cfg->ctx = doca_comch_client_as_ctx(cfg->client);
494 
495  result = doca_pe_connect_ctx(cfg->pe, cfg->ctx);
496  if (result != DOCA_SUCCESS) {
497  DOCA_LOG_ERR("Failed to connect comch client context to progress engine: %s",
499  goto destroy_comch_ep;
500  }
501 
506  if (result != DOCA_SUCCESS) {
507  DOCA_LOG_ERR("Failed to configure client task pool: %s", doca_error_get_descr(result));
508  goto destroy_comch_ep;
509  }
510 
512  if (result != DOCA_SUCCESS) {
513  DOCA_LOG_ERR("Failed to register comch client receive event callback: %s",
515  goto destroy_comch_ep;
516  }
517 
518  /* Only set consumer events if app is interesting in fast path */
519  if (new_consumer_event_cb != NULL || expired_consumer_event_cb != NULL) {
520  /* Both callbacks must be non NULL for function to succeed */
522  new_consumer_event_cb,
523  expired_consumer_event_cb);
524  if (result != DOCA_SUCCESS) {
525  DOCA_LOG_ERR("Failed to register comch client consumer callback: %s",
527  goto destroy_comch_ep;
528  }
529  }
530 
531  doca_ctx_set_user_data(cfg->ctx, comch_user_data);
532 
533  result = doca_ctx_start(cfg->ctx);
535  DOCA_LOG_ERR("Failed to start comch client context: %s", doca_error_get_descr(result));
536  goto destroy_comch_ep;
537  }
538 
539  /* Wait for client/server handshake to complete */
540  (void)doca_ctx_get_state(cfg->ctx, &state);
541  while (state != DOCA_CTX_STATE_RUNNING) {
542  (void)doca_pe_progress(cfg->pe);
543  nanosleep(&ts, &ts);
544  (void)doca_ctx_get_state(cfg->ctx, &state);
545  }
546 
547  (void)doca_comch_client_get_connection(cfg->client, &cfg->active_connection);
548  doca_comch_connection_set_user_data(cfg->active_connection, comch_user_data);
549  }
550 
551  *comch_cfg = cfg;
552 
553  return DOCA_SUCCESS;
554 
555 destroy_comch_ep:
556  if (cfg->is_server)
558  else
560 close_rep_device:
561  if (cfg->is_server)
562  doca_dev_rep_close(cfg->dev_rep);
563 close_device:
564  doca_dev_close(cfg->dev);
565 destroy_pe:
566  doca_pe_destroy(cfg->pe);
567 destroy_comch_cfg:
568  free(cfg);
569 
570  return result;
571 }
572 
573 doca_error_t comch_utils_init(const char *server_name,
574  const char *pci_addr,
575  const char *rep_pci_addr,
576  void *user_data,
579  struct comch_cfg **comch_cfg)
580 {
581  return comch_utils_fast_path_init(server_name,
582  pci_addr,
583  rep_pci_addr,
584  user_data,
587  NULL,
588  NULL,
589  comch_cfg);
590 }
591 
593 {
594  enum doca_ctx_states state;
595  struct timespec ts = {
596  .tv_nsec = SLEEP_IN_NANOS,
597  };
599 
600  if (comch_cfg->is_server) {
601  /* Wait until the client has closed the connection to end gracefully */
602  while (comch_cfg->active_connection != NULL) {
603  (void)doca_pe_progress(comch_cfg->pe);
604  nanosleep(&ts, &ts);
605  }
606  }
607 
610  DOCA_LOG_ERR("Failed to stop comch ctx: %s", doca_error_get_descr(result));
611  return result;
612  }
613 
614  (void)doca_ctx_get_state(comch_cfg->ctx, &state);
615  while (state != DOCA_CTX_STATE_IDLE) {
616  (void)doca_pe_progress(comch_cfg->pe);
617  nanosleep(&ts, &ts);
618  (void)doca_ctx_get_state(comch_cfg->ctx, &state);
619  }
620 
621  if (comch_cfg->is_server) {
623  if (result != DOCA_SUCCESS) {
624  DOCA_LOG_ERR("Failed to destroy server: %s", doca_error_get_descr(result));
625  return result;
626  }
627 
629  if (result != DOCA_SUCCESS) {
630  DOCA_LOG_ERR("Failed to close device representor: %s", doca_error_get_descr(result));
631  return result;
632  }
633  } else {
635  if (result != DOCA_SUCCESS) {
636  DOCA_LOG_ERR("Failed to destroy client: %s", doca_error_get_descr(result));
637  return result;
638  }
639  }
640 
642  if (result != DOCA_SUCCESS) {
643  DOCA_LOG_ERR("Failed to close device: %s", doca_error_get_descr(result));
644  return result;
645  }
646 
648  if (result != DOCA_SUCCESS) {
649  DOCA_LOG_ERR("Failed to destroy progress engine: %s", doca_error_get_descr(result));
650  return result;
651  }
652 
653  free(comch_cfg);
654 
655  return DOCA_SUCCESS;
656 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
void * comch_utils_get_user_data(struct doca_comch_connection *connection)
Definition: comch_utils.c:254
static void comch_send_completion_err(struct doca_comch_task_send *task, union doca_data task_user_data, union doca_data ctx_user_data)
Definition: comch_utils.c:86
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_LOG_REGISTER(COMCH_UTILS)
static void server_connection_cb(struct doca_comch_event_connection_status_changed *event, struct doca_comch_connection *comch_connection, uint8_t change_successful)
Definition: comch_utils.c:104
static struct comch_cfg * get_comch_cfg_from_connection(struct doca_comch_connection *connection)
Definition: comch_utils.c:193
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
#define COMCH_NUM_TASKS
Definition: comch_utils.c:39
static void server_disconnection_cb(struct doca_comch_event_connection_status_changed *event, struct doca_comch_connection *comch_connection, uint8_t change_successful)
Definition: comch_utils.c:158
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
#define SLEEP_IN_NANOS
Definition: comch_utils.c:40
static void comch_send_completion(struct doca_comch_task_send *task, union doca_data task_user_data, union doca_data ctx_user_data)
Definition: comch_utils.c:66
doca_error_t open_doca_device_rep_with_pci(struct doca_dev *local, enum doca_devinfo_rep_filter filter, const char *pci_addr, struct doca_dev_rep **retval)
Definition: common.c:267
static doca_error_t open_doca_device_with_pci(const char *pcie_value, struct doca_dev **retval)
Definition: device.c:43
uint64_t len
if(bitoffset % 64+bitlength > 64) result|
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)
DOCA_STABLE doca_error_t doca_comch_client_set_max_msg_size(struct doca_comch_client *comch_client, uint32_t size)
DOCA_STABLE doca_error_t doca_comch_client_get_connection(const struct doca_comch_client *comch_client, struct doca_comch_connection **connection)
DOCA_STABLE struct doca_comch_server * doca_comch_server_get_server_ctx(const struct doca_comch_connection *connection)
DOCA_STABLE doca_error_t doca_comch_server_event_msg_recv_register(struct doca_comch_server *comch_server, doca_comch_event_msg_recv_cb_t recv_event_cb)
Configure the doca_comch recv event callback for server context.
DOCA_STABLE doca_error_t doca_comch_server_event_connection_status_changed_register(struct doca_comch_server *comch_server, doca_comch_event_connection_status_changed_cb_t connect_event_cb, doca_comch_event_connection_status_changed_cb_t disconnect_event_cb)
Configure the doca_comch recv event callback for server context.
DOCA_STABLE doca_error_t doca_comch_client_event_consumer_register(struct doca_comch_client *comch_client, doca_comch_event_consumer_cb_t new_consumer_event_cb, doca_comch_event_consumer_cb_t expired_consumer_event_cb)
Configure the doca_comch callback for for receiving consumer events on client context.
DOCA_STABLE doca_error_t doca_comch_connection_set_user_data(struct doca_comch_connection *connection, union doca_data user_data)
DOCA_STABLE union doca_data doca_comch_connection_get_user_data(const struct doca_comch_connection *connection)
DOCA_STABLE struct doca_ctx * doca_comch_client_as_ctx(struct doca_comch_client *comch_client)
DOCA_STABLE doca_error_t doca_comch_server_event_consumer_register(struct doca_comch_server *comch_server, doca_comch_event_consumer_cb_t new_consumer_event_cb, doca_comch_event_consumer_cb_t expired_consumer_event_cb)
Configure the doca_comch callback for for receiving consumer events on server context.
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
DOCA_STABLE doca_error_t doca_comch_client_task_send_alloc_init(struct doca_comch_client *comch_client, struct doca_comch_connection *peer, const void *msg, uint32_t len, struct doca_comch_task_send **task)
DOCA_STABLE doca_error_t doca_comch_cap_get_max_msg_size(const struct doca_devinfo *devinfo, uint32_t *size)
DOCA_STABLE doca_error_t doca_comch_server_destroy(struct doca_comch_server *comch_server)
DOCA_STABLE doca_error_t doca_comch_cap_client_is_supported(const struct doca_devinfo *devinfo)
DOCA_STABLE doca_error_t doca_comch_server_task_send_set_conf(struct doca_comch_server *comch_server, doca_comch_task_send_completion_cb_t task_completion_cb, doca_comch_task_send_completion_cb_t task_error_cb, uint32_t num_send_tasks)
DOCA_STABLE doca_error_t doca_comch_client_task_send_set_conf(struct doca_comch_client *comch_client, doca_comch_task_send_completion_cb_t task_completion_cb, doca_comch_task_send_completion_cb_t task_error_cb, uint32_t num_send_tasks)
DOCA_STABLE doca_error_t doca_comch_client_event_msg_recv_register(struct doca_comch_client *comch_client, doca_comch_event_msg_recv_cb_t recv_event_cb)
Configure the doca_comch recv event callback for client context.
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
DOCA_STABLE doca_error_t doca_comch_client_destroy(struct doca_comch_client *comch_client)
DOCA_STABLE doca_error_t doca_comch_server_create(struct doca_dev *dev, struct doca_dev_rep *repr, const char *name, struct doca_comch_server **comch_server)
DOCA_STABLE struct doca_task * doca_comch_task_send_as_task(struct doca_comch_task_send *task)
DOCA_STABLE doca_error_t doca_comch_server_set_max_msg_size(struct doca_comch_server *comch_server, uint32_t size)
DOCA_STABLE doca_error_t doca_comch_cap_server_is_supported(const struct doca_devinfo *devinfo)
DOCA_STABLE doca_error_t doca_comch_client_create(struct doca_dev *dev, const char *name, struct doca_comch_client **comch_client)
DOCA_STABLE doca_error_t doca_comch_server_task_send_alloc_init(struct doca_comch_server *comch_server, struct doca_comch_connection *peer, const void *msg, uint32_t len, struct doca_comch_task_send **task)
DOCA_STABLE struct doca_ctx * doca_comch_server_as_ctx(struct doca_comch_server *comch_server)
DOCA_STABLE doca_error_t doca_comch_server_disconnect(struct doca_comch_server *comch_server, struct doca_comch_connection *connection)
DOCA_STABLE doca_error_t doca_ctx_start(struct doca_ctx *ctx)
Finalizes all configurations, and starts the DOCA CTX.
DOCA_STABLE doca_error_t doca_ctx_get_state(const struct doca_ctx *ctx, enum doca_ctx_states *state)
Get context state.
DOCA_STABLE doca_error_t doca_ctx_set_user_data(struct doca_ctx *ctx, union doca_data user_data)
set user data to context
DOCA_STABLE doca_error_t doca_ctx_stop(struct doca_ctx *ctx)
Stops the context allowing reconfiguration.
doca_ctx_states
This enum defines the states of a context.
Definition: doca_ctx.h:83
DOCA_STABLE doca_error_t doca_ctx_get_user_data(const struct doca_ctx *ctx, union doca_data *user_data)
get user data from context
@ DOCA_CTX_STATE_IDLE
Definition: doca_ctx.h:88
@ DOCA_CTX_STATE_RUNNING
Definition: doca_ctx.h:98
DOCA_STABLE doca_error_t doca_dev_rep_close(struct doca_dev_rep *dev)
Destroy allocated representor device instance.
DOCA_STABLE struct doca_devinfo * doca_dev_as_devinfo(const struct doca_dev *dev)
Get local device info from device. This should be useful when wanting to query information about devi...
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
@ DOCA_DEVINFO_REP_FILTER_NET
Definition: doca_dev.h:67
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_INVALID_VALUE
Definition: doca_error.h:44
@ DOCA_ERROR_NOT_FOUND
Definition: doca_error.h:54
@ DOCA_ERROR_AGAIN
Definition: doca_error.h:43
@ DOCA_SUCCESS
Definition: doca_error.h:38
@ DOCA_ERROR_NO_MEMORY
Definition: doca_error.h:45
@ DOCA_ERROR_IN_PROGRESS
Definition: doca_error.h:64
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
#define DOCA_LOG_TRC(format,...)
Generates a TRACE application log message.
Definition: doca_log.h:513
DOCA_STABLE doca_error_t doca_pe_destroy(struct doca_pe *pe)
Destroy doca progress engine.
DOCA_STABLE doca_error_t doca_pe_connect_ctx(struct doca_pe *pe, struct doca_ctx *ctx)
This method connects a context to a progress engine.
DOCA_STABLE doca_error_t doca_task_submit(struct doca_task *task)
Submit a task to a progress engine.
DOCA_STABLE uint8_t doca_pe_progress(struct doca_pe *pe)
Run the progress engine.
DOCA_STABLE doca_error_t doca_pe_create(struct doca_pe **pe)
Creates DOCA progress engine.
DOCA_STABLE void doca_task_free(struct doca_task *task)
Free a task back to where it was allocated from.
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
uint8_t is_server
Definition: comch_utils.c:54
struct doca_dev_rep * dev_rep
Definition: comch_utils.c:52
uint32_t max_buf_size
Definition: comch_utils.c:53
struct doca_ctx * ctx
Definition: comch_utils.c:45
struct doca_comch_connection * active_connection
Definition: comch_utils.c:50
struct doca_pe * pe
Definition: comch_utils.c:44
struct doca_comch_client * client
Definition: comch_utils.c:48
struct doca_dev * dev
Definition: comch_utils.c:51
struct doca_comch_server * server
Definition: comch_utils.c:47
void * app_user_data
Definition: comch_utils.c:43
Convenience type for representing opaque data.
Definition: doca_types.h:56
void * ptr
Definition: doca_types.h:57