#include <stdbool.h>
#include "event_helper.h"
+#include "ipsec-secgw.h"
+
+#define DEFAULT_VECTOR_SIZE 16
+#define DEFAULT_VECTOR_TMO 102400
static volatile bool eth_core_running;
return 0;
}
+static int
+eh_event_vector_limits_validate(struct eventmode_conf *em_conf,
+ uint8_t ev_dev_id, uint8_t ethdev_id)
+{
+ struct rte_event_eth_rx_adapter_vector_limits limits = {0};
+ uint16_t vector_size = em_conf->ext_params.vector_size;
+ int ret;
+
+ ret = rte_event_eth_rx_adapter_vector_limits_get(ev_dev_id, ethdev_id,
+ &limits);
+ if (ret) {
+ EH_LOG_ERR("failed to get vector limits");
+ return ret;
+ }
+
+ if (vector_size < limits.min_sz || vector_size > limits.max_sz) {
+ EH_LOG_ERR("Vector size [%d] not within limits min[%d] max[%d]",
+ vector_size, limits.min_sz, limits.max_sz);
+ return -EINVAL;
+ }
+
+ if (limits.log2_sz && !rte_is_power_of_2(vector_size)) {
+ EH_LOG_ERR("Vector size [%d] not power of 2", vector_size);
+ return -EINVAL;
+ }
+
+ if (em_conf->vector_tmo_ns > limits.max_timeout_ns ||
+ em_conf->vector_tmo_ns < limits.min_timeout_ns) {
+ EH_LOG_ERR("Vector timeout [%" PRIu64
+ "] not within limits max[%" PRIu64
+ "] min[%" PRIu64 "]",
+ em_conf->vector_tmo_ns,
+ limits.max_timeout_ns,
+ limits.min_timeout_ns);
+ return -EINVAL;
+ }
+ return 0;
+}
+
static int
eh_rx_adapter_configure(struct eventmode_conf *em_conf,
struct rx_adapter_conf *adapter)
struct rte_event_dev_info evdev_default_conf = {0};
struct rte_event_port_conf port_conf = {0};
struct rx_adapter_connection_info *conn;
+ uint32_t service_id, socket_id, nb_elem;
+ struct rte_mempool *vector_pool = NULL;
+ uint32_t lcore_id = rte_lcore_id();
uint8_t eventdev_id;
- uint32_t service_id;
int ret;
int j;
return ret;
}
+ if (em_conf->ext_params.event_vector) {
+ socket_id = rte_lcore_to_socket_id(lcore_id);
+ nb_elem = (nb_bufs_in_pool / em_conf->ext_params.vector_size)
+ + 1;
+
+ vector_pool = rte_event_vector_pool_create(
+ "vector_pool", nb_elem, 0,
+ em_conf->ext_params.vector_size,
+ socket_id);
+ if (vector_pool == NULL) {
+ EH_LOG_ERR("failed to create event vector pool");
+ return -ENOMEM;
+ }
+ }
/* Setup port conf */
port_conf.new_event_threshold = 1200;
port_conf.dequeue_depth =
queue_conf.ev.sched_type = em_conf->ext_params.sched_type;
queue_conf.ev.event_type = RTE_EVENT_TYPE_ETHDEV;
+ if (em_conf->ext_params.event_vector) {
+ ret = eh_event_vector_limits_validate(em_conf,
+ eventdev_id,
+ conn->ethdev_id);
+ if (ret)
+ return ret;
+
+ queue_conf.vector_sz = em_conf->ext_params.vector_size;
+ queue_conf.vector_timeout_ns = em_conf->vector_tmo_ns;
+ queue_conf.vector_mp = vector_pool;
+ queue_conf.rx_queue_flags =
+ RTE_EVENT_ETH_RX_ADAPTER_QUEUE_EVENT_VECTOR;
+ }
+
/* Add queue to the adapter */
ret = rte_event_eth_rx_adapter_queue_add(adapter->adapter_id,
conn->ethdev_id, conn->ethdev_rx_qid,
rte_bitmap_set(em_conf->eth_core_mask, eth_core_id);
+ em_conf->ext_params.vector_size = DEFAULT_VECTOR_SIZE;
+ em_conf->vector_tmo_ns = DEFAULT_VECTOR_TMO;
+
return conf;
free_bitmap:
#define CMD_LINE_OPT_REASSEMBLE "reassemble"
#define CMD_LINE_OPT_MTU "mtu"
#define CMD_LINE_OPT_FRAG_TTL "frag-ttl"
+#define CMD_LINE_OPT_EVENT_VECTOR "event-vector"
+#define CMD_LINE_OPT_VECTOR_SIZE "vector-size"
+#define CMD_LINE_OPT_VECTOR_TIMEOUT "vector-tmo"
#define CMD_LINE_ARG_EVENT "event"
#define CMD_LINE_ARG_POLL "poll"
CMD_LINE_OPT_REASSEMBLE_NUM,
CMD_LINE_OPT_MTU_NUM,
CMD_LINE_OPT_FRAG_TTL_NUM,
+ CMD_LINE_OPT_EVENT_VECTOR_NUM,
+ CMD_LINE_OPT_VECTOR_SIZE_NUM,
+ CMD_LINE_OPT_VECTOR_TIMEOUT_NUM,
};
static const struct option lgopts[] = {
{CMD_LINE_OPT_REASSEMBLE, 1, 0, CMD_LINE_OPT_REASSEMBLE_NUM},
{CMD_LINE_OPT_MTU, 1, 0, CMD_LINE_OPT_MTU_NUM},
{CMD_LINE_OPT_FRAG_TTL, 1, 0, CMD_LINE_OPT_FRAG_TTL_NUM},
+ {CMD_LINE_OPT_EVENT_VECTOR, 0, 0, CMD_LINE_OPT_EVENT_VECTOR_NUM},
+ {CMD_LINE_OPT_VECTOR_SIZE, 1, 0, CMD_LINE_OPT_VECTOR_SIZE_NUM},
+ {CMD_LINE_OPT_VECTOR_TIMEOUT, 1, 0, CMD_LINE_OPT_VECTOR_TIMEOUT_NUM},
{NULL, 0, 0, 0}
};
static int32_t numa_on = 1; /**< NUMA is enabled by default. */
static uint32_t nb_lcores;
static uint32_t single_sa;
-static uint32_t nb_bufs_in_pool;
+uint32_t nb_bufs_in_pool;
/*
* RX/TX HW offload capabilities to enable/use on ethernet ports.
" [--" CMD_LINE_OPT_TX_OFFLOAD " TX_OFFLOAD_MASK]"
" [--" CMD_LINE_OPT_REASSEMBLE " REASSEMBLE_TABLE_SIZE]"
" [--" CMD_LINE_OPT_MTU " MTU]"
+ " [--event-vector]"
+ " [--vector-size SIZE]"
+ " [--vector-tmo TIMEOUT in ns]"
"\n\n"
" -p PORTMASK: Hexadecimal bitmask of ports to configure\n"
" -P : Enable promiscuous mode\n"
" --" CMD_LINE_OPT_FRAG_TTL " FRAG_TTL_NS"
": fragments lifetime in nanoseconds, default\n"
" and maximum value is 10.000.000.000 ns (10 s)\n"
+ " --event-vector enables event vectorization\n"
+ " --vector-size Max vector size (default value: 16)\n"
+ " --vector-tmo Max vector timeout in nanoseconds"
+ " (default value: 102400)\n"
"\n",
prgname);
}
int32_t option_index;
char *prgname = argv[0];
int32_t f_present = 0;
+ struct eventmode_conf *em_conf = NULL;
argvopt = argv;
}
frag_ttl_ns = ret;
break;
+ case CMD_LINE_OPT_EVENT_VECTOR_NUM:
+ em_conf = eh_conf->mode_params;
+ em_conf->ext_params.event_vector = 1;
+ break;
+ case CMD_LINE_OPT_VECTOR_SIZE_NUM:
+ ret = parse_decimal(optarg);
+
+ if (ret > MAX_PKT_BURST) {
+ printf("Invalid argument for \'%s\': %s\n",
+ CMD_LINE_OPT_VECTOR_SIZE, optarg);
+ print_usage(prgname);
+ return -1;
+ }
+ em_conf = eh_conf->mode_params;
+ em_conf->ext_params.vector_size = ret;
+ break;
+ case CMD_LINE_OPT_VECTOR_TIMEOUT_NUM:
+ ret = parse_decimal(optarg);
+
+ em_conf = eh_conf->mode_params;
+ em_conf->vector_tmo_ns = ret;
+ break;
default:
print_usage(prgname);
return -1;
rte_event_eth_tx_adapter_txq_set(m, 0);
}
+static inline void
+ev_vector_attr_init(struct rte_event_vector *vec)
+{
+ vec->attr_valid = 1;
+ vec->port = 0xFFFF;
+ vec->queue = 0;
+}
+
+static inline void
+ev_vector_attr_update(struct rte_event_vector *vec, struct rte_mbuf *pkt)
+{
+ if (vec->port == 0xFFFF) {
+ vec->port = pkt->port;
+ return;
+ }
+ if (vec->attr_valid && (vec->port != pkt->port))
+ vec->attr_valid = 0;
+}
+
static inline void
prepare_out_sessions_tbl(struct sa_ctx *sa_out,
struct port_drv_mode_data *data,
return 1;
}
+static inline void
+check_sp_bulk(struct sp_ctx *sp, struct traffic_type *ip,
+ struct traffic_type *ipsec)
+{
+ uint32_t i, j, res;
+ struct rte_mbuf *m;
+
+ if (unlikely(sp == NULL || ip->num == 0))
+ return;
+
+ rte_acl_classify((struct rte_acl_ctx *)sp, ip->data, ip->res, ip->num,
+ DEFAULT_MAX_CATEGORIES);
+
+ j = 0;
+ for (i = 0; i < ip->num; i++) {
+ m = ip->pkts[i];
+ res = ip->res[i];
+ if (unlikely(res == DISCARD))
+ free_pkts(&m, 1);
+ else if (res == BYPASS)
+ ip->pkts[j++] = m;
+ else {
+ ipsec->res[ipsec->num] = res - 1;
+ ipsec->pkts[ipsec->num++] = m;
+ }
+ }
+ ip->num = j;
+}
+
+static inline void
+check_sp_sa_bulk(struct sp_ctx *sp, struct sa_ctx *sa_ctx,
+ struct traffic_type *ip)
+{
+ struct ipsec_sa *sa;
+ uint32_t i, j, res;
+ struct rte_mbuf *m;
+
+ if (unlikely(sp == NULL || ip->num == 0))
+ return;
+
+ rte_acl_classify((struct rte_acl_ctx *)sp, ip->data, ip->res, ip->num,
+ DEFAULT_MAX_CATEGORIES);
+
+ j = 0;
+ for (i = 0; i < ip->num; i++) {
+ m = ip->pkts[i];
+ res = ip->res[i];
+ if (unlikely(res == DISCARD))
+ free_pkts(&m, 1);
+ else if (res == BYPASS)
+ ip->pkts[j++] = m;
+ else {
+ sa = *(struct ipsec_sa **)rte_security_dynfield(m);
+ if (sa == NULL)
+ free_pkts(&m, 1);
+
+ /* SPI on the packet should match with the one in SA */
+ if (unlikely(sa->spi != sa_ctx->sa[res - 1].spi))
+ free_pkts(&m, 1);
+
+ ip->pkts[j++] = m;
+ }
+ }
+ ip->num = j;
+}
+
static inline uint16_t
route4_pkt(struct rte_mbuf *pkt, struct rt_ctx *rt_ctx)
{
return PKT_DROPPED;
}
+static inline int
+ipsec_ev_route_pkts(struct rte_event_vector *vec, struct route_table *rt,
+ struct ipsec_traffic *t, struct sa_ctx *sa_ctx)
+{
+ struct rte_ipsec_session *sess;
+ uint32_t sa_idx, i, j = 0;
+ uint16_t port_id = 0;
+ struct rte_mbuf *pkt;
+ struct ipsec_sa *sa;
+
+ /* Route IPv4 packets */
+ for (i = 0; i < t->ip4.num; i++) {
+ pkt = t->ip4.pkts[i];
+ port_id = route4_pkt(pkt, rt->rt4_ctx);
+ if (port_id != RTE_MAX_ETHPORTS) {
+ /* Update mac addresses */
+ update_mac_addrs(pkt, port_id);
+ /* Update the event with the dest port */
+ ipsec_event_pre_forward(pkt, port_id);
+ ev_vector_attr_update(vec, pkt);
+ vec->mbufs[j++] = pkt;
+ } else
+ free_pkts(&pkt, 1);
+ }
+
+ /* Route IPv6 packets */
+ for (i = 0; i < t->ip6.num; i++) {
+ pkt = t->ip6.pkts[i];
+ port_id = route6_pkt(pkt, rt->rt6_ctx);
+ if (port_id != RTE_MAX_ETHPORTS) {
+ /* Update mac addresses */
+ update_mac_addrs(pkt, port_id);
+ /* Update the event with the dest port */
+ ipsec_event_pre_forward(pkt, port_id);
+ ev_vector_attr_update(vec, pkt);
+ vec->mbufs[j++] = pkt;
+ } else
+ free_pkts(&pkt, 1);
+ }
+
+ /* Route ESP packets */
+ for (i = 0; i < t->ipsec.num; i++) {
+ /* Validate sa_idx */
+ sa_idx = t->ipsec.res[i];
+ pkt = t->ipsec.pkts[i];
+ if (unlikely(sa_idx >= sa_ctx->nb_sa))
+ free_pkts(&pkt, 1);
+ else {
+ /* Else the packet has to be protected */
+ sa = &(sa_ctx->sa[sa_idx]);
+ /* Get IPsec session */
+ sess = ipsec_get_primary_session(sa);
+ /* Allow only inline protocol for now */
+ if (unlikely(sess->type !=
+ RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)) {
+ RTE_LOG(ERR, IPSEC, "SA type not supported\n");
+ free_pkts(&pkt, 1);
+ }
+ rte_security_set_pkt_metadata(sess->security.ctx,
+ sess->security.ses, pkt, NULL);
+
+ pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+ port_id = sa->portid;
+ update_mac_addrs(pkt, port_id);
+ ipsec_event_pre_forward(pkt, port_id);
+ ev_vector_attr_update(vec, pkt);
+ vec->mbufs[j++] = pkt;
+ }
+ }
+
+ return j;
+}
+
+static inline void
+classify_pkt(struct rte_mbuf *pkt, struct ipsec_traffic *t)
+{
+ enum pkt_type type;
+ uint8_t *nlp;
+
+ /* Check the packet type */
+ type = process_ipsec_get_pkt_type(pkt, &nlp);
+
+ switch (type) {
+ case PKT_TYPE_PLAIN_IPV4:
+ t->ip4.data[t->ip4.num] = nlp;
+ t->ip4.pkts[(t->ip4.num)++] = pkt;
+ break;
+ case PKT_TYPE_PLAIN_IPV6:
+ t->ip6.data[t->ip6.num] = nlp;
+ t->ip6.pkts[(t->ip6.num)++] = pkt;
+ break;
+ default:
+ RTE_LOG(ERR, IPSEC, "Unsupported packet type = %d\n", type);
+ free_pkts(&pkt, 1);
+ break;
+ }
+}
+
+static inline int
+process_ipsec_ev_inbound_vector(struct ipsec_ctx *ctx, struct route_table *rt,
+ struct rte_event_vector *vec)
+{
+ struct ipsec_traffic t;
+ struct rte_mbuf *pkt;
+ int i;
+
+ t.ip4.num = 0;
+ t.ip6.num = 0;
+ t.ipsec.num = 0;
+
+ for (i = 0; i < vec->nb_elem; i++) {
+ /* Get pkt from event */
+ pkt = vec->mbufs[i];
+
+ if (pkt->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD) {
+ if (unlikely(pkt->ol_flags &
+ RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED)) {
+ RTE_LOG(ERR, IPSEC,
+ "Inbound security offload failed\n");
+ free_pkts(&pkt, 1);
+ continue;
+ }
+ }
+
+ classify_pkt(pkt, &t);
+ }
+
+ check_sp_sa_bulk(ctx->sp4_ctx, ctx->sa_ctx, &t.ip4);
+ check_sp_sa_bulk(ctx->sp6_ctx, ctx->sa_ctx, &t.ip6);
+
+ return ipsec_ev_route_pkts(vec, rt, &t, ctx->sa_ctx);
+}
+
+static inline int
+process_ipsec_ev_outbound_vector(struct ipsec_ctx *ctx, struct route_table *rt,
+ struct rte_event_vector *vec)
+{
+ struct ipsec_traffic t;
+ struct rte_mbuf *pkt;
+ uint32_t i;
+
+ t.ip4.num = 0;
+ t.ip6.num = 0;
+ t.ipsec.num = 0;
+
+ for (i = 0; i < vec->nb_elem; i++) {
+ /* Get pkt from event */
+ pkt = vec->mbufs[i];
+
+ classify_pkt(pkt, &t);
+
+ /* Provide L2 len for Outbound processing */
+ pkt->l2_len = RTE_ETHER_HDR_LEN;
+ }
+
+ check_sp_bulk(ctx->sp4_ctx, &t.ip4, &t.ipsec);
+ check_sp_bulk(ctx->sp6_ctx, &t.ip6, &t.ipsec);
+
+ return ipsec_ev_route_pkts(vec, rt, &t, ctx->sa_ctx);
+}
+
+static inline int
+process_ipsec_ev_drv_mode_outbound_vector(struct rte_event_vector *vec,
+ struct port_drv_mode_data *data)
+{
+ struct rte_mbuf *pkt;
+ int16_t port_id;
+ uint32_t i;
+ int j = 0;
+
+ for (i = 0; i < vec->nb_elem; i++) {
+ pkt = vec->mbufs[i];
+ port_id = pkt->port;
+
+ if (unlikely(!data[port_id].sess)) {
+ free_pkts(&pkt, 1);
+ continue;
+ }
+ ipsec_event_pre_forward(pkt, port_id);
+ /* Save security session */
+ rte_security_set_pkt_metadata(data[port_id].ctx,
+ data[port_id].sess, pkt,
+ NULL);
+
+ /* Mark the packet for Tx security offload */
+ pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+
+ /* Provide L2 len for Outbound processing */
+ pkt->l2_len = RTE_ETHER_HDR_LEN;
+
+ vec->mbufs[j++] = pkt;
+ }
+
+ return j;
+}
+
+static inline void
+ipsec_ev_vector_process(struct lcore_conf_ev_tx_int_port_wrkr *lconf,
+ struct eh_event_link_info *links,
+ struct rte_event *ev)
+{
+ struct rte_event_vector *vec = ev->vec;
+ struct rte_mbuf *pkt;
+ int ret;
+
+ pkt = vec->mbufs[0];
+
+ ev_vector_attr_init(vec);
+ if (is_unprotected_port(pkt->port))
+ ret = process_ipsec_ev_inbound_vector(&lconf->inbound,
+ &lconf->rt, vec);
+ else
+ ret = process_ipsec_ev_outbound_vector(&lconf->outbound,
+ &lconf->rt, vec);
+
+ if (ret > 0) {
+ vec->nb_elem = ret;
+ rte_event_eth_tx_adapter_enqueue(links[0].eventdev_id,
+ links[0].event_port_id,
+ ev, 1, 0);
+ }
+}
+
+static inline void
+ipsec_ev_vector_drv_mode_process(struct eh_event_link_info *links,
+ struct rte_event *ev,
+ struct port_drv_mode_data *data)
+{
+ struct rte_event_vector *vec = ev->vec;
+ struct rte_mbuf *pkt;
+
+ pkt = vec->mbufs[0];
+
+ if (!is_unprotected_port(pkt->port))
+ vec->nb_elem = process_ipsec_ev_drv_mode_outbound_vector(vec,
+ data);
+ if (vec->nb_elem > 0)
+ rte_event_eth_tx_adapter_enqueue(links[0].eventdev_id,
+ links[0].event_port_id,
+ ev, 1, 0);
+}
+
/*
* Event mode exposes various operating modes depending on the
* capabilities of the event device and the operating mode
if (nb_rx == 0)
continue;
+ switch (ev.event_type) {
+ case RTE_EVENT_TYPE_ETH_RX_ADAPTER_VECTOR:
+ case RTE_EVENT_TYPE_ETHDEV_VECTOR:
+ ipsec_ev_vector_drv_mode_process(links, &ev, data);
+ continue;
+ case RTE_EVENT_TYPE_ETHDEV:
+ break;
+ default:
+ RTE_LOG(ERR, IPSEC, "Invalid event type %u",
+ ev.event_type);
+ continue;
+ }
+
pkt = ev.mbuf;
port_id = pkt->port;
if (nb_rx == 0)
continue;
- if (unlikely(ev.event_type != RTE_EVENT_TYPE_ETHDEV)) {
+ switch (ev.event_type) {
+ case RTE_EVENT_TYPE_ETH_RX_ADAPTER_VECTOR:
+ case RTE_EVENT_TYPE_ETHDEV_VECTOR:
+ ipsec_ev_vector_process(&lconf, links, &ev);
+ continue;
+ case RTE_EVENT_TYPE_ETHDEV:
+ break;
+ default:
RTE_LOG(ERR, IPSEC, "Invalid event type %u",
ev.event_type);
-
continue;
}