[dpdk-dev] [PATCH v10 02/24] ethdev: format a link status text
Morten Brørup
mb at smartsharesystems.com
Thu Sep 10 21:58:46 CEST 2020
> From: Ivan Dyukov [mailto:i.dyukov at samsung.com]
> Sent: Thursday, September 10, 2020 9:34 PM
>
> There is new link_speed value introduced. It's INT_MAX value which
> means that speed is unknown. To simplify processing of the value
> in application, new function is added which convert link_speed to
> string. Also dpdk examples have many duplicated code which format
> entire link status structure to text.
>
> This commit adds two functions:
> * rte_eth_link_speed_to_str - format link_speed to string
> * rte_eth_link_to_str - convert link status structure to string
>
> Signed-off-by: Ivan Dyukov <i.dyukov at samsung.com>
> ---
[...]
> diff --git a/lib/librte_ethdev/rte_ethdev.c
> b/lib/librte_ethdev/rte_ethdev.c
> index d06b7f9b1..cb624b7b4 100644
> --- a/lib/librte_ethdev/rte_ethdev.c
> +++ b/lib/librte_ethdev/rte_ethdev.c
> @@ -2383,6 +2383,59 @@ rte_eth_link_get_nowait(uint16_t port_id, struct
> rte_eth_link *eth_link)
> return 0;
> }
>
> +const char *
> +rte_eth_link_speed_to_str(uint32_t link_speed)
> +{
> + switch (link_speed) {
> + case ETH_SPEED_NUM_UNKNOWN:
> + return "Unknown";
Suggest moving case ETH_SPEED_NUM_UNKNOWN to the bottom of the switch, keeping it in the same order as the enums in the header file. No strong opinion on this, just an observation.
> + case ETH_SPEED_NUM_NONE:
> + return "0 Mbps";
Return "None" instead of "0 Mbps".
> + case ETH_SPEED_NUM_10M:
> + return "10 Mbps";
> + case ETH_SPEED_NUM_100M:
> + return "100 Mbps";
> + case ETH_SPEED_NUM_1G:
> + return "1 Gbps";
> + case ETH_SPEED_NUM_2_5G:
> + return "2.5 Gbps";
> + case ETH_SPEED_NUM_5G:
> + return "5 Gbps";
> + case ETH_SPEED_NUM_10G:
> + return "10 Gbps";
> + case ETH_SPEED_NUM_20G:
> + return "20 Gbps";
> + case ETH_SPEED_NUM_25G:
> + return "25 Gbps";
> + case ETH_SPEED_NUM_40G:
> + return "40 Gbps";
> + case ETH_SPEED_NUM_50G:
> + return "50 Gbps";
> + case ETH_SPEED_NUM_56G:
> + return "56 Gbps";
> + case ETH_SPEED_NUM_100G:
> + return "100 Gbps";
> + case ETH_SPEED_NUM_200G:
> + return "200 Gbps";
> + default:
> + return "Invalid speed";
Suggest "Invalid" instead, only to avoid a relatively long string. Again, no strong opinion on this.
> + }
> +}
Remember to update test_link_speed_all_values() accordingly.
More information about the dev
mailing list