]> git.itanic.dy.fi Git - linux-stable/commitdiff
bonding: add software tx timestamping support
authorHangbin Liu <liuhangbin@gmail.com>
Tue, 18 Apr 2023 03:48:41 +0000 (11:48 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 19 Apr 2023 03:48:59 +0000 (20:48 -0700)
Currently, bonding only obtain the timestamp (ts) information of
the active slave, which is available only for modes 1, 5, and 6.
For other modes, bonding only has software rx timestamping support.

However, some users who use modes such as LACP also want tx timestamp
support. To address this issue, let's check the ts information of each
slave. If all slaves support tx timestamping, we can enable tx
timestamping support for the bond.

Add a note that the get_ts_info may be called with RCU, or rtnl or
reference on the device in ethtool.h>

Suggested-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Acked-by: Jay Vosburgh <jay.vosburgh@canonical.com>
Link: https://lore.kernel.org/r/20230418034841.2566262-1-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/bonding/bond_main.c
include/linux/ethtool.h

index 8cc9a74789b799da9d3764bcf1a0a6d6d087b45d..db7e650d9ebb7d12f6ada2f3c8a65dbcbcae23d9 100644 (file)
@@ -5696,9 +5696,13 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev,
                                    struct ethtool_ts_info *info)
 {
        struct bonding *bond = netdev_priv(bond_dev);
+       struct ethtool_ts_info ts_info;
        const struct ethtool_ops *ops;
        struct net_device *real_dev;
+       bool sw_tx_support = false;
        struct phy_device *phydev;
+       struct list_head *iter;
+       struct slave *slave;
        int ret = 0;
 
        rcu_read_lock();
@@ -5717,10 +5721,36 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev,
                        ret = ops->get_ts_info(real_dev, info);
                        goto out;
                }
+       } else {
+               /* Check if all slaves support software tx timestamping */
+               rcu_read_lock();
+               bond_for_each_slave_rcu(bond, slave, iter) {
+                       ret = -1;
+                       ops = slave->dev->ethtool_ops;
+                       phydev = slave->dev->phydev;
+
+                       if (phy_has_tsinfo(phydev))
+                               ret = phy_ts_info(phydev, &ts_info);
+                       else if (ops->get_ts_info)
+                               ret = ops->get_ts_info(slave->dev, &ts_info);
+
+                       if (!ret && (ts_info.so_timestamping & SOF_TIMESTAMPING_TX_SOFTWARE)) {
+                               sw_tx_support = true;
+                               continue;
+                       }
+
+                       sw_tx_support = false;
+                       break;
+               }
+               rcu_read_unlock();
        }
 
+       ret = 0;
        info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
                                SOF_TIMESTAMPING_SOFTWARE;
+       if (sw_tx_support)
+               info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE;
+
        info->phc_index = -1;
 
 out:
index 798d35890118f2b41ac3c01b72ef82dea1e3c9a5..62b61527bcc4f665788f3dfec21fd98dc3df460b 100644 (file)
@@ -711,6 +711,7 @@ struct ethtool_mm_stats {
  * @get_dump_data: Get dump data.
  * @set_dump: Set dump specific flags to the device.
  * @get_ts_info: Get the time stamping and PTP hardware clock capabilities.
+ *     It may be called with RCU, or rtnl or reference on the device.
  *     Drivers supporting transmit time stamps in software should set this to
  *     ethtool_op_get_ts_info().
  * @get_module_info: Get the size and type of the eeprom contained within