remove useless memzone includes
[dpdk.git] / examples / l3fwd-vf / main.c
index 7cc7228..7a3964b 100644 (file)
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_memcpy.h>
-#include <rte_memzone.h>
-#include <rte_tailq.h>
 #include <rte_eal.h>
-#include <rte_per_lcore.h>
 #include <rte_launch.h>
 #include <rte_atomic.h>
 #include <rte_spinlock.h>
@@ -66,7 +63,6 @@
 #include <rte_debug.h>
 #include <rte_ether.h>
 #include <rte_ethdev.h>
-#include <rte_ring.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 
 #define MEMPOOL_CACHE_SIZE 256
 
-#define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
-
 /*
  * This expression is used to calculate the number of mbufs needed depending on user input, taking
  *  into account memory for rx and tx hardware rings, cache per lcore and mtable per port per lcore.
  *  RTE_MAX is used to ensure that NB_MBUF never goes below a minimum value of 8192
  */
 
-#define NB_MBUF RTE_MAX        (                                                                                                                                       \
-                               (nb_ports*nb_rx_queue*RTE_TEST_RX_DESC_DEFAULT +                                                        \
-                               nb_ports*nb_lcores*MAX_PKT_BURST +                                                                                      \
-                               nb_ports*n_tx_queue*RTE_TEST_TX_DESC_DEFAULT +                                                          \
-                               nb_lcores*MEMPOOL_CACHE_SIZE),                                                                                          \
+#define NB_MBUF RTE_MAX        (                                               \
+                               (nb_ports*nb_rx_queue*nb_rxd +          \
+                               nb_ports*nb_lcores*MAX_PKT_BURST +      \
+                               nb_ports*n_tx_queue*nb_txd +            \
+                               nb_lcores*MEMPOOL_CACHE_SIZE),          \
                                (unsigned)8192)
 
 /*
@@ -160,7 +154,7 @@ struct mbuf_table {
 };
 
 struct lcore_rx_queue {
-       uint8_t port_id;
+       uint16_t port_id;
        uint8_t queue_id;
 } __rte_cache_aligned;
 
@@ -170,7 +164,7 @@ struct lcore_rx_queue {
 
 #define MAX_LCORE_PARAMS 1024
 struct lcore_params {
-       uint8_t port_id;
+       uint16_t port_id;
        uint8_t queue_id;
        uint8_t lcore_id;
 } __rte_cache_aligned;
@@ -201,7 +195,7 @@ static struct rte_eth_conf port_conf = {
                .hw_ip_checksum = 1, /**< IP checksum offload enabled */
                .hw_vlan_filter = 0, /**< VLAN filtering disabled */
                .jumbo_frame    = 0, /**< Jumbo Frame Support disabled */
-               .hw_strip_crc   = 0, /**< CRC stripped by hardware */
+               .hw_strip_crc   = 1, /**< CRC stripped by hardware */
        },
        .rx_adv_conf = {
                .rss_conf = {
@@ -219,7 +213,7 @@ static struct rte_mempool * pktmbuf_pool[NB_SOCKETS];
 
 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
 
-#ifdef RTE_MACHINE_CPUFLAG_SSE4_2
+#ifdef RTE_ARCH_X86
 #include <rte_hash_crc.h>
 #define DEFAULT_HASH_FUNC       rte_hash_crc
 #else
@@ -254,7 +248,6 @@ static lookup_struct_t *l3fwd_lookup_struct[NB_SOCKETS];
 struct rte_hash_parameters l3fwd_hash_params = {
        .name = "l3fwd_hash_0",
        .entries = L3FWD_HASH_ENTRIES,
-       .bucket_entries = 4,
        .key_len = sizeof(struct ipv4_5tuple),
        .hash_func = DEFAULT_HASH_FUNC,
        .hash_func_init_val = 0,
@@ -306,7 +299,7 @@ static struct lcore_conf lcore_conf[RTE_MAX_LCORE];
 static rte_spinlock_t spinlock_conf[RTE_MAX_ETHPORTS] = {RTE_SPINLOCK_INITIALIZER};
 /* Send burst of packets on an output interface */
 static inline int
-send_burst(struct lcore_conf *qconf, uint16_t n, uint8_t port)
+send_burst(struct lcore_conf *qconf, uint16_t n, uint16_t port)
 {
        struct rte_mbuf **m_table;
        int ret;
@@ -330,7 +323,7 @@ send_burst(struct lcore_conf *qconf, uint16_t n, uint8_t port)
 
 /* Enqueue a single packet, and send burst if queue is filled */
 static inline int
-send_single_packet(struct rte_mbuf *m, uint8_t port)
+send_single_packet(struct rte_mbuf *m, uint16_t port)
 {
        uint32_t lcore_id;
        uint16_t len;
@@ -402,8 +395,9 @@ print_key(struct ipv4_5tuple key)
               (unsigned)key.ip_dst, (unsigned)key.ip_src, key.port_dst, key.port_src, key.proto);
 }
 
-static inline uint8_t
-get_dst_port(struct ipv4_hdr *ipv4_hdr,  uint8_t portid, lookup_struct_t * l3fwd_lookup_struct)
+static inline uint16_t
+get_dst_port(struct ipv4_hdr *ipv4_hdr, uint16_t portid,
+             lookup_struct_t *l3fwd_lookup_struct)
 {
        struct ipv4_5tuple key;
        struct tcp_hdr *tcp;
@@ -436,34 +430,36 @@ get_dst_port(struct ipv4_hdr *ipv4_hdr,  uint8_t portid, lookup_struct_t * l3fwd
 
        /* Find destination port */
        ret = rte_hash_lookup(l3fwd_lookup_struct, (const void *)&key);
-       return (uint8_t)((ret < 0)? portid : l3fwd_out_if[ret]);
+       return ((ret < 0) ? portid : l3fwd_out_if[ret]);
 }
 #endif
 
 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
-static inline uint8_t
-get_dst_port(struct ipv4_hdr *ipv4_hdr,  uint8_t portid, lookup_struct_t * l3fwd_lookup_struct)
+static inline uint32_t
+get_dst_port(struct ipv4_hdr *ipv4_hdr, uint16_t portid,
+             lookup_struct_t *l3fwd_lookup_struct)
 {
-       uint8_t next_hop;
+       uint32_t next_hop;
 
-       return (uint8_t) ((rte_lpm_lookup(l3fwd_lookup_struct,
-                       rte_be_to_cpu_32(ipv4_hdr->dst_addr), &next_hop) == 0)?
-                       next_hop : portid);
+       return ((rte_lpm_lookup(l3fwd_lookup_struct,
+               rte_be_to_cpu_32(ipv4_hdr->dst_addr), &next_hop) == 0) ?
+               next_hop : portid);
 }
 #endif
 
 static inline void
-l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid, lookup_struct_t * l3fwd_lookup_struct)
+l3fwd_simple_forward(struct rte_mbuf *m, uint16_t portid,
+                     lookup_struct_t *l3fwd_lookup_struct)
 {
        struct ether_hdr *eth_hdr;
        struct ipv4_hdr *ipv4_hdr;
        void *tmp;
-       uint8_t dst_port;
+       uint16_t dst_port;
 
        eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
-       ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(m, unsigned char *) +
-                               sizeof(struct ether_hdr));
+       ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
+                                          sizeof(struct ether_hdr));
 
 #ifdef DO_RFC_1812_CHECKS
        /* Check to make sure the packet is valid (RFC1812) */
@@ -502,7 +498,8 @@ main_loop(__attribute__((unused)) void *dummy)
        unsigned lcore_id;
        uint64_t prev_tsc, diff_tsc, cur_tsc;
        int i, j, nb_rx;
-       uint8_t portid, queueid;
+       uint8_t queueid;
+       uint16_t portid;
        struct lcore_conf *qconf;
        const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US;
 
@@ -522,8 +519,8 @@ main_loop(__attribute__((unused)) void *dummy)
 
                portid = qconf->rx_queue_list[i].port_id;
                queueid = qconf->rx_queue_list[i].queue_id;
-               RTE_LOG(INFO, L3FWD, " -- lcoreid=%u portid=%hhu rxqueueid=%hhu\n", lcore_id,
-                       portid, queueid);
+               RTE_LOG(INFO, L3FWD, " --lcoreid=%u portid=%u rxqueueid=%hhu\n",
+               lcore_id, portid, queueid);
        }
 
        while (1) {
@@ -630,7 +627,7 @@ check_port_config(const unsigned nb_ports)
 }
 
 static uint8_t
-get_port_n_rx_queues(const uint8_t port)
+get_port_n_rx_queues(const uint16_t port)
 {
        int queue = -1;
        uint16_t i;
@@ -682,8 +679,8 @@ print_usage(const char *prgname)
 static void
 signal_handler(int signum)
 {
-       uint8_t portid;
-       uint8_t nb_ports = rte_eth_dev_count();
+       uint16_t portid;
+       uint16_t nb_ports = rte_eth_dev_count();
 
        /* When we receive a SIGINT signal */
        if (signum == SIGINT) {
@@ -755,7 +752,7 @@ parse_config(const char *q_arg)
                                nb_lcore_params);
                        return -1;
                }
-               lcore_params_array[nb_lcore_params].port_id = (uint8_t)int_fld[FLD_PORT];
+               lcore_params_array[nb_lcore_params].port_id = int_fld[FLD_PORT];
                lcore_params_array[nb_lcore_params].queue_id = (uint8_t)int_fld[FLD_QUEUE];
                lcore_params_array[nb_lcore_params].lcore_id = (uint8_t)int_fld[FLD_LCORE];
                ++nb_lcore_params;
@@ -821,7 +818,7 @@ parse_args(int argc, char **argv)
                argv[optind-1] = prgname;
 
        ret = optind-1;
-       optind = 0; /* reset getopt lib */
+       optind = 1; /* reset getopt lib */
        return ret;
 }
 
@@ -873,10 +870,16 @@ setup_lpm(int socketid)
        int ret;
        char s[64];
 
+       struct rte_lpm_config lpm_ipv4_config;
+
+       lpm_ipv4_config.max_rules = L3FWD_LPM_MAX_RULES;
+       lpm_ipv4_config.number_tbl8s = 256;
+       lpm_ipv4_config.flags = 0;
+
        /* create the LPM table */
        snprintf(s, sizeof(s), "L3FWD_LPM_%d", socketid);
-       l3fwd_lookup_struct[socketid] = rte_lpm_create(s, socketid,
-                               L3FWD_LPM_MAX_RULES, 0);
+       l3fwd_lookup_struct[socketid] =
+                       rte_lpm_create(s, socketid, &lpm_ipv4_config);
        if (l3fwd_lookup_struct[socketid] == NULL)
                rte_exit(EXIT_FAILURE, "Unable to create the l3fwd LPM table"
                                " on socket %d\n", socketid);
@@ -925,13 +928,9 @@ init_mem(unsigned nb_mbuf)
                }
                if (pktmbuf_pool[socketid] == NULL) {
                        snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
-                       pktmbuf_pool[socketid] =
-                               rte_mempool_create(s, nb_mbuf, MBUF_SIZE,
-                                                  MEMPOOL_CACHE_SIZE,
-                                       sizeof(struct rte_pktmbuf_pool_private),
-                                       rte_pktmbuf_pool_init, NULL,
-                                       rte_pktmbuf_init, NULL,
-                                       socketid, 0);
+                       pktmbuf_pool[socketid] = rte_pktmbuf_pool_create(s,
+                               nb_mbuf, MEMPOOL_CACHE_SIZE, 0,
+                               RTE_MBUF_DEFAULT_BUF_SIZE, socketid);
                        if (pktmbuf_pool[socketid] == NULL)
                                rte_exit(EXIT_FAILURE, "Cannot init mbuf pool on socket %d\n", socketid);
                        else
@@ -957,11 +956,11 @@ main(int argc, char **argv)
        struct rte_eth_txconf *txconf;
        int ret;
        unsigned nb_ports;
-       uint16_t queueid;
+       uint16_t queueid, portid;
        unsigned lcore_id;
        uint32_t nb_lcores;
        uint16_t n_tx_queue;
-       uint8_t portid, nb_rx_queue, queue, socketid;
+       uint8_t nb_rx_queue, queue, socketid;
 
        signal(SIGINT, signal_handler);
        /* init EAL */
@@ -984,8 +983,6 @@ main(int argc, char **argv)
                rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
 
        nb_ports = rte_eth_dev_count();
-       if (nb_ports > RTE_MAX_ETHPORTS)
-               nb_ports = RTE_MAX_ETHPORTS;
 
        if (check_port_config(nb_ports) < 0)
                rte_exit(EXIT_FAILURE, "check_port_config failed\n");
@@ -1015,6 +1012,13 @@ main(int argc, char **argv)
                        rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%d\n",
                                ret, portid);
 
+               ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
+                                                      &nb_txd);
+               if (ret < 0)
+                       rte_exit(EXIT_FAILURE,
+                                "Cannot adjust number of descriptors: err=%d, port=%d\n",
+                                ret, portid);
+
                rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
                print_ethaddr(" Address:", &ports_eth_addr[portid]);
                printf(", ");