[dpdk-dev] [PATCH 1/2] ethdev: deduplicate functions to get link infos

Asaf Penso asafp at mellanox.com
Wed Apr 8 07:21:17 CEST 2020


Thank you, Thomas, for taking care of this.
PSB.

Regards,
Asaf Penso

> -----Original Message-----
> From: dev <dev-bounces at dpdk.org> On Behalf Of Thomas Monjalon
> Sent: Wednesday, April 8, 2020 1:27 AM
> To: dev at dpdk.org
> Cc: Ferruh Yigit <ferruh.yigit at intel.com>; Andrew Rybchenko
> <arybchenko at solarflare.com>
> Subject: [dpdk-dev] [PATCH 1/2] ethdev: deduplicate functions to get link
> infos
> 
> There are two function to retrieve link informations.
> The only small difference is a boolean timeout parameter.
> Adding a new static function, with an additional parameter,
> removes the code redundancy.
> 
> Signed-off-by: Thomas Monjalon <thomas at monjalon.net>
> ---
>  lib/librte_ethdev/rte_ethdev.c | 52 ++++++++++++++--------------------
>  1 file changed, 22 insertions(+), 30 deletions(-)
> 
> diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
> index 0854ef8832..0df39dff97 100644
> --- a/lib/librte_ethdev/rte_ethdev.c
> +++ b/lib/librte_ethdev/rte_ethdev.c
> @@ -2332,44 +2332,36 @@ rte_eth_allmulticast_get(uint16_t port_id)
>  	return dev->data->all_multicast;
>  }
> 
> +static int
> +get_link_infos(uint16_t port_id, struct rte_eth_link *eth_link, int wait)

I would recommend renaming to link_get_infos, to have the same naming convention as rte_eth_*link_get* and rte_eth_*link_get*_nowait

> +{
> +	struct rte_eth_dev *dev;
> +
> +	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
> +	dev = &rte_eth_devices[port_id];
> +
> +	if (dev->data->dev_conf.intr_conf.lsc &&
> +	    dev->data->dev_started)
> +		rte_eth_linkstatus_get(dev, eth_link);
> +	else {
> +		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops-
> >link_update, -ENOTSUP);
> +		(*dev->dev_ops->link_update)(dev, wait);
> +		*eth_link = dev->data->dev_link;
> +	}
> +
> +	return 0;

Since it's a static function, I think it can return void, and the calling functions can decide what to return, but it's a matter of taste.
Do we want to check that the return value for eth_link is not NULL and return -1 in case it is?

> +}
> +
>  int
>  rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
>  {
> -	struct rte_eth_dev *dev;
> -
> -	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
> -	dev = &rte_eth_devices[port_id];
> -
> -	if (dev->data->dev_conf.intr_conf.lsc &&
> -	    dev->data->dev_started)
> -		rte_eth_linkstatus_get(dev, eth_link);
> -	else {
> -		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops-
> >link_update, -ENOTSUP);
> -		(*dev->dev_ops->link_update)(dev, 1);
> -		*eth_link = dev->data->dev_link;
> -	}
> -
> -	return 0;
> +	return get_link_infos(port_id, eth_link, 1);
>  }
> 
>  int
>  rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
>  {
> -	struct rte_eth_dev *dev;
> -
> -	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
> -	dev = &rte_eth_devices[port_id];
> -
> -	if (dev->data->dev_conf.intr_conf.lsc &&
> -	    dev->data->dev_started)
> -		rte_eth_linkstatus_get(dev, eth_link);
> -	else {
> -		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops-
> >link_update, -ENOTSUP);
> -		(*dev->dev_ops->link_update)(dev, 0);
> -		*eth_link = dev->data->dev_link;
> -	}
> -
> -	return 0;
> +	return get_link_infos(port_id, eth_link, 0);
>  }
> 
>  int
> --
> 2.26.0



More information about the dev mailing list