examples/ipsec-secgw: add driver mode worker
[dpdk.git] / examples / ipsec-secgw / ipsec-secgw.c
index ad16606..1eb7667 100644 (file)
@@ -71,8 +71,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 +78,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
  */
@@ -188,15 +184,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 +278,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 +999,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 +1115,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 +1160,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 +1179,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 +1203,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 +1339,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 +2852,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;