Skip to content

Commit 94dd016

Browse files
liuhangbindavem330
authored andcommitted
bond: pass get_ts_info and SIOC[SG]HWTSTAMP ioctl to active device
We have VLAN PTP support(via get_ts_info) on kernel, and bond support(by getting active interface via netlink message) on userspace tool linuxptp. But there are always some users who want to use PTP with VLAN over bond, which is not able to do with the current implementation. This patch passed get_ts_info and SIOC[SG]HWTSTAMP ioctl to active device with bond mode active-backup/tlb/alb. With this users could get kernel native bond or VLAN over bond PTP support. Test with ptp4l and it works with VLAN over bond after this patch: ]# ptp4l -m -i bond0.23 ptp4l[53377.141]: selected /dev/ptp4 as PTP clock ptp4l[53377.142]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[53377.143]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[53377.143]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[53384.127]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ptp4l[53384.127]: selected local clock e41d2d.fffe.123db0 as best master ptp4l[53384.127]: port 1: assuming the grand master role Signed-off-by: Hangbin Liu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6167597 commit 94dd016

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include <linux/ethtool.h>
7272
#include <linux/if_vlan.h>
7373
#include <linux/if_bonding.h>
74+
#include <linux/phy.h>
7475
#include <linux/jiffies.h>
7576
#include <linux/preempt.h>
7677
#include <net/route.h>
@@ -4091,7 +4092,10 @@ static int bond_eth_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cm
40914092
{
40924093
struct bonding *bond = netdev_priv(bond_dev);
40934094
struct mii_ioctl_data *mii = NULL;
4094-
int res;
4095+
const struct net_device_ops *ops;
4096+
struct net_device *real_dev;
4097+
struct ifreq ifrr;
4098+
int res = 0;
40954099

40964100
netdev_dbg(bond_dev, "bond_eth_ioctl: cmd=%d\n", cmd);
40974101

@@ -4117,7 +4121,24 @@ static int bond_eth_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cm
41174121
mii->val_out = BMSR_LSTATUS;
41184122
}
41194123

4120-
return 0;
4124+
break;
4125+
case SIOCSHWTSTAMP:
4126+
case SIOCGHWTSTAMP:
4127+
rcu_read_lock();
4128+
real_dev = bond_option_active_slave_get_rcu(bond);
4129+
rcu_read_unlock();
4130+
if (real_dev) {
4131+
strscpy_pad(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
4132+
ifrr.ifr_ifru = ifr->ifr_ifru;
4133+
4134+
ops = real_dev->netdev_ops;
4135+
if (netif_device_present(real_dev) && ops->ndo_eth_ioctl)
4136+
res = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd);
4137+
4138+
if (!res)
4139+
ifr->ifr_ifru = ifrr.ifr_ifru;
4140+
}
4141+
break;
41214142
default:
41224143
res = -EOPNOTSUPP;
41234144
}
@@ -5319,10 +5340,40 @@ static void bond_ethtool_get_drvinfo(struct net_device *bond_dev,
53195340
BOND_ABI_VERSION);
53205341
}
53215342

5343+
static int bond_ethtool_get_ts_info(struct net_device *bond_dev,
5344+
struct ethtool_ts_info *info)
5345+
{
5346+
struct bonding *bond = netdev_priv(bond_dev);
5347+
const struct ethtool_ops *ops;
5348+
struct net_device *real_dev;
5349+
struct phy_device *phydev;
5350+
5351+
rcu_read_lock();
5352+
real_dev = bond_option_active_slave_get_rcu(bond);
5353+
rcu_read_unlock();
5354+
if (real_dev) {
5355+
ops = real_dev->ethtool_ops;
5356+
phydev = real_dev->phydev;
5357+
5358+
if (phy_has_tsinfo(phydev)) {
5359+
return phy_ts_info(phydev, info);
5360+
} else if (ops->get_ts_info) {
5361+
return ops->get_ts_info(real_dev, info);
5362+
}
5363+
}
5364+
5365+
info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
5366+
SOF_TIMESTAMPING_SOFTWARE;
5367+
info->phc_index = -1;
5368+
5369+
return 0;
5370+
}
5371+
53225372
static const struct ethtool_ops bond_ethtool_ops = {
53235373
.get_drvinfo = bond_ethtool_get_drvinfo,
53245374
.get_link = ethtool_op_get_link,
53255375
.get_link_ksettings = bond_ethtool_get_link_ksettings,
5376+
.get_ts_info = bond_ethtool_get_ts_info,
53265377
};
53275378

53285379
static const struct net_device_ops bond_netdev_ops = {

0 commit comments

Comments
 (0)