[v11,13/24] examples/kni: new link status print format
diff mbox series

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

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ivan Dyukov Sept. 15, 2020, 7:07 p.m. UTC
Add usage of rte_eth_link_to_str function to example
applications

Signed-off-by: Ivan Dyukov <i.dyukov@samsung.com>
---
 examples/kni/main.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

Comments

Ferruh Yigit Sept. 18, 2020, 6:07 p.m. UTC | #1
On 9/15/2020 8:07 PM, Ivan Dyukov wrote:
> Add usage of rte_eth_link_to_str function to example
> applications
> 
> Signed-off-by: Ivan Dyukov <i.dyukov@samsung.com>
> ---
>   examples/kni/main.c | 27 ++++++++++-----------------
>   1 file changed, 10 insertions(+), 17 deletions(-)
> 
> diff --git a/examples/kni/main.c b/examples/kni/main.c
> index f5d12a5b8..49d888064 100644
> --- a/examples/kni/main.c
> +++ b/examples/kni/main.c
> @@ -661,6 +661,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_text[RTE_ETH_LINK_MAX_STR_LEN];
>   
>   	printf("\nChecking link status\n");
>   	fflush(stdout);
> @@ -680,14 +681,10 @@ 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 %uMbps - %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_text,
> +					sizeof(link_status_text), &link);
> +				printf("Port %d %s\n", portid,
> +					link_status_text);
>   				continue;
>   			}
>   			/* clear all_ports_up flag if any link down */
> @@ -717,19 +714,15 @@ check_all_ports_link_status(uint32_t port_mask)
>   static void
>   log_link_state(struct rte_kni *kni, int prev, struct rte_eth_link *link)
>   {
> +	char link_status_text[60];

'60' seems forgotten, it also can be replaced with 
'RTE_ETH_LINK_MAX_STR_LEN'

Also good to have an empty line between variables declarations and code.

>   	if (kni == NULL || link == NULL)
>   		return;
>   
> -	if (prev == ETH_LINK_DOWN && link->link_status == ETH_LINK_UP) {
> -		RTE_LOG(INFO, APP, "%s NIC Link is Up %d Mbps %s %s.\n",
> +	rte_eth_link_to_str(link_status_text, 60, NULL, link);
> +	if (prev != link->link_status)
> +		RTE_LOG(INFO, APP, "%s NIC %s",
>   			rte_kni_get_name(kni),
> -			link->link_speed,
> -			link->link_autoneg ?  "(AutoNeg)" : "(Fixed)",
> -			link->link_duplex ?  "Full Duplex" : "Half Duplex");
> -	} else if (prev == ETH_LINK_UP && link->link_status == ETH_LINK_DOWN) {
> -		RTE_LOG(INFO, APP, "%s NIC Link is Down.\n",
> -			rte_kni_get_name(kni));
> -	}
> +			link_status_text);
>   }
>   
>   /*
>

Patch
diff mbox series

diff --git a/examples/kni/main.c b/examples/kni/main.c
index f5d12a5b8..49d888064 100644
--- a/examples/kni/main.c
+++ b/examples/kni/main.c
@@ -661,6 +661,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_text[RTE_ETH_LINK_MAX_STR_LEN];
 
 	printf("\nChecking link status\n");
 	fflush(stdout);
@@ -680,14 +681,10 @@  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 %uMbps - %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_text,
+					sizeof(link_status_text), &link);
+				printf("Port %d %s\n", portid,
+					link_status_text);
 				continue;
 			}
 			/* clear all_ports_up flag if any link down */
@@ -717,19 +714,15 @@  check_all_ports_link_status(uint32_t port_mask)
 static void
 log_link_state(struct rte_kni *kni, int prev, struct rte_eth_link *link)
 {
+	char link_status_text[60];
 	if (kni == NULL || link == NULL)
 		return;
 
-	if (prev == ETH_LINK_DOWN && link->link_status == ETH_LINK_UP) {
-		RTE_LOG(INFO, APP, "%s NIC Link is Up %d Mbps %s %s.\n",
+	rte_eth_link_to_str(link_status_text, 60, NULL, link);
+	if (prev != link->link_status)
+		RTE_LOG(INFO, APP, "%s NIC %s",
 			rte_kni_get_name(kni),
-			link->link_speed,
-			link->link_autoneg ?  "(AutoNeg)" : "(Fixed)",
-			link->link_duplex ?  "Full Duplex" : "Half Duplex");
-	} else if (prev == ETH_LINK_UP && link->link_status == ETH_LINK_DOWN) {
-		RTE_LOG(INFO, APP, "%s NIC Link is Down.\n",
-			rte_kni_get_name(kni));
-	}
+			link_status_text);
 }
 
 /*