Skip to content

Commit b8768dc

Browse files
richardcochrandavem330
authored andcommitted
net: ethtool: Refactor identical get_ts_info implementations.
The vlan, macvlan and the bonding drivers call their "real" device driver in order to report the time stamping capabilities. Provide a core ethtool helper function to avoid copy/paste in the stack. Signed-off-by: Richard Cochran <richardcochran@gmail.com> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Reviewed-by: Jay Vosburgh <jay.vosburgh@canonical.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 430dc32 commit b8768dc

File tree

5 files changed

+18
-54
lines changed

5 files changed

+18
-54
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5755,10 +5755,8 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev,
57555755
{
57565756
struct bonding *bond = netdev_priv(bond_dev);
57575757
struct ethtool_ts_info ts_info;
5758-
const struct ethtool_ops *ops;
57595758
struct net_device *real_dev;
57605759
bool sw_tx_support = false;
5761-
struct phy_device *phydev;
57625760
struct list_head *iter;
57635761
struct slave *slave;
57645762
int ret = 0;
@@ -5769,29 +5767,12 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev,
57695767
rcu_read_unlock();
57705768

57715769
if (real_dev) {
5772-
ops = real_dev->ethtool_ops;
5773-
phydev = real_dev->phydev;
5774-
5775-
if (phy_has_tsinfo(phydev)) {
5776-
ret = phy_ts_info(phydev, info);
5777-
goto out;
5778-
} else if (ops->get_ts_info) {
5779-
ret = ops->get_ts_info(real_dev, info);
5780-
goto out;
5781-
}
5770+
ret = ethtool_get_ts_info_by_layer(real_dev, info);
57825771
} else {
57835772
/* Check if all slaves support software tx timestamping */
57845773
rcu_read_lock();
57855774
bond_for_each_slave_rcu(bond, slave, iter) {
5786-
ret = -1;
5787-
ops = slave->dev->ethtool_ops;
5788-
phydev = slave->dev->phydev;
5789-
5790-
if (phy_has_tsinfo(phydev))
5791-
ret = phy_ts_info(phydev, &ts_info);
5792-
else if (ops->get_ts_info)
5793-
ret = ops->get_ts_info(slave->dev, &ts_info);
5794-
5775+
ret = ethtool_get_ts_info_by_layer(slave->dev, &ts_info);
57955776
if (!ret && (ts_info.so_timestamping & SOF_TIMESTAMPING_TX_SOFTWARE)) {
57965777
sw_tx_support = true;
57975778
continue;
@@ -5803,15 +5784,9 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev,
58035784
rcu_read_unlock();
58045785
}
58055786

5806-
ret = 0;
5807-
info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
5808-
SOF_TIMESTAMPING_SOFTWARE;
58095787
if (sw_tx_support)
58105788
info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE;
58115789

5812-
info->phc_index = -1;
5813-
5814-
out:
58155790
dev_put(real_dev);
58165791
return ret;
58175792
}

drivers/net/macvlan.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,20 +1086,8 @@ static int macvlan_ethtool_get_ts_info(struct net_device *dev,
10861086
struct ethtool_ts_info *info)
10871087
{
10881088
struct net_device *real_dev = macvlan_dev_real_dev(dev);
1089-
const struct ethtool_ops *ops = real_dev->ethtool_ops;
1090-
struct phy_device *phydev = real_dev->phydev;
10911089

1092-
if (phy_has_tsinfo(phydev)) {
1093-
return phy_ts_info(phydev, info);
1094-
} else if (ops->get_ts_info) {
1095-
return ops->get_ts_info(real_dev, info);
1096-
} else {
1097-
info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
1098-
SOF_TIMESTAMPING_SOFTWARE;
1099-
info->phc_index = -1;
1100-
}
1101-
1102-
return 0;
1090+
return ethtool_get_ts_info_by_layer(real_dev, info);
11031091
}
11041092

11051093
static netdev_features_t macvlan_fix_features(struct net_device *dev,

include/linux/ethtool.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,14 @@ static inline int ethtool_mm_frag_size_min_to_add(u32 val_min, u32 *val_add,
10431043
return -EINVAL;
10441044
}
10451045

1046+
/**
1047+
* ethtool_get_ts_info_by_layer - Obtains time stamping capabilities from the MAC or PHY layer.
1048+
* @dev: pointer to net_device structure
1049+
* @info: buffer to hold the result
1050+
* Returns zero on success, non-zero otherwise.
1051+
*/
1052+
int ethtool_get_ts_info_by_layer(struct net_device *dev, struct ethtool_ts_info *info);
1053+
10461054
/**
10471055
* ethtool_sprintf - Write formatted string to ethtool string data
10481056
* @data: Pointer to a pointer to the start of string to update

net/8021q/vlan_dev.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -702,20 +702,7 @@ static int vlan_ethtool_get_ts_info(struct net_device *dev,
702702
struct ethtool_ts_info *info)
703703
{
704704
const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
705-
const struct ethtool_ops *ops = vlan->real_dev->ethtool_ops;
706-
struct phy_device *phydev = vlan->real_dev->phydev;
707-
708-
if (phy_has_tsinfo(phydev)) {
709-
return phy_ts_info(phydev, info);
710-
} else if (ops->get_ts_info) {
711-
return ops->get_ts_info(vlan->real_dev, info);
712-
} else {
713-
info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
714-
SOF_TIMESTAMPING_SOFTWARE;
715-
info->phc_index = -1;
716-
}
717-
718-
return 0;
705+
return ethtool_get_ts_info_by_layer(vlan->real_dev, info);
719706
}
720707

721708
static void vlan_dev_get_stats64(struct net_device *dev,

net/ethtool/common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,12 @@ int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index)
661661
}
662662
EXPORT_SYMBOL(ethtool_get_phc_vclocks);
663663

664+
int ethtool_get_ts_info_by_layer(struct net_device *dev, struct ethtool_ts_info *info)
665+
{
666+
return __ethtool_get_ts_info(dev, info);
667+
}
668+
EXPORT_SYMBOL(ethtool_get_ts_info_by_layer);
669+
664670
const struct ethtool_phy_ops *ethtool_phy_ops;
665671

666672
void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops)

0 commit comments

Comments
 (0)