forked from mirrors/linux
		
	net: Move PHY statistics code into PHY library helpers
In order to make it possible for network device drivers that do not necessarily have a phy_device attached, but still report PHY statistics, have a preliminary refactoring consisting in creating helper functions that encapsulate the PHY device driver knowledge within PHYLIB. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									8349440733
								
							
						
					
					
						commit
						c59530d0d5
					
				
					 3 changed files with 76 additions and 30 deletions
				
			
		|  | @ -1277,3 +1277,51 @@ int phy_ethtool_nway_reset(struct net_device *ndev) | ||||||
| 	return phy_restart_aneg(phydev); | 	return phy_restart_aneg(phydev); | ||||||
| } | } | ||||||
| EXPORT_SYMBOL(phy_ethtool_nway_reset); | EXPORT_SYMBOL(phy_ethtool_nway_reset); | ||||||
|  | 
 | ||||||
|  | int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data) | ||||||
|  | { | ||||||
|  | 	if (!phydev->drv) | ||||||
|  | 		return -EIO; | ||||||
|  | 
 | ||||||
|  | 	mutex_lock(&phydev->lock); | ||||||
|  | 	phydev->drv->get_strings(phydev, data); | ||||||
|  | 	mutex_unlock(&phydev->lock); | ||||||
|  | 
 | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  | EXPORT_SYMBOL(phy_ethtool_get_strings); | ||||||
|  | 
 | ||||||
|  | int phy_ethtool_get_sset_count(struct phy_device *phydev) | ||||||
|  | { | ||||||
|  | 	int ret; | ||||||
|  | 
 | ||||||
|  | 	if (!phydev->drv) | ||||||
|  | 		return -EIO; | ||||||
|  | 
 | ||||||
|  | 	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; | ||||||
|  | } | ||||||
|  | EXPORT_SYMBOL(phy_ethtool_get_sset_count); | ||||||
|  | 
 | ||||||
|  | int phy_ethtool_get_stats(struct phy_device *phydev, | ||||||
|  | 			  struct ethtool_stats *stats, u64 *data) | ||||||
|  | { | ||||||
|  | 	if (!phydev->drv) | ||||||
|  | 		return -EIO; | ||||||
|  | 
 | ||||||
|  | 	mutex_lock(&phydev->lock); | ||||||
|  | 	phydev->drv->get_stats(phydev, stats, data); | ||||||
|  | 	mutex_unlock(&phydev->lock); | ||||||
|  | 
 | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  | EXPORT_SYMBOL(phy_ethtool_get_stats); | ||||||
|  |  | ||||||
|  | @ -1066,6 +1066,26 @@ int phy_ethtool_nway_reset(struct net_device *ndev); | ||||||
| #if IS_ENABLED(CONFIG_PHYLIB) | #if IS_ENABLED(CONFIG_PHYLIB) | ||||||
| int __init mdio_bus_init(void); | int __init mdio_bus_init(void); | ||||||
| void mdio_bus_exit(void); | void mdio_bus_exit(void); | ||||||
|  | int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data); | ||||||
|  | int phy_ethtool_get_sset_count(struct phy_device *phydev); | ||||||
|  | int phy_ethtool_get_stats(struct phy_device *phydev, | ||||||
|  | 			  struct ethtool_stats *stats, u64 *data); | ||||||
|  | #else | ||||||
|  | int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data) | ||||||
|  | { | ||||||
|  | 	return -EOPNOTSUPP; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | int phy_ethtool_get_sset_count(struct phy_device *phydev) | ||||||
|  | { | ||||||
|  | 	return -EOPNOTSUPP; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | int phy_ethtool_get_stats(struct phy_device *phydev, | ||||||
|  | 			  struct ethtool_stats *stats, u64 *data) | ||||||
|  | { | ||||||
|  | 	return -EOPNOTSUPP; | ||||||
|  | } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| extern struct bus_type mdio_bus_type; | extern struct bus_type mdio_bus_type; | ||||||
|  |  | ||||||
|  | @ -211,23 +211,6 @@ static int ethtool_set_features(struct net_device *dev, void __user *useraddr) | ||||||
| 	return ret; | 	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) | static int __ethtool_get_sset_count(struct net_device *dev, int sset) | ||||||
| { | { | ||||||
| 	const struct ethtool_ops *ops = dev->ethtool_ops; | 	const struct ethtool_ops *ops = dev->ethtool_ops; | ||||||
|  | @ -246,7 +229,7 @@ static int __ethtool_get_sset_count(struct net_device *dev, int sset) | ||||||
| 
 | 
 | ||||||
| 	if (sset == ETH_SS_PHY_STATS) { | 	if (sset == ETH_SS_PHY_STATS) { | ||||||
| 		if (dev->phydev) | 		if (dev->phydev) | ||||||
| 			return phy_get_sset_count(dev->phydev); | 			return phy_ethtool_get_sset_count(dev->phydev); | ||||||
| 		else | 		else | ||||||
| 			return -EOPNOTSUPP; | 			return -EOPNOTSUPP; | ||||||
| 	} | 	} | ||||||
|  | @ -273,15 +256,10 @@ static void __ethtool_get_strings(struct net_device *dev, | ||||||
| 	else if (stringset == ETH_SS_PHY_TUNABLES) | 	else if (stringset == ETH_SS_PHY_TUNABLES) | ||||||
| 		memcpy(data, phy_tunable_strings, sizeof(phy_tunable_strings)); | 		memcpy(data, phy_tunable_strings, sizeof(phy_tunable_strings)); | ||||||
| 	else if (stringset == ETH_SS_PHY_STATS) { | 	else if (stringset == ETH_SS_PHY_STATS) { | ||||||
| 		struct phy_device *phydev = dev->phydev; | 		if (dev->phydev) | ||||||
| 
 | 			phy_ethtool_get_strings(dev->phydev, data); | ||||||
| 		if (phydev) { | 		else | ||||||
| 			mutex_lock(&phydev->lock); |  | ||||||
| 			phydev->drv->get_strings(phydev, data); |  | ||||||
| 			mutex_unlock(&phydev->lock); |  | ||||||
| 		} else { |  | ||||||
| 			return; | 			return; | ||||||
| 		} |  | ||||||
| 	} else | 	} else | ||||||
| 		/* ops->get_strings is valid because checked earlier */ | 		/* ops->get_strings is valid because checked earlier */ | ||||||
| 		ops->get_strings(dev, stringset, data); | 		ops->get_strings(dev, stringset, data); | ||||||
|  | @ -2002,7 +1980,7 @@ static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr) | ||||||
| 	if (!phydev) | 	if (!phydev) | ||||||
| 		return -EOPNOTSUPP; | 		return -EOPNOTSUPP; | ||||||
| 
 | 
 | ||||||
| 	n_stats = phy_get_sset_count(phydev); | 	n_stats = phy_ethtool_get_sset_count(dev->phydev); | ||||||
| 	if (n_stats < 0) | 	if (n_stats < 0) | ||||||
| 		return n_stats; | 		return n_stats; | ||||||
| 	if (n_stats > S32_MAX / sizeof(u64)) | 	if (n_stats > S32_MAX / sizeof(u64)) | ||||||
|  | @ -2017,9 +1995,9 @@ static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr) | ||||||
| 	if (n_stats && !data) | 	if (n_stats && !data) | ||||||
| 		return -ENOMEM; | 		return -ENOMEM; | ||||||
| 
 | 
 | ||||||
| 	mutex_lock(&phydev->lock); | 	ret = phy_ethtool_get_stats(dev->phydev, &stats, data); | ||||||
| 	phydev->drv->get_stats(phydev, &stats, data); | 	if (ret < 0) | ||||||
| 	mutex_unlock(&phydev->lock); | 		return ret; | ||||||
| 
 | 
 | ||||||
| 	ret = -EFAULT; | 	ret = -EFAULT; | ||||||
| 	if (copy_to_user(useraddr, &stats, sizeof(stats))) | 	if (copy_to_user(useraddr, &stats, sizeof(stats))) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Florian Fainelli
						Florian Fainelli