examples: fix port mask parsing failure handling
[dpdk.git] / examples / l2fwd-jobstats / main.c
index 033104d..29d5705 100644 (file)
@@ -329,6 +329,9 @@ show_stats_cb(__rte_unused void *param)
        }
 
        printf("\n====================================================\n");
+
+       fflush(stdout);
+
        rte_eal_alarm_set(timer_period * US_PER_S, show_stats_cb, NULL);
 }
 
@@ -349,7 +352,7 @@ l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid)
        *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dst_port << 40);
 
        /* src addr */
-       ether_addr_copy(&l2fwd_ports_eth_addr[dst_port], &eth->s_addr);
+       rte_ether_addr_copy(&l2fwd_ports_eth_addr[dst_port], &eth->s_addr);
 
        buffer = tx_buffer[dst_port];
        sent = rte_eth_tx_buffer(dst_port, 0, buffer, m);
@@ -535,7 +538,7 @@ l2fwd_main_loop(void)
 }
 
 static int
-l2fwd_launch_one_lcore(__attribute__((unused)) void *dummy)
+l2fwd_launch_one_lcore(__rte_unused void *dummy)
 {
        l2fwd_main_loop();
        return 0;
@@ -562,10 +565,7 @@ l2fwd_parse_portmask(const char *portmask)
        /* parse hexadecimal string */
        pm = strtoul(portmask, &end, 16);
        if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
-               return -1;
-
-       if (pm == 0)
-               return -1;
+               return 0;
 
        return pm;
 }
@@ -685,6 +685,7 @@ check_all_ports_link_status(uint32_t port_mask)
        uint16_t portid;
        uint8_t count, all_ports_up, print_flag = 0;
        struct rte_eth_link link;
+       int ret;
 
        printf("\nChecking link status");
        fflush(stdout);
@@ -694,7 +695,14 @@ check_all_ports_link_status(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)
@@ -702,7 +710,7 @@ check_all_ports_link_status(uint32_t port_mask)
                                        "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"));
+                                       ("full-duplex") : ("half-duplex"));
                                else
                                        printf("Port %d Link Down\n", portid);
                                continue;
@@ -842,7 +850,13 @@ main(int argc, char **argv)
                /* init port */
                printf("Initializing port %u... ", portid);
                fflush(stdout);
-               rte_eth_dev_info_get(portid, &dev_info);
+
+               ret = rte_eth_dev_info_get(portid, &dev_info);
+               if (ret != 0)
+                       rte_exit(EXIT_FAILURE,
+                               "Error during getting device (port %u) info: %s\n",
+                               portid, strerror(-ret));
+
                if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
                        local_port_conf.txmode.offloads |=
                                DEV_TX_OFFLOAD_MBUF_FAST_FREE;
@@ -858,7 +872,12 @@ main(int argc, char **argv)
                                 "Cannot adjust number of descriptors: err=%d, port=%u\n",
                                 ret, portid);
 
-               rte_eth_macaddr_get(portid, &l2fwd_ports_eth_addr[portid]);
+               ret = rte_eth_macaddr_get(portid,
+                                         &l2fwd_ports_eth_addr[portid]);
+               if (ret < 0)
+                       rte_exit(EXIT_FAILURE,
+                                "Cannot get MAC address: err=%d, port=%u\n",
+                                ret, portid);
 
                /* init one RX queue */
                fflush(stdout);
@@ -910,7 +929,14 @@ main(int argc, char **argv)
 
                printf("done:\n");
 
-               rte_eth_promiscuous_enable(portid);
+               ret = rte_eth_promiscuous_enable(portid);
+               if (ret != 0) {
+                       rte_exit(EXIT_FAILURE,
+                                "rte_eth_promiscuous_enable:err=%s, port=%u\n",
+                                rte_strerror(-ret), portid);
+                       return ret;
+
+               }
 
                printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
                                portid,