update Intel copyright years to 2014
[dpdk.git] / examples / multi_process / symmetric_mp / main.c
index ad783f1..6912618 100644 (file)
@@ -1,36 +1,34 @@
 /*-
  *   BSD LICENSE
  * 
- *   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   All rights reserved.
  * 
- *   Redistribution and use in source and binary forms, with or without 
- *   modification, are permitted provided that the following conditions 
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
  *   are met:
  * 
- *     * Redistributions of source code must retain the above copyright 
+ *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright 
- *       notice, this list of conditions and the following disclaimer in 
- *       the documentation and/or other materials provided with the 
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
  *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its 
- *       contributors may be used to endorse or promote products derived 
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
  * 
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- *  version: DPDK.L.1.2.3-3
  */
 
 /*
 #include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_string_fns.h>
+#include <rte_cycles.h>
 
 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
 
-#define SOCKET0 0
-
 #define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
 #define NB_MBUFS 64*1024 /* use 64k mbufs */
 #define MBUF_CACHE_SIZE 256
@@ -234,22 +231,6 @@ smp_parse_args(int argc, char **argv)
        return (ret);
 }
 
-/* Queries the link status of a port and prints it to screen */
-static void
-report_link_status(uint8_t port)
-{
-       /* get link status */
-       struct rte_eth_link link;
-       rte_eth_link_get(port, &link);
-       if (link.link_status)
-               printf("Port %u: Link Up - %u Gbps - %s\n", (unsigned)port,
-                               (unsigned) link.link_speed / 1000,
-                               (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
-                                               ("full-duplex") : ("half-duplex\n"));
-       else
-               printf("Port %u: Link Down\n", (unsigned)port);
-}
-
 /*
  * Initialises a given port using global settings and with the rx buffers
  * coming from the mbuf_pool passed as parameter
@@ -259,7 +240,7 @@ smp_port_init(uint8_t port, struct rte_mempool *mbuf_pool, uint16_t num_queues)
 {
        struct rte_eth_conf port_conf = {
                        .rxmode = {
-                               .mq_mode = ETH_RSS,
+                               .mq_mode = ETH_MQ_RX_RSS,
                                .split_hdr_size = 0,
                                .header_split   = 0, /**< Header Split disabled */
                                .hw_ip_checksum = 1, /**< IP checksum offload enabled */
@@ -270,10 +251,11 @@ smp_port_init(uint8_t port, struct rte_mempool *mbuf_pool, uint16_t num_queues)
                        .rx_adv_conf = {
                                .rss_conf = {
                                        .rss_key = NULL,
-                                       .rss_hf = ETH_RSS_IPV4,
+                                       .rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6,
                                },
                        },
                        .txmode = {
+                               .mq_mode = ETH_MQ_TX_NONE,
                        }
        };
        const uint16_t rx_rings = num_queues, tx_rings = num_queues;
@@ -295,7 +277,7 @@ smp_port_init(uint8_t port, struct rte_mempool *mbuf_pool, uint16_t num_queues)
 
        for (q = 0; q < rx_rings; q ++) {
                retval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE,
-                               SOCKET0, &rx_conf_default,
+                               rte_eth_dev_socket_id(port), &rx_conf_default,
                                mbuf_pool);
                if (retval < 0)
                        return retval;
@@ -303,7 +285,7 @@ smp_port_init(uint8_t port, struct rte_mempool *mbuf_pool, uint16_t num_queues)
 
        for (q = 0; q < tx_rings; q ++) {
                retval = rte_eth_tx_queue_setup(port, q, RX_RING_SIZE,
-                               SOCKET0, &tx_conf_default);
+                               rte_eth_dev_socket_id(port), &tx_conf_default);
                if (retval < 0)
                        return retval;
        }
@@ -400,6 +382,61 @@ lcore_main(void *arg __rte_unused)
        }
 }
 
+/* Check the link status of all ports in up to 9s, and print them finally */
+static void
+check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)
+{
+#define CHECK_INTERVAL 100 /* 100ms */
+#define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
+       uint8_t portid, count, all_ports_up, print_flag = 0;
+       struct rte_eth_link link;
+
+       printf("\nChecking link status");
+       fflush(stdout);
+       for (count = 0; count <= MAX_CHECK_TIME; count++) {
+               all_ports_up = 1;
+               for (portid = 0; portid < port_num; portid++) {
+                       if ((port_mask & (1 << portid)) == 0)
+                               continue;
+                       memset(&link, 0, sizeof(link));
+                       rte_eth_link_get_nowait(portid, &link);
+                       /* print link status if flag set */
+                       if (print_flag == 1) {
+                               if (link.link_status)
+                                       printf("Port %d Link Up - speed %u "
+                                               "Mbps - %s\n", (uint8_t)portid,
+                                               (unsigned)link.link_speed,
+                               (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
+                                       ("full-duplex") : ("half-duplex\n"));
+                               else
+                                       printf("Port %d Link Down\n",
+                                                       (uint8_t)portid);
+                               continue;
+                       }
+                       /* clear all_ports_up flag if any link down */
+                       if (link.link_status == 0) {
+                               all_ports_up = 0;
+                               break;
+                       }
+               }
+               /* after finally printing all link status, get out */
+               if (print_flag == 1)
+                       break;
+
+               if (all_ports_up == 0) {
+                       printf(".");
+                       fflush(stdout);
+                       rte_delay_ms(CHECK_INTERVAL);
+               }
+
+               /* set the print_flag if all ports up or timeout */
+               if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
+                       print_flag = 1;
+                       printf("done\n");
+               }
+       }
+}
+
 /* Main function.
  * Performs initialisation and then calls the lcore_main on each core
  * to do the packet-processing work.
@@ -426,14 +463,8 @@ main(int argc, char **argv)
 
        /* probe to determine the NIC devices available */
        proc_type = rte_eal_process_type();
-#ifdef RTE_LIBRTE_IGB_PMD
-       if (rte_igb_pmd_init() < 0)
-               rte_exit(EXIT_FAILURE, "Cannot init igb pmd\n");
-#endif
-#ifdef RTE_LIBRTE_IXGBE_PMD
-       if (rte_ixgbe_pmd_init() < 0)
-               rte_exit(EXIT_FAILURE, "Cannot init ixgbe pmd\n");
-#endif
+       if (rte_pmd_init_all() < 0)
+               rte_exit(EXIT_FAILURE, "Cannot init pmd\n");
        if (rte_eal_pci_probe() < 0)
                rte_exit(EXIT_FAILURE, "Cannot probe PCI\n");
        if (rte_eth_dev_count() == 0)
@@ -448,7 +479,7 @@ main(int argc, char **argv)
                                        MBUF_CACHE_SIZE, sizeof(struct rte_pktmbuf_pool_private),
                                        rte_pktmbuf_pool_init, NULL,
                                        rte_pktmbuf_init, NULL,
-                                       SOCKET0, 0);
+                                       rte_socket_id(), 0);
        if (mp == NULL)
                rte_exit(EXIT_FAILURE, "Cannot get memory pool for buffers\n");
 
@@ -458,9 +489,11 @@ main(int argc, char **argv)
                if(proc_type == RTE_PROC_PRIMARY)
                        if (smp_port_init(ports[i], mp, (uint16_t)num_procs) < 0)
                                rte_exit(EXIT_FAILURE, "Error initialising ports\n");
-               report_link_status(ports[i]);
        }
 
+       if (proc_type == RTE_PROC_PRIMARY)
+               check_all_ports_link_status((uint8_t)num_ports, (~0x0));
+
        assign_ports_to_cores();
 
        RTE_LOG(INFO, APP, "Finished Process Init.\n");