NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
sha_partial_create_sample.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 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 <string.h>
27 #include <stdbool.h>
28 #include <stdlib.h>
29 #include <time.h>
30 #include <unistd.h>
31 
32 #include <doca_buf.h>
33 #include <doca_buf_inventory.h>
34 #include <doca_ctx.h>
35 #include <doca_mmap.h>
36 #include <doca_pe.h>
37 #include <doca_error.h>
38 #include <doca_log.h>
39 #include <doca_sha.h>
40 
41 #include "common.h"
42 
43 DOCA_LOG_REGISTER(SHA_PARTIAL_CREATE);
44 
45 #define SLEEP_IN_NANOS (10 * 1000) /* Sample the task every 10 microseconds */
46 #define LOG_NUM_PARTIAL_SHA_TASKS (0) /* Log of SHA tasks number */
47 #define SHA_SAMPLE_ALGORITHM (DOCA_SHA_ALGORITHM_SHA256) /* doca_sha_algorithm for the sample */
48 
49 struct sha_resources {
50  struct program_core_objects state; /* Core objects that manage our "state" */
51  struct doca_sha *sha_ctx; /* DOCA SHA context */
52  struct doca_buf *src_doca_buf; /* Source buffer as a DOCA Buffer */
53  void *src_buffer; /* Source buffer as a C pointer */
54  size_t remaining_src_len; /* Remaining bytes in source buffer */
55  uint32_t partial_block_size; /* SHA block size */
56  doca_error_t result; /* Current DOCA Error result */
57  bool run_pe_progress; /* Should we keep on progressing the PE? */
58 };
59 
60 /*
61  * Free callback - free doca_buf allocated pointer
62  *
63  * @addr [in]: Memory range pointer
64  * @len [in]: Memory range length
65  * @opaque [in]: An opaque pointer passed to iterator
66  */
67 void free_cb(void *addr, size_t len, void *opaque)
68 {
69  (void)len;
70  (void)opaque;
71 
72  free(addr);
73 }
74 
75 /*
76  * Clean all the sample resources
77  *
78  * @resources [in]: sha_resources struct
79  * @return: DOCA_SUCCESS if the device supports SHA hash task and DOCA_ERROR otherwise.
80  */
82 {
83  struct program_core_objects *state = &resources->state;
84  doca_error_t result = DOCA_SUCCESS, tmp_result;
85 
86  if (state->pe != NULL && state->ctx != NULL) {
87  tmp_result = doca_ctx_stop(state->ctx);
88  if (tmp_result != DOCA_SUCCESS) {
89  DOCA_ERROR_PROPAGATE(result, tmp_result);
90  DOCA_LOG_ERR("Failed to destroy DOCA SHA: %s", doca_error_get_descr(tmp_result));
91  }
92 
93  state->ctx = NULL;
94  }
95 
96  if (resources->sha_ctx != NULL) {
97  tmp_result = doca_sha_destroy(resources->sha_ctx);
98  if (tmp_result != DOCA_SUCCESS) {
99  DOCA_ERROR_PROPAGATE(result, tmp_result);
100  DOCA_LOG_ERR("Failed to destroy DOCA SHA: %s", doca_error_get_descr(tmp_result));
101  }
102  }
103 
104  tmp_result = destroy_core_objects(state);
105  if (tmp_result != DOCA_SUCCESS) {
106  DOCA_ERROR_PROPAGATE(result, tmp_result);
107  DOCA_LOG_ERR("Failed to destroy DOCA SHA: %s", doca_error_get_descr(tmp_result));
108  }
109 
110  return result;
111 }
112 
113 /*
114  * Prepare next block in partial task and then submit the task
115  *
116  * @resources [in]: sha_resources struct
117  * @sha_partial_hash_task [in]: the allocated partial SHA task
118  * @return: DOCA_SUCCESS if the device supports SHA hash task and DOCA_ERROR otherwise.
119  */
121  struct doca_sha_task_partial_hash *sha_partial_hash_task)
122 {
123  struct doca_task *task;
124  size_t src_len;
126 
127  if (resources->remaining_src_len > resources->partial_block_size)
128  src_len = resources->partial_block_size;
129  else
130  src_len = resources->remaining_src_len;
131 
132  /* Set data address and length in the doca_buf */
133  result = doca_buf_set_data(resources->src_doca_buf, resources->src_buffer, src_len);
134  if (result != DOCA_SUCCESS) {
135  DOCA_LOG_ERR("Failed to set data for source buffer: %s", doca_error_get_descr(result));
136  return result;
137  }
138 
139  result = doca_sha_task_partial_hash_set_src(sha_partial_hash_task, resources->src_doca_buf);
140  if (result != DOCA_SUCCESS) {
141  DOCA_LOG_ERR("Failed to set source buffer for SHA partial hash task: %s", doca_error_get_descr(result));
142  return result;
143  }
144 
145  /* If we got to final task then mark it as such */
146  if (src_len == resources->remaining_src_len) {
147  result = doca_sha_task_partial_hash_set_is_final_buf(sha_partial_hash_task);
148  if (result != DOCA_SUCCESS) {
149  DOCA_LOG_ERR("Failed to set final buffer for SHA partial hash task: %s",
151  return result;
152  }
153  }
154 
155  /* Move the src buffer to the next block and decrease the remaining source length */
156  resources->src_buffer += src_len;
157  resources->remaining_src_len -= src_len;
158 
159  task = doca_sha_task_partial_hash_as_task(sha_partial_hash_task);
160 
161  /* Submit SHA partial hash task */
162  result = doca_task_submit(task);
163  if (result != DOCA_SUCCESS) {
164  DOCA_LOG_ERR("Failed to submit SHA partial hash task: %s", doca_error_get_descr(result));
165  return result;
166  }
167 
168  return DOCA_SUCCESS;
169 }
170 
171 /*
172  * SHA partial hash task completed callback
173  *
174  * @sha_partial_hash_task [in]: Completed task
175  * @task_user_data [in]: doca_data from the task
176  * @ctx_user_data [in]: doca_data from the context
177  */
178 static void sha_partial_hash_completed_callback(struct doca_sha_task_partial_hash *sha_partial_hash_task,
179  union doca_data task_user_data,
180  union doca_data ctx_user_data)
181 {
182  struct sha_resources *resources = (struct sha_resources *)ctx_user_data.ptr;
183  bool last_task_finished = resources->remaining_src_len == 0;
184 
185  (void)task_user_data.ptr;
186 
187  /* Assign success to the result */
188  resources->result = DOCA_SUCCESS;
189  DOCA_LOG_INFO("SHA hash task has completed successfully");
190 
191  /* If not last task prepare the next one */
192  if (!last_task_finished)
193  resources->result = prepare_and_submit_partial_sha_hash_task(resources, sha_partial_hash_task);
194 
195  /* Free task and stop context once all tasks are completed or entered error */
196  if (last_task_finished || resources->result != DOCA_SUCCESS) {
197  doca_task_free(doca_sha_task_partial_hash_as_task(sha_partial_hash_task));
198  (void)doca_ctx_stop(resources->state.ctx);
199  }
200 }
201 
202 /*
203  * SHA partial hash task error callback
204  *
205  * @sha_partial_hash_task [in]: Failed task
206  * @task_user_data [in]: doca_data from the task
207  * @ctx_user_data [in]: doca_data from the context
208  */
209 static void sha_partial_hash_error_callback(struct doca_sha_task_partial_hash *sha_partial_hash_task,
210  union doca_data task_user_data,
211  union doca_data ctx_user_data)
212 {
213  struct sha_resources *resources = (struct sha_resources *)ctx_user_data.ptr;
214  struct doca_task *task = doca_sha_task_partial_hash_as_task(sha_partial_hash_task);
215 
216  (void)task_user_data.ptr;
217 
218  /* Get the result of the task */
219  resources->result = doca_task_get_status(task);
220  DOCA_LOG_ERR("SHA partial hash task failed: %s", doca_error_get_descr(resources->result));
221 
222  /* Free task */
223  doca_task_free(task);
224  /* Stop context once error encountered */
225  (void)doca_ctx_stop(resources->state.ctx);
226 }
227 
228 /*
229  * Check if given device is capable of executing a SHA partial hash task.
230  *
231  * @devinfo [in]: The DOCA device information
232  * @return: DOCA_SUCCESS if the device supports SHA hash task and DOCA_ERROR otherwise.
233  */
234 static doca_error_t sha_partial_hash_is_supported(struct doca_devinfo *devinfo)
235 {
237 }
238 
239 /*
240  * Perform a series of SHA partial hash tasks, which includes allocating the task, submitting it with different slices
241  * of the source buffer and waiting for its completions
242  *
243  * @resources [in]: sha_resources struct
244  * @dst_doca_buf [out]: Destination buffer
245  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
246  */
247 static doca_error_t perform_partial_sha_hash_task(struct sha_resources *resources, struct doca_buf **dst_doca_buf)
248 {
249  struct program_core_objects *state = &resources->state;
250  struct doca_sha_task_partial_hash *sha_partial_hash_task = NULL;
251  struct doca_task *task = NULL;
252  union doca_data task_user_data = {0};
253  struct timespec ts = {
254  .tv_sec = 0,
255  .tv_nsec = SLEEP_IN_NANOS,
256  };
258 
259  /* Construct DOCA buffer for the source SHA buffer */
261  state->src_mmap,
262  resources->src_buffer,
263  resources->remaining_src_len,
264  &resources->src_doca_buf);
265  if (result != DOCA_SUCCESS) {
266  DOCA_LOG_ERR("Unable to acquire DOCA buffer representing source buffer: %s",
268  return result;
269  }
270 
271  /* Allocate and construct SHA partial hash task. We will reuse this task for submitting all partial hash task */
274  resources->src_doca_buf,
275  *dst_doca_buf,
276  task_user_data,
277  &sha_partial_hash_task);
278  if (result != DOCA_SUCCESS) {
279  DOCA_LOG_ERR("Failed to allocate SHA partial hash task: %s", doca_error_get_descr(result));
280  doca_buf_dec_refcount(resources->src_doca_buf, NULL);
281  return result;
282  }
283 
284  task = doca_sha_task_partial_hash_as_task(sha_partial_hash_task);
285  if (task == NULL) {
286  DOCA_LOG_ERR("Failed to get SHA partial hash task as DOCA task: %s", doca_error_get_descr(result));
287  doca_buf_dec_refcount(resources->src_doca_buf, NULL);
288  return result;
289  }
290 
292  if (result != DOCA_SUCCESS) {
293  doca_task_free(task);
294  doca_buf_dec_refcount(resources->src_doca_buf, NULL);
295  return result;
296  }
297 
298  resources->run_pe_progress = true;
299 
300  /* Wait for the task to be completed and for the context to be stopped */
301  while (resources->run_pe_progress) {
302  if (doca_pe_progress(state->pe) == 0)
303  nanosleep(&ts, &ts);
304  }
305 
306  doca_buf_dec_refcount(resources->src_doca_buf, NULL);
307 
308  /* Propagate result of task according to the result we update in the callbacks */
310 
311  return result;
312 }
313 
322 static void sha_state_changed_callback(const union doca_data user_data,
323  struct doca_ctx *ctx,
324  enum doca_ctx_states prev_state,
325  enum doca_ctx_states next_state)
326 {
327  (void)ctx;
328  (void)prev_state;
329 
330  struct sha_resources *resources = (struct sha_resources *)user_data.ptr;
331 
332  switch (next_state) {
333  case DOCA_CTX_STATE_IDLE:
334  DOCA_LOG_INFO("SHA context has been stopped");
335  /* We can stop progressing the PE */
336  resources->run_pe_progress = false;
337  break;
342  DOCA_LOG_ERR("SHA context entered into starting state. Unexpected transition");
343  break;
345  DOCA_LOG_INFO("SHA context is running");
346  break;
355  DOCA_LOG_INFO("SHA context entered into stopping state. Any inflight tasks will be flushed");
356  break;
357  default:
358  break;
359  }
360 }
361 
362 /*
363  * Run sha_partial_create sample
364  *
365  * @src_buffer [in]: source data for the SHA task
366  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
367  */
369 {
370  struct sha_resources resources;
371  struct program_core_objects *state = &resources.state;
372  union doca_data ctx_user_data = {0};
373  struct doca_buf *dst_doca_buf = NULL;
374  uint8_t *dst_buffer = NULL;
375  uint8_t *dst_buffer_data = NULL;
376  char *sha_output = NULL;
377  uint32_t max_bufs = 2; /* The sample will use 2 DOCA buffers */
378  uint32_t min_dst_sha_buffer_size, i;
379  size_t hash_length;
381 
382  memset(&resources, 0, sizeof(resources));
383  resources.src_buffer = src_buffer;
384  resources.remaining_src_len = strlen(src_buffer);
385 
387  if (result != DOCA_SUCCESS) {
388  DOCA_LOG_ERR("Unable to open DOCA device for SHA partial hash task: %s", doca_error_get_descr(result));
389  return result;
390  }
391 
394  &min_dst_sha_buffer_size);
395  if (result != DOCA_SUCCESS) {
396  DOCA_LOG_ERR("Failed to get minimum destination buffer size for DOCA SHA: %s",
399  return result;
400  }
401 
404  &resources.partial_block_size);
405  if (result != DOCA_SUCCESS) {
406  DOCA_LOG_ERR("Failed to get the partial hash block size for DOCA SHA: %s",
409  return result;
410  }
411 
412  if (resources.remaining_src_len <= resources.partial_block_size) {
413  DOCA_LOG_ERR("User data length %lu should be bigger than one partial hash block size %u",
414  resources.remaining_src_len,
415  resources.partial_block_size);
418  }
419 
420  result = doca_sha_create(state->dev, &resources.sha_ctx);
421  if (result != DOCA_SUCCESS) {
422  DOCA_LOG_ERR("Unable to create sha engine: %s", doca_error_get_descr(result));
424  return result;
425  }
426 
427  state->ctx = doca_sha_as_ctx(resources.sha_ctx);
428 
429  result = create_core_objects(state, max_bufs);
430  if (result != DOCA_SUCCESS) {
432  return result;
433  }
434 
435  /* Connect context to progress engine */
436  result = doca_pe_connect_ctx(state->pe, state->ctx);
437  if (result != DOCA_SUCCESS) {
438  DOCA_LOG_ERR("Failed to connect progress engine to context: %s", doca_error_get_descr(result));
440  return result;
441  }
442 
447  if (result != DOCA_SUCCESS) {
449  return result;
450  }
451 
453  if (result != DOCA_SUCCESS) {
454  DOCA_LOG_ERR("Unable to set SHA state change callback: %s", doca_error_get_descr(result));
456  return result;
457  }
458 
459  dst_buffer = calloc(1, min_dst_sha_buffer_size);
460  if (dst_buffer == NULL) {
461  DOCA_LOG_ERR("Failed to allocate memory");
463  return DOCA_ERROR_NO_MEMORY;
464  }
465 
466  result = doca_mmap_set_memrange(state->src_mmap, resources.src_buffer, resources.remaining_src_len);
467  if (result != DOCA_SUCCESS) {
468  free(dst_buffer);
470  return result;
471  }
472 
473  result = doca_mmap_start(state->src_mmap);
474  if (result != DOCA_SUCCESS) {
475  free(dst_buffer);
477  return result;
478  }
479 
480  result = doca_mmap_set_memrange(state->dst_mmap, dst_buffer, min_dst_sha_buffer_size);
481  if (result != DOCA_SUCCESS) {
482  free(dst_buffer);
484  return result;
485  }
486 
488  if (result != DOCA_SUCCESS) {
489  free(dst_buffer);
491  return result;
492  }
493 
494  result = doca_mmap_start(state->dst_mmap);
495  if (result != DOCA_SUCCESS) {
496  free(dst_buffer);
498  return result;
499  }
500 
501  /* Construct response DOCA buffer for all partial tasks */
503  state->dst_mmap,
504  dst_buffer,
505  min_dst_sha_buffer_size,
506  &dst_doca_buf);
507  if (result != DOCA_SUCCESS) {
508  DOCA_LOG_ERR("Unable to acquire DOCA buffer representing destination buffer: %s",
511  return result;
512  }
513 
514  /* Include tasks counter in user data of context to be decremented in callbacks */
515  ctx_user_data.ptr = &resources;
516  doca_ctx_set_user_data(state->ctx, ctx_user_data);
517 
518  result = doca_ctx_start(state->ctx);
519  if (result != DOCA_SUCCESS) {
520  doca_buf_dec_refcount(dst_doca_buf, NULL);
522  return result;
523  }
524 
525  /* Perform partial hashing */
527  if (result != DOCA_SUCCESS) {
528  DOCA_LOG_ERR("Failed to perform partial SHA hash tasks: %s", doca_error_get_descr(result));
529  doca_buf_dec_refcount(dst_doca_buf, NULL);
531  return result;
532  }
533 
534  result = doca_buf_get_data_len(dst_doca_buf, &hash_length);
535  if (result != DOCA_SUCCESS) {
536  DOCA_LOG_ERR("Failed to get the data length of DOCA buffer: %s", doca_error_get_descr(result));
537  doca_buf_dec_refcount(dst_doca_buf, NULL);
539  return result;
540  }
541 
542  result = doca_buf_get_data(dst_doca_buf, (void **)&dst_buffer_data);
543  if (result != DOCA_SUCCESS) {
544  DOCA_LOG_ERR("Failed to get the data of DOCA buffer: %s", doca_error_get_descr(result));
545  doca_buf_dec_refcount(dst_doca_buf, NULL);
547  return result;
548  }
549 
550  /* Engine outputs hex format. For char format output, we need double the length */
551  sha_output = calloc(1, (hash_length * 2) + 1);
552  if (sha_output == NULL) {
553  DOCA_LOG_ERR("Failed to allocate memory");
554  doca_buf_dec_refcount(dst_doca_buf, NULL);
556  return DOCA_ERROR_NO_MEMORY;
557  }
558 
559  /* Convert the hex output to string */
560  for (i = 0; i < hash_length; i++)
561  snprintf(sha_output + (2 * i), 3, "%02x", dst_buffer_data[i]);
562  DOCA_LOG_INFO("SHA256 output is: %s", sha_output);
563 
564  /* Clean and destroy all relevant objects */
565  free(sha_output);
566  doca_buf_dec_refcount(dst_doca_buf, NULL);
568 
569  return DOCA_SUCCESS;
570 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
doca_error_t destroy_core_objects(struct program_core_objects *state)
Definition: common.c:392
doca_error_t create_core_objects(struct program_core_objects *state, uint32_t max_bufs)
Definition: common.c:302
doca_error_t open_doca_device_with_capabilities(tasks_check func, struct doca_dev **retval)
Definition: common.c:188
uintptr_t addr
uint64_t len
struct rdma_resources resources
static doca_error_t doca_buf_inventory_buf_get_by_addr(struct doca_buf_inventory *inventory, struct doca_mmap *mmap, void *addr, size_t len, struct doca_buf **buf)
Allocate single element from buffer inventory and point it to the buffer defined by addr & len argume...
static doca_error_t doca_buf_inventory_buf_get_by_data(struct doca_buf_inventory *inventory, struct doca_mmap *mmap, void *data, size_t data_len, struct doca_buf **buf)
Allocate single element from buffer inventory and point it to the buffer defined by data & data_len a...
DOCA_STABLE doca_error_t doca_buf_dec_refcount(struct doca_buf *buf, uint16_t *refcount)
Decrease the object reference count by 1, if 0 reached, return the element back to the inventory.
DOCA_STABLE doca_error_t doca_buf_get_data(const struct doca_buf *buf, void **data)
Get the buffer's data.
DOCA_STABLE doca_error_t doca_buf_get_data_len(const struct doca_buf *buf, size_t *data_len)
Get buffer's data length.
DOCA_STABLE doca_error_t doca_buf_set_data(struct doca_buf *buf, void *data, size_t data_len)
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_set_state_changed_cb(struct doca_ctx *ctx, doca_ctx_state_changed_callback_t cb)
Set state changed callback.
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_CTX_STATE_STARTING
Definition: doca_ctx.h:93
@ DOCA_CTX_STATE_STOPPING
Definition: doca_ctx.h:106
@ DOCA_CTX_STATE_IDLE
Definition: doca_ctx.h:88
@ DOCA_CTX_STATE_RUNNING
Definition: doca_ctx.h:98
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...
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
Definition: doca_error.h:83
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_SUCCESS
Definition: doca_error.h:38
@ DOCA_ERROR_NO_MEMORY
Definition: doca_error.h:45
#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
DOCA_STABLE doca_error_t doca_mmap_set_memrange(struct doca_mmap *mmap, void *addr, size_t len)
Set the memory range of DOCA memory map.
DOCA_STABLE doca_error_t doca_mmap_start(struct doca_mmap *mmap)
Start DOCA Memory Map.
DOCA_STABLE doca_error_t doca_mmap_set_free_cb(struct doca_mmap *mmap, doca_mmap_memrange_free_cb_t *free_cb, void *opaque)
Set callback that will free the memory range when destroying DOCA memory map.
DOCA_STABLE doca_error_t doca_task_get_status(const struct doca_task *task)
Get task status.
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 void doca_task_free(struct doca_task *task)
Free a task back to where it was allocated from.
DOCA_EXPERIMENTAL doca_error_t doca_sha_cap_get_partial_hash_block_size(struct doca_devinfo const *devinfo, enum doca_sha_algorithm algorithm, uint32_t *partial_block_size)
DOCA_EXPERIMENTAL struct doca_task * doca_sha_task_partial_hash_as_task(struct doca_sha_task_partial_hash *task)
DOCA_EXPERIMENTAL doca_error_t doca_sha_create(struct doca_dev *dev, struct doca_sha **sha)
DOCA_EXPERIMENTAL doca_error_t doca_sha_cap_get_min_dst_buf_size(struct doca_devinfo const *devinfo, enum doca_sha_algorithm algorithm, uint32_t *min_dst_buf_size)
DOCA_EXPERIMENTAL doca_error_t doca_sha_task_partial_hash_set_is_final_buf(struct doca_sha_task_partial_hash *task)
DOCA_EXPERIMENTAL doca_error_t doca_sha_task_partial_hash_alloc_init(struct doca_sha *sha, enum doca_sha_algorithm algorithm, struct doca_buf const *src_buf, struct doca_buf *dst_buf, union doca_data user_data, struct doca_sha_task_partial_hash **task)
DOCA_EXPERIMENTAL doca_error_t doca_sha_cap_task_partial_hash_get_supported(struct doca_devinfo const *devinfo, enum doca_sha_algorithm algorithm)
DOCA_EXPERIMENTAL doca_error_t doca_sha_task_partial_hash_set_conf(struct doca_sha *sha, doca_sha_task_partial_hash_completion_cb_t task_completion_cb, doca_sha_task_partial_hash_completion_cb_t task_error_cb, uint8_t log_num_tasks)
This method sets the doca_sha partial hash task pool configuration.
DOCA_EXPERIMENTAL doca_error_t doca_sha_task_partial_hash_set_src(struct doca_sha_task_partial_hash *task, struct doca_buf const *src_buf)
DOCA_EXPERIMENTAL doca_error_t doca_sha_destroy(struct doca_sha *sha)
DOCA_EXPERIMENTAL struct doca_ctx * doca_sha_as_ctx(struct doca_sha *sha)
#define SHA_SAMPLE_ALGORITHM
#define LOG_NUM_PARTIAL_SHA_TASKS
doca_error_t sha_partial_create(char *src_buffer)
static doca_error_t sha_cleanup(struct sha_resources *resources)
static void sha_state_changed_callback(const union doca_data user_data, struct doca_ctx *ctx, enum doca_ctx_states prev_state, enum doca_ctx_states next_state)
static void sha_partial_hash_error_callback(struct doca_sha_task_partial_hash *sha_partial_hash_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t prepare_and_submit_partial_sha_hash_task(struct sha_resources *resources, struct doca_sha_task_partial_hash *sha_partial_hash_task)
DOCA_LOG_REGISTER(SHA_PARTIAL_CREATE)
static void sha_partial_hash_completed_callback(struct doca_sha_task_partial_hash *sha_partial_hash_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t sha_partial_hash_is_supported(struct doca_devinfo *devinfo)
void free_cb(void *addr, size_t len, void *opaque)
#define SLEEP_IN_NANOS
static doca_error_t perform_partial_sha_hash_task(struct sha_resources *resources, struct doca_buf **dst_doca_buf)
struct doca_pe * pe
Definition: common.h:51
struct doca_mmap * src_mmap
Definition: common.h:47
struct doca_buf_inventory * buf_inv
Definition: common.h:49
struct doca_dev * dev
Definition: common.h:46
struct doca_mmap * dst_mmap
Definition: common.h:48
struct doca_ctx * ctx
Definition: common.h:50
bool run_pe_progress
Definition: rdma_common.h:133
struct doca_sha * sha_ctx
struct program_core_objects state
struct doca_buf * src_doca_buf
Convenience type for representing opaque data.
Definition: doca_types.h:56
void * ptr
Definition: doca_types.h:57
struct upf_accel_ctx * ctx