Skip to content

Commit b23ec2b

Browse files
committed
Merge branch 'introduce-ndo_hwtstamp_get-and-ndo_hwtstamp_set'
Vladimir Oltean says: ==================== Introduce ndo_hwtstamp_get() and ndo_hwtstamp_set() Based on previous RFCs from Maxim Georgiev: https://lore.kernel.org/netdev/20230502043150.17097-1-glipus@gmail.com/ this series attempts to introduce new API for the hardware timestamping control path (SIOCGHWTSTAMP and SIOCSHWTSTAMP handling). I don't have any board with phylib hardware timestamping, so I would appreciate testing (especially on lan966x, the most intricate conversion). I was, however, able to test netdev level timestamping, because I also have some more unsubmitted conversions in progress: https://github.com/vladimiroltean/linux/commits/ndo-hwtstamp-v9 I hope that the concerns expressed in the comments of previous series were addressed, and that Köry Maincent's series: https://lore.kernel.org/netdev/20230406173308.401924-1-kory.maincent@bootlin.com/ can make progress in parallel with the conversion of the rest of drivers. ==================== Link: https://lore.kernel.org/r/20230801142824.1772134-1-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 72c1a28 + fd770e8 commit b23ec2b

File tree

23 files changed

+630
-209
lines changed

23 files changed

+630
-209
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7752,6 +7752,7 @@ F: include/linux/mii.h
77527752
F: include/linux/of_net.h
77537753
F: include/linux/phy.h
77547754
F: include/linux/phy_fixed.h
7755+
F: include/linux/phylib_stubs.h
77557756
F: include/linux/platform_data/mdio-bcm-unimac.h
77567757
F: include/linux/platform_data/mdio-gpio.h
77577758
F: include/trace/events/mdio.h

drivers/net/bonding/bond_main.c

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4446,11 +4446,6 @@ static int bond_eth_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cm
44464446
{
44474447
struct bonding *bond = netdev_priv(bond_dev);
44484448
struct mii_ioctl_data *mii = NULL;
4449-
const struct net_device_ops *ops;
4450-
struct net_device *real_dev;
4451-
struct hwtstamp_config cfg;
4452-
struct ifreq ifrr;
4453-
int res = 0;
44544449

44554450
netdev_dbg(bond_dev, "bond_eth_ioctl: cmd=%d\n", cmd);
44564451

@@ -4477,44 +4472,11 @@ static int bond_eth_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cm
44774472
}
44784473

44794474
break;
4480-
case SIOCSHWTSTAMP:
4481-
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
4482-
return -EFAULT;
4483-
4484-
if (!(cfg.flags & HWTSTAMP_FLAG_BONDED_PHC_INDEX))
4485-
return -EOPNOTSUPP;
4486-
4487-
fallthrough;
4488-
case SIOCGHWTSTAMP:
4489-
real_dev = bond_option_active_slave_get_rcu(bond);
4490-
if (!real_dev)
4491-
return -EOPNOTSUPP;
4492-
4493-
strscpy_pad(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
4494-
ifrr.ifr_ifru = ifr->ifr_ifru;
4495-
4496-
ops = real_dev->netdev_ops;
4497-
if (netif_device_present(real_dev) && ops->ndo_eth_ioctl) {
4498-
res = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd);
4499-
if (res)
4500-
return res;
4501-
4502-
ifr->ifr_ifru = ifrr.ifr_ifru;
4503-
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
4504-
return -EFAULT;
4505-
4506-
/* Set the BOND_PHC_INDEX flag to notify user space */
4507-
cfg.flags |= HWTSTAMP_FLAG_BONDED_PHC_INDEX;
4508-
4509-
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ?
4510-
-EFAULT : 0;
4511-
}
4512-
fallthrough;
45134475
default:
4514-
res = -EOPNOTSUPP;
4476+
return -EOPNOTSUPP;
45154477
}
45164478

4517-
return res;
4479+
return 0;
45184480
}
45194481

45204482
static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd)
@@ -5688,6 +5650,67 @@ static u32 bond_mode_bcast_speed(struct slave *slave, u32 speed)
56885650
return speed;
56895651
}
56905652

5653+
/* Set the BOND_PHC_INDEX flag to notify user space */
5654+
static int bond_set_phc_index_flag(struct kernel_hwtstamp_config *kernel_cfg)
5655+
{
5656+
struct ifreq *ifr = kernel_cfg->ifr;
5657+
struct hwtstamp_config cfg;
5658+
5659+
if (kernel_cfg->copied_to_user) {
5660+
/* Lower device has a legacy implementation */
5661+
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
5662+
return -EFAULT;
5663+
5664+
cfg.flags |= HWTSTAMP_FLAG_BONDED_PHC_INDEX;
5665+
if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)))
5666+
return -EFAULT;
5667+
} else {
5668+
kernel_cfg->flags |= HWTSTAMP_FLAG_BONDED_PHC_INDEX;
5669+
}
5670+
5671+
return 0;
5672+
}
5673+
5674+
static int bond_hwtstamp_get(struct net_device *dev,
5675+
struct kernel_hwtstamp_config *cfg)
5676+
{
5677+
struct bonding *bond = netdev_priv(dev);
5678+
struct net_device *real_dev;
5679+
int err;
5680+
5681+
real_dev = bond_option_active_slave_get_rcu(bond);
5682+
if (!real_dev)
5683+
return -EOPNOTSUPP;
5684+
5685+
err = generic_hwtstamp_get_lower(real_dev, cfg);
5686+
if (err)
5687+
return err;
5688+
5689+
return bond_set_phc_index_flag(cfg);
5690+
}
5691+
5692+
static int bond_hwtstamp_set(struct net_device *dev,
5693+
struct kernel_hwtstamp_config *cfg,
5694+
struct netlink_ext_ack *extack)
5695+
{
5696+
struct bonding *bond = netdev_priv(dev);
5697+
struct net_device *real_dev;
5698+
int err;
5699+
5700+
if (!(cfg->flags & HWTSTAMP_FLAG_BONDED_PHC_INDEX))
5701+
return -EOPNOTSUPP;
5702+
5703+
real_dev = bond_option_active_slave_get_rcu(bond);
5704+
if (!real_dev)
5705+
return -EOPNOTSUPP;
5706+
5707+
err = generic_hwtstamp_set_lower(real_dev, cfg, extack);
5708+
if (err)
5709+
return err;
5710+
5711+
return bond_set_phc_index_flag(cfg);
5712+
}
5713+
56915714
static int bond_ethtool_get_link_ksettings(struct net_device *bond_dev,
56925715
struct ethtool_link_ksettings *cmd)
56935716
{
@@ -5836,6 +5859,8 @@ static const struct net_device_ops bond_netdev_ops = {
58365859
.ndo_bpf = bond_xdp,
58375860
.ndo_xdp_xmit = bond_xdp_xmit,
58385861
.ndo_xdp_get_xmit_slave = bond_xdp_get_xmit_slave,
5862+
.ndo_hwtstamp_get = bond_hwtstamp_get,
5863+
.ndo_hwtstamp_set = bond_hwtstamp_set,
58395864
};
58405865

58415866
static const struct device_type bond_type = {

drivers/net/ethernet/freescale/fec.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,9 @@ struct fec_enet_private {
698698
void fec_ptp_init(struct platform_device *pdev, int irq_idx);
699699
void fec_ptp_stop(struct platform_device *pdev);
700700
void fec_ptp_start_cyclecounter(struct net_device *ndev);
701-
void fec_ptp_disable_hwts(struct net_device *ndev);
702-
int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr);
703-
int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr);
701+
int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config,
702+
struct netlink_ext_ack *extack);
703+
void fec_ptp_get(struct net_device *ndev, struct kernel_hwtstamp_config *config);
704704

705705
/****************************************************************************/
706706
#endif /* FEC_H */

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,33 +3203,6 @@ static const struct ethtool_ops fec_enet_ethtool_ops = {
32033203
.self_test = net_selftest,
32043204
};
32053205

3206-
static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
3207-
{
3208-
struct fec_enet_private *fep = netdev_priv(ndev);
3209-
struct phy_device *phydev = ndev->phydev;
3210-
3211-
if (!netif_running(ndev))
3212-
return -EINVAL;
3213-
3214-
if (!phydev)
3215-
return -ENODEV;
3216-
3217-
if (fep->bufdesc_ex) {
3218-
bool use_fec_hwts = !phy_has_hwtstamp(phydev);
3219-
3220-
if (cmd == SIOCSHWTSTAMP) {
3221-
if (use_fec_hwts)
3222-
return fec_ptp_set(ndev, rq);
3223-
fec_ptp_disable_hwts(ndev);
3224-
} else if (cmd == SIOCGHWTSTAMP) {
3225-
if (use_fec_hwts)
3226-
return fec_ptp_get(ndev, rq);
3227-
}
3228-
}
3229-
3230-
return phy_mii_ioctl(phydev, rq, cmd);
3231-
}
3232-
32333206
static void fec_enet_free_buffers(struct net_device *ndev)
32343207
{
32353208
struct fec_enet_private *fep = netdev_priv(ndev);
@@ -3895,6 +3868,37 @@ static int fec_enet_xdp_xmit(struct net_device *dev,
38953868
return sent_frames;
38963869
}
38973870

3871+
static int fec_hwtstamp_get(struct net_device *ndev,
3872+
struct kernel_hwtstamp_config *config)
3873+
{
3874+
struct fec_enet_private *fep = netdev_priv(ndev);
3875+
3876+
if (!netif_running(ndev))
3877+
return -EINVAL;
3878+
3879+
if (!fep->bufdesc_ex)
3880+
return -EOPNOTSUPP;
3881+
3882+
fec_ptp_get(ndev, config);
3883+
3884+
return 0;
3885+
}
3886+
3887+
static int fec_hwtstamp_set(struct net_device *ndev,
3888+
struct kernel_hwtstamp_config *config,
3889+
struct netlink_ext_ack *extack)
3890+
{
3891+
struct fec_enet_private *fep = netdev_priv(ndev);
3892+
3893+
if (!netif_running(ndev))
3894+
return -EINVAL;
3895+
3896+
if (!fep->bufdesc_ex)
3897+
return -EOPNOTSUPP;
3898+
3899+
return fec_ptp_set(ndev, config, extack);
3900+
}
3901+
38983902
static const struct net_device_ops fec_netdev_ops = {
38993903
.ndo_open = fec_enet_open,
39003904
.ndo_stop = fec_enet_close,
@@ -3904,13 +3908,15 @@ static const struct net_device_ops fec_netdev_ops = {
39043908
.ndo_validate_addr = eth_validate_addr,
39053909
.ndo_tx_timeout = fec_timeout,
39063910
.ndo_set_mac_address = fec_set_mac_address,
3907-
.ndo_eth_ioctl = fec_enet_ioctl,
3911+
.ndo_eth_ioctl = phy_do_ioctl_running,
39083912
#ifdef CONFIG_NET_POLL_CONTROLLER
39093913
.ndo_poll_controller = fec_poll_controller,
39103914
#endif
39113915
.ndo_set_features = fec_set_features,
39123916
.ndo_bpf = fec_enet_bpf,
39133917
.ndo_xdp_xmit = fec_enet_xdp_xmit,
3918+
.ndo_hwtstamp_get = fec_hwtstamp_get,
3919+
.ndo_hwtstamp_set = fec_hwtstamp_set,
39143920
};
39153921

39163922
static const unsigned short offset_des_active_rxq[] = {

drivers/net/ethernet/freescale/fec_ptp.c

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -605,28 +605,12 @@ static int fec_ptp_enable(struct ptp_clock_info *ptp,
605605
}
606606
}
607607

608-
/**
609-
* fec_ptp_disable_hwts - disable hardware time stamping
610-
* @ndev: pointer to net_device
611-
*/
612-
void fec_ptp_disable_hwts(struct net_device *ndev)
608+
int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config,
609+
struct netlink_ext_ack *extack)
613610
{
614611
struct fec_enet_private *fep = netdev_priv(ndev);
615612

616-
fep->hwts_tx_en = 0;
617-
fep->hwts_rx_en = 0;
618-
}
619-
620-
int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr)
621-
{
622-
struct fec_enet_private *fep = netdev_priv(ndev);
623-
624-
struct hwtstamp_config config;
625-
626-
if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
627-
return -EFAULT;
628-
629-
switch (config.tx_type) {
613+
switch (config->tx_type) {
630614
case HWTSTAMP_TX_OFF:
631615
fep->hwts_tx_en = 0;
632616
break;
@@ -637,33 +621,28 @@ int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr)
637621
return -ERANGE;
638622
}
639623

640-
switch (config.rx_filter) {
624+
switch (config->rx_filter) {
641625
case HWTSTAMP_FILTER_NONE:
642626
fep->hwts_rx_en = 0;
643627
break;
644628

645629
default:
646630
fep->hwts_rx_en = 1;
647-
config.rx_filter = HWTSTAMP_FILTER_ALL;
631+
config->rx_filter = HWTSTAMP_FILTER_ALL;
648632
break;
649633
}
650634

651-
return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
652-
-EFAULT : 0;
635+
return 0;
653636
}
654637

655-
int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr)
638+
void fec_ptp_get(struct net_device *ndev, struct kernel_hwtstamp_config *config)
656639
{
657640
struct fec_enet_private *fep = netdev_priv(ndev);
658-
struct hwtstamp_config config;
659-
660-
config.flags = 0;
661-
config.tx_type = fep->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
662-
config.rx_filter = (fep->hwts_rx_en ?
663-
HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
664641

665-
return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
666-
-EFAULT : 0;
642+
config->flags = 0;
643+
config->tx_type = fep->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
644+
config->rx_filter = (fep->hwts_rx_en ?
645+
HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
667646
}
668647

669648
/*

0 commit comments

Comments
 (0)