1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
3 * Copyright (C) 2020 Marvell International Ltd.
6 #include <rte_event_eth_tx_adapter.h>
10 #include "event_helper.h"
12 #include "ipsec-secgw.h"
13 #include "ipsec_worker.h"
15 struct port_drv_mode_data {
16 struct rte_security_session *sess;
17 struct rte_security_ctx *ctx;
20 static inline enum pkt_type
21 process_ipsec_get_pkt_type(struct rte_mbuf *pkt, uint8_t **nlp)
23 struct rte_ether_hdr *eth;
24 uint32_t ptype = pkt->packet_type;
26 eth = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
29 if (RTE_ETH_IS_IPV4_HDR(ptype)) {
30 *nlp = RTE_PTR_ADD(eth, RTE_ETHER_HDR_LEN +
31 offsetof(struct ip, ip_p));
32 if ((ptype & RTE_PTYPE_TUNNEL_MASK) == RTE_PTYPE_TUNNEL_ESP)
33 return PKT_TYPE_IPSEC_IPV4;
35 return PKT_TYPE_PLAIN_IPV4;
36 } else if (RTE_ETH_IS_IPV6_HDR(ptype)) {
37 *nlp = RTE_PTR_ADD(eth, RTE_ETHER_HDR_LEN +
38 offsetof(struct ip6_hdr, ip6_nxt));
39 if ((ptype & RTE_PTYPE_TUNNEL_MASK) == RTE_PTYPE_TUNNEL_ESP)
40 return PKT_TYPE_IPSEC_IPV6;
42 return PKT_TYPE_PLAIN_IPV6;
45 /* Unknown/Unsupported type */
46 return PKT_TYPE_INVALID;
50 update_mac_addrs(struct rte_mbuf *pkt, uint16_t portid)
52 struct rte_ether_hdr *ethhdr;
54 ethhdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
55 memcpy(ðhdr->src_addr, ðaddr_tbl[portid].src, RTE_ETHER_ADDR_LEN);
56 memcpy(ðhdr->dst_addr, ðaddr_tbl[portid].dst, RTE_ETHER_ADDR_LEN);
60 ipsec_event_pre_forward(struct rte_mbuf *m, unsigned int port_id)
62 /* Save the destination port in the mbuf */
65 /* Save eth queue for Tx */
66 rte_event_eth_tx_adapter_txq_set(m, 0);
70 ev_vector_attr_init(struct rte_event_vector *vec)
78 ev_vector_attr_update(struct rte_event_vector *vec, struct rte_mbuf *pkt)
80 if (vec->port == 0xFFFF) {
81 vec->port = pkt->port;
84 if (vec->attr_valid && (vec->port != pkt->port))
89 prepare_out_sessions_tbl(struct sa_ctx *sa_out,
90 struct port_drv_mode_data *data,
93 struct rte_ipsec_session *pri_sess;
100 for (i = 0; i < sa_out->nb_sa; i++) {
106 pri_sess = ipsec_get_primary_session(sa);
110 if (pri_sess->type !=
111 RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL) {
113 RTE_LOG(ERR, IPSEC, "Invalid session type %d\n",
118 if (sa->portid >= size) {
120 "Port id >= than table size %d, %d\n",
125 /* Use only first inline session found for a given port */
126 if (data[sa->portid].sess)
128 data[sa->portid].sess = pri_sess->security.ses;
129 data[sa->portid].ctx = pri_sess->security.ctx;
134 check_sp(struct sp_ctx *sp, const uint8_t *nlp, uint32_t *sa_idx)
138 if (unlikely(sp == NULL))
141 rte_acl_classify((struct rte_acl_ctx *)sp, &nlp, &res, 1,
142 DEFAULT_MAX_CATEGORIES);
144 if (unlikely(res == DISCARD))
146 else if (res == BYPASS) {
156 check_sp_bulk(struct sp_ctx *sp, struct traffic_type *ip,
157 struct traffic_type *ipsec)
162 if (unlikely(sp == NULL || ip->num == 0))
165 rte_acl_classify((struct rte_acl_ctx *)sp, ip->data, ip->res, ip->num,
166 DEFAULT_MAX_CATEGORIES);
169 for (i = 0; i < ip->num; i++) {
172 if (unlikely(res == DISCARD))
174 else if (res == BYPASS)
177 ipsec->res[ipsec->num] = res - 1;
178 ipsec->pkts[ipsec->num++] = m;
185 check_sp_sa_bulk(struct sp_ctx *sp, struct sa_ctx *sa_ctx,
186 struct traffic_type *ip)
192 if (unlikely(sp == NULL || ip->num == 0))
195 rte_acl_classify((struct rte_acl_ctx *)sp, ip->data, ip->res, ip->num,
196 DEFAULT_MAX_CATEGORIES);
199 for (i = 0; i < ip->num; i++) {
202 if (unlikely(res == DISCARD))
204 else if (res == BYPASS)
207 sa = *(struct ipsec_sa **)rte_security_dynfield(m);
213 /* SPI on the packet should match with the one in SA */
214 if (unlikely(sa->spi != sa_ctx->sa[res - 1].spi)) {
225 static inline uint16_t
226 route4_pkt(struct rte_mbuf *pkt, struct rt_ctx *rt_ctx)
233 offset = RTE_ETHER_HDR_LEN + offsetof(struct ip, ip_dst);
234 dst_ip = *rte_pktmbuf_mtod_offset(pkt, uint32_t *, offset);
235 dst_ip = rte_be_to_cpu_32(dst_ip);
237 ret = rte_lpm_lookup((struct rte_lpm *)rt_ctx, dst_ip, &hop);
245 return RTE_MAX_ETHPORTS;
248 /* TODO: To be tested */
249 static inline uint16_t
250 route6_pkt(struct rte_mbuf *pkt, struct rt_ctx *rt_ctx)
258 offset = RTE_ETHER_HDR_LEN + offsetof(struct ip6_hdr, ip6_dst);
259 ip6_dst = rte_pktmbuf_mtod_offset(pkt, uint8_t *, offset);
260 memcpy(&dst_ip[0], ip6_dst, 16);
262 ret = rte_lpm6_lookup((struct rte_lpm6 *)rt_ctx, dst_ip, &hop);
270 return RTE_MAX_ETHPORTS;
273 static inline uint16_t
274 get_route(struct rte_mbuf *pkt, struct route_table *rt, enum pkt_type type)
276 if (type == PKT_TYPE_PLAIN_IPV4 || type == PKT_TYPE_IPSEC_IPV4)
277 return route4_pkt(pkt, rt->rt4_ctx);
278 else if (type == PKT_TYPE_PLAIN_IPV6 || type == PKT_TYPE_IPSEC_IPV6)
279 return route6_pkt(pkt, rt->rt6_ctx);
281 return RTE_MAX_ETHPORTS;
285 process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
286 struct rte_event *ev)
288 struct ipsec_sa *sa = NULL;
289 struct rte_mbuf *pkt;
290 uint16_t port_id = 0;
295 /* Get pkt from event */
298 /* Check the packet type */
299 type = process_ipsec_get_pkt_type(pkt, &nlp);
302 case PKT_TYPE_PLAIN_IPV4:
303 if (pkt->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD) {
304 if (unlikely(pkt->ol_flags &
305 RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED)) {
307 "Inbound security offload failed\n");
308 goto drop_pkt_and_exit;
310 sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
313 /* Check if we have a match */
314 if (check_sp(ctx->sp4_ctx, nlp, &sa_idx) == 0) {
316 goto drop_pkt_and_exit;
320 case PKT_TYPE_PLAIN_IPV6:
321 if (pkt->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD) {
322 if (unlikely(pkt->ol_flags &
323 RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED)) {
325 "Inbound security offload failed\n");
326 goto drop_pkt_and_exit;
328 sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
331 /* Check if we have a match */
332 if (check_sp(ctx->sp6_ctx, nlp, &sa_idx) == 0) {
334 goto drop_pkt_and_exit;
339 RTE_LOG_DP(DEBUG, IPSEC_ESP, "Unsupported packet type = %d\n",
341 goto drop_pkt_and_exit;
344 /* Check if the packet has to be bypassed */
345 if (sa_idx == BYPASS)
346 goto route_and_send_pkt;
348 /* Validate sa_idx */
349 if (sa_idx >= ctx->sa_ctx->nb_sa)
350 goto drop_pkt_and_exit;
352 /* Else the packet has to be protected with SA */
354 /* If the packet was IPsec processed, then SA pointer should be set */
356 goto drop_pkt_and_exit;
358 /* SPI on the packet should match with the one in SA */
359 if (unlikely(sa->spi != ctx->sa_ctx->sa[sa_idx].spi))
360 goto drop_pkt_and_exit;
363 port_id = get_route(pkt, rt, type);
364 if (unlikely(port_id == RTE_MAX_ETHPORTS)) {
366 goto drop_pkt_and_exit;
368 /* else, we have a matching route */
370 /* Update mac addresses */
371 update_mac_addrs(pkt, port_id);
373 /* Update the event with the dest port */
374 ipsec_event_pre_forward(pkt, port_id);
375 return PKT_FORWARDED;
378 RTE_LOG(ERR, IPSEC, "Inbound packet dropped\n");
379 rte_pktmbuf_free(pkt);
385 process_ipsec_ev_outbound(struct ipsec_ctx *ctx, struct route_table *rt,
386 struct rte_event *ev)
388 struct rte_ipsec_session *sess;
389 struct sa_ctx *sa_ctx;
390 struct rte_mbuf *pkt;
391 uint16_t port_id = 0;
397 /* Get pkt from event */
400 /* Check the packet type */
401 type = process_ipsec_get_pkt_type(pkt, &nlp);
404 case PKT_TYPE_PLAIN_IPV4:
405 /* Check if we have a match */
406 if (check_sp(ctx->sp4_ctx, nlp, &sa_idx) == 0) {
408 goto drop_pkt_and_exit;
411 case PKT_TYPE_PLAIN_IPV6:
412 /* Check if we have a match */
413 if (check_sp(ctx->sp6_ctx, nlp, &sa_idx) == 0) {
415 goto drop_pkt_and_exit;
420 * Only plain IPv4 & IPv6 packets are allowed
421 * on protected port. Drop the rest.
423 RTE_LOG(ERR, IPSEC, "Unsupported packet type = %d\n", type);
424 goto drop_pkt_and_exit;
427 /* Check if the packet has to be bypassed */
428 if (sa_idx == BYPASS) {
429 port_id = get_route(pkt, rt, type);
430 if (unlikely(port_id == RTE_MAX_ETHPORTS)) {
432 goto drop_pkt_and_exit;
434 /* else, we have a matching route */
438 /* Validate sa_idx */
439 if (unlikely(sa_idx >= ctx->sa_ctx->nb_sa))
440 goto drop_pkt_and_exit;
442 /* Else the packet has to be protected */
445 sa_ctx = ctx->sa_ctx;
448 sa = &(sa_ctx->sa[sa_idx]);
450 /* Get IPsec session */
451 sess = ipsec_get_primary_session(sa);
453 /* Allow only inline protocol for now */
454 if (unlikely(sess->type != RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)) {
455 RTE_LOG(ERR, IPSEC, "SA type not supported\n");
456 goto drop_pkt_and_exit;
459 rte_security_set_pkt_metadata(sess->security.ctx,
460 sess->security.ses, pkt, NULL);
462 /* Mark the packet for Tx security offload */
463 pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
465 /* Get the port to which this pkt need to be submitted */
466 port_id = sa->portid;
469 /* Provide L2 len for Outbound processing */
470 pkt->l2_len = RTE_ETHER_HDR_LEN;
472 /* Update mac addresses */
473 update_mac_addrs(pkt, port_id);
475 /* Update the event with the dest port */
476 ipsec_event_pre_forward(pkt, port_id);
477 return PKT_FORWARDED;
480 RTE_LOG(ERR, IPSEC, "Outbound packet dropped\n");
481 rte_pktmbuf_free(pkt);
487 ipsec_ev_route_pkts(struct rte_event_vector *vec, struct route_table *rt,
488 struct ipsec_traffic *t, struct sa_ctx *sa_ctx)
490 struct rte_ipsec_session *sess;
491 uint32_t sa_idx, i, j = 0;
492 uint16_t port_id = 0;
493 struct rte_mbuf *pkt;
496 /* Route IPv4 packets */
497 for (i = 0; i < t->ip4.num; i++) {
498 pkt = t->ip4.pkts[i];
499 port_id = route4_pkt(pkt, rt->rt4_ctx);
500 if (port_id != RTE_MAX_ETHPORTS) {
501 /* Update mac addresses */
502 update_mac_addrs(pkt, port_id);
503 /* Update the event with the dest port */
504 ipsec_event_pre_forward(pkt, port_id);
505 ev_vector_attr_update(vec, pkt);
506 vec->mbufs[j++] = pkt;
511 /* Route IPv6 packets */
512 for (i = 0; i < t->ip6.num; i++) {
513 pkt = t->ip6.pkts[i];
514 port_id = route6_pkt(pkt, rt->rt6_ctx);
515 if (port_id != RTE_MAX_ETHPORTS) {
516 /* Update mac addresses */
517 update_mac_addrs(pkt, port_id);
518 /* Update the event with the dest port */
519 ipsec_event_pre_forward(pkt, port_id);
520 ev_vector_attr_update(vec, pkt);
521 vec->mbufs[j++] = pkt;
526 /* Route ESP packets */
527 for (i = 0; i < t->ipsec.num; i++) {
528 /* Validate sa_idx */
529 sa_idx = t->ipsec.res[i];
530 pkt = t->ipsec.pkts[i];
531 if (unlikely(sa_idx >= sa_ctx->nb_sa))
534 /* Else the packet has to be protected */
535 sa = &(sa_ctx->sa[sa_idx]);
536 /* Get IPsec session */
537 sess = ipsec_get_primary_session(sa);
538 /* Allow only inline protocol for now */
539 if (unlikely(sess->type !=
540 RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)) {
541 RTE_LOG(ERR, IPSEC, "SA type not supported\n");
545 rte_security_set_pkt_metadata(sess->security.ctx,
546 sess->security.ses, pkt, NULL);
548 pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
549 port_id = sa->portid;
550 update_mac_addrs(pkt, port_id);
551 ipsec_event_pre_forward(pkt, port_id);
552 ev_vector_attr_update(vec, pkt);
553 vec->mbufs[j++] = pkt;
561 classify_pkt(struct rte_mbuf *pkt, struct ipsec_traffic *t)
566 /* Check the packet type */
567 type = process_ipsec_get_pkt_type(pkt, &nlp);
570 case PKT_TYPE_PLAIN_IPV4:
571 t->ip4.data[t->ip4.num] = nlp;
572 t->ip4.pkts[(t->ip4.num)++] = pkt;
574 case PKT_TYPE_PLAIN_IPV6:
575 t->ip6.data[t->ip6.num] = nlp;
576 t->ip6.pkts[(t->ip6.num)++] = pkt;
579 RTE_LOG_DP(DEBUG, IPSEC_ESP, "Unsupported packet type = %d\n",
587 process_ipsec_ev_inbound_vector(struct ipsec_ctx *ctx, struct route_table *rt,
588 struct rte_event_vector *vec)
590 struct ipsec_traffic t;
591 struct rte_mbuf *pkt;
598 for (i = 0; i < vec->nb_elem; i++) {
599 /* Get pkt from event */
602 if (pkt->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD) {
603 if (unlikely(pkt->ol_flags &
604 RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED)) {
606 "Inbound security offload failed\n");
612 classify_pkt(pkt, &t);
615 check_sp_sa_bulk(ctx->sp4_ctx, ctx->sa_ctx, &t.ip4);
616 check_sp_sa_bulk(ctx->sp6_ctx, ctx->sa_ctx, &t.ip6);
618 return ipsec_ev_route_pkts(vec, rt, &t, ctx->sa_ctx);
622 process_ipsec_ev_outbound_vector(struct ipsec_ctx *ctx, struct route_table *rt,
623 struct rte_event_vector *vec)
625 struct ipsec_traffic t;
626 struct rte_mbuf *pkt;
633 for (i = 0; i < vec->nb_elem; i++) {
634 /* Get pkt from event */
637 classify_pkt(pkt, &t);
639 /* Provide L2 len for Outbound processing */
640 pkt->l2_len = RTE_ETHER_HDR_LEN;
643 check_sp_bulk(ctx->sp4_ctx, &t.ip4, &t.ipsec);
644 check_sp_bulk(ctx->sp6_ctx, &t.ip6, &t.ipsec);
646 return ipsec_ev_route_pkts(vec, rt, &t, ctx->sa_ctx);
650 process_ipsec_ev_drv_mode_outbound_vector(struct rte_event_vector *vec,
651 struct port_drv_mode_data *data)
653 struct rte_mbuf *pkt;
658 for (i = 0; i < vec->nb_elem; i++) {
662 if (unlikely(!data[port_id].sess)) {
666 ipsec_event_pre_forward(pkt, port_id);
667 /* Save security session */
668 rte_security_set_pkt_metadata(data[port_id].ctx,
669 data[port_id].sess, pkt,
672 /* Mark the packet for Tx security offload */
673 pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
675 /* Provide L2 len for Outbound processing */
676 pkt->l2_len = RTE_ETHER_HDR_LEN;
678 vec->mbufs[j++] = pkt;
685 ipsec_ev_vector_process(struct lcore_conf_ev_tx_int_port_wrkr *lconf,
686 struct eh_event_link_info *links,
687 struct rte_event *ev)
689 struct rte_event_vector *vec = ev->vec;
690 struct rte_mbuf *pkt;
695 ev_vector_attr_init(vec);
696 if (is_unprotected_port(pkt->port))
697 ret = process_ipsec_ev_inbound_vector(&lconf->inbound,
700 ret = process_ipsec_ev_outbound_vector(&lconf->outbound,
703 if (likely(ret > 0)) {
705 rte_event_eth_tx_adapter_enqueue(links[0].eventdev_id,
706 links[0].event_port_id,
709 rte_mempool_put(rte_mempool_from_obj(vec), vec);
714 ipsec_ev_vector_drv_mode_process(struct eh_event_link_info *links,
715 struct rte_event *ev,
716 struct port_drv_mode_data *data)
718 struct rte_event_vector *vec = ev->vec;
719 struct rte_mbuf *pkt;
723 if (!is_unprotected_port(pkt->port))
724 vec->nb_elem = process_ipsec_ev_drv_mode_outbound_vector(vec,
726 if (vec->nb_elem > 0)
727 rte_event_eth_tx_adapter_enqueue(links[0].eventdev_id,
728 links[0].event_port_id,
731 rte_mempool_put(rte_mempool_from_obj(vec), vec);
735 * Event mode exposes various operating modes depending on the
736 * capabilities of the event device and the operating mode
740 /* Workers registered */
741 #define IPSEC_EVENTMODE_WORKERS 2
745 * Operating parameters : non-burst - Tx internal port - driver mode
748 ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links,
751 struct port_drv_mode_data data[RTE_MAX_ETHPORTS];
752 unsigned int nb_rx = 0;
753 struct rte_mbuf *pkt;
759 /* Check if we have links registered for this lcore */
761 /* No links registered - exit */
765 memset(&data, 0, sizeof(struct port_drv_mode_data));
768 lcore_id = rte_lcore_id();
771 socket_id = rte_lcore_to_socket_id(lcore_id);
774 * Prepare security sessions table. In outbound driver mode
775 * we always use first session configured for a given port
777 prepare_out_sessions_tbl(socket_ctx[socket_id].sa_out, data,
781 "Launching event mode worker (non-burst - Tx internal port - "
782 "driver mode) on lcore %d\n", lcore_id);
784 /* We have valid links */
786 /* Check if it's single link */
789 "Multiple links not supported. Using first link\n");
792 RTE_LOG(INFO, IPSEC, " -- lcoreid=%u event_port_id=%u\n", lcore_id,
793 links[0].event_port_id);
794 while (!force_quit) {
795 /* Read packet from event queues */
796 nb_rx = rte_event_dequeue_burst(links[0].eventdev_id,
797 links[0].event_port_id,
800 0 /* timeout_ticks */);
805 switch (ev.event_type) {
806 case RTE_EVENT_TYPE_ETH_RX_ADAPTER_VECTOR:
807 case RTE_EVENT_TYPE_ETHDEV_VECTOR:
808 ipsec_ev_vector_drv_mode_process(links, &ev, data);
810 case RTE_EVENT_TYPE_ETHDEV:
813 RTE_LOG(ERR, IPSEC, "Invalid event type %u",
821 rte_prefetch0(rte_pktmbuf_mtod(pkt, void *));
824 ipsec_event_pre_forward(pkt, port_id);
826 if (!is_unprotected_port(port_id)) {
828 if (unlikely(!data[port_id].sess)) {
829 rte_pktmbuf_free(pkt);
833 /* Save security session */
834 rte_security_set_pkt_metadata(data[port_id].ctx,
835 data[port_id].sess, pkt,
838 /* Mark the packet for Tx security offload */
839 pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
841 /* Provide L2 len for Outbound processing */
842 pkt->l2_len = RTE_ETHER_HDR_LEN;
846 * Since tx internal port is available, events can be
847 * directly enqueued to the adapter and it would be
848 * internally submitted to the eth device.
850 rte_event_eth_tx_adapter_enqueue(links[0].eventdev_id,
851 links[0].event_port_id,
860 * Operating parameters : non-burst - Tx internal port - app mode
863 ipsec_wrkr_non_burst_int_port_app_mode(struct eh_event_link_info *links,
866 struct lcore_conf_ev_tx_int_port_wrkr lconf;
867 unsigned int nb_rx = 0;
873 /* Check if we have links registered for this lcore */
875 /* No links registered - exit */
879 /* We have valid links */
882 lcore_id = rte_lcore_id();
885 socket_id = rte_lcore_to_socket_id(lcore_id);
887 /* Save routing table */
888 lconf.rt.rt4_ctx = socket_ctx[socket_id].rt_ip4;
889 lconf.rt.rt6_ctx = socket_ctx[socket_id].rt_ip6;
890 lconf.inbound.sp4_ctx = socket_ctx[socket_id].sp_ip4_in;
891 lconf.inbound.sp6_ctx = socket_ctx[socket_id].sp_ip6_in;
892 lconf.inbound.sa_ctx = socket_ctx[socket_id].sa_in;
893 lconf.inbound.session_pool = socket_ctx[socket_id].session_pool;
894 lconf.inbound.session_priv_pool =
895 socket_ctx[socket_id].session_priv_pool;
896 lconf.outbound.sp4_ctx = socket_ctx[socket_id].sp_ip4_out;
897 lconf.outbound.sp6_ctx = socket_ctx[socket_id].sp_ip6_out;
898 lconf.outbound.sa_ctx = socket_ctx[socket_id].sa_out;
899 lconf.outbound.session_pool = socket_ctx[socket_id].session_pool;
900 lconf.outbound.session_priv_pool =
901 socket_ctx[socket_id].session_priv_pool;
904 "Launching event mode worker (non-burst - Tx internal port - "
905 "app mode) on lcore %d\n", lcore_id);
907 /* Check if it's single link */
910 "Multiple links not supported. Using first link\n");
913 RTE_LOG(INFO, IPSEC, " -- lcoreid=%u event_port_id=%u\n", lcore_id,
914 links[0].event_port_id);
916 while (!force_quit) {
917 /* Read packet from event queues */
918 nb_rx = rte_event_dequeue_burst(links[0].eventdev_id,
919 links[0].event_port_id,
922 0 /* timeout_ticks */);
927 switch (ev.event_type) {
928 case RTE_EVENT_TYPE_ETH_RX_ADAPTER_VECTOR:
929 case RTE_EVENT_TYPE_ETHDEV_VECTOR:
930 ipsec_ev_vector_process(&lconf, links, &ev);
932 case RTE_EVENT_TYPE_ETHDEV:
935 RTE_LOG(ERR, IPSEC, "Invalid event type %u",
940 if (is_unprotected_port(ev.mbuf->port))
941 ret = process_ipsec_ev_inbound(&lconf.inbound,
944 ret = process_ipsec_ev_outbound(&lconf.outbound,
947 /* The pkt has been dropped */
951 * Since tx internal port is available, events can be
952 * directly enqueued to the adapter and it would be
953 * internally submitted to the eth device.
955 rte_event_eth_tx_adapter_enqueue(links[0].eventdev_id,
956 links[0].event_port_id,
964 ipsec_eventmode_populate_wrkr_params(struct eh_app_worker_params *wrkrs)
966 struct eh_app_worker_params *wrkr;
967 uint8_t nb_wrkr_param = 0;
972 /* Non-burst - Tx internal port - driver mode */
973 wrkr->cap.burst = EH_RX_TYPE_NON_BURST;
974 wrkr->cap.tx_internal_port = EH_TX_TYPE_INTERNAL_PORT;
975 wrkr->cap.ipsec_mode = EH_IPSEC_MODE_TYPE_DRIVER;
976 wrkr->worker_thread = ipsec_wrkr_non_burst_int_port_drv_mode;
980 /* Non-burst - Tx internal port - app mode */
981 wrkr->cap.burst = EH_RX_TYPE_NON_BURST;
982 wrkr->cap.tx_internal_port = EH_TX_TYPE_INTERNAL_PORT;
983 wrkr->cap.ipsec_mode = EH_IPSEC_MODE_TYPE_APP;
984 wrkr->worker_thread = ipsec_wrkr_non_burst_int_port_app_mode;
987 return nb_wrkr_param;
991 ipsec_eventmode_worker(struct eh_conf *conf)
993 struct eh_app_worker_params ipsec_wrkr[IPSEC_EVENTMODE_WORKERS] = {
995 uint8_t nb_wrkr_param;
997 /* Populate l2fwd_wrkr params */
998 nb_wrkr_param = ipsec_eventmode_populate_wrkr_params(ipsec_wrkr);
1001 * Launch correct worker after checking
1002 * the event device's capabilities.
1004 eh_launch_worker(conf, ipsec_wrkr, nb_wrkr_param);
1007 int ipsec_launch_one_lcore(void *args)
1009 struct eh_conf *conf;
1011 conf = (struct eh_conf *)args;
1013 if (conf->mode == EH_PKT_TRANSFER_MODE_POLL) {
1014 /* Run in poll mode */
1015 ipsec_poll_mode_worker();
1016 } else if (conf->mode == EH_PKT_TRANSFER_MODE_EVENT) {
1017 /* Run in event mode */
1018 ipsec_eventmode_worker(conf);