Skip to content

Commit

Permalink
Merge branch 'net-define-new-hwtstamp-flag-and-return-it-to-userspace'
Browse files Browse the repository at this point in the history
Hangbin Liu says:

====================
net: define new hwtstamp flag and return it to userspace

This patchset defined the new hwtstamp flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
to make userspace program build pass with old kernel header by settting ifdef.

Let's also return the flag when do SIOC[G/S]HWTSTAMP to let userspace know
that it's necessary for a given netdev.
====================

Link: https://lore.kernel.org/r/20211229080938.231324-1-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Dec 29, 2021
2 parents 9ed319e + cfe355c commit cfcad56
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
42 changes: 26 additions & 16 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4124,28 +4124,38 @@ static int bond_eth_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cm

break;
case SIOCSHWTSTAMP:
case SIOCGHWTSTAMP:
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
return -EFAULT;

if (cfg.flags & HWTSTAMP_FLAG_BONDED_PHC_INDEX) {
rcu_read_lock();
real_dev = bond_option_active_slave_get_rcu(bond);
rcu_read_unlock();
if (real_dev) {
strscpy_pad(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
ifrr.ifr_ifru = ifr->ifr_ifru;
if (!(cfg.flags & HWTSTAMP_FLAG_BONDED_PHC_INDEX))
return -EOPNOTSUPP;

ops = real_dev->netdev_ops;
if (netif_device_present(real_dev) && ops->ndo_eth_ioctl) {
res = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd);
fallthrough;
case SIOCGHWTSTAMP:
rcu_read_lock();
real_dev = bond_option_active_slave_get_rcu(bond);
rcu_read_unlock();
if (!real_dev)
return -EOPNOTSUPP;

if (!res)
ifr->ifr_ifru = ifrr.ifr_ifru;
strscpy_pad(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
ifrr.ifr_ifru = ifr->ifr_ifru;

return res;
}
}
ops = real_dev->netdev_ops;
if (netif_device_present(real_dev) && ops->ndo_eth_ioctl) {
res = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd);
if (res)
return res;

ifr->ifr_ifru = ifrr.ifr_ifru;
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
return -EFAULT;

/* Set the BOND_PHC_INDEX flag to notify user space */
cfg.flags |= HWTSTAMP_FLAG_BONDED_PHC_INDEX;

return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ?
-EFAULT : 0;
}
fallthrough;
default:
Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/net_tstamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ enum hwtstamp_flags {
* will be the PHC index.
*/
HWTSTAMP_FLAG_BONDED_PHC_INDEX = (1<<0),
#define HWTSTAMP_FLAG_BONDED_PHC_INDEX HWTSTAMP_FLAG_BONDED_PHC_INDEX

HWTSTAMP_FLAG_LAST = HWTSTAMP_FLAG_BONDED_PHC_INDEX,
HWTSTAMP_FLAG_MASK = (HWTSTAMP_FLAG_LAST - 1) | HWTSTAMP_FLAG_LAST
Expand Down

0 comments on commit cfcad56

Please sign in to comment.