diff mbox

[v4,10/16] api: crypto: Use odp_event_t instead of odp_buffer_t

Message ID 1422013344-6655-11-git-send-email-petri.savolainen@linaro.org
State Superseded
Headers show

Commit Message

Petri Savolainen Jan. 23, 2015, 11:42 a.m. UTC
Changed crypto API to use odp_event_t instead of odp_buffer_t.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
---
 example/ipsec/odp_ipsec.c                          | 12 ++++----
 platform/linux-generic/include/api/odp_crypto.h    | 12 ++++----
 platform/linux-generic/odp_crypto.c                | 34 ++++++++++++----------
 test/validation/crypto/odp_crypto_test_async_inp.c | 34 ++++++++++------------
 test/validation/crypto/odp_crypto_test_sync_inp.c  |  3 +-
 5 files changed, 49 insertions(+), 46 deletions(-)
diff mbox

Patch

diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 9fdaeab..e375396 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -740,7 +740,7 @@  pkt_disposition_e do_ipsec_in_classify(odp_packet_t pkt,
 	*skip = FALSE;
 	if (odp_crypto_operation(&params,
 				 &posted,
-				 odp_buffer_from_event(odp_packet_to_event(pkt)))) {
+				 odp_packet_to_event(pkt))) {
 		abort();
 	}
 	return (posted) ? PKT_POSTED : PKT_CONTINUE;
@@ -758,7 +758,7 @@  static
 pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt,
 				     pkt_ctx_t *ctx)
 {
-	odp_buffer_t event;
+	odp_event_t event;
 	odp_crypto_compl_status_t cipher_rc;
 	odp_crypto_compl_status_t auth_rc;
 	odph_ipv4hdr_t *ip;
@@ -766,7 +766,7 @@  pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt,
 	int trl_len = 0;
 
 	/* Check crypto result */
-	event = odp_buffer_from_event(odp_packet_to_event(pkt));
+	event = odp_packet_to_event(pkt);
 	odp_crypto_get_operation_compl_status(event, &auth_rc, &cipher_rc);
 	if (!is_crypto_compl_status_ok(&cipher_rc))
 		return PKT_DROP;
@@ -974,7 +974,7 @@  pkt_disposition_e do_ipsec_out_seq(odp_packet_t pkt,
 	/* Issue crypto request */
 	if (odp_crypto_operation(&ctx->ipsec.params,
 				 &posted,
-				 odp_buffer_from_event(odp_packet_to_event(pkt)))) {
+				 odp_packet_to_event(pkt))) {
 		abort();
 	}
 	return (posted) ? PKT_POSTED : PKT_CONTINUE;
@@ -992,13 +992,13 @@  static
 pkt_disposition_e do_ipsec_out_finish(odp_packet_t pkt,
 				      pkt_ctx_t *ctx)
 {
-	odp_buffer_t event;
+	odp_event_t event;
 	odp_crypto_compl_status_t cipher_rc;
 	odp_crypto_compl_status_t auth_rc;
 	odph_ipv4hdr_t *ip;
 
 	/* Check crypto result */
-	event = odp_buffer_from_event(odp_packet_to_event(pkt));
+	event = odp_packet_to_event(pkt);
 	odp_crypto_get_operation_compl_status(event, &auth_rc, &cipher_rc);
 	if (!is_crypto_compl_status_ok(&cipher_rc))
 		return PKT_DROP;
diff --git a/platform/linux-generic/include/api/odp_crypto.h b/platform/linux-generic/include/api/odp_crypto.h
index 337e7cf..00a0090 100644
--- a/platform/linux-generic/include/api/odp_crypto.h
+++ b/platform/linux-generic/include/api/odp_crypto.h
@@ -19,7 +19,7 @@  extern "C" {
 #endif
 
 #include <odp_std_types.h>
-#include <odp_buffer.h>
+#include <odp_event.h>
 #include <odp_buffer_pool.h>
 #include <odp_queue.h>
 #include <odp_packet.h>
@@ -247,7 +247,7 @@  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_event_t completion_event);
 
 /**
  * Crypto per packet operation set user context in completion event
@@ -256,7 +256,7 @@  odp_crypto_operation(odp_crypto_op_params_t *params,
  * @param ctx               User data
  */
 void
-odp_crypto_set_operation_compl_ctx(odp_buffer_t completion_event,
+odp_crypto_set_operation_compl_ctx(odp_event_t completion_event,
 				   void *ctx);
 
 /**
@@ -269,7 +269,7 @@  odp_crypto_set_operation_compl_ctx(odp_buffer_t completion_event,
  * @param cipher            Pointer to store cipher results
  */
 void
-odp_crypto_get_operation_compl_status(odp_buffer_t completion_event,
+odp_crypto_get_operation_compl_status(odp_event_t completion_event,
 				      odp_crypto_compl_status_t *auth,
 				      odp_crypto_compl_status_t *cipher);
 
@@ -284,7 +284,7 @@  odp_crypto_get_operation_compl_status(odp_buffer_t completion_event,
  * @return Packet structure where data now resides
  */
 odp_packet_t
-odp_crypto_get_operation_compl_packet(odp_buffer_t completion_event);
+odp_crypto_get_operation_compl_packet(odp_event_t completion_event);
 
 /**
  * Crypto per packet operation query user context in completion event
@@ -294,7 +294,7 @@  odp_crypto_get_operation_compl_packet(odp_buffer_t completion_event);
  * @return User data
  */
 void *
-odp_crypto_get_operation_compl_ctx(odp_buffer_t completion_event);
+odp_crypto_get_operation_compl_ctx(odp_event_t completion_event);
 
 /**
  * Generate random byte string
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index 74fac5c..0a37878 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -41,10 +41,15 @@  static odp_crypto_global_t *global;
  *       of packets versus events on completion queues is closed.
  */
 static
-odp_crypto_generic_op_result_t *get_op_result_from_buffer(odp_buffer_t buf)
+odp_crypto_generic_op_result_t *get_op_result_from_event(odp_event_t ev)
 {
 	uint8_t   *temp;
 	odp_crypto_generic_op_result_t *result;
+	odp_buffer_t buf;
+
+	/* HACK: Buffer is not packet any more in the API.
+	 * Implementation still works that way. */
+	buf = odp_buffer_from_event(ev);
 
 	temp  = odp_buffer_addr(buf);
 	temp += odp_buffer_size(buf);
@@ -344,7 +349,7 @@  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_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;
@@ -364,9 +369,9 @@  odp_crypto_operation(odp_crypto_op_params_t *params,
 			ODP_ABORT();
 		_odp_packet_copy_to_packet(params->pkt, 0, params->out_pkt, 0,
 					   odp_packet_len(params->pkt));
-		if (completion_event == _odp_packet_to_buffer(params->pkt))
+		if (completion_event == odp_packet_to_event(params->pkt))
 			completion_event =
-				_odp_packet_to_buffer(params->out_pkt);
+				odp_packet_to_event(params->out_pkt);
 		odp_packet_free(params->pkt);
 		params->pkt = ODP_PACKET_INVALID;
 	}
@@ -381,7 +386,7 @@  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_event(completion_event);
 	result->magic = OP_RESULT_MAGIC;
 	result->cipher.alg_err = rc_cipher;
 	result->cipher.hw_err = ODP_CRYPTO_HW_ERR_NONE;
@@ -391,8 +396,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,
-			      odp_buffer_to_event(completion_event));
+		odp_queue_enq(session->compl_queue, completion_event);
 		*posted = 1;
 	}
 	return 0;
@@ -432,13 +436,13 @@  odp_hw_random_get(uint8_t *buf, size_t *len, bool use_entropy ODP_UNUSED)
 }
 
 void
-odp_crypto_get_operation_compl_status(odp_buffer_t completion_event,
+odp_crypto_get_operation_compl_status(odp_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_event(completion_event);
 
 	if (OP_RESULT_MAGIC != result->magic)
 		ODP_ABORT();
@@ -449,12 +453,12 @@  odp_crypto_get_operation_compl_status(odp_buffer_t completion_event,
 
 
 void
-odp_crypto_set_operation_compl_ctx(odp_buffer_t completion_event,
+odp_crypto_set_operation_compl_ctx(odp_event_t completion_event,
 				   void *ctx)
 {
 	odp_crypto_generic_op_result_t *result;
 
-	result = get_op_result_from_buffer(completion_event);
+	result = get_op_result_from_event(completion_event);
 	/*
 	 * Completion event magic can't be checked here, because it is filled
 	 * later in odp_crypto_operation() function.
@@ -464,22 +468,22 @@  odp_crypto_set_operation_compl_ctx(odp_buffer_t completion_event,
 }
 
 void
-*odp_crypto_get_operation_compl_ctx(odp_buffer_t completion_event)
+*odp_crypto_get_operation_compl_ctx(odp_event_t completion_event)
 {
 	odp_crypto_generic_op_result_t *result;
 
-	result = get_op_result_from_buffer(completion_event);
+	result = get_op_result_from_event(completion_event);
 	ODP_ASSERT(OP_RESULT_MAGIC == result->magic, "Bad completion magic");
 
 	return result->op_context;
 }
 
 odp_packet_t
-odp_crypto_get_operation_compl_packet(odp_buffer_t completion_event)
+odp_crypto_get_operation_compl_packet(odp_event_t completion_event)
 {
 	odp_crypto_generic_op_result_t *result;
 
-	result = get_op_result_from_buffer(completion_event);
+	result = get_op_result_from_event(completion_event);
 	ODP_ASSERT(OP_RESULT_MAGIC == result->magic, "Bad completion magic");
 
 	return result->out_pkt;
diff --git a/test/validation/crypto/odp_crypto_test_async_inp.c b/test/validation/crypto/odp_crypto_test_async_inp.c
index b5d257d..5cc1131 100644
--- a/test/validation/crypto/odp_crypto_test_async_inp.c
+++ b/test/validation/crypto/odp_crypto_test_async_inp.c
@@ -25,7 +25,7 @@  static void alg_test(enum odp_crypto_op op,
 		     odp_crypto_key_t cipher_key,
 		     enum odp_auth_alg auth_alg,
 		     odp_crypto_key_t auth_key,
-		     odp_buffer_t compl_new,
+		     odp_event_t compl_new,
 		     uint8_t *input_vec,
 		     unsigned int input_vec_len,
 		     uint8_t *output_vec,
@@ -88,12 +88,10 @@  static void alg_test(enum odp_crypto_op op,
 		CU_FAIL("%s : not implemented for combined alg mode\n");
 	}
 
-	if (compl_new == ODP_BUFFER_INVALID) {
-		/* hack: buf is removed after crypto API update tp events */
-		odp_buffer_t buf;
-		buf = odp_buffer_from_event(odp_packet_to_event(pkt));
-		odp_crypto_set_operation_compl_ctx(buf, (void *)0xdeadbeef);
-		rc = odp_crypto_operation(&op_params, &posted, buf);
+	if (compl_new == ODP_EVENT_INVALID) {
+		odp_event_t ev = odp_packet_to_event(pkt);
+		odp_crypto_set_operation_compl_ctx(ev, (void *)0xdeadbeef);
+		rc = odp_crypto_operation(&op_params, &posted, ev);
 	} else {
 		odp_crypto_set_operation_compl_ctx(compl_new,
 						   (void *)0xdeadbeef);
@@ -106,13 +104,13 @@  static void alg_test(enum odp_crypto_op op,
 		compl_event = odp_queue_deq(compl_queue);
 	} while (compl_event == ODP_EVENT_INVALID);
 
-	if (compl_new == ODP_BUFFER_INVALID)
+	if (compl_new == ODP_EVENT_INVALID)
 		CU_ASSERT(compl_event == odp_packet_to_event(pkt))
 	else
-		CU_ASSERT(odp_buffer_from_event(compl_event) == compl_new)
+		CU_ASSERT(compl_event == compl_new)
 
 	struct odp_crypto_compl_status auth_status, cipher_status;
-	odp_crypto_get_operation_compl_status(odp_buffer_from_event(compl_event),
+	odp_crypto_get_operation_compl_status(compl_event,
 					      &auth_status, &cipher_status);
 	CU_ASSERT(auth_status.alg_err == ODP_CRYPTO_ALG_ERR_NONE);
 	CU_ASSERT(auth_status.hw_err == ODP_CRYPTO_HW_ERR_NONE);
@@ -120,12 +118,12 @@  static void alg_test(enum odp_crypto_op op,
 	CU_ASSERT(cipher_status.hw_err == ODP_CRYPTO_HW_ERR_NONE);
 
 	odp_packet_t out_pkt;
-	out_pkt = odp_crypto_get_operation_compl_packet(odp_buffer_from_event(compl_event));
+	out_pkt = odp_crypto_get_operation_compl_packet(compl_event);
 	CU_ASSERT(out_pkt == pkt);
 
 	CU_ASSERT(!memcmp(data_addr, output_vec, output_vec_len));
 
-	void *ctx = odp_crypto_get_operation_compl_ctx(odp_buffer_from_event(compl_event));
+	void *ctx = odp_crypto_get_operation_compl_ctx(compl_event);
 	CU_ASSERT(ctx == (void *)0xdeadbeef);
 
 	odp_packet_free(pkt);
@@ -158,7 +156,7 @@  static void enc_alg_3des_cbc(void)
 			 cipher_key,
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
-			 ODP_BUFFER_INVALID,
+			 ODP_EVENT_INVALID,
 			 tdes_cbc_reference_plaintext[i],
 			 tdes_cbc_reference_length[i],
 			 tdes_cbc_reference_ciphertext[i],
@@ -190,7 +188,7 @@  static void enc_alg_3des_cbc_ovr_iv(void)
 			 cipher_key,
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
-			 ODP_BUFFER_INVALID,
+			 ODP_EVENT_INVALID,
 			 tdes_cbc_reference_plaintext[i],
 			 tdes_cbc_reference_length[i],
 			 tdes_cbc_reference_ciphertext[i],
@@ -227,7 +225,7 @@  static void dec_alg_3des_cbc(void)
 			 cipher_key,
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
-			 ODP_BUFFER_INVALID,
+			 ODP_EVENT_INVALID,
 			 tdes_cbc_reference_ciphertext[i],
 			 tdes_cbc_reference_length[i],
 			 tdes_cbc_reference_plaintext[i],
@@ -261,7 +259,7 @@  static void dec_alg_3des_cbc_ovr_iv(void)
 			 cipher_key,
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
-			 ODP_BUFFER_INVALID,
+			 ODP_EVENT_INVALID,
 			 tdes_cbc_reference_ciphertext[i],
 			 tdes_cbc_reference_length[i],
 			 tdes_cbc_reference_plaintext[i],
@@ -299,7 +297,7 @@  static void alg_hmac_md5(void)
 			 cipher_key,
 			 ODP_AUTH_ALG_MD5_96,
 			 auth_key,
-			 ODP_BUFFER_INVALID,
+			 ODP_EVENT_INVALID,
 			 hmac_md5_reference_plaintext[i],
 			 hmac_md5_reference_length[i],
 			 hmac_md5_reference_digest[i],
@@ -341,7 +339,7 @@  static void enc_alg_3des_cbc_compl_new(void)
 			 cipher_key,
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
-			 compl_new,
+			 odp_buffer_to_event(compl_new),
 			 tdes_cbc_reference_plaintext[i],
 			 tdes_cbc_reference_length[i],
 			 tdes_cbc_reference_ciphertext[i],
diff --git a/test/validation/crypto/odp_crypto_test_sync_inp.c b/test/validation/crypto/odp_crypto_test_sync_inp.c
index c527b90..08f501b 100644
--- a/test/validation/crypto/odp_crypto_test_sync_inp.c
+++ b/test/validation/crypto/odp_crypto_test_sync_inp.c
@@ -78,7 +78,8 @@  static void alg_test(enum odp_crypto_op op,
 	}
 
 	/* TEST : odp_crypto_operation */
-	rc = odp_crypto_operation(&op_params, &posted, odp_buffer_from_event(odp_packet_to_event(pkt)));
+	rc = odp_crypto_operation(&op_params, &posted,
+				  odp_packet_to_event(pkt));
 	CU_ASSERT(!rc);
 	/* indication that the operation completed */
 	CU_ASSERT(!posted);