Signed-off-by: Robbie King <robk...@cisco.com>
---
.../linux-generic/include/odp_crypto_internal.h | 2 +
platform/linux-generic/odp_crypto.c | 98 ++++++++++++++++++----
2 files changed, 83 insertions(+), 17 deletions(-)
diff --git a/platform/linux-generic/include/odp_crypto_internal.h
b/platform/linux-generic/include/odp_crypto_internal.h
index 04db333..40fe9d2 100644
--- a/platform/linux-generic/include/odp_crypto_internal.h
+++ b/platform/linux-generic/include/odp_crypto_internal.h
@@ -67,6 +67,8 @@ struct odp_crypto_generic_session {
*/
typedef struct odp_crypto_generic_op_result {
uint32_t magic;
+ void *ctx;
+ odp_packet_t pkt;
odp_crypto_compl_status_t cipher;
odp_crypto_compl_status_t auth;
} odp_crypto_generic_op_result_t;
diff --git a/platform/linux-generic/odp_crypto.c
b/platform/linux-generic/odp_crypto.c
index d3cdec7..5a74831 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -53,6 +53,15 @@ odp_crypto_generic_op_result_t
*get_op_result_from_buffer(odp_buffer_t buf)
return result;
}
+static odp_crypto_generic_op_result_t *
+get_op_result_from_compl_event(odp_crypto_compl_event_t completion_event)
+{
+ if (completion_event.is_buffer)
+ return get_op_result_from_buffer(completion_event.buffer);
+ else
+ return completion_event.ptr;
+}
+
static
odp_crypto_generic_session_t *alloc_session(void)
{
@@ -338,13 +347,14 @@ odp_crypto_session_create(odp_crypto_session_params_t
*params,
int
odp_crypto_operation(odp_crypto_op_params_t *params,
bool *posted,
- odp_buffer_t completion_event)
+ odp_crypto_compl_event_t completion_event)
{
enum crypto_alg_err rc_cipher = ODP_CRYPTO_ALG_ERR_NONE;
enum crypto_alg_err rc_auth = ODP_CRYPTO_ALG_ERR_NONE;
odp_crypto_generic_session_t *session;
odp_crypto_generic_op_result_t *result;
-
+ void *ctx = odp_crypto_get_operation_compl_ctx(completion_event);
+
*posted = 0;
session = (odp_crypto_generic_session_t *)(intptr_t)params->session;
@@ -357,8 +367,8 @@ odp_crypto_operation(odp_crypto_op_params_t *params,
if (odp_unlikely(ODP_PACKET_INVALID == params->out_pkt))
abort();
odp_packet_copy(params->out_pkt, params->pkt);
- if (completion_event == odp_packet_to_buffer(params->pkt))
- completion_event =
+ if (completion_event.buffer ==
odp_packet_to_buffer(params->pkt))
+ completion_event.buffer =
odp_packet_to_buffer(params->out_pkt);
odph_packet_free(params->pkt);
params->pkt = ODP_PACKET_INVALID;
@@ -374,8 +384,10 @@ odp_crypto_operation(odp_crypto_op_params_t *params,
}
/* Build Result (no HW so no errors) */
- result = get_op_result_from_buffer(completion_event);
+ result = get_op_result_from_compl_event(completion_event);
result->magic = OP_RESULT_MAGIC;
+ result->ctx = ctx;
+ result->pkt = params->out_pkt;
result->cipher.alg_err = rc_cipher;
result->cipher.hw_err = ODP_CRYPTO_HW_ERR_NONE;
result->auth.alg_err = rc_auth;
@@ -383,7 +395,7 @@ odp_crypto_operation(odp_crypto_op_params_t *params,
/* If specified during creation post event to completion queue */
if (ODP_QUEUE_INVALID != session->compl_queue) {
- odp_queue_enq(session->compl_queue, completion_event);
+ odp_queue_enq(session->compl_queue, completion_event.buffer);
*posted = 1;
}
return 0;
@@ -422,14 +434,16 @@ odp_hw_random_get(uint8_t *buf, size_t *len, bool
use_entropy ODP_UNUSED)
return ((1 == rc) ? 0 : -1);
}
+static __thread odp_crypto_generic_op_result_t sync_result;
+
void
-odp_crypto_get_operation_compl_status(odp_buffer_t completion_event,
+odp_crypto_get_operation_compl_status(odp_crypto_compl_event_t
completion_event,
odp_crypto_compl_status_t *auth,
odp_crypto_compl_status_t *cipher)
{
odp_crypto_generic_op_result_t *result;
- result = get_op_result_from_buffer(completion_event);
+ result = get_op_result_from_compl_event(completion_event);
if (OP_RESULT_MAGIC != result->magic)
abort();
@@ -440,22 +454,72 @@ odp_crypto_get_operation_compl_status(odp_buffer_t
completion_event,
void
-odp_crypto_set_operation_compl_ctx(odp_buffer_t completion_event ODP_UNUSED,
- void *ctx ODP_UNUSED)
+odp_crypto_set_operation_compl_ctx(odp_crypto_compl_event_t completion_event,
+ void *ctx)
{
- ODP_UNIMPLEMENTED();
+ odp_crypto_generic_op_result_t *result;
+
+ result = get_op_result_from_compl_event(completion_event);
+
+ result->ctx = ctx;
}
void
-*odp_crypto_get_operation_compl_ctx(odp_buffer_t completion_event ODP_UNUSED)
+*odp_crypto_get_operation_compl_ctx(odp_crypto_compl_event_t completion_event)
{
- ODP_UNIMPLEMENTED();
- return NULL;
+ odp_crypto_generic_op_result_t *result;
+
+ result = get_op_result_from_compl_event(completion_event);
+
+ return result->ctx;
}
odp_packet_t
-odp_crypto_get_operation_compl_packet(odp_buffer_t completion_event ODP_UNUSED)
+odp_crypto_get_operation_compl_packet(odp_crypto_compl_event_t
completion_event)
{
- ODP_UNIMPLEMENTED();
- return ODP_PACKET_INVALID;
+ return odp_packet_from_buffer(completion_event.buffer);
}
+
+odp_crypto_compl_event_t
+odp_crypto_get_compl_event(odp_crypto_op_params_t *params)
+{
+ odp_crypto_generic_session_t *session;
+ odp_crypto_compl_event_t event;
+
+ /* If queue specified during creation then use buffer else memory */
+ session = (odp_crypto_generic_session_t *)(intptr_t)params->session;
+ if (ODP_QUEUE_INVALID != session->compl_queue) {
+ event.is_buffer = 1;
+ event.buffer = odp_packet_to_buffer(params->pkt);
+ } else {
+ event.is_buffer = 0;
+ event.ptr = &sync_result;
+ }
+ return event;
+}