update copyright date to 2013
[dpdk.git] / examples / exception_path / main.c
index 6cf05a8..0a19831 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  * 
- *   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
  *   All rights reserved.
  * 
  *   Redistribution and use in source and binary forms, with or without 
@@ -30,7 +30,6 @@
  *   (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 <stdio.h>
@@ -73,6 +72,7 @@
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
 #include <rte_string_fns.h>
+#include <rte_cycles.h>
 
 /* Macros for printing using RTE_LOG */
 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
@@ -149,6 +149,7 @@ static const struct rte_eth_conf port_conf = {
                .hw_strip_crc = 0,      /* CRC stripped by hardware */
        },
        .txmode = {
+               .mq_mode = ETH_DCB_NONE,
        },
 };
 
@@ -446,7 +447,6 @@ parse_args(int argc, char **argv)
 static void
 init_port(uint8_t port)
 {
-       struct rte_eth_link link;
        int ret;
 
        /* Initialise device and RX/TX queues */
@@ -472,19 +472,64 @@ init_port(uint8_t port)
        if (ret < 0)
                FATAL_ERROR("Could not start port%u (%d)", (unsigned)port, ret);
 
-       /*  Everything is setup and started, print link status */
-       rte_eth_link_get(port, &link);
-       if (link.link_status)
-               PRINT_INFO("    link up - %u Mbit/s - %s",
-                          (unsigned)link.link_speed,
-                          (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
-                          ("full-duplex") : ("half-duplex"));
-       else
-               PRINT_INFO("    link down");
-
        rte_eth_promiscuous_enable(port);
 }
 
+/* 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");
+               }
+       }
+}
+
 /* Initialise ports/queues etc. and start main loop on each core */
 int
 main(int argc, char** argv)
@@ -519,16 +564,9 @@ main(int argc, char** argv)
        }
 
        /* Initialise PMD driver(s) */
-#ifdef RTE_LIBRTE_IGB_PMD
-       ret = rte_igb_pmd_init();
-       if (ret < 0)
-               FATAL_ERROR("Could not initialise igb PMD (%d)", ret);
-#endif
-#ifdef RTE_LIBRTE_IXGBE_PMD
-       ret = rte_ixgbe_pmd_init();
+       ret = rte_pmd_init_all();
        if (ret < 0)
-               FATAL_ERROR("Could not initialise ixgbe PMD (%d)", ret);
-#endif
+               FATAL_ERROR("Could not probe PMD (%d)", ret);
 
        /* Scan PCI bus for recognised devices */
        ret = rte_eal_pci_probe();
@@ -557,6 +595,7 @@ main(int argc, char** argv)
                }
                init_port(port);
        }
+       check_all_ports_link_status(nb_sys_ports, ports_mask);
 
        /* Launch per-lcore function on every lcore */
        rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);