1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation.
8 #include <rte_common.h>
9 #include <rte_malloc.h>
10 #include <rte_mempool.h>
12 #include <rte_cryptodev.h>
14 #ifdef RTE_EXEC_ENV_WINDOWS
16 test_event_crypto_adapter(void)
18 printf("event_crypto_adapter not supported on Windows, skipping test\n");
24 #include <rte_eventdev.h>
25 #include <rte_bus_vdev.h>
26 #include <rte_service.h>
27 #include <rte_event_crypto_adapter.h>
31 #define DEFAULT_NUM_XFORMS (2)
32 #define NUM_MBUFS (8191)
33 #define MBUF_CACHE_SIZE (256)
34 #define MAXIMUM_IV_LENGTH (16)
35 #define DEFAULT_NUM_OPS_INFLIGHT (128)
36 #define MAX_NB_SESSIONS 4
37 #define TEST_APP_PORT_ID 0
38 #define TEST_APP_EV_QUEUE_ID 0
39 #define TEST_APP_EV_PRIORITY 0
40 #define TEST_APP_EV_FLOWID 0xAABB
41 #define TEST_CRYPTO_EV_QUEUE_ID 1
42 #define TEST_ADAPTER_ID 0
43 #define TEST_CDEV_ID 0
44 #define TEST_CDEV_QP_ID 0
45 #define PACKET_LENGTH 64
46 #define NB_TEST_PORTS 1
47 #define NB_TEST_QUEUES 2
49 #define CRYPTODEV_NAME_NULL_PMD crypto_null
51 #define MBUF_SIZE (sizeof(struct rte_mbuf) + \
52 RTE_PKTMBUF_HEADROOM + PACKET_LENGTH)
53 #define IV_OFFSET (sizeof(struct rte_crypto_op) + \
54 sizeof(struct rte_crypto_sym_op) + \
55 DEFAULT_NUM_XFORMS * \
56 sizeof(struct rte_crypto_sym_xform))
58 /* Handle log statements in same manner as test macros */
59 #define LOG_DBG(...) RTE_LOG(DEBUG, EAL, __VA_ARGS__)
61 static const uint8_t text_64B[] = {
62 0x05, 0x15, 0x77, 0x32, 0xc9, 0x66, 0x91, 0x50,
63 0x93, 0x9f, 0xbb, 0x4e, 0x2e, 0x5a, 0x02, 0xd0,
64 0x2d, 0x9d, 0x31, 0x5d, 0xc8, 0x9e, 0x86, 0x36,
65 0x54, 0x5c, 0x50, 0xe8, 0x75, 0x54, 0x74, 0x5e,
66 0xd5, 0xa2, 0x84, 0x21, 0x2d, 0xc5, 0xf8, 0x1c,
67 0x55, 0x1a, 0xba, 0x91, 0xce, 0xb5, 0xa3, 0x1e,
68 0x31, 0xbf, 0xe9, 0xa1, 0x97, 0x5c, 0x2b, 0xd6,
69 0x57, 0xa5, 0x9f, 0xab, 0xbd, 0xb0, 0x9b, 0x9c
72 struct modex_test_data {
73 enum rte_crypto_asym_xform_type xform_type;
75 uint8_t data[DATA_SIZE];
79 uint8_t data[DATA_SIZE];
83 uint8_t data[DATA_SIZE];
87 uint8_t data[DATA_SIZE];
94 modex_test_data modex_test_case = {
95 .xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
98 0xF8, 0xBA, 0x1A, 0x55, 0xD0, 0x2F, 0x85,
99 0xAE, 0x96, 0x7B, 0xB6, 0x2F, 0xB6, 0xCD,
100 0xA8, 0xEB, 0x7E, 0x78, 0xA0, 0x50
112 0x2C, 0x60, 0x75, 0x45, 0x98, 0x9D, 0xE0, 0x72,
113 0xA0, 0x9D, 0x3A, 0x9E, 0x03, 0x38, 0x73, 0x3C,
114 0x31, 0x83, 0x04, 0xFE, 0x75, 0x43, 0xE6, 0x17,
115 0x5C, 0x01, 0x29, 0x51, 0x69, 0x33, 0x62, 0x2D,
116 0x78, 0xBE, 0xAE, 0xC4, 0xBC, 0xDE, 0x7E, 0x2C,
117 0x77, 0x84, 0xF2, 0xC5, 0x14, 0xB5, 0x2F, 0xF7,
118 0xC5, 0x94, 0xEF, 0x86, 0x75, 0x75, 0xB5, 0x11,
119 0xE5, 0x0E, 0x0A, 0x29, 0x76, 0xE2, 0xEA, 0x32,
120 0x0E, 0x43, 0x77, 0x7E, 0x2C, 0x27, 0xAC, 0x3B,
121 0x86, 0xA5, 0xDB, 0xC9, 0x48, 0x40, 0xE8, 0x99,
122 0x9A, 0x0A, 0x3D, 0xD6, 0x74, 0xFA, 0x2E, 0x2E,
123 0x5B, 0xAF, 0x8C, 0x99, 0x44, 0x2A, 0x67, 0x38,
124 0x27, 0x41, 0x59, 0x9D, 0xB8, 0x51, 0xC9, 0xF7,
125 0x43, 0x61, 0x31, 0x6E, 0xF1, 0x25, 0x38, 0x7F,
126 0xAE, 0xC6, 0xD0, 0xBB, 0x29, 0x76, 0x3F, 0x46,
127 0x2E, 0x1B, 0xE4, 0x67, 0x71, 0xE3, 0x87, 0x5A
133 0xb3, 0xa1, 0xaf, 0xb7, 0x13, 0x08, 0x00, 0x0a,
134 0x35, 0xdc, 0x2b, 0x20, 0x8d, 0xa1, 0xb5, 0xce,
135 0x47, 0x8a, 0xc3, 0x80, 0xf4, 0x7d, 0x4a, 0xa2,
136 0x62, 0xfd, 0x61, 0x7f, 0xb5, 0xa8, 0xde, 0x0a,
137 0x17, 0x97, 0xa0, 0xbf, 0xdf, 0x56, 0x5a, 0x3d,
138 0x51, 0x56, 0x4f, 0x70, 0x70, 0x3f, 0x63, 0x6a,
139 0x44, 0x5b, 0xad, 0x84, 0x0d, 0x3f, 0x27, 0x6e,
140 0x3b, 0x34, 0x91, 0x60, 0x14, 0xb9, 0xaa, 0x72,
141 0xfd, 0xa3, 0x64, 0xd2, 0x03, 0xa7, 0x53, 0x87,
142 0x9e, 0x88, 0x0b, 0xc1, 0x14, 0x93, 0x1a, 0x62,
143 0xff, 0xb1, 0x5d, 0x74, 0xcd, 0x59, 0x63, 0x18,
144 0x11, 0x3d, 0x4f, 0xba, 0x75, 0xd4, 0x33, 0x4e,
145 0x23, 0x6b, 0x7b, 0x57, 0x44, 0xe1, 0xd3, 0x03,
146 0x13, 0xa6, 0xf0, 0x8b, 0x60, 0xb0, 0x9e, 0xee,
147 0x75, 0x08, 0x9d, 0x71, 0x63, 0x13, 0xcb, 0xa6,
148 0x81, 0x92, 0x14, 0x03, 0x22, 0x2d, 0xde, 0x55
155 struct event_crypto_adapter_test_params {
156 struct rte_mempool *mbuf_pool;
157 struct rte_mempool *op_mpool;
158 struct rte_mempool *asym_op_mpool;
159 struct rte_mempool *session_mpool;
160 struct rte_mempool *session_priv_mpool;
161 struct rte_mempool *asym_sess_mpool;
162 struct rte_cryptodev_config *config;
163 uint8_t crypto_event_port_id;
164 uint8_t internal_port_op_fwd;
167 struct rte_event response_info = {
168 .queue_id = TEST_APP_EV_QUEUE_ID,
169 .sched_type = RTE_SCHED_TYPE_ATOMIC,
170 .flow_id = TEST_APP_EV_FLOWID,
171 .priority = TEST_APP_EV_PRIORITY
174 struct rte_event_crypto_request request_info = {
175 .cdev_id = TEST_CDEV_ID,
176 .queue_pair_id = TEST_CDEV_QP_ID
179 static struct event_crypto_adapter_test_params params;
180 static uint8_t crypto_adapter_setup_done;
181 static uint32_t slcore_id;
184 static struct rte_mbuf *
185 alloc_fill_mbuf(struct rte_mempool *mpool, const uint8_t *data,
186 size_t len, uint8_t blocksize)
188 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
189 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
192 char *dst = rte_pktmbuf_append(m, t_len);
199 rte_memcpy(dst, (const void *)data, t_len);
205 send_recv_ev(struct rte_event *ev)
207 struct rte_crypto_op *op;
208 struct rte_event recv_ev;
211 if (params.internal_port_op_fwd)
212 ret = rte_event_crypto_adapter_enqueue(evdev, TEST_APP_PORT_ID,
215 ret = rte_event_enqueue_burst(evdev, TEST_APP_PORT_ID, ev, NUM);
216 TEST_ASSERT_EQUAL(ret, NUM, "Failed to send event to crypto adapter\n");
218 while (rte_event_dequeue_burst(evdev,
219 TEST_APP_PORT_ID, &recv_ev, NUM, 0) == 0)
222 op = recv_ev.event_ptr;
223 if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
225 struct rte_mbuf *m = op->sym->m_src;
226 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
228 rte_pktmbuf_free(op->sym->m_src);
230 uint8_t *data_expected = NULL, *data_received = NULL;
233 data_expected = modex_test_case.reminder.data;
234 data_received = op->asym->modex.result.data;
235 data_size = op->asym->modex.result.length;
236 ret = memcmp(data_expected, data_received, data_size);
237 TEST_ASSERT_EQUAL(ret, 0,
238 "Data mismatch for asym crypto adapter\n");
239 rte_free(op->asym->modex.result.data);
241 rte_crypto_op_free(op);
247 test_crypto_adapter_stats(void)
249 struct rte_event_crypto_adapter_stats stats;
251 rte_event_crypto_adapter_stats_get(TEST_ADAPTER_ID, &stats);
252 printf(" +------------------------------------------------------+\n");
253 printf(" + Crypto adapter stats for instance %u:\n", TEST_ADAPTER_ID);
254 printf(" + Event port poll count %" PRIx64 "\n",
255 stats.event_poll_count);
256 printf(" + Event dequeue count %" PRIx64 "\n",
257 stats.event_deq_count);
258 printf(" + Cryptodev enqueue count %" PRIx64 "\n",
259 stats.crypto_enq_count);
260 printf(" + Cryptodev enqueue failed count %" PRIx64 "\n",
261 stats.crypto_enq_fail);
262 printf(" + Cryptodev dequeue count %" PRIx64 "\n",
263 stats.crypto_deq_count);
264 printf(" + Event enqueue count %" PRIx64 "\n",
265 stats.event_enq_count);
266 printf(" + Event enqueue retry count %" PRIx64 "\n",
267 stats.event_enq_retry_count);
268 printf(" + Event enqueue fail count %" PRIx64 "\n",
269 stats.event_enq_fail_count);
270 printf(" +------------------------------------------------------+\n");
272 rte_event_crypto_adapter_stats_reset(TEST_ADAPTER_ID);
277 test_op_forward_mode(uint8_t session_less)
279 struct rte_crypto_sym_xform cipher_xform;
280 struct rte_cryptodev_sym_session *sess;
281 union rte_event_crypto_metadata m_data;
282 struct rte_crypto_sym_op *sym_op;
283 struct rte_crypto_op *op;
289 memset(&m_data, 0, sizeof(m_data));
291 m = alloc_fill_mbuf(params.mbuf_pool, text_64B, PACKET_LENGTH, 0);
292 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf!\n");
294 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
296 /* Setup Cipher Parameters */
297 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
298 cipher_xform.next = NULL;
299 cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
300 cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
302 op = rte_crypto_op_alloc(params.op_mpool,
303 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
304 TEST_ASSERT_NOT_NULL(op,
305 "Failed to allocate symmetric crypto operation struct\n");
310 sess = rte_cryptodev_sym_session_create(
311 params.session_mpool);
312 TEST_ASSERT_NOT_NULL(sess, "Session creation failed\n");
314 /* Create Crypto session*/
315 ret = rte_cryptodev_sym_session_init(TEST_CDEV_ID, sess,
316 &cipher_xform, params.session_priv_mpool);
317 TEST_ASSERT_SUCCESS(ret, "Failed to init session\n");
319 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID,
321 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
323 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA) {
324 /* Fill in private user data information */
325 m_data.request_info.cdev_id = request_info.cdev_id;
326 m_data.request_info.queue_pair_id =
327 request_info.queue_pair_id;
328 m_data.response_info.event = response_info.event;
329 rte_cryptodev_session_event_mdata_set(TEST_CDEV_ID,
330 sess, RTE_CRYPTO_OP_TYPE_SYMMETRIC,
331 RTE_CRYPTO_OP_WITH_SESSION,
332 &m_data, sizeof(m_data));
335 rte_crypto_op_attach_sym_session(op, sess);
337 struct rte_crypto_sym_xform *first_xform;
339 rte_crypto_op_sym_xforms_alloc(op, NUM);
340 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
341 first_xform = &cipher_xform;
342 sym_op->xform = first_xform;
343 uint32_t len = IV_OFFSET + MAXIMUM_IV_LENGTH;
344 op->private_data_offset = len;
345 /* Fill in private data information */
346 m_data.request_info.cdev_id = request_info.cdev_id;
347 m_data.request_info.queue_pair_id = request_info.queue_pair_id;
348 m_data.response_info.event = response_info.event;
349 rte_memcpy((uint8_t *)op + len, &m_data, sizeof(m_data));
353 sym_op->cipher.data.offset = 0;
354 sym_op->cipher.data.length = PACKET_LENGTH;
356 /* Fill in event info and update event_ptr with rte_crypto_op */
357 memset(&ev, 0, sizeof(ev));
358 ev.queue_id = TEST_CRYPTO_EV_QUEUE_ID;
359 ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
363 ret = send_recv_ev(&ev);
364 TEST_ASSERT_SUCCESS(ret, "Failed to send/receive event to "
367 test_crypto_adapter_stats();
373 map_adapter_service_core(void)
375 uint32_t adapter_service_id;
378 if (rte_event_crypto_adapter_service_id_get(TEST_ADAPTER_ID,
379 &adapter_service_id) == 0) {
380 uint32_t core_list[NUM_CORES];
382 ret = rte_service_lcore_list(core_list, NUM_CORES);
383 TEST_ASSERT(ret >= 0, "Failed to get service core list!");
385 if (core_list[0] != slcore_id) {
386 TEST_ASSERT_SUCCESS(rte_service_lcore_add(slcore_id),
387 "Failed to add service core");
388 TEST_ASSERT_SUCCESS(rte_service_lcore_start(slcore_id),
389 "Failed to start service core");
392 TEST_ASSERT_SUCCESS(rte_service_map_lcore_set(
393 adapter_service_id, slcore_id, 1),
394 "Failed to map adapter service");
401 test_sessionless_with_op_forward_mode(void)
406 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
407 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
409 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
410 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
411 map_adapter_service_core();
413 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))
417 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID),
418 "Failed to start event crypto adapter");
420 ret = test_op_forward_mode(1);
421 TEST_ASSERT_SUCCESS(ret, "Sessionless - FORWARD mode test failed\n");
426 test_session_with_op_forward_mode(void)
431 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
432 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
434 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
435 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
436 map_adapter_service_core();
438 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))
442 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID
443 ), "Failed to start event crypto adapter");
445 ret = test_op_forward_mode(0);
446 TEST_ASSERT_SUCCESS(ret, "Session based - FORWARD mode test failed\n");
451 test_asym_op_forward_mode(uint8_t session_less)
453 const struct rte_cryptodev_asymmetric_xform_capability *capability;
454 struct rte_cryptodev_asym_capability_idx cap_idx;
455 struct rte_crypto_asym_xform xform_tc;
456 union rte_event_crypto_metadata m_data;
457 struct rte_cryptodev_info dev_info;
458 struct rte_crypto_asym_op *asym_op;
459 struct rte_crypto_op *op;
460 uint8_t input[4096] = {0};
461 uint8_t *result = NULL;
467 memset(&m_data, 0, sizeof(m_data));
469 rte_cryptodev_info_get(TEST_CDEV_ID, &dev_info);
470 if (session_less && !(dev_info.feature_flags &
471 RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
473 "Device doesn't support Asym sessionless ops. Test Skipped\n");
476 /* Setup Cipher Parameters */
477 xform_tc.next = NULL;
478 xform_tc.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
479 cap_idx.type = xform_tc.xform_type;
480 capability = rte_cryptodev_asym_capability_get(TEST_CDEV_ID, &cap_idx);
482 if (capability == NULL) {
484 "Device doesn't support MODEX. Test Skipped\n");
488 op = rte_crypto_op_alloc(params.asym_op_mpool,
489 RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
490 TEST_ASSERT_NOT_NULL(op,
491 "Failed to allocate asymmetric crypto operation struct\n");
495 result = rte_zmalloc(NULL, modex_test_case.result_len, 0);
496 xform_tc.modex.modulus.data = modex_test_case.modulus.data;
497 xform_tc.modex.modulus.length = modex_test_case.modulus.len;
498 xform_tc.modex.exponent.data = modex_test_case.exponent.data;
499 xform_tc.modex.exponent.length = modex_test_case.exponent.len;
500 memcpy(input, modex_test_case.base.data,
501 modex_test_case.base.len);
502 asym_op->modex.base.data = input;
503 asym_op->modex.base.length = modex_test_case.base.len;
504 asym_op->modex.result.data = result;
505 asym_op->modex.result.length = modex_test_case.result_len;
506 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
507 xform_tc.modex.modulus.length)) {
509 "line %u FAILED: %s", __LINE__,
510 "Invalid MODULUS length specified");
515 /* Create Crypto session*/
516 ret = rte_cryptodev_asym_session_create(TEST_CDEV_ID,
517 &xform_tc, params.asym_sess_mpool, &sess);
518 TEST_ASSERT_SUCCESS(ret, "Failed to init session\n");
520 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID,
522 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
524 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA) {
525 /* Fill in private user data information */
526 m_data.request_info.cdev_id = request_info.cdev_id;
527 m_data.request_info.queue_pair_id =
528 request_info.queue_pair_id;
529 m_data.response_info.event = response_info.event;
530 rte_cryptodev_session_event_mdata_set(TEST_CDEV_ID,
531 sess, RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
532 RTE_CRYPTO_OP_WITH_SESSION,
533 &m_data, sizeof(m_data));
536 rte_crypto_op_attach_asym_session(op, sess);
538 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
539 asym_op->xform = &xform_tc;
540 op->private_data_offset = (sizeof(struct rte_crypto_op) +
541 sizeof(struct rte_crypto_asym_op) +
543 sizeof(struct rte_crypto_asym_xform));
544 /* Fill in private data information */
545 m_data.request_info.cdev_id = request_info.cdev_id;
546 m_data.request_info.queue_pair_id = request_info.queue_pair_id;
547 m_data.response_info.event = response_info.event;
548 rte_memcpy((uint8_t *)op + op->private_data_offset,
549 &m_data, sizeof(m_data));
551 /* Fill in event info and update event_ptr with rte_crypto_op */
552 memset(&ev, 0, sizeof(ev));
553 ev.queue_id = TEST_CRYPTO_EV_QUEUE_ID;
554 ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
558 ret = send_recv_ev(&ev);
559 TEST_ASSERT_SUCCESS(ret, "Failed to send/receive event to "
562 test_crypto_adapter_stats();
569 test_asym_sessionless_with_op_forward_mode(void)
574 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
575 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
577 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
578 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
579 map_adapter_service_core();
581 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))
585 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID),
586 "Failed to start event crypto adapter");
588 return test_asym_op_forward_mode(1);
592 test_asym_session_with_op_forward_mode(void)
597 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
598 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
600 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
601 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
602 map_adapter_service_core();
604 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))
608 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID
609 ), "Failed to start event crypto adapter");
611 return test_asym_op_forward_mode(0);
615 send_op_recv_ev(struct rte_crypto_op *op)
617 struct rte_crypto_op *recv_op;
621 ret = rte_cryptodev_enqueue_burst(TEST_CDEV_ID, TEST_CDEV_QP_ID,
623 TEST_ASSERT_EQUAL(ret, NUM, "Failed to enqueue to cryptodev\n");
624 memset(&ev, 0, sizeof(ev));
626 while (rte_event_dequeue_burst(evdev,
627 TEST_APP_PORT_ID, &ev, NUM, 0) == 0)
630 recv_op = ev.event_ptr;
631 if (recv_op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
633 struct rte_mbuf *m = recv_op->sym->m_src;
634 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
636 rte_pktmbuf_free(recv_op->sym->m_src);
638 uint8_t *data_expected = NULL, *data_received = NULL;
641 data_expected = modex_test_case.reminder.data;
642 data_received = op->asym->modex.result.data;
643 data_size = op->asym->modex.result.length;
644 ret = memcmp(data_expected, data_received, data_size);
645 TEST_ASSERT_EQUAL(ret, 0,
646 "Data mismatch for asym crypto adapter\n");
647 rte_free(op->asym->modex.result.data);
649 rte_crypto_op_free(recv_op);
655 test_op_new_mode(uint8_t session_less)
657 struct rte_crypto_sym_xform cipher_xform;
658 struct rte_cryptodev_sym_session *sess;
659 union rte_event_crypto_metadata m_data;
660 struct rte_crypto_sym_op *sym_op;
661 struct rte_crypto_op *op;
666 memset(&m_data, 0, sizeof(m_data));
668 m = alloc_fill_mbuf(params.mbuf_pool, text_64B, PACKET_LENGTH, 0);
669 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf!\n");
671 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
673 /* Setup Cipher Parameters */
674 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
675 cipher_xform.next = NULL;
676 cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
677 cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
679 op = rte_crypto_op_alloc(params.op_mpool,
680 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
681 TEST_ASSERT_NOT_NULL(op, "Failed to allocate crypto_op!\n");
686 sess = rte_cryptodev_sym_session_create(
687 params.session_mpool);
688 TEST_ASSERT_NOT_NULL(sess, "Session creation failed\n");
690 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID,
692 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
694 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA) {
695 /* Fill in private user data information */
696 m_data.response_info.event = response_info.event;
697 rte_cryptodev_session_event_mdata_set(TEST_CDEV_ID,
698 sess, RTE_CRYPTO_OP_TYPE_SYMMETRIC,
699 RTE_CRYPTO_OP_WITH_SESSION,
700 &m_data, sizeof(m_data));
702 ret = rte_cryptodev_sym_session_init(TEST_CDEV_ID, sess,
703 &cipher_xform, params.session_priv_mpool);
704 TEST_ASSERT_SUCCESS(ret, "Failed to init session\n");
706 rte_crypto_op_attach_sym_session(op, sess);
708 struct rte_crypto_sym_xform *first_xform;
710 rte_crypto_op_sym_xforms_alloc(op, NUM);
711 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
712 first_xform = &cipher_xform;
713 sym_op->xform = first_xform;
714 uint32_t len = IV_OFFSET + MAXIMUM_IV_LENGTH;
715 op->private_data_offset = len;
716 /* Fill in private data information */
717 m_data.response_info.event = response_info.event;
718 rte_memcpy((uint8_t *)op + len, &m_data, sizeof(m_data));
722 sym_op->cipher.data.offset = 0;
723 sym_op->cipher.data.length = PACKET_LENGTH;
725 ret = send_op_recv_ev(op);
726 TEST_ASSERT_SUCCESS(ret, "Failed to enqueue op to cryptodev\n");
728 test_crypto_adapter_stats();
734 test_sessionless_with_op_new_mode(void)
739 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
740 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
742 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
743 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
744 map_adapter_service_core();
746 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
750 /* start the event crypto adapter */
751 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID),
752 "Failed to start event crypto adapter");
754 ret = test_op_new_mode(1);
755 TEST_ASSERT_SUCCESS(ret, "Sessionless - NEW mode test failed\n");
760 test_session_with_op_new_mode(void)
765 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
766 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
768 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
769 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
770 map_adapter_service_core();
772 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
776 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID),
777 "Failed to start event crypto adapter");
779 ret = test_op_new_mode(0);
780 TEST_ASSERT_SUCCESS(ret, "Session based - NEW mode test failed\n");
785 test_asym_op_new_mode(uint8_t session_less)
787 const struct rte_cryptodev_asymmetric_xform_capability *capability;
788 struct rte_cryptodev_asym_capability_idx cap_idx;
789 struct rte_crypto_asym_xform xform_tc;
790 union rte_event_crypto_metadata m_data;
791 struct rte_cryptodev_info dev_info;
792 struct rte_crypto_asym_op *asym_op;
793 struct rte_crypto_op *op;
794 uint8_t input[4096] = {0};
795 uint8_t *result = NULL;
800 memset(&m_data, 0, sizeof(m_data));
802 rte_cryptodev_info_get(TEST_CDEV_ID, &dev_info);
803 if (session_less && !(dev_info.feature_flags &
804 RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
806 "Device doesn't support Asym sessionless ops. Test Skipped\n");
809 /* Setup Cipher Parameters */
810 xform_tc.next = NULL;
811 xform_tc.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
812 cap_idx.type = xform_tc.xform_type;
813 capability = rte_cryptodev_asym_capability_get(TEST_CDEV_ID, &cap_idx);
815 if (capability == NULL) {
817 "Device doesn't support MODEX. Test Skipped\n");
821 op = rte_crypto_op_alloc(params.asym_op_mpool,
822 RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
823 TEST_ASSERT_NOT_NULL(op, "Failed to allocate asym crypto_op!\n");
827 result = rte_zmalloc(NULL, modex_test_case.result_len, 0);
828 xform_tc.modex.modulus.data = modex_test_case.modulus.data;
829 xform_tc.modex.modulus.length = modex_test_case.modulus.len;
830 xform_tc.modex.exponent.data = modex_test_case.exponent.data;
831 xform_tc.modex.exponent.length = modex_test_case.exponent.len;
832 memcpy(input, modex_test_case.base.data,
833 modex_test_case.base.len);
834 asym_op->modex.base.data = input;
835 asym_op->modex.base.length = modex_test_case.base.len;
836 asym_op->modex.result.data = result;
837 asym_op->modex.result.length = modex_test_case.result_len;
838 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
839 xform_tc.modex.modulus.length)) {
841 "line %u FAILED: %s", __LINE__,
842 "Invalid MODULUS length specified");
847 ret = rte_cryptodev_asym_session_create(TEST_CDEV_ID,
848 &xform_tc, params.asym_sess_mpool, &sess);
849 TEST_ASSERT_NOT_NULL(sess, "Session creation failed\n");
850 TEST_ASSERT_SUCCESS(ret, "Failed to init session\n");
852 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID,
854 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
856 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA) {
857 /* Fill in private user data information */
858 m_data.response_info.event = response_info.event;
859 rte_cryptodev_session_event_mdata_set(TEST_CDEV_ID,
860 sess, RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
861 RTE_CRYPTO_OP_WITH_SESSION,
862 &m_data, sizeof(m_data));
865 rte_crypto_op_attach_asym_session(op, sess);
867 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
868 asym_op->xform = &xform_tc;
869 op->private_data_offset = (sizeof(struct rte_crypto_op) +
870 sizeof(struct rte_crypto_asym_op) +
872 sizeof(struct rte_crypto_asym_xform));
873 /* Fill in private data information */
874 m_data.response_info.event = response_info.event;
875 rte_memcpy((uint8_t *)op + op->private_data_offset,
876 &m_data, sizeof(m_data));
879 ret = send_op_recv_ev(op);
880 TEST_ASSERT_SUCCESS(ret, "Failed to enqueue op to cryptodev\n");
882 test_crypto_adapter_stats();
888 test_asym_sessionless_with_op_new_mode(void)
893 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
894 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
896 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
897 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
898 map_adapter_service_core();
900 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
904 /* start the event crypto adapter */
905 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID),
906 "Failed to start event crypto adapter");
908 return test_asym_op_new_mode(1);
912 test_asym_session_with_op_new_mode(void)
917 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
918 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
920 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
921 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
922 map_adapter_service_core();
924 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
928 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID),
929 "Failed to start event crypto adapter");
931 return test_asym_op_new_mode(0);
935 configure_cryptodev(void)
937 const struct rte_cryptodev_capabilities *capability;
938 struct rte_cryptodev_qp_conf qp_conf;
939 struct rte_cryptodev_config conf;
940 struct rte_cryptodev_info info;
941 unsigned int session_size;
947 params.mbuf_pool = rte_pktmbuf_pool_create(
948 "CRYPTO_ADAPTER_MBUFPOOL",
949 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
951 if (params.mbuf_pool == NULL) {
952 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
956 params.op_mpool = rte_crypto_op_pool_create(
957 "EVENT_CRYPTO_SYM_OP_POOL",
958 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
959 NUM_MBUFS, MBUF_CACHE_SIZE,
961 sizeof(struct rte_crypto_sym_xform) +
963 sizeof(union rte_event_crypto_metadata),
965 if (params.op_mpool == NULL) {
966 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
970 /* Create a NULL crypto device */
971 nb_devs = rte_cryptodev_device_count_by_driver(
972 rte_cryptodev_driver_id_get(
973 RTE_STR(CRYPTODEV_NAME_NULL_PMD)));
976 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
978 TEST_ASSERT(ret == 0, "Failed to create pmd:%s instance\n",
979 RTE_STR(CRYPTODEV_NAME_NULL_PMD));
982 nb_devs = rte_cryptodev_count();
984 RTE_LOG(ERR, USER1, "No crypto devices found!\n");
989 * Create mempool with maximum number of sessions * 2,
990 * to include the session headers & private data
992 session_size = rte_cryptodev_sym_get_private_session_size(TEST_CDEV_ID);
993 session_size += sizeof(union rte_event_crypto_metadata);
995 params.session_mpool = rte_cryptodev_sym_session_pool_create(
996 "CRYPTO_ADAPTER_SESSION_MP",
997 MAX_NB_SESSIONS, 0, 0,
998 sizeof(union rte_event_crypto_metadata),
1000 TEST_ASSERT_NOT_NULL(params.session_mpool,
1001 "session mempool allocation failed\n");
1003 params.session_priv_mpool = rte_mempool_create(
1004 "CRYPTO_AD_SESS_MP_PRIV",
1007 0, 0, NULL, NULL, NULL,
1008 NULL, SOCKET_ID_ANY,
1010 TEST_ASSERT_NOT_NULL(params.session_priv_mpool,
1011 "session mempool allocation failed\n");
1013 rte_cryptodev_info_get(TEST_CDEV_ID, &info);
1015 while ((capability = &info.capabilities[i++])->op !=
1016 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
1017 if (capability->op == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1018 params.asym_op_mpool = rte_crypto_op_pool_create(
1019 "EVENT_CRYPTO_ASYM_OP_POOL",
1020 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
1021 NUM_MBUFS, MBUF_CACHE_SIZE,
1022 (DEFAULT_NUM_XFORMS *
1023 sizeof(struct rte_crypto_asym_xform)) +
1024 sizeof(union rte_event_crypto_metadata),
1026 TEST_ASSERT_NOT_NULL(params.asym_op_mpool,
1027 "Can't create CRYPTO_ASYM_OP_POOL\n");
1029 params.asym_sess_mpool =
1030 rte_cryptodev_asym_session_pool_create(
1031 "CRYPTO_AD_ASYM_SESS_MP",
1033 sizeof(union rte_event_crypto_metadata),
1035 TEST_ASSERT_NOT_NULL(params.asym_sess_mpool,
1036 "asym session mempool allocation failed\n");
1041 conf.nb_queue_pairs = info.max_nb_queue_pairs;
1042 conf.socket_id = SOCKET_ID_ANY;
1043 conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
1045 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(TEST_CDEV_ID, &conf),
1046 "Failed to configure cryptodev %u with %u qps\n",
1047 TEST_CDEV_ID, conf.nb_queue_pairs);
1049 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1050 qp_conf.mp_session = params.session_mpool;
1051 qp_conf.mp_session_private = params.session_priv_mpool;
1053 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1054 TEST_CDEV_ID, TEST_CDEV_QP_ID, &qp_conf,
1055 rte_cryptodev_socket_id(TEST_CDEV_ID)),
1056 "Failed to setup queue pair %u on cryptodev %u\n",
1057 TEST_CDEV_QP_ID, TEST_CDEV_ID);
1059 return TEST_SUCCESS;
1063 evdev_set_conf_values(struct rte_event_dev_config *dev_conf,
1064 struct rte_event_dev_info *info)
1066 memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
1067 dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
1068 dev_conf->nb_event_ports = NB_TEST_PORTS;
1069 dev_conf->nb_event_queues = NB_TEST_QUEUES;
1070 dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
1071 dev_conf->nb_event_port_dequeue_depth =
1072 info->max_event_port_dequeue_depth;
1073 dev_conf->nb_event_port_enqueue_depth =
1074 info->max_event_port_enqueue_depth;
1075 dev_conf->nb_event_port_enqueue_depth =
1076 info->max_event_port_enqueue_depth;
1077 dev_conf->nb_events_limit =
1078 info->max_num_events;
1082 configure_eventdev(void)
1084 struct rte_event_queue_conf queue_conf;
1085 struct rte_event_dev_config devconf;
1086 struct rte_event_dev_info info;
1087 uint32_t queue_count;
1088 uint32_t port_count;
1092 if (!rte_event_dev_count()) {
1093 /* If there is no hardware eventdev, or no software vdev was
1094 * specified on the command line, create an instance of
1097 LOG_DBG("Failed to find a valid event device... "
1098 "testing with event_sw device\n");
1099 TEST_ASSERT_SUCCESS(rte_vdev_init("event_sw0", NULL),
1100 "Error creating eventdev");
1101 evdev = rte_event_dev_get_dev_id("event_sw0");
1104 ret = rte_event_dev_info_get(evdev, &info);
1105 TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info\n");
1107 evdev_set_conf_values(&devconf, &info);
1109 ret = rte_event_dev_configure(evdev, &devconf);
1110 TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev\n");
1112 /* Set up event queue */
1113 ret = rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
1115 TEST_ASSERT_SUCCESS(ret, "Queue count get failed\n");
1116 TEST_ASSERT_EQUAL(queue_count, 2, "Unexpected queue count\n");
1118 qid = TEST_APP_EV_QUEUE_ID;
1119 ret = rte_event_queue_setup(evdev, qid, NULL);
1120 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue=%d\n", qid);
1122 queue_conf.nb_atomic_flows = info.max_event_queue_flows;
1123 queue_conf.nb_atomic_order_sequences = 32;
1124 queue_conf.schedule_type = RTE_SCHED_TYPE_ATOMIC;
1125 queue_conf.priority = RTE_EVENT_DEV_PRIORITY_HIGHEST;
1126 queue_conf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
1128 qid = TEST_CRYPTO_EV_QUEUE_ID;
1129 ret = rte_event_queue_setup(evdev, qid, &queue_conf);
1130 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue=%u\n", qid);
1132 /* Set up event port */
1133 ret = rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
1135 TEST_ASSERT_SUCCESS(ret, "Port count get failed\n");
1136 TEST_ASSERT_EQUAL(port_count, 1, "Unexpected port count\n");
1138 ret = rte_event_port_setup(evdev, TEST_APP_PORT_ID, NULL);
1139 TEST_ASSERT_SUCCESS(ret, "Failed to setup port=%d\n",
1142 qid = TEST_APP_EV_QUEUE_ID;
1143 ret = rte_event_port_link(evdev, TEST_APP_PORT_ID, &qid, NULL, 1);
1144 TEST_ASSERT(ret >= 0, "Failed to link queue port=%d\n",
1147 return TEST_SUCCESS;
1151 test_crypto_adapter_free(void)
1153 rte_event_crypto_adapter_free(TEST_ADAPTER_ID);
1157 test_crypto_adapter_create(void)
1159 struct rte_event_port_conf conf = {
1162 .new_event_threshold = 1200,
1166 /* Create adapter with default port creation callback */
1167 ret = rte_event_crypto_adapter_create(TEST_ADAPTER_ID,
1170 TEST_ASSERT_SUCCESS(ret, "Failed to create event crypto adapter\n");
1172 return TEST_SUCCESS;
1176 test_crypto_adapter_qp_add_del(void)
1181 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
1182 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
1184 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) {
1185 ret = rte_event_crypto_adapter_queue_pair_add(TEST_ADAPTER_ID,
1186 TEST_CDEV_ID, TEST_CDEV_QP_ID, &response_info);
1188 ret = rte_event_crypto_adapter_queue_pair_add(TEST_ADAPTER_ID,
1189 TEST_CDEV_ID, TEST_CDEV_QP_ID, NULL);
1191 TEST_ASSERT_SUCCESS(ret, "Failed to create add queue pair\n");
1193 ret = rte_event_crypto_adapter_queue_pair_del(TEST_ADAPTER_ID,
1194 TEST_CDEV_ID, TEST_CDEV_QP_ID);
1195 TEST_ASSERT_SUCCESS(ret, "Failed to delete add queue pair\n");
1197 return TEST_SUCCESS;
1201 configure_event_crypto_adapter(enum rte_event_crypto_adapter_mode mode)
1203 struct rte_event_port_conf conf = {
1206 .new_event_threshold = 1200,
1212 ret = rte_event_crypto_adapter_caps_get(evdev, TEST_CDEV_ID, &cap);
1213 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
1215 /* Skip mode and capability mismatch check for SW eventdev */
1216 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW) &&
1217 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) &&
1218 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND))
1219 goto adapter_create;
1221 if (mode == RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD) {
1222 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD)
1223 params.internal_port_op_fwd = 1;
1228 if ((mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) &&
1229 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
1233 /* Create adapter with default port creation callback */
1234 ret = rte_event_crypto_adapter_create(TEST_ADAPTER_ID,
1237 TEST_ASSERT_SUCCESS(ret, "Failed to create event crypto adapter\n");
1239 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) {
1240 ret = rte_event_crypto_adapter_queue_pair_add(TEST_ADAPTER_ID,
1241 TEST_CDEV_ID, TEST_CDEV_QP_ID, &response_info);
1243 ret = rte_event_crypto_adapter_queue_pair_add(TEST_ADAPTER_ID,
1244 TEST_CDEV_ID, TEST_CDEV_QP_ID, NULL);
1246 TEST_ASSERT_SUCCESS(ret, "Failed to add queue pair\n");
1248 if (!params.internal_port_op_fwd) {
1249 ret = rte_event_crypto_adapter_event_port_get(TEST_ADAPTER_ID,
1250 ¶ms.crypto_event_port_id);
1251 TEST_ASSERT_SUCCESS(ret, "Failed to get event port\n");
1254 return TEST_SUCCESS;
1258 test_crypto_adapter_stop(void)
1260 uint32_t evdev_service_id, adapter_service_id;
1262 /* retrieve service ids & stop services */
1263 if (rte_event_crypto_adapter_service_id_get(TEST_ADAPTER_ID,
1264 &adapter_service_id) == 0) {
1265 rte_service_runstate_set(adapter_service_id, 0);
1266 rte_service_lcore_stop(slcore_id);
1267 rte_service_lcore_del(slcore_id);
1268 rte_event_crypto_adapter_stop(TEST_ADAPTER_ID);
1271 if (rte_event_dev_service_id_get(evdev, &evdev_service_id) == 0) {
1272 rte_service_runstate_set(evdev_service_id, 0);
1273 rte_service_lcore_stop(slcore_id);
1274 rte_service_lcore_del(slcore_id);
1275 rte_cryptodev_stop(TEST_CDEV_ID);
1276 rte_event_dev_stop(evdev);
1278 rte_cryptodev_stop(TEST_CDEV_ID);
1279 rte_event_dev_stop(evdev);
1284 test_crypto_adapter_conf(enum rte_event_crypto_adapter_mode mode)
1286 uint32_t evdev_service_id;
1290 if (!crypto_adapter_setup_done) {
1291 ret = configure_event_crypto_adapter(mode);
1294 if (!params.internal_port_op_fwd) {
1295 qid = TEST_CRYPTO_EV_QUEUE_ID;
1296 ret = rte_event_port_link(evdev,
1297 params.crypto_event_port_id, &qid, NULL, 1);
1298 TEST_ASSERT(ret >= 0, "Failed to link queue %d "
1300 params.crypto_event_port_id);
1302 crypto_adapter_setup_done = 1;
1305 /* retrieve service ids */
1306 if (rte_event_dev_service_id_get(evdev, &evdev_service_id) == 0) {
1307 /* add a service core and start it */
1308 TEST_ASSERT_SUCCESS(rte_service_lcore_add(slcore_id),
1309 "Failed to add service core");
1310 TEST_ASSERT_SUCCESS(rte_service_lcore_start(slcore_id),
1311 "Failed to start service core");
1313 /* map services to it */
1314 TEST_ASSERT_SUCCESS(rte_service_map_lcore_set(evdev_service_id,
1315 slcore_id, 1), "Failed to map evdev service");
1317 /* set services to running */
1318 TEST_ASSERT_SUCCESS(rte_service_runstate_set(evdev_service_id,
1319 1), "Failed to start evdev service");
1322 /* start the eventdev */
1323 TEST_ASSERT_SUCCESS(rte_event_dev_start(evdev),
1324 "Failed to start event device");
1326 /* start the cryptodev */
1327 TEST_ASSERT_SUCCESS(rte_cryptodev_start(TEST_CDEV_ID),
1328 "Failed to start crypto device");
1330 return TEST_SUCCESS;
1334 test_crypto_adapter_conf_op_forward_mode(void)
1336 enum rte_event_crypto_adapter_mode mode;
1338 mode = RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD;
1340 return test_crypto_adapter_conf(mode);
1344 test_crypto_adapter_conf_op_new_mode(void)
1346 enum rte_event_crypto_adapter_mode mode;
1348 mode = RTE_EVENT_CRYPTO_ADAPTER_OP_NEW;
1350 return test_crypto_adapter_conf(mode);
1355 testsuite_setup(void)
1359 slcore_id = rte_get_next_lcore(-1, 1, 0);
1360 TEST_ASSERT_NOT_EQUAL(slcore_id, RTE_MAX_LCORE, "At least 2 lcores "
1361 "are required to run this autotest\n");
1363 /* Setup and start event device. */
1364 ret = configure_eventdev();
1365 TEST_ASSERT_SUCCESS(ret, "Failed to setup eventdev\n");
1367 /* Setup and start crypto device. */
1368 ret = configure_cryptodev();
1369 TEST_ASSERT_SUCCESS(ret, "cryptodev initialization failed\n");
1371 return TEST_SUCCESS;
1375 crypto_adapter_teardown(void)
1379 ret = rte_event_crypto_adapter_stop(TEST_ADAPTER_ID);
1381 RTE_LOG(ERR, USER1, "Failed to stop adapter!");
1383 ret = rte_event_crypto_adapter_queue_pair_del(TEST_ADAPTER_ID,
1384 TEST_CDEV_ID, TEST_CDEV_QP_ID);
1386 RTE_LOG(ERR, USER1, "Failed to delete queue pair!");
1388 ret = rte_event_crypto_adapter_free(TEST_ADAPTER_ID);
1390 RTE_LOG(ERR, USER1, "Failed to free adapter!");
1392 crypto_adapter_setup_done = 0;
1396 crypto_teardown(void)
1398 /* Free mbuf mempool */
1399 if (params.mbuf_pool != NULL) {
1400 RTE_LOG(DEBUG, USER1, "CRYPTO_ADAPTER_MBUFPOOL count %u\n",
1401 rte_mempool_avail_count(params.mbuf_pool));
1402 rte_mempool_free(params.mbuf_pool);
1403 params.mbuf_pool = NULL;
1406 /* Free session mempool */
1407 if (params.session_mpool != NULL) {
1408 RTE_LOG(DEBUG, USER1, "CRYPTO_ADAPTER_SESSION_MP count %u\n",
1409 rte_mempool_avail_count(params.session_mpool));
1410 rte_mempool_free(params.session_mpool);
1411 params.session_mpool = NULL;
1413 if (params.session_priv_mpool != NULL) {
1414 rte_mempool_avail_count(params.session_priv_mpool);
1415 rte_mempool_free(params.session_priv_mpool);
1416 params.session_priv_mpool = NULL;
1419 /* Free asym session mempool */
1420 if (params.asym_sess_mpool != NULL) {
1421 RTE_LOG(DEBUG, USER1, "CRYPTO_AD_ASYM_SESS_MP count %u\n",
1422 rte_mempool_avail_count(params.asym_sess_mpool));
1423 rte_mempool_free(params.asym_sess_mpool);
1424 params.asym_sess_mpool = NULL;
1426 /* Free asym ops mempool */
1427 if (params.asym_op_mpool != NULL) {
1428 RTE_LOG(DEBUG, USER1, "EVENT_CRYPTO_ASYM_OP_POOL count %u\n",
1429 rte_mempool_avail_count(params.asym_op_mpool));
1430 rte_mempool_free(params.asym_op_mpool);
1431 params.asym_op_mpool = NULL;
1434 /* Free ops mempool */
1435 if (params.op_mpool != NULL) {
1436 RTE_LOG(DEBUG, USER1, "EVENT_CRYPTO_SYM_OP_POOL count %u\n",
1437 rte_mempool_avail_count(params.op_mpool));
1438 rte_mempool_free(params.op_mpool);
1439 params.op_mpool = NULL;
1444 eventdev_teardown(void)
1446 rte_event_dev_stop(evdev);
1450 testsuite_teardown(void)
1452 crypto_adapter_teardown();
1454 eventdev_teardown();
1457 static struct unit_test_suite functional_testsuite = {
1458 .suite_name = "Event crypto adapter test suite",
1459 .setup = testsuite_setup,
1460 .teardown = testsuite_teardown,
1461 .unit_test_cases = {
1463 TEST_CASE_ST(NULL, test_crypto_adapter_free,
1464 test_crypto_adapter_create),
1466 TEST_CASE_ST(test_crypto_adapter_create,
1467 test_crypto_adapter_free,
1468 test_crypto_adapter_qp_add_del),
1470 TEST_CASE_ST(test_crypto_adapter_create,
1471 test_crypto_adapter_free,
1472 test_crypto_adapter_stats),
1474 TEST_CASE_ST(test_crypto_adapter_conf_op_forward_mode,
1475 test_crypto_adapter_stop,
1476 test_session_with_op_forward_mode),
1478 TEST_CASE_ST(test_crypto_adapter_conf_op_forward_mode,
1479 test_crypto_adapter_stop,
1480 test_sessionless_with_op_forward_mode),
1482 TEST_CASE_ST(test_crypto_adapter_conf_op_new_mode,
1483 test_crypto_adapter_stop,
1484 test_session_with_op_new_mode),
1486 TEST_CASE_ST(test_crypto_adapter_conf_op_new_mode,
1487 test_crypto_adapter_stop,
1488 test_sessionless_with_op_new_mode),
1490 TEST_CASE_ST(test_crypto_adapter_conf_op_forward_mode,
1491 test_crypto_adapter_stop,
1492 test_asym_session_with_op_forward_mode),
1494 TEST_CASE_ST(test_crypto_adapter_conf_op_forward_mode,
1495 test_crypto_adapter_stop,
1496 test_asym_sessionless_with_op_forward_mode),
1498 TEST_CASE_ST(test_crypto_adapter_conf_op_new_mode,
1499 test_crypto_adapter_stop,
1500 test_asym_session_with_op_new_mode),
1502 TEST_CASE_ST(test_crypto_adapter_conf_op_new_mode,
1503 test_crypto_adapter_stop,
1504 test_asym_sessionless_with_op_new_mode),
1506 TEST_CASES_END() /**< NULL terminate unit test array */
1511 test_event_crypto_adapter(void)
1513 return unit_test_suite_runner(&functional_testsuite);
1516 #endif /* !RTE_EXEC_ENV_WINDOWS */
1518 REGISTER_TEST_COMMAND(event_crypto_adapter_autotest,
1519 test_event_crypto_adapter);