update copyright date to 2013
[dpdk.git] / examples / multi_process / client_server_mp / mp_server / init.c
index 6e08a0b..ebf69ae 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 
@@ -62,9 +62,9 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_malloc.h>
-#include <rte_hash_crc.h>
 #include <rte_fbk_hash.h>
 #include <rte_string_fns.h>
+#include <rte_cycles.h>
 
 #include "common.h"
 #include "init_drivers.h"
@@ -171,7 +171,6 @@ init_port(uint8_t port_num)
        const uint16_t rx_ring_size = RTE_MP_RX_DESC_DEFAULT;
        const uint16_t tx_ring_size = RTE_MP_TX_DESC_DEFAULT;
 
-       struct rte_eth_link link;
        uint16_t q;
        int retval;
 
@@ -201,19 +200,8 @@ init_port(uint8_t port_num)
        retval  = rte_eth_dev_start(port_num);
        if (retval < 0) return retval;
 
-       printf( "done: ");
+       printf( "done: \n");
 
-       /* get link status */
-       rte_eth_link_get(port_num, &link);
-       if (link.link_status) {
-               printf(" Link Up - speed %u Mbps - %s\n",
-                      (uint32_t) link.link_speed,
-                      (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
-                      ("full-duplex") : ("half-duplex\n"));
-       }
-       else{
-               printf(" Link Down\n");
-       }
        return 0;
 }
 
@@ -244,6 +232,61 @@ init_shm_rings(void)
        return 0;
 }
 
+/* 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 init function for the multi-process server app,
  * calls subfunctions to do each stage of the initialisation.
@@ -296,6 +339,8 @@ init(int argc, char *argv[])
                                        (unsigned)i);
        }
 
+       check_all_ports_link_status(ports->num_ports, (~0x0));
+
        /* initialise the client queues/rings for inter-eu comms */
        init_shm_rings();