* All rights reserved.
*/
+#include "test.h"
#include <string.h>
#include <rte_common.h>
#include <rte_mempool.h>
#include <rte_mbuf.h>
#include <rte_cryptodev.h>
+
+#ifdef RTE_EXEC_ENV_WINDOWS
+static int
+test_event_crypto_adapter(void)
+{
+ printf("event_crypto_adapter not supported on Windows, skipping test\n");
+ return TEST_SKIPPED;
+}
+
+#else
+
#include <rte_eventdev.h>
#include <rte_bus_vdev.h>
#include <rte_service.h>
#include <rte_event_crypto_adapter.h>
-#include "test.h"
#define PKT_TRACE 0
#define NUM 1
struct rte_mempool *session_priv_mpool;
struct rte_cryptodev_config *config;
uint8_t crypto_event_port_id;
+ uint8_t internal_port_op_fwd;
};
struct rte_event response_info = {
struct rte_event recv_ev;
int ret;
- ret = rte_event_enqueue_burst(evdev, TEST_APP_PORT_ID, ev, NUM);
- TEST_ASSERT_EQUAL(ret, NUM,
- "Failed to send event to crypto adapter\n");
+ if (params.internal_port_op_fwd)
+ ret = rte_event_crypto_adapter_enqueue(evdev, TEST_APP_PORT_ID,
+ ev, NUM);
+ else
+ ret = rte_event_enqueue_burst(evdev, TEST_APP_PORT_ID, ev, NUM);
+ TEST_ASSERT_EQUAL(ret, NUM, "Failed to send event to crypto adapter\n");
while (rte_event_dequeue_burst(evdev,
TEST_APP_PORT_ID, &recv_ev, NUM, 0) == 0)
struct rte_event ev;
uint32_t cap;
int ret;
- uint8_t cipher_key[17];
memset(&m_data, 0, sizeof(m_data));
/* Setup Cipher Parameters */
cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
cipher_xform.next = NULL;
-
- cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
+ cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
- cipher_xform.cipher.key.data = cipher_key;
- cipher_xform.cipher.key.length = 16;
- cipher_xform.cipher.iv.offset = IV_OFFSET;
- cipher_xform.cipher.iv.length = 16;
-
op = rte_crypto_op_alloc(params.op_mpool,
RTE_CRYPTO_OP_TYPE_SYMMETRIC);
TEST_ASSERT_NOT_NULL(op,
&cipher_xform, params.session_priv_mpool);
TEST_ASSERT_SUCCESS(ret, "Failed to init session\n");
- ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID,
- evdev, &cap);
+ ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID,
+ &cap);
TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA) {
/* Fill in private user data information */
- rte_memcpy(&m_data.response_info, &response_info,
- sizeof(response_info));
- rte_memcpy(&m_data.request_info, &request_info,
- sizeof(request_info));
+ m_data.request_info.cdev_id = request_info.cdev_id;
+ m_data.request_info.queue_pair_id =
+ request_info.queue_pair_id;
+ m_data.response_info.event = response_info.event;
rte_cryptodev_sym_session_set_user_data(sess,
&m_data, sizeof(m_data));
}
op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
first_xform = &cipher_xform;
sym_op->xform = first_xform;
- uint32_t len = IV_OFFSET + MAXIMUM_IV_LENGTH +
- (sizeof(struct rte_crypto_sym_xform) * 2);
+ uint32_t len = IV_OFFSET + MAXIMUM_IV_LENGTH;
op->private_data_offset = len;
/* Fill in private data information */
- rte_memcpy(&m_data.response_info, &response_info,
- sizeof(response_info));
- rte_memcpy(&m_data.request_info, &request_info,
- sizeof(request_info));
+ m_data.request_info.cdev_id = request_info.cdev_id;
+ m_data.request_info.queue_pair_id = request_info.queue_pair_id;
+ m_data.response_info.event = response_info.event;
rte_memcpy((uint8_t *)op + len, &m_data, sizeof(m_data));
}
uint32_t cap;
int ret;
- ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
+ ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
uint32_t cap;
int ret;
- ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
+ ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
struct rte_mbuf *m;
uint32_t cap;
int ret;
- uint8_t cipher_key[17];
memset(&m_data, 0, sizeof(m_data));
/* Setup Cipher Parameters */
cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
cipher_xform.next = NULL;
-
- cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
+ cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
- cipher_xform.cipher.key.data = cipher_key;
- cipher_xform.cipher.key.length = 16;
- cipher_xform.cipher.iv.offset = IV_OFFSET;
- cipher_xform.cipher.iv.length = 16;
-
op = rte_crypto_op_alloc(params.op_mpool,
RTE_CRYPTO_OP_TYPE_SYMMETRIC);
TEST_ASSERT_NOT_NULL(op, "Failed to allocate crypto_op!\n");
params.session_mpool);
TEST_ASSERT_NOT_NULL(sess, "Session creation failed\n");
- ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID,
- evdev, &cap);
+ ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID,
+ &cap);
TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA) {
/* Fill in private user data information */
- rte_memcpy(&m_data.response_info, &response_info,
- sizeof(m_data));
+ m_data.response_info.event = response_info.event;
rte_cryptodev_sym_session_set_user_data(sess,
&m_data, sizeof(m_data));
}
op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
first_xform = &cipher_xform;
sym_op->xform = first_xform;
- uint32_t len = IV_OFFSET + MAXIMUM_IV_LENGTH +
- (sizeof(struct rte_crypto_sym_xform) * 2);
+ uint32_t len = IV_OFFSET + MAXIMUM_IV_LENGTH;
op->private_data_offset = len;
/* Fill in private data information */
- rte_memcpy(&m_data.response_info, &response_info,
- sizeof(m_data));
+ m_data.response_info.event = response_info.event;
rte_memcpy((uint8_t *)op + len, &m_data, sizeof(m_data));
}
uint32_t cap;
int ret;
- ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
+ ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
uint32_t cap;
int ret;
- ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
+ ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
NUM_MBUFS, MBUF_CACHE_SIZE,
DEFAULT_NUM_XFORMS *
sizeof(struct rte_crypto_sym_xform) +
- MAXIMUM_IV_LENGTH,
+ MAXIMUM_IV_LENGTH +
+ sizeof(union rte_event_crypto_metadata),
rte_socket_id());
if (params.op_mpool == NULL) {
RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
params.session_mpool = rte_cryptodev_sym_session_pool_create(
"CRYPTO_ADAPTER_SESSION_MP",
- MAX_NB_SESSIONS, 0, 0, 0, SOCKET_ID_ANY);
+ MAX_NB_SESSIONS, 0, 0,
+ sizeof(union rte_event_crypto_metadata),
+ SOCKET_ID_ANY);
TEST_ASSERT_NOT_NULL(params.session_mpool,
"session mempool allocation failed\n");
/* Create adapter with default port creation callback */
ret = rte_event_crypto_adapter_create(TEST_ADAPTER_ID,
- TEST_CDEV_ID,
+ evdev,
&conf, 0);
TEST_ASSERT_SUCCESS(ret, "Failed to create event crypto adapter\n");
uint32_t cap;
int ret;
- ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
+ ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) {
uint32_t cap;
int ret;
+ ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
+ TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
+
+ /* Skip mode and capability mismatch check for SW eventdev */
+ if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW) &&
+ !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
+ !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND))
+ goto adapter_create;
+
+ if (mode == RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD) {
+ if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD)
+ params.internal_port_op_fwd = 1;
+ else
+ return -ENOTSUP;
+ }
+
+ if ((mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) &&
+ !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
+ return -ENOTSUP;
+
+adapter_create:
/* Create adapter with default port creation callback */
ret = rte_event_crypto_adapter_create(TEST_ADAPTER_ID,
- TEST_CDEV_ID,
+ evdev,
&conf, mode);
TEST_ASSERT_SUCCESS(ret, "Failed to create event crypto adapter\n");
- ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
- TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
-
if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) {
ret = rte_event_crypto_adapter_queue_pair_add(TEST_ADAPTER_ID,
TEST_CDEV_ID, TEST_CDEV_QP_ID, &response_info);
TEST_ASSERT_SUCCESS(ret, "Failed to add queue pair\n");
- ret = rte_event_crypto_adapter_event_port_get(TEST_ADAPTER_ID,
- ¶ms.crypto_event_port_id);
- TEST_ASSERT_SUCCESS(ret, "Failed to get event port\n");
+ if (!params.internal_port_op_fwd) {
+ ret = rte_event_crypto_adapter_event_port_get(TEST_ADAPTER_ID,
+ ¶ms.crypto_event_port_id);
+ TEST_ASSERT_SUCCESS(ret, "Failed to get event port\n");
+ }
return TEST_SUCCESS;
}
rte_service_runstate_set(evdev_service_id, 0);
rte_service_lcore_stop(slcore_id);
rte_service_lcore_del(slcore_id);
+ rte_cryptodev_stop(TEST_CDEV_ID);
+ rte_event_dev_stop(evdev);
+ } else {
+ rte_cryptodev_stop(TEST_CDEV_ID);
rte_event_dev_stop(evdev);
}
}
if (!crypto_adapter_setup_done) {
ret = configure_event_crypto_adapter(mode);
- if (!ret) {
+ if (ret)
+ return ret;
+ if (!params.internal_port_op_fwd) {
qid = TEST_CRYPTO_EV_QUEUE_ID;
ret = rte_event_port_link(evdev,
params.crypto_event_port_id, &qid, NULL, 1);
TEST_ASSERT_SUCCESS(rte_event_dev_start(evdev),
"Failed to start event device");
+ /* start the cryptodev */
+ TEST_ASSERT_SUCCESS(rte_cryptodev_start(TEST_CDEV_ID),
+ "Failed to start crypto device");
+
return TEST_SUCCESS;
}
enum rte_event_crypto_adapter_mode mode;
mode = RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD;
- TEST_ASSERT_SUCCESS(test_crypto_adapter_conf(mode),
- "Failed to config crypto adapter");
- return TEST_SUCCESS;
+ return test_crypto_adapter_conf(mode);
}
static int
enum rte_event_crypto_adapter_mode mode;
mode = RTE_EVENT_CRYPTO_ADAPTER_OP_NEW;
- TEST_ASSERT_SUCCESS(test_crypto_adapter_conf(mode),
- "Failed to config crypto adapter");
- return TEST_SUCCESS;
+ return test_crypto_adapter_conf(mode);
}
return TEST_SUCCESS;
}
+static void
+crypto_adapter_teardown(void)
+{
+ int ret;
+
+ ret = rte_event_crypto_adapter_stop(TEST_ADAPTER_ID);
+ if (ret < 0)
+ RTE_LOG(ERR, USER1, "Failed to stop adapter!");
+
+ ret = rte_event_crypto_adapter_queue_pair_del(TEST_ADAPTER_ID,
+ TEST_CDEV_ID, TEST_CDEV_QP_ID);
+ if (ret < 0)
+ RTE_LOG(ERR, USER1, "Failed to delete queue pair!");
+
+ ret = rte_event_crypto_adapter_free(TEST_ADAPTER_ID);
+ if (ret < 0)
+ RTE_LOG(ERR, USER1, "Failed to free adapter!");
+
+ crypto_adapter_setup_done = 0;
+}
+
static void
crypto_teardown(void)
{
static void
testsuite_teardown(void)
{
+ crypto_adapter_teardown();
crypto_teardown();
eventdev_teardown();
}
return unit_test_suite_runner(&functional_testsuite);
}
+#endif /* !RTE_EXEC_ENV_WINDOWS */
+
REGISTER_TEST_COMMAND(event_crypto_adapter_autotest,
test_event_crypto_adapter);