45 #define SLEEP_IN_NANOS (10 * 1000)
46 #define LOG_NUM_SHA_TASKS (0)
47 #define SHA_SAMPLE_ALGORITHM (DOCA_SHA_ALGORITHM_SHA256)
184 struct doca_ctx *
ctx,
193 switch (next_state) {
203 DOCA_LOG_ERR(
"SHA context entered into starting state. Unexpected transition");
216 DOCA_LOG_INFO(
"SHA context entered into stopping state. Any inflight tasks will be flushed");
234 struct doca_sha_task_hash *sha_hash_task;
235 struct doca_task *task;
237 struct doca_buf *src_doca_buf =
NULL;
238 struct doca_buf *dst_doca_buf =
NULL;
239 uint8_t *dst_buffer =
NULL;
240 uint8_t *dst_buffer_data =
NULL;
241 char *sha_output =
NULL;
242 uint32_t max_bufs = 2;
243 uint32_t min_dst_sha_buffer_size;
244 uint64_t max_source_buffer_size;
245 size_t src_buffer_len = strlen(src_buffer);
248 struct timespec ts = {
270 if (src_buffer_len > max_source_buffer_size) {
271 DOCA_LOG_ERR(
"User data length %lu exceeds the maximum length %lu for DOCA SHA: %s",
273 max_source_buffer_size,
281 &min_dst_sha_buffer_size);
283 DOCA_LOG_ERR(
"Failed to get minimum destination buffer size for DOCA SHA: %s",
328 dst_buffer = calloc(1, min_dst_sha_buffer_size);
329 if (dst_buffer ==
NULL) {
375 DOCA_LOG_ERR(
"Unable to acquire DOCA buffer representing source buffer: %s",
385 min_dst_sha_buffer_size,
388 DOCA_LOG_ERR(
"Unable to acquire DOCA buffer representing destination buffer: %s",
409 task_user_data.
ptr = &task_result;
484 sha_output = calloc(1, (hash_length * 2) + 1);
485 if (sha_output ==
NULL) {
494 for (i = 0; i < hash_length; i++)
495 snprintf(sha_output + (2 * i), 3,
"%02x", dst_buffer_data[i]);
502 DOCA_LOG_ERR(
"Failed to decrease DOCA buffer reference count");
doca_error_t destroy_core_objects(struct program_core_objects *state)
doca_error_t create_core_objects(struct program_core_objects *state, uint32_t max_bufs)
doca_error_t open_doca_device_with_capabilities(tasks_check func, struct doca_dev **retval)
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_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.
@ DOCA_CTX_STATE_STARTING
@ DOCA_CTX_STATE_STOPPING
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.
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.
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
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_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 struct doca_task * doca_sha_task_hash_as_task(struct doca_sha_task_hash *task)
DOCA_EXPERIMENTAL doca_error_t doca_sha_cap_task_hash_get_supported(struct doca_devinfo const *devinfo, enum doca_sha_algorithm algorithm)
DOCA_EXPERIMENTAL doca_error_t doca_sha_task_hash_set_conf(struct doca_sha *sha, doca_sha_task_hash_completion_cb_t task_completion_cb, doca_sha_task_hash_completion_cb_t task_error_cb, uint8_t log_num_tasks)
This method sets the doca_sha hash task pool configuration.
DOCA_EXPERIMENTAL doca_error_t doca_sha_destroy(struct doca_sha *sha)
DOCA_EXPERIMENTAL doca_error_t doca_sha_task_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_hash **task)
DOCA_EXPERIMENTAL doca_error_t doca_sha_cap_get_max_src_buf_size(struct doca_devinfo const *devinfo, uint64_t *max_src_buf_size)
DOCA_EXPERIMENTAL struct doca_ctx * doca_sha_as_ctx(struct doca_sha *sha)
#define SHA_SAMPLE_ALGORITHM
doca_error_t sha_create(char *src_buffer)
static doca_error_t sha_cleanup(struct sha_resources *resources)
static doca_error_t sha_hash_is_supported(struct doca_devinfo *devinfo)
DOCA_LOG_REGISTER(SHA_CREATE)
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_hash_completed_callback(struct doca_sha_task_hash *sha_hash_task, union doca_data task_user_data, union doca_data ctx_user_data)
#define LOG_NUM_SHA_TASKS
void free_cb(void *addr, size_t len, void *opaque)
static void sha_hash_error_callback(struct doca_sha_task_hash *sha_hash_task, union doca_data task_user_data, union doca_data ctx_user_data)
struct doca_mmap * src_mmap
struct doca_buf_inventory * buf_inv
struct doca_mmap * dst_mmap
size_t num_remaining_tasks
struct doca_sha * sha_ctx
struct program_core_objects state
size_t num_remaining_tasks
Convenience type for representing opaque data.
struct upf_accel_ctx * ctx