app: use new link status print format
authorIvan Dyukov <i.dyukov@samsung.com>
Tue, 15 Sep 2020 19:06:58 +0000 (22:06 +0300)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 21 Sep 2020 16:05:37 +0000 (18:05 +0200)
Add usage of rte_eth_link_to_str function to applications and docs.

Signed-off-by: Ivan Dyukov <i.dyukov@samsung.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
app/proc-info/main.c
app/test-pipeline/init.c
app/test-pmd/config.c
app/test-pmd/testpmd.c
app/test/test_pmd_perf.c
doc/guides/sample_app_ug/link_status_intr.rst

index abeca4a..0b030d3 100644 (file)
@@ -672,6 +672,7 @@ show_port(void)
                struct rte_eth_dev_info dev_info;
                struct rte_eth_rxq_info queue_info;
                struct rte_eth_rss_conf rss_conf;
+               char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
 
                memset(&rss_conf, 0, sizeof(rss_conf));
 
@@ -685,12 +686,10 @@ show_port(void)
                        printf("Link get failed (port %u): %s\n",
                               i, rte_strerror(-ret));
                } else {
-                       printf("\t  -- link speed %d duplex %d,"
-                                       " auto neg %d status %d\n",
-                                       link.link_speed,
-                                       link.link_duplex,
-                                       link.link_autoneg,
-                                       link.link_status);
+                       rte_eth_link_to_str(link_status_text,
+                                       sizeof(link_status_text),
+                                       &link);
+                       printf("\t%s\n", link_status_text);
                }
                printf("\t  -- promiscuous (%d)\n",
                                rte_eth_promiscuous_get(i));
index 67d54ae..fe37d63 100644 (file)
@@ -155,7 +155,7 @@ static void
 app_ports_check_link(void)
 {
        uint32_t all_ports_up, i;
-
+       char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
        all_ports_up = 1;
 
        for (i = 0; i < app.n_ports; i++) {
@@ -173,12 +173,11 @@ app_ports_check_link(void)
                        all_ports_up = 0;
                        continue;
                }
-
-               RTE_LOG(INFO, USER1, "Port %u (%u Gbps) %s\n",
+               rte_eth_link_to_str(link_status_text, sizeof(link_status_text),
+                                   &link);
+               RTE_LOG(INFO, USER1, "Port %u %s\n",
                        port,
-                       link.link_speed / 1000,
-                       link.link_status ? "UP" : "DOWN");
-
+                       link_status_text);
                if (link.link_status == ETH_LINK_DOWN)
                        all_ports_up = 0;
        }
index dabe7c1..b6eb2a5 100644 (file)
@@ -630,7 +630,7 @@ port_infos_display(portid_t port_id)
                printf("\nmemory allocation on the socket: %u",port->socket_id);
 
        printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
-       printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
+       printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
        printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
               ("full-duplex") : ("half-duplex"));
 
@@ -775,12 +775,12 @@ port_summary_display(portid_t port_id)
        if (ret != 0)
                return;
 
-       printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
+       printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %s\n",
                port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
                mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
                mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
                dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
-               (unsigned int) link.link_speed);
+               rte_eth_link_speed_to_str(link.link_speed));
 }
 
 void
@@ -4032,7 +4032,8 @@ set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
        ret = eth_link_get_nowait_print_err(port_id, &link);
        if (ret < 0)
                return 1;
-       if (rate > link.link_speed) {
+       if (link.link_speed != ETH_SPEED_NUM_UNKNOWN &&
+           rate > link.link_speed) {
                printf("Invalid rate value:%u bigger than link speed: %u\n",
                        rate, link.link_speed);
                return 1;
index ee3dd27..fe6450c 100644 (file)
@@ -3002,6 +3002,7 @@ check_all_ports_link_status(uint32_t port_mask)
        uint8_t count, all_ports_up, print_flag = 0;
        struct rte_eth_link link;
        int ret;
+       char link_status[RTE_ETH_LINK_MAX_STR_LEN];
 
        printf("Checking link statuses...\n");
        fflush(stdout);
@@ -3021,14 +3022,9 @@ check_all_ports_link_status(uint32_t port_mask)
                        }
                        /* 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"));
-                               else
-                                       printf("Port %d Link Down\n", portid);
+                               rte_eth_link_to_str(link_status,
+                                       sizeof(link_status), &link);
+                               printf("Port %d %s\n", portid, link_status);
                                continue;
                        }
                        /* clear all_ports_up flag if any link down */
index 352cd47..d1240b7 100644 (file)
@@ -126,6 +126,7 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
        uint8_t count, all_ports_up, print_flag = 0;
        struct rte_eth_link link;
        int ret;
+       char link_status[RTE_ETH_LINK_MAX_STR_LEN];
 
        printf("Checking link statuses...\n");
        fflush(stdout);
@@ -146,16 +147,12 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
 
                        /* 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"));
-                                       if (link_mbps == 0)
-                                               link_mbps = link.link_speed;
-                               } else
-                                       printf("Port %d Link Down\n", portid);
+                               if (link.link_status && link_mbps == 0)
+                                       link_mbps = link.link_speed;
+
+                               rte_eth_link_to_str(link_status,
+                                       sizeof(link_status), &link);
+                               printf("Port %d %s\n", portid, link_status);
                                continue;
                        }
                        /* clear all_ports_up flag if any link down */
index 04c40f2..1057c75 100644 (file)
@@ -158,6 +158,7 @@ An example callback function that has been written as indicated below.
     {
         struct rte_eth_link link;
         int ret;
+        char link_status[RTE_ETH_LINK_MAX_STR_LEN];
 
         RTE_SET_USED(param);
 
@@ -169,11 +170,10 @@ An example callback function that has been written as indicated below.
         if (ret < 0) {
             printf("Failed to get port %d link status: %s\n\n",
                    port_id, rte_strerror(-ret));
-        } else if (link.link_status) {
-            printf("Port %d Link Up - speed %u Mbps - %s\n\n", port_id, (unsigned)link.link_speed,
-                  (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex"));
-        } else
-            printf("Port %d Link Down\n\n", port_id);
+        } else {
+            rte_eth_link_to_str(link_status, sizeof(link_status), &link);
+            printf("Port %d %s\n", port_id, link_status);
+        }
     }
 
 This function is called when a link status interrupt is present for the right port.