diff options
| author | David S. Miller <[email protected]> | 2018-04-27 11:53:04 -0400 | 
|---|---|---|
| committer | David S. Miller <[email protected]> | 2018-04-27 11:53:04 -0400 | 
| commit | 21fca6e01beb9cae33c7d45a69e032d91c81f07d (patch) | |
| tree | ee5924b4a53b16f813c239101935af3f480b7781 /net/core/ethtool.c | |
| parent | 834944073301e85001c3ed9913027ca47c6f889b (diff) | |
| parent | 96cbddcd52e76d9052948e408b17bedc8aa1c11a (diff) | |
Merge branch 'net-Extend-availability-of-PHY-statistics'
Florian Fainelli says:
====================
net: Extend availability of PHY statistics
This patch series adds support for retrieving PHY statistics with DSA switches
when the CPU port uses a PHY to PHY connection (as opposed to MAC to MAC).
To get there a number of things are done:
- first we move the code dealing with PHY statistics outside of net/core/ethtool.c
  and create helper functions since the same code will be reused
- then we allow network device drivers to provide an ethtool_get_phy_stats callback
  when the standard PHY library helpers are not suitable
- we update the DSA functions dealing with ethtool operations to get passed a
  stringset instead of assuming ETH_SS_STATS like they currently do
- then we provide a set of standard helpers within DSA as a framework and add
  the plumbing to allow retrieving the PHY statistics of the CPU port(s)
- finally plug support for retrieving such PHY statistics with the b53 driver
Changes in v3:
- retrict the b53 change to 539x and 531x5 series of switches
- added a change to dsa_loop.c to help test the feature
Changes in v2:
- got actual testing when the DSA master network device has a PHY that
  already provides statistics (thanks Nikita!)
- fixed the kbuild error reported when CONFIG_PHYLIB=n
- removed the checking of ops which is redundant and not needed
====================
Signed-off-by: David S. Miller <[email protected]>
Diffstat (limited to 'net/core/ethtool.c')
| -rw-r--r-- | net/core/ethtool.c | 61 | 
1 files changed, 21 insertions, 40 deletions
| diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 4650fd6d678c..b849fdae7e87 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -211,23 +211,6 @@ static int ethtool_set_features(struct net_device *dev, void __user *useraddr)  	return ret;  } -static int phy_get_sset_count(struct phy_device *phydev) -{ -	int ret; - -	if (phydev->drv->get_sset_count && -	    phydev->drv->get_strings && -	    phydev->drv->get_stats) { -		mutex_lock(&phydev->lock); -		ret = phydev->drv->get_sset_count(phydev); -		mutex_unlock(&phydev->lock); - -		return ret; -	} - -	return -EOPNOTSUPP; -} -  static int __ethtool_get_sset_count(struct net_device *dev, int sset)  {  	const struct ethtool_ops *ops = dev->ethtool_ops; @@ -244,12 +227,9 @@ static int __ethtool_get_sset_count(struct net_device *dev, int sset)  	if (sset == ETH_SS_PHY_TUNABLES)  		return ARRAY_SIZE(phy_tunable_strings); -	if (sset == ETH_SS_PHY_STATS) { -		if (dev->phydev) -			return phy_get_sset_count(dev->phydev); -		else -			return -EOPNOTSUPP; -	} +	if (sset == ETH_SS_PHY_STATS && dev->phydev && +	    !ops->get_ethtool_phy_stats) +		return phy_ethtool_get_sset_count(dev->phydev);  	if (ops->get_sset_count && ops->get_strings)  		return ops->get_sset_count(dev, sset); @@ -272,17 +252,10 @@ static void __ethtool_get_strings(struct net_device *dev,  		memcpy(data, tunable_strings, sizeof(tunable_strings));  	else if (stringset == ETH_SS_PHY_TUNABLES)  		memcpy(data, phy_tunable_strings, sizeof(phy_tunable_strings)); -	else if (stringset == ETH_SS_PHY_STATS) { -		struct phy_device *phydev = dev->phydev; - -		if (phydev) { -			mutex_lock(&phydev->lock); -			phydev->drv->get_strings(phydev, data); -			mutex_unlock(&phydev->lock); -		} else { -			return; -		} -	} else +	else if (stringset == ETH_SS_PHY_STATS && dev->phydev && +		 !ops->get_ethtool_phy_stats) +		phy_ethtool_get_strings(dev->phydev, data); +	else  		/* ops->get_strings is valid because checked earlier */  		ops->get_strings(dev, stringset, data);  } @@ -1994,15 +1967,19 @@ static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)  static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr)  { -	struct ethtool_stats stats; +	const struct ethtool_ops *ops = dev->ethtool_ops;  	struct phy_device *phydev = dev->phydev; +	struct ethtool_stats stats;  	u64 *data;  	int ret, n_stats; -	if (!phydev) +	if (!phydev && (!ops->get_ethtool_phy_stats || !ops->get_sset_count))  		return -EOPNOTSUPP; -	n_stats = phy_get_sset_count(phydev); +	if (dev->phydev && !ops->get_ethtool_phy_stats) +		n_stats = phy_ethtool_get_sset_count(dev->phydev); +	else +		n_stats = ops->get_sset_count(dev, ETH_SS_PHY_STATS);  	if (n_stats < 0)  		return n_stats;  	if (n_stats > S32_MAX / sizeof(u64)) @@ -2017,9 +1994,13 @@ static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr)  	if (n_stats && !data)  		return -ENOMEM; -	mutex_lock(&phydev->lock); -	phydev->drv->get_stats(phydev, &stats, data); -	mutex_unlock(&phydev->lock); +	if (dev->phydev && !ops->get_ethtool_phy_stats) { +		ret = phy_ethtool_get_stats(dev->phydev, &stats, data); +		if (ret < 0) +			return ret; +	} else { +		ops->get_ethtool_phy_stats(dev, &stats, data); +	}  	ret = -EFAULT;  	if (copy_to_user(useraddr, &stats, sizeof(stats))) |