1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation.
7 #include <rte_common.h>
8 #include <rte_mempool.h>
10 #include <rte_cryptodev.h>
11 #include <rte_eventdev.h>
12 #include <rte_bus_vdev.h>
13 #include <rte_service.h>
14 #include <rte_event_crypto_adapter.h>
19 #define DEFAULT_NUM_XFORMS (2)
20 #define NUM_MBUFS (8191)
21 #define MBUF_CACHE_SIZE (256)
22 #define MAXIMUM_IV_LENGTH (16)
23 #define DEFAULT_NUM_OPS_INFLIGHT (128)
24 #define MAX_NB_SESSIONS 4
25 #define TEST_APP_PORT_ID 0
26 #define TEST_APP_EV_QUEUE_ID 0
27 #define TEST_APP_EV_PRIORITY 0
28 #define TEST_APP_EV_FLOWID 0xAABB
29 #define TEST_CRYPTO_EV_QUEUE_ID 1
30 #define TEST_ADAPTER_ID 0
31 #define TEST_CDEV_ID 0
32 #define TEST_CDEV_QP_ID 0
33 #define PACKET_LENGTH 64
34 #define NB_TEST_PORTS 1
35 #define NB_TEST_QUEUES 2
37 #define CRYPTODEV_NAME_NULL_PMD crypto_null
39 #define MBUF_SIZE (sizeof(struct rte_mbuf) + \
40 RTE_PKTMBUF_HEADROOM + PACKET_LENGTH)
41 #define IV_OFFSET (sizeof(struct rte_crypto_op) + \
42 sizeof(struct rte_crypto_sym_op) + \
43 DEFAULT_NUM_XFORMS * \
44 sizeof(struct rte_crypto_sym_xform))
46 /* Handle log statements in same manner as test macros */
47 #define LOG_DBG(...) RTE_LOG(DEBUG, EAL, __VA_ARGS__)
49 static const uint8_t text_64B[] = {
50 0x05, 0x15, 0x77, 0x32, 0xc9, 0x66, 0x91, 0x50,
51 0x93, 0x9f, 0xbb, 0x4e, 0x2e, 0x5a, 0x02, 0xd0,
52 0x2d, 0x9d, 0x31, 0x5d, 0xc8, 0x9e, 0x86, 0x36,
53 0x54, 0x5c, 0x50, 0xe8, 0x75, 0x54, 0x74, 0x5e,
54 0xd5, 0xa2, 0x84, 0x21, 0x2d, 0xc5, 0xf8, 0x1c,
55 0x55, 0x1a, 0xba, 0x91, 0xce, 0xb5, 0xa3, 0x1e,
56 0x31, 0xbf, 0xe9, 0xa1, 0x97, 0x5c, 0x2b, 0xd6,
57 0x57, 0xa5, 0x9f, 0xab, 0xbd, 0xb0, 0x9b, 0x9c
60 struct event_crypto_adapter_test_params {
61 struct rte_mempool *mbuf_pool;
62 struct rte_mempool *op_mpool;
63 struct rte_mempool *session_mpool;
64 struct rte_mempool *session_priv_mpool;
65 struct rte_cryptodev_config *config;
66 uint8_t crypto_event_port_id;
69 struct rte_event response_info = {
70 .queue_id = TEST_APP_EV_QUEUE_ID,
71 .sched_type = RTE_SCHED_TYPE_ATOMIC,
72 .flow_id = TEST_APP_EV_FLOWID,
73 .priority = TEST_APP_EV_PRIORITY
76 struct rte_event_crypto_request request_info = {
77 .cdev_id = TEST_CDEV_ID,
78 .queue_pair_id = TEST_CDEV_QP_ID
81 static struct event_crypto_adapter_test_params params;
82 static uint8_t crypto_adapter_setup_done;
83 static uint32_t slcore_id;
86 static struct rte_mbuf *
87 alloc_fill_mbuf(struct rte_mempool *mpool, const uint8_t *data,
88 size_t len, uint8_t blocksize)
90 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
91 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
94 char *dst = rte_pktmbuf_append(m, t_len);
101 rte_memcpy(dst, (const void *)data, t_len);
107 send_recv_ev(struct rte_event *ev)
109 struct rte_crypto_op *op;
110 struct rte_event recv_ev;
113 ret = rte_event_enqueue_burst(evdev, TEST_APP_PORT_ID, ev, NUM);
114 TEST_ASSERT_EQUAL(ret, NUM,
115 "Failed to send event to crypto adapter\n");
117 while (rte_event_dequeue_burst(evdev,
118 TEST_APP_PORT_ID, &recv_ev, NUM, 0) == 0)
121 op = recv_ev.event_ptr;
123 struct rte_mbuf *m = op->sym->m_src;
124 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
126 rte_pktmbuf_free(op->sym->m_src);
127 rte_crypto_op_free(op);
133 test_crypto_adapter_stats(void)
135 struct rte_event_crypto_adapter_stats stats;
137 rte_event_crypto_adapter_stats_get(TEST_ADAPTER_ID, &stats);
138 printf(" +------------------------------------------------------+\n");
139 printf(" + Crypto adapter stats for instance %u:\n", TEST_ADAPTER_ID);
140 printf(" + Event port poll count %" PRIx64 "\n",
141 stats.event_poll_count);
142 printf(" + Event dequeue count %" PRIx64 "\n",
143 stats.event_deq_count);
144 printf(" + Cryptodev enqueue count %" PRIx64 "\n",
145 stats.crypto_enq_count);
146 printf(" + Cryptodev enqueue failed count %" PRIx64 "\n",
147 stats.crypto_enq_fail);
148 printf(" + Cryptodev dequeue count %" PRIx64 "\n",
149 stats.crypto_deq_count);
150 printf(" + Event enqueue count %" PRIx64 "\n",
151 stats.event_enq_count);
152 printf(" + Event enqueue retry count %" PRIx64 "\n",
153 stats.event_enq_retry_count);
154 printf(" + Event enqueue fail count %" PRIx64 "\n",
155 stats.event_enq_fail_count);
156 printf(" +------------------------------------------------------+\n");
158 rte_event_crypto_adapter_stats_reset(TEST_ADAPTER_ID);
163 test_op_forward_mode(uint8_t session_less)
165 struct rte_crypto_sym_xform cipher_xform;
166 struct rte_cryptodev_sym_session *sess;
167 union rte_event_crypto_metadata m_data;
168 struct rte_crypto_sym_op *sym_op;
169 struct rte_crypto_op *op;
175 memset(&m_data, 0, sizeof(m_data));
177 m = alloc_fill_mbuf(params.mbuf_pool, text_64B, PACKET_LENGTH, 0);
178 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf!\n");
180 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
182 /* Setup Cipher Parameters */
183 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
184 cipher_xform.next = NULL;
186 cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
187 cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
189 op = rte_crypto_op_alloc(params.op_mpool,
190 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
191 TEST_ASSERT_NOT_NULL(op,
192 "Failed to allocate symmetric crypto operation struct\n");
197 sess = rte_cryptodev_sym_session_create(
198 params.session_mpool);
199 TEST_ASSERT_NOT_NULL(sess, "Session creation failed\n");
201 /* Create Crypto session*/
202 rte_cryptodev_sym_session_init(TEST_CDEV_ID, sess,
203 &cipher_xform, params.session_priv_mpool);
205 ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID,
207 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
209 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA) {
210 /* Fill in private user data information */
211 rte_memcpy(&m_data.response_info, &response_info,
212 sizeof(response_info));
213 rte_memcpy(&m_data.request_info, &request_info,
214 sizeof(request_info));
215 rte_cryptodev_sym_session_set_user_data(sess,
216 &m_data, sizeof(m_data));
219 rte_crypto_op_attach_sym_session(op, sess);
221 struct rte_crypto_sym_xform *first_xform;
223 rte_crypto_op_sym_xforms_alloc(op, NUM);
224 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
225 first_xform = &cipher_xform;
226 sym_op->xform = first_xform;
227 uint32_t len = IV_OFFSET + MAXIMUM_IV_LENGTH +
228 (sizeof(struct rte_crypto_sym_xform) * 2);
229 op->private_data_offset = len;
230 /* Fill in private data information */
231 rte_memcpy(&m_data.response_info, &response_info,
232 sizeof(response_info));
233 rte_memcpy(&m_data.request_info, &request_info,
234 sizeof(request_info));
235 rte_memcpy((uint8_t *)op + len, &m_data, sizeof(m_data));
239 sym_op->cipher.data.offset = 0;
240 sym_op->cipher.data.length = PACKET_LENGTH;
242 /* Fill in event info and update event_ptr with rte_crypto_op */
243 memset(&ev, 0, sizeof(ev));
244 ev.queue_id = TEST_CRYPTO_EV_QUEUE_ID;
245 ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
249 ret = send_recv_ev(&ev);
250 TEST_ASSERT_SUCCESS(ret, "Failed to send/receive event to "
253 test_crypto_adapter_stats();
259 map_adapter_service_core(void)
261 uint32_t adapter_service_id;
264 if (rte_event_crypto_adapter_service_id_get(TEST_ADAPTER_ID,
265 &adapter_service_id) == 0) {
266 uint32_t core_list[NUM_CORES];
268 ret = rte_service_lcore_list(core_list, NUM_CORES);
269 TEST_ASSERT(ret >= 0, "Failed to get service core list!");
271 if (core_list[0] != slcore_id) {
272 TEST_ASSERT_SUCCESS(rte_service_lcore_add(slcore_id),
273 "Failed to add service core");
274 TEST_ASSERT_SUCCESS(rte_service_lcore_start(slcore_id),
275 "Failed to start service core");
278 TEST_ASSERT_SUCCESS(rte_service_map_lcore_set(
279 adapter_service_id, slcore_id, 1),
280 "Failed to map adapter service");
287 test_sessionless_with_op_forward_mode(void)
292 ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
293 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
295 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))
296 map_adapter_service_core();
298 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID),
299 "Failed to start event crypto adapter");
301 ret = test_op_forward_mode(1);
302 TEST_ASSERT_SUCCESS(ret, "Sessionless - FORWARD mode test failed\n");
307 test_session_with_op_forward_mode(void)
312 ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
313 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
315 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))
316 map_adapter_service_core();
318 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID
319 ), "Failed to start event crypto adapter");
321 ret = test_op_forward_mode(0);
322 TEST_ASSERT_SUCCESS(ret, "Session based - FORWARD mode test failed\n");
327 send_op_recv_ev(struct rte_crypto_op *op)
329 struct rte_crypto_op *recv_op;
333 ret = rte_cryptodev_enqueue_burst(TEST_CDEV_ID, TEST_CDEV_QP_ID,
335 TEST_ASSERT_EQUAL(ret, NUM, "Failed to enqueue to cryptodev\n");
336 memset(&ev, 0, sizeof(ev));
338 while (rte_event_dequeue_burst(evdev,
339 TEST_APP_PORT_ID, &ev, NUM, 0) == 0)
342 recv_op = ev.event_ptr;
344 struct rte_mbuf *m = recv_op->sym->m_src;
345 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
347 rte_pktmbuf_free(recv_op->sym->m_src);
348 rte_crypto_op_free(recv_op);
354 test_op_new_mode(uint8_t session_less)
356 struct rte_crypto_sym_xform cipher_xform;
357 struct rte_cryptodev_sym_session *sess;
358 union rte_event_crypto_metadata m_data;
359 struct rte_crypto_sym_op *sym_op;
360 struct rte_crypto_op *op;
365 memset(&m_data, 0, sizeof(m_data));
367 m = alloc_fill_mbuf(params.mbuf_pool, text_64B, PACKET_LENGTH, 0);
368 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf!\n");
370 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
372 /* Setup Cipher Parameters */
373 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
374 cipher_xform.next = NULL;
376 cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
377 cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
379 op = rte_crypto_op_alloc(params.op_mpool,
380 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
381 TEST_ASSERT_NOT_NULL(op, "Failed to allocate crypto_op!\n");
386 sess = rte_cryptodev_sym_session_create(
387 params.session_mpool);
388 TEST_ASSERT_NOT_NULL(sess, "Session creation failed\n");
390 ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID,
392 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
394 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA) {
395 /* Fill in private user data information */
396 rte_memcpy(&m_data.response_info, &response_info,
398 rte_cryptodev_sym_session_set_user_data(sess,
399 &m_data, sizeof(m_data));
401 rte_cryptodev_sym_session_init(TEST_CDEV_ID, sess,
402 &cipher_xform, params.session_priv_mpool);
403 rte_crypto_op_attach_sym_session(op, sess);
405 struct rte_crypto_sym_xform *first_xform;
407 rte_crypto_op_sym_xforms_alloc(op, NUM);
408 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
409 first_xform = &cipher_xform;
410 sym_op->xform = first_xform;
411 uint32_t len = IV_OFFSET + MAXIMUM_IV_LENGTH +
412 (sizeof(struct rte_crypto_sym_xform) * 2);
413 op->private_data_offset = len;
414 /* Fill in private data information */
415 rte_memcpy(&m_data.response_info, &response_info,
417 rte_memcpy((uint8_t *)op + len, &m_data, sizeof(m_data));
421 sym_op->cipher.data.offset = 0;
422 sym_op->cipher.data.length = PACKET_LENGTH;
424 ret = send_op_recv_ev(op);
425 TEST_ASSERT_SUCCESS(ret, "Failed to enqueue op to cryptodev\n");
427 test_crypto_adapter_stats();
433 test_sessionless_with_op_new_mode(void)
438 ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
439 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
441 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) ||
442 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
443 map_adapter_service_core();
445 /* start the event crypto adapter */
446 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID),
447 "Failed to start event crypto adapter");
449 ret = test_op_new_mode(1);
450 TEST_ASSERT_SUCCESS(ret, "Sessionless - NEW mode test failed\n");
455 test_session_with_op_new_mode(void)
460 ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
461 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
463 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) ||
464 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW))
465 map_adapter_service_core();
467 TEST_ASSERT_SUCCESS(rte_event_crypto_adapter_start(TEST_ADAPTER_ID),
468 "Failed to start event crypto adapter");
470 ret = test_op_new_mode(0);
471 TEST_ASSERT_SUCCESS(ret, "Session based - NEW mode test failed\n");
476 configure_cryptodev(void)
478 struct rte_cryptodev_qp_conf qp_conf;
479 struct rte_cryptodev_config conf;
480 struct rte_cryptodev_info info;
481 unsigned int session_size;
485 params.mbuf_pool = rte_pktmbuf_pool_create(
486 "CRYPTO_ADAPTER_MBUFPOOL",
487 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
489 if (params.mbuf_pool == NULL) {
490 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
494 params.op_mpool = rte_crypto_op_pool_create(
495 "EVENT_CRYPTO_SYM_OP_POOL",
496 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
497 NUM_MBUFS, MBUF_CACHE_SIZE,
499 sizeof(struct rte_crypto_sym_xform) +
502 if (params.op_mpool == NULL) {
503 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
507 /* Create a NULL crypto device */
508 nb_devs = rte_cryptodev_device_count_by_driver(
509 rte_cryptodev_driver_id_get(
510 RTE_STR(CRYPTODEV_NAME_NULL_PMD)));
513 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
515 TEST_ASSERT(ret == 0, "Failed to create pmd:%s instance\n",
516 RTE_STR(CRYPTODEV_NAME_NULL_PMD));
519 nb_devs = rte_cryptodev_count();
521 RTE_LOG(ERR, USER1, "No crypto devices found!\n");
526 * Create mempool with maximum number of sessions * 2,
527 * to include the session headers & private data
529 session_size = rte_cryptodev_sym_get_private_session_size(TEST_CDEV_ID);
530 session_size += sizeof(union rte_event_crypto_metadata);
532 params.session_mpool = rte_cryptodev_sym_session_pool_create(
533 "CRYPTO_ADAPTER_SESSION_MP",
534 MAX_NB_SESSIONS, 0, 0, 0, SOCKET_ID_ANY);
535 TEST_ASSERT_NOT_NULL(params.session_mpool,
536 "session mempool allocation failed\n");
538 params.session_priv_mpool = rte_mempool_create(
539 "CRYPTO_ADAPTER_SESSION_MP_PRIV",
542 0, 0, NULL, NULL, NULL,
545 TEST_ASSERT_NOT_NULL(params.session_priv_mpool,
546 "session mempool allocation failed\n");
548 rte_cryptodev_info_get(TEST_CDEV_ID, &info);
549 conf.nb_queue_pairs = info.max_nb_queue_pairs;
550 conf.socket_id = SOCKET_ID_ANY;
552 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(TEST_CDEV_ID, &conf),
553 "Failed to configure cryptodev %u with %u qps\n",
554 TEST_CDEV_ID, conf.nb_queue_pairs);
556 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
557 qp_conf.mp_session = params.session_mpool;
558 qp_conf.mp_session_private = params.session_priv_mpool;
560 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
561 TEST_CDEV_ID, TEST_CDEV_QP_ID, &qp_conf,
562 rte_cryptodev_socket_id(TEST_CDEV_ID)),
563 "Failed to setup queue pair %u on cryptodev %u\n",
564 TEST_CDEV_QP_ID, TEST_CDEV_ID);
570 evdev_set_conf_values(struct rte_event_dev_config *dev_conf,
571 struct rte_event_dev_info *info)
573 memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
574 dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
575 dev_conf->nb_event_ports = NB_TEST_PORTS;
576 dev_conf->nb_event_queues = NB_TEST_QUEUES;
577 dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
578 dev_conf->nb_event_port_dequeue_depth =
579 info->max_event_port_dequeue_depth;
580 dev_conf->nb_event_port_enqueue_depth =
581 info->max_event_port_enqueue_depth;
582 dev_conf->nb_event_port_enqueue_depth =
583 info->max_event_port_enqueue_depth;
584 dev_conf->nb_events_limit =
585 info->max_num_events;
589 configure_eventdev(void)
591 struct rte_event_queue_conf queue_conf;
592 struct rte_event_dev_config devconf;
593 struct rte_event_dev_info info;
594 uint32_t queue_count;
599 if (!rte_event_dev_count()) {
600 /* If there is no hardware eventdev, or no software vdev was
601 * specified on the command line, create an instance of
604 LOG_DBG("Failed to find a valid event device... "
605 "testing with event_sw device\n");
606 TEST_ASSERT_SUCCESS(rte_vdev_init("event_sw0", NULL),
607 "Error creating eventdev");
608 evdev = rte_event_dev_get_dev_id("event_sw0");
611 ret = rte_event_dev_info_get(evdev, &info);
612 TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info\n");
614 evdev_set_conf_values(&devconf, &info);
616 ret = rte_event_dev_configure(evdev, &devconf);
617 TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev\n");
619 /* Set up event queue */
620 ret = rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
622 TEST_ASSERT_SUCCESS(ret, "Queue count get failed\n");
623 TEST_ASSERT_EQUAL(queue_count, 2, "Unexpected queue count\n");
625 qid = TEST_APP_EV_QUEUE_ID;
626 ret = rte_event_queue_setup(evdev, qid, NULL);
627 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue=%d\n", qid);
629 queue_conf.nb_atomic_flows = info.max_event_queue_flows;
630 queue_conf.nb_atomic_order_sequences = 32;
631 queue_conf.schedule_type = RTE_SCHED_TYPE_ATOMIC;
632 queue_conf.priority = RTE_EVENT_DEV_PRIORITY_HIGHEST;
633 queue_conf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
635 qid = TEST_CRYPTO_EV_QUEUE_ID;
636 ret = rte_event_queue_setup(evdev, qid, &queue_conf);
637 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue=%u\n", qid);
639 /* Set up event port */
640 ret = rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
642 TEST_ASSERT_SUCCESS(ret, "Port count get failed\n");
643 TEST_ASSERT_EQUAL(port_count, 1, "Unexpected port count\n");
645 ret = rte_event_port_setup(evdev, TEST_APP_PORT_ID, NULL);
646 TEST_ASSERT_SUCCESS(ret, "Failed to setup port=%d\n",
649 qid = TEST_APP_EV_QUEUE_ID;
650 ret = rte_event_port_link(evdev, TEST_APP_PORT_ID, &qid, NULL, 1);
651 TEST_ASSERT(ret >= 0, "Failed to link queue port=%d\n",
658 test_crypto_adapter_free(void)
660 rte_event_crypto_adapter_free(TEST_ADAPTER_ID);
664 test_crypto_adapter_create(void)
666 struct rte_event_port_conf conf = {
669 .new_event_threshold = 1200,
673 /* Create adapter with default port creation callback */
674 ret = rte_event_crypto_adapter_create(TEST_ADAPTER_ID,
677 TEST_ASSERT_SUCCESS(ret, "Failed to create event crypto adapter\n");
683 test_crypto_adapter_qp_add_del(void)
688 ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
689 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
691 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) {
692 ret = rte_event_crypto_adapter_queue_pair_add(TEST_ADAPTER_ID,
693 TEST_CDEV_ID, TEST_CDEV_QP_ID, &response_info);
695 ret = rte_event_crypto_adapter_queue_pair_add(TEST_ADAPTER_ID,
696 TEST_CDEV_ID, TEST_CDEV_QP_ID, NULL);
698 TEST_ASSERT_SUCCESS(ret, "Failed to create add queue pair\n");
700 ret = rte_event_crypto_adapter_queue_pair_del(TEST_ADAPTER_ID,
701 TEST_CDEV_ID, TEST_CDEV_QP_ID);
702 TEST_ASSERT_SUCCESS(ret, "Failed to delete add queue pair\n");
708 configure_event_crypto_adapter(enum rte_event_crypto_adapter_mode mode)
710 struct rte_event_port_conf conf = {
713 .new_event_threshold = 1200,
719 /* Create adapter with default port creation callback */
720 ret = rte_event_crypto_adapter_create(TEST_ADAPTER_ID,
723 TEST_ASSERT_SUCCESS(ret, "Failed to create event crypto adapter\n");
725 ret = rte_event_crypto_adapter_caps_get(TEST_ADAPTER_ID, evdev, &cap);
726 TEST_ASSERT_SUCCESS(ret, "Failed to get adapter capabilities\n");
728 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) {
729 ret = rte_event_crypto_adapter_queue_pair_add(TEST_ADAPTER_ID,
730 TEST_CDEV_ID, TEST_CDEV_QP_ID, &response_info);
732 ret = rte_event_crypto_adapter_queue_pair_add(TEST_ADAPTER_ID,
733 TEST_CDEV_ID, TEST_CDEV_QP_ID, NULL);
735 TEST_ASSERT_SUCCESS(ret, "Failed to add queue pair\n");
737 ret = rte_event_crypto_adapter_event_port_get(TEST_ADAPTER_ID,
738 ¶ms.crypto_event_port_id);
739 TEST_ASSERT_SUCCESS(ret, "Failed to get event port\n");
745 test_crypto_adapter_stop(void)
747 uint32_t evdev_service_id, adapter_service_id;
749 /* retrieve service ids & stop services */
750 if (rte_event_crypto_adapter_service_id_get(TEST_ADAPTER_ID,
751 &adapter_service_id) == 0) {
752 rte_service_runstate_set(adapter_service_id, 0);
753 rte_service_lcore_stop(slcore_id);
754 rte_service_lcore_del(slcore_id);
755 rte_event_crypto_adapter_stop(TEST_ADAPTER_ID);
758 if (rte_event_dev_service_id_get(evdev, &evdev_service_id) == 0) {
759 rte_service_runstate_set(evdev_service_id, 0);
760 rte_service_lcore_stop(slcore_id);
761 rte_service_lcore_del(slcore_id);
762 rte_event_dev_stop(evdev);
767 test_crypto_adapter_conf(enum rte_event_crypto_adapter_mode mode)
769 uint32_t evdev_service_id;
773 if (!crypto_adapter_setup_done) {
774 ret = configure_event_crypto_adapter(mode);
776 qid = TEST_CRYPTO_EV_QUEUE_ID;
777 ret = rte_event_port_link(evdev,
778 params.crypto_event_port_id, &qid, NULL, 1);
779 TEST_ASSERT(ret >= 0, "Failed to link queue %d "
781 params.crypto_event_port_id);
783 crypto_adapter_setup_done = 1;
786 /* retrieve service ids */
787 if (rte_event_dev_service_id_get(evdev, &evdev_service_id) == 0) {
788 /* add a service core and start it */
789 TEST_ASSERT_SUCCESS(rte_service_lcore_add(slcore_id),
790 "Failed to add service core");
791 TEST_ASSERT_SUCCESS(rte_service_lcore_start(slcore_id),
792 "Failed to start service core");
794 /* map services to it */
795 TEST_ASSERT_SUCCESS(rte_service_map_lcore_set(evdev_service_id,
796 slcore_id, 1), "Failed to map evdev service");
798 /* set services to running */
799 TEST_ASSERT_SUCCESS(rte_service_runstate_set(evdev_service_id,
800 1), "Failed to start evdev service");
803 /* start the eventdev */
804 TEST_ASSERT_SUCCESS(rte_event_dev_start(evdev),
805 "Failed to start event device");
811 test_crypto_adapter_conf_op_forward_mode(void)
813 enum rte_event_crypto_adapter_mode mode;
815 mode = RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD;
816 test_crypto_adapter_conf(mode);
822 test_crypto_adapter_conf_op_new_mode(void)
824 enum rte_event_crypto_adapter_mode mode;
826 mode = RTE_EVENT_CRYPTO_ADAPTER_OP_NEW;
827 test_crypto_adapter_conf(mode);
833 testsuite_setup(void)
837 slcore_id = rte_get_next_lcore(-1, 1, 0);
838 TEST_ASSERT_NOT_EQUAL(slcore_id, RTE_MAX_LCORE, "At least 2 lcores "
839 "are required to run this autotest\n");
841 /* Setup and start event device. */
842 ret = configure_eventdev();
843 TEST_ASSERT_SUCCESS(ret, "Failed to setup eventdev\n");
845 /* Setup and start crypto device. */
846 ret = configure_cryptodev();
847 TEST_ASSERT_SUCCESS(ret, "cryptodev initialization failed\n");
853 crypto_teardown(void)
855 /* Free mbuf mempool */
856 if (params.mbuf_pool != NULL) {
857 RTE_LOG(DEBUG, USER1, "CRYPTO_ADAPTER_MBUFPOOL count %u\n",
858 rte_mempool_avail_count(params.mbuf_pool));
859 rte_mempool_free(params.mbuf_pool);
860 params.mbuf_pool = NULL;
863 /* Free session mempool */
864 if (params.session_mpool != NULL) {
865 RTE_LOG(DEBUG, USER1, "CRYPTO_ADAPTER_SESSION_MP count %u\n",
866 rte_mempool_avail_count(params.session_mpool));
867 rte_mempool_free(params.session_mpool);
868 params.session_mpool = NULL;
870 if (params.session_priv_mpool != NULL) {
871 rte_mempool_free(params.session_priv_mpool);
872 params.session_priv_mpool = NULL;
875 /* Free ops mempool */
876 if (params.op_mpool != NULL) {
877 RTE_LOG(DEBUG, USER1, "EVENT_CRYPTO_SYM_OP_POOL count %u\n",
878 rte_mempool_avail_count(params.op_mpool));
879 rte_mempool_free(params.op_mpool);
880 params.op_mpool = NULL;
885 eventdev_teardown(void)
887 rte_event_dev_stop(evdev);
891 testsuite_teardown(void)
897 static struct unit_test_suite functional_testsuite = {
898 .suite_name = "Event crypto adapter test suite",
899 .setup = testsuite_setup,
900 .teardown = testsuite_teardown,
903 TEST_CASE_ST(NULL, test_crypto_adapter_free,
904 test_crypto_adapter_create),
906 TEST_CASE_ST(test_crypto_adapter_create,
907 test_crypto_adapter_free,
908 test_crypto_adapter_qp_add_del),
910 TEST_CASE_ST(test_crypto_adapter_create,
911 test_crypto_adapter_free,
912 test_crypto_adapter_stats),
914 TEST_CASE_ST(test_crypto_adapter_conf_op_forward_mode,
915 test_crypto_adapter_stop,
916 test_session_with_op_forward_mode),
918 TEST_CASE_ST(test_crypto_adapter_conf_op_forward_mode,
919 test_crypto_adapter_stop,
920 test_sessionless_with_op_forward_mode),
922 TEST_CASE_ST(test_crypto_adapter_conf_op_new_mode,
923 test_crypto_adapter_stop,
924 test_session_with_op_new_mode),
926 TEST_CASE_ST(test_crypto_adapter_conf_op_new_mode,
927 test_crypto_adapter_stop,
928 test_sessionless_with_op_new_mode),
930 TEST_CASES_END() /**< NULL terminate unit test array */
935 test_event_crypto_adapter(void)
937 return unit_test_suite_runner(&functional_testsuite);
940 REGISTER_TEST_COMMAND(event_crypto_adapter_autotest,
941 test_event_crypto_adapter);