ethdev: add namespace
[dpdk.git] / examples / multi_process / symmetric_mp / main.c
index 1c77205..b35886a 100644 (file)
@@ -31,7 +31,6 @@
 #include <rte_eal.h>
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
-#include <rte_atomic.h>
 #include <rte_branch_prediction.h>
 #include <rte_debug.h>
 #include <rte_interrupts.h>
@@ -48,8 +47,8 @@
 #define NB_MBUFS 64*1024 /* use 64k mbufs */
 #define MBUF_CACHE_SIZE 256
 #define PKT_BURST 32
-#define RX_RING_SIZE 128
-#define TX_RING_SIZE 512
+#define RX_RING_SIZE 1024
+#define TX_RING_SIZE 1024
 
 #define PARAM_PROC_ID "proc-id"
 #define PARAM_NUM_PROCS "num-procs"
@@ -66,7 +65,7 @@ struct port_stats{
        unsigned rx;
        unsigned tx;
        unsigned drop;
-} __attribute__((aligned(RTE_CACHE_LINE_SIZE / 2)));
+} __rte_aligned(RTE_CACHE_LINE_SIZE / 2);
 
 static int proc_id = -1;
 static unsigned num_procs = 0;
@@ -115,7 +114,7 @@ smp_parse_args(int argc, char **argv)
        int opt, ret;
        char **argvopt;
        int option_index;
-       unsigned i, port_mask = 0;
+       uint16_t i, port_mask = 0;
        char *prgname = argv[0];
        static struct option lgopts[] = {
                        {PARAM_NUM_PROCS, 1, 0, 0},
@@ -156,7 +155,7 @@ smp_parse_args(int argc, char **argv)
                smp_usage(prgname, "Invalid or missing port mask\n");
 
        /* get the port numbers from the port mask */
-       for(i = 0; i < rte_eth_dev_count(); i++)
+       RTE_ETH_FOREACH_DEV(i)
                if(port_mask & (1 << i))
                        ports[num_ports++] = (uint8_t)i;
 
@@ -176,20 +175,18 @@ smp_port_init(uint16_t port, struct rte_mempool *mbuf_pool,
 {
        struct rte_eth_conf port_conf = {
                        .rxmode = {
-                               .mq_mode        = ETH_MQ_RX_RSS,
+                               .mq_mode        = RTE_ETH_MQ_RX_RSS,
                                .split_hdr_size = 0,
-                               .ignore_offload_bitfield = 1,
-                               .offloads = (DEV_RX_OFFLOAD_CHECKSUM |
-                                            DEV_RX_OFFLOAD_CRC_STRIP),
+                               .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM,
                        },
                        .rx_adv_conf = {
                                .rss_conf = {
                                        .rss_key = NULL,
-                                       .rss_hf = ETH_RSS_IP,
+                                       .rss_hf = RTE_ETH_RSS_IP,
                                },
                        },
                        .txmode = {
-                               .mq_mode = ETH_MQ_TX_NONE,
+                               .mq_mode = RTE_ETH_MQ_TX_NONE,
                        }
        };
        const uint16_t rx_rings = num_queues, tx_rings = num_queues;
@@ -200,22 +197,40 @@ smp_port_init(uint16_t port, struct rte_mempool *mbuf_pool,
        uint16_t q;
        uint16_t nb_rxd = RX_RING_SIZE;
        uint16_t nb_txd = TX_RING_SIZE;
+       uint64_t rss_hf_tmp;
 
        if (rte_eal_process_type() == RTE_PROC_SECONDARY)
                return 0;
 
-       if (port >= rte_eth_dev_count())
+       if (!rte_eth_dev_is_valid_port(port))
                return -1;
 
        printf("# Initialising port %u... ", port);
        fflush(stdout);
 
-       rte_eth_dev_info_get(port, &info);
+       retval = rte_eth_dev_info_get(port, &info);
+       if (retval != 0) {
+               printf("Error during getting device (port %u) info: %s\n",
+                               port, strerror(-retval));
+               return retval;
+       }
+
        info.default_rxconf.rx_drop_en = 1;
 
-       if (info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
+       if (info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
                port_conf.txmode.offloads |=
-                       DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+                       RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
+
+       rss_hf_tmp = port_conf.rx_adv_conf.rss_conf.rss_hf;
+       port_conf.rx_adv_conf.rss_conf.rss_hf &= info.flow_type_rss_offloads;
+       if (port_conf.rx_adv_conf.rss_conf.rss_hf != rss_hf_tmp) {
+               printf("Port %u modified RSS hash function based on hardware support,"
+                       "requested:%#"PRIx64" configured:%#"PRIx64"\n",
+                       port,
+                       rss_hf_tmp,
+                       port_conf.rx_adv_conf.rss_conf.rss_hf);
+       }
+
        retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
        if (retval < 0)
                return retval;
@@ -236,7 +251,6 @@ smp_port_init(uint16_t port, struct rte_mempool *mbuf_pool,
        }
 
        txq_conf = info.default_txconf;
-       txq_conf.txq_flags = ETH_TXQ_FLAGS_IGNORE;
        txq_conf.offloads = port_conf.txmode.offloads;
        for (q = 0; q < tx_rings; q ++) {
                retval = rte_eth_tx_queue_setup(port, q, nb_txd,
@@ -246,7 +260,9 @@ smp_port_init(uint16_t port, struct rte_mempool *mbuf_pool,
                        return retval;
        }
 
-       rte_eth_promiscuous_enable(port);
+       retval = rte_eth_promiscuous_enable(port);
+       if (retval != 0)
+               return retval;
 
        retval  = rte_eth_dev_start(port);
        if (retval < 0)
@@ -262,7 +278,7 @@ static void
 assign_ports_to_cores(void)
 {
 
-       const unsigned lcores = rte_eal_get_configuration()->lcore_count;
+       const unsigned int lcores = rte_lcore_count();
        const unsigned port_pairs = num_ports / 2;
        const unsigned pairs_per_lcore = port_pairs / lcores;
        unsigned extra_pairs = port_pairs % lcores;
@@ -347,6 +363,8 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
        uint16_t portid;
        uint8_t count, all_ports_up, print_flag = 0;
        struct rte_eth_link link;
+       int ret;
+       char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
 
        printf("\nChecking link status");
        fflush(stdout);
@@ -356,21 +374,24 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
                        if ((port_mask & (1 << portid)) == 0)
                                continue;
                        memset(&link, 0, sizeof(link));
-                       rte_eth_link_get_nowait(portid, &link);
+                       ret = rte_eth_link_get_nowait(portid, &link);
+                       if (ret < 0) {
+                               all_ports_up = 0;
+                               if (print_flag == 1)
+                                       printf("Port %u link get failed: %s\n",
+                                               portid, rte_strerror(-ret));
+                               continue;
+                       }
                        /* print link status if flag set */
                        if (print_flag == 1) {
-                               if (link.link_status)
-                                       printf(
-                                       "Port%d Link Up. Speed %u Mbps - %s\n",
-                                               portid, link.link_speed,
-                               (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
-                                       ("full-duplex") : ("half-duplex\n"));
-                               else
-                                       printf("Port %d Link Down\n", portid);
+                               rte_eth_link_to_str(link_status_text,
+                                       sizeof(link_status_text), &link);
+                               printf("Port %d %s\n", portid,
+                                      link_status_text);
                                continue;
                        }
                        /* clear all_ports_up flag if any link down */
-                       if (link.link_status == ETH_LINK_DOWN) {
+                       if (link.link_status == RTE_ETH_LINK_DOWN) {
                                all_ports_up = 0;
                                break;
                        }
@@ -418,7 +439,7 @@ main(int argc, char **argv)
        argv += ret;
 
        /* determine the NIC devices available */
-       if (rte_eth_dev_count() == 0)
+       if (rte_eth_dev_count_avail() == 0)
                rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
 
        /* parse application arguments (those after the EAL ones) */
@@ -433,6 +454,7 @@ main(int argc, char **argv)
        if (mp == NULL)
                rte_exit(EXIT_FAILURE, "Cannot get memory pool for buffers\n");
 
+       /* Primary instance initialized. 8< */
        if (num_ports & 1)
                rte_exit(EXIT_FAILURE, "Application must use an even number of ports\n");
        for(i = 0; i < num_ports; i++){
@@ -440,6 +462,7 @@ main(int argc, char **argv)
                        if (smp_port_init(ports[i], mp, (uint16_t)num_procs) < 0)
                                rte_exit(EXIT_FAILURE, "Error initialising ports\n");
        }
+       /* >8 End of primary instance initialization. */
 
        if (proc_type == RTE_PROC_PRIMARY)
                check_all_ports_link_status((uint8_t)num_ports, (~0x0));
@@ -448,7 +471,10 @@ main(int argc, char **argv)
 
        RTE_LOG(INFO, APP, "Finished Process Init.\n");
 
-       rte_eal_mp_remote_launch(lcore_main, NULL, CALL_MASTER);
+       rte_eal_mp_remote_launch(lcore_main, NULL, CALL_MAIN);
+
+       /* clean up the EAL */
+       rte_eal_cleanup();
 
        return 0;
 }