[v7,03/25] app: UNKNOWN link speed print format
diff mbox series

Message ID 20200710070226.6045-4-i.dyukov@samsung.com
State Deferred
Delegated to: Ferruh Yigit
Headers show
Series
  • ethdev: allow unknown link speed
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/checkpatch success coding style OK

Commit Message

Ivan Dyukov July 10, 2020, 7:02 a.m. UTC
Add usage of rte_eth_link_strf function to example
applications

Signed-off-by: Ivan Dyukov <i.dyukov@samsung.com>
---
 app/proc-info/main.c     |  9 +++------
 app/test-pipeline/init.c | 11 +++++------
 app/test-pmd/config.c    | 20 ++++++++++++--------
 app/test-pmd/testpmd.c   |  9 +--------
 app/test/test_pmd_perf.c | 17 +++++++----------
 5 files changed, 28 insertions(+), 38 deletions(-)

Patch
diff mbox series

diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index abeca4aab..4a4c572c3 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -685,12 +685,9 @@  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_printf("\t  -- link speed: %M, duplex: %D,"
+					" auto neg: %A, status: %S\n",
+					&link);
 		}
 		printf("\t  -- promiscuous (%d)\n",
 				rte_eth_promiscuous_get(i));
diff --git a/app/test-pipeline/init.c b/app/test-pipeline/init.c
index 67d54ae05..b59064672 100644
--- a/app/test-pipeline/init.c
+++ b/app/test-pipeline/init.c
@@ -155,7 +155,7 @@  static void
 app_ports_check_link(void)
 {
 	uint32_t all_ports_up, i;
-
+	char link_status_text[50];
 	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_strf(link_status_text, 50, "(%G Gbps) %S",
+				  &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;
 	}
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index a7112c998..cb2795a94 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -604,10 +604,9 @@  port_infos_display(portid_t port_id)
 	} else
 		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 duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
-	       ("full-duplex") : ("half-duplex"));
+	rte_eth_link_printf("\nLink status: %S\n"
+			    "Link speed: %M Mbps\n"
+			    "Link duplex: %D\n", &link);
 
 	if (!rte_eth_dev_get_mtu(port_id, &mtu))
 		printf("MTU: %u\n", mtu);
@@ -730,6 +729,8 @@  port_summary_display(portid_t port_id)
 	struct rte_eth_link link;
 	struct rte_eth_dev_info dev_info;
 	char name[RTE_ETH_NAME_MAX_LEN];
+	char status_text[6];
+	char speed_text[12];
 	int ret;
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN)) {
@@ -750,12 +751,14 @@  port_summary_display(portid_t port_id)
 	if (ret != 0)
 		return;
 
-	printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
+	rte_eth_link_strf(status_text, 6, "%S", &link);
+	rte_eth_link_strf(speed_text, 12, "%M", &link);
+	printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %sMbps\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);
+		dev_info.driver_name, status_text,
+		speed_text);
 }
 
 void
@@ -3899,7 +3902,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;
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 4989d22ca..a1b9c1c1c 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3010,14 +3010,7 @@  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_printf(NULL, &link);
 				continue;
 			}
 			/* clear all_ports_up flag if any link down */
diff --git a/app/test/test_pmd_perf.c b/app/test/test_pmd_perf.c
index 352cd4715..7ebe4efae 100644
--- a/app/test/test_pmd_perf.c
+++ b/app/test/test_pmd_perf.c
@@ -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[50];
 
 	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_strf(link_status, 50, NULL,
+						  &link);
+				printf("Port %d %s\n", portid, link_status);
 				continue;
 			}
 			/* clear all_ports_up flag if any link down */