examples/ipsec-secgw: add app mode worker
[dpdk.git] / examples / ipsec-secgw / ipsec-secgw.c
index ad16606..2e55614 100644 (file)
 
 #include "event_helper.h"
 #include "ipsec.h"
+#include "ipsec_worker.h"
 #include "parser.h"
 #include "sad.h"
 
 volatile bool force_quit;
 
-#define RTE_LOGTYPE_IPSEC RTE_LOGTYPE_USER1
-
 #define MAX_JUMBO_PKT_LEN  9600
 
 #define MEMPOOL_CACHE_SIZE 256
@@ -71,8 +70,6 @@ volatile bool force_quit;
 
 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
 
-#define NB_SOCKETS 4
-
 /* Configure how many packets ahead to prefetch, when reading packets */
 #define PREFETCH_OFFSET        3
 
@@ -80,8 +77,6 @@ volatile bool force_quit;
 
 #define MAX_LCORE_PARAMS 1024
 
-#define UNPROTECTED_PORT(port) (unprotected_port_mask & (1 << portid))
-
 /*
  * Configurable number of RX/TX ring descriptors
  */
@@ -90,29 +85,6 @@ volatile bool force_quit;
 static uint16_t nb_rxd = IPSEC_SECGW_RX_DESC_DEFAULT;
 static uint16_t nb_txd = IPSEC_SECGW_TX_DESC_DEFAULT;
 
-#if RTE_BYTE_ORDER != RTE_LITTLE_ENDIAN
-#define __BYTES_TO_UINT64(a, b, c, d, e, f, g, h) \
-       (((uint64_t)((a) & 0xff) << 56) | \
-       ((uint64_t)((b) & 0xff) << 48) | \
-       ((uint64_t)((c) & 0xff) << 40) | \
-       ((uint64_t)((d) & 0xff) << 32) | \
-       ((uint64_t)((e) & 0xff) << 24) | \
-       ((uint64_t)((f) & 0xff) << 16) | \
-       ((uint64_t)((g) & 0xff) << 8)  | \
-       ((uint64_t)(h) & 0xff))
-#else
-#define __BYTES_TO_UINT64(a, b, c, d, e, f, g, h) \
-       (((uint64_t)((h) & 0xff) << 56) | \
-       ((uint64_t)((g) & 0xff) << 48) | \
-       ((uint64_t)((f) & 0xff) << 40) | \
-       ((uint64_t)((e) & 0xff) << 32) | \
-       ((uint64_t)((d) & 0xff) << 24) | \
-       ((uint64_t)((c) & 0xff) << 16) | \
-       ((uint64_t)((b) & 0xff) << 8) | \
-       ((uint64_t)(a) & 0xff))
-#endif
-#define ETHADDR(a, b, c, d, e, f) (__BYTES_TO_UINT64(a, b, c, d, e, f, 0, 0))
-
 #define ETHADDR_TO_UINT64(addr) __BYTES_TO_UINT64( \
                (addr)->addr_bytes[0], (addr)->addr_bytes[1], \
                (addr)->addr_bytes[2], (addr)->addr_bytes[3], \
@@ -124,11 +96,6 @@ static uint16_t nb_txd = IPSEC_SECGW_TX_DESC_DEFAULT;
 
 #define MTU_TO_FRAMELEN(x)     ((x) + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)
 
-/* port/source ethernet addr and destination ethernet addr */
-struct ethaddr_info {
-       uint64_t src, dst;
-};
-
 struct ethaddr_info ethaddr_tbl[RTE_MAX_ETHPORTS] = {
        { 0, ETHADDR(0x00, 0x16, 0x3e, 0x7e, 0x94, 0x9a) },
        { 0, ETHADDR(0x00, 0x16, 0x3e, 0x22, 0xa1, 0xd9) },
@@ -188,15 +155,15 @@ static const struct option lgopts[] = {
        {NULL, 0, 0, 0}
 };
 
+uint32_t unprotected_port_mask;
+uint32_t single_sa_idx;
 /* mask of enabled ports */
 static uint32_t enabled_port_mask;
 static uint64_t enabled_cryptodev_mask = UINT64_MAX;
-static uint32_t unprotected_port_mask;
 static int32_t promiscuous_on = 1;
 static int32_t numa_on = 1; /**< NUMA is enabled by default. */
 static uint32_t nb_lcores;
 static uint32_t single_sa;
-static uint32_t single_sa_idx;
 
 /*
  * RX/TX HW offload capabilities to enable/use on ethernet ports.
@@ -282,7 +249,7 @@ static struct rte_eth_conf port_conf = {
        },
 };
 
-static struct socket_ctx socket_ctx[NB_SOCKETS];
+struct socket_ctx socket_ctx[NB_SOCKETS];
 
 /*
  * Determine is multi-segment support required:
@@ -1003,12 +970,12 @@ process_pkts(struct lcore_conf *qconf, struct rte_mbuf **pkts,
        prepare_traffic(pkts, &traffic, nb_pkts);
 
        if (unlikely(single_sa)) {
-               if (UNPROTECTED_PORT(portid))
+               if (is_unprotected_port(portid))
                        process_pkts_inbound_nosp(&qconf->inbound, &traffic);
                else
                        process_pkts_outbound_nosp(&qconf->outbound, &traffic);
        } else {
-               if (UNPROTECTED_PORT(portid))
+               if (is_unprotected_port(portid))
                        process_pkts_inbound(&qconf->inbound, &traffic);
                else
                        process_pkts_outbound(&qconf->outbound, &traffic);
@@ -1119,8 +1086,8 @@ drain_outbound_crypto_queues(const struct lcore_conf *qconf,
 }
 
 /* main processing loop */
-static int32_t
-main_loop(__attribute__((unused)) void *dummy)
+void
+ipsec_poll_mode_worker(void)
 {
        struct rte_mbuf *pkts[MAX_PKT_BURST];
        uint32_t lcore_id;
@@ -1164,13 +1131,13 @@ main_loop(__attribute__((unused)) void *dummy)
                RTE_LOG(ERR, IPSEC,
                        "SAD cache init on lcore %u, failed with code: %d\n",
                        lcore_id, rc);
-               return rc;
+               return;
        }
 
        if (qconf->nb_rx_queue == 0) {
                RTE_LOG(DEBUG, IPSEC, "lcore %u has nothing to do\n",
                        lcore_id);
-               return 0;
+               return;
        }
 
        RTE_LOG(INFO, IPSEC, "entering main loop on lcore %u\n", lcore_id);
@@ -1183,7 +1150,7 @@ main_loop(__attribute__((unused)) void *dummy)
                        lcore_id, portid, queueid);
        }
 
-       while (1) {
+       while (!force_quit) {
                cur_tsc = rte_rdtsc();
 
                /* TX queue buffer drain */
@@ -1207,7 +1174,7 @@ main_loop(__attribute__((unused)) void *dummy)
                                process_pkts(qconf, pkts, nb_rx, portid);
 
                        /* dequeue and process completed crypto-ops */
-                       if (UNPROTECTED_PORT(portid))
+                       if (is_unprotected_port(portid))
                                drain_inbound_crypto_queues(qconf,
                                        &qconf->inbound);
                        else
@@ -1343,8 +1310,10 @@ print_usage(const char *prgname)
                "                               In event mode this option is not used\n"
                "                               as packets are dynamically scheduled\n"
                "                               to cores by HW.\n"
-               "  --single-sa SAIDX: Use single SA index for outbound traffic,\n"
-               "                     bypassing the SP\n"
+               "  --single-sa SAIDX: In poll mode use single SA index for\n"
+               "                     outbound traffic, bypassing the SP\n"
+               "                     In event mode selects driver submode,\n"
+               "                     SA index value is ignored\n"
                "  --cryptodev_mask MASK: Hexadecimal bitmask of the crypto\n"
                "                         devices to configure\n"
                "  --transfer-mode MODE\n"
@@ -2854,7 +2823,7 @@ main(int32_t argc, char **argv)
        check_all_ports_link_status(enabled_port_mask);
 
        /* launch per-lcore init on every lcore */
-       rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);
+       rte_eal_mp_remote_launch(ipsec_launch_one_lcore, eh_conf, CALL_MASTER);
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
                if (rte_eal_wait_lcore(lcore_id) < 0)
                        return -1;