Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: enetc: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()

New timestamping API was introduced in commit 66f7223039c0 ("net: add
NDOs for configuring hardware timestamping") from kernel v6.6. It is
time to convert the ENETC driver to the new API, so that the
ndo_eth_ioctl() path can be removed completely.

Move the enetc_hwtstamp_get() and enetc_hwtstamp_set() calls away from
enetc_ioctl() to dedicated net_device_ops for the LS1028A PF and VF
(NETC v4 does not yet implement enetc_ioctl()), adapt the prototypes and
export these symbols (enetc_ioctl() is also exported).

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Wei Fang <wei.fang@nxp.com>
Link: https://patch.msgid.link/20250512112402.4100618-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
51672a65 904c6ad8

+31 -26
+21 -26
drivers/net/ethernet/freescale/enetc/enetc.c
··· 3296 3296 } 3297 3297 EXPORT_SYMBOL_GPL(enetc_set_features); 3298 3298 3299 - static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr) 3299 + int enetc_hwtstamp_set(struct net_device *ndev, 3300 + struct kernel_hwtstamp_config *config, 3301 + struct netlink_ext_ack *extack) 3300 3302 { 3301 3303 struct enetc_ndev_priv *priv = netdev_priv(ndev); 3302 3304 int err, new_offloads = priv->active_offloads; 3303 - struct hwtstamp_config config; 3304 3305 3305 - if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 3306 - return -EFAULT; 3306 + if (!IS_ENABLED(CONFIG_FSL_ENETC_PTP_CLOCK)) 3307 + return -EOPNOTSUPP; 3307 3308 3308 - switch (config.tx_type) { 3309 + switch (config->tx_type) { 3309 3310 case HWTSTAMP_TX_OFF: 3310 3311 new_offloads &= ~ENETC_F_TX_TSTAMP_MASK; 3311 3312 break; ··· 3325 3324 return -ERANGE; 3326 3325 } 3327 3326 3328 - switch (config.rx_filter) { 3327 + switch (config->rx_filter) { 3329 3328 case HWTSTAMP_FILTER_NONE: 3330 3329 new_offloads &= ~ENETC_F_RX_TSTAMP; 3331 3330 break; 3332 3331 default: 3333 3332 new_offloads |= ENETC_F_RX_TSTAMP; 3334 - config.rx_filter = HWTSTAMP_FILTER_ALL; 3333 + config->rx_filter = HWTSTAMP_FILTER_ALL; 3335 3334 } 3336 3335 3337 3336 if ((new_offloads ^ priv->active_offloads) & ENETC_F_RX_TSTAMP) { ··· 3344 3343 3345 3344 priv->active_offloads = new_offloads; 3346 3345 3347 - return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? 3348 - -EFAULT : 0; 3346 + return 0; 3349 3347 } 3348 + EXPORT_SYMBOL_GPL(enetc_hwtstamp_set); 3350 3349 3351 - static int enetc_hwtstamp_get(struct net_device *ndev, struct ifreq *ifr) 3350 + int enetc_hwtstamp_get(struct net_device *ndev, 3351 + struct kernel_hwtstamp_config *config) 3352 3352 { 3353 3353 struct enetc_ndev_priv *priv = netdev_priv(ndev); 3354 - struct hwtstamp_config config; 3355 3354 3356 - config.flags = 0; 3355 + if (!IS_ENABLED(CONFIG_FSL_ENETC_PTP_CLOCK)) 3356 + return -EOPNOTSUPP; 3357 3357 3358 3358 if (priv->active_offloads & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) 3359 - config.tx_type = HWTSTAMP_TX_ONESTEP_SYNC; 3359 + config->tx_type = HWTSTAMP_TX_ONESTEP_SYNC; 3360 3360 else if (priv->active_offloads & ENETC_F_TX_TSTAMP) 3361 - config.tx_type = HWTSTAMP_TX_ON; 3361 + config->tx_type = HWTSTAMP_TX_ON; 3362 3362 else 3363 - config.tx_type = HWTSTAMP_TX_OFF; 3363 + config->tx_type = HWTSTAMP_TX_OFF; 3364 3364 3365 - config.rx_filter = (priv->active_offloads & ENETC_F_RX_TSTAMP) ? 3366 - HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE; 3365 + config->rx_filter = (priv->active_offloads & ENETC_F_RX_TSTAMP) ? 3366 + HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE; 3367 3367 3368 - return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? 3369 - -EFAULT : 0; 3368 + return 0; 3370 3369 } 3370 + EXPORT_SYMBOL_GPL(enetc_hwtstamp_get); 3371 3371 3372 3372 int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) 3373 3373 { 3374 3374 struct enetc_ndev_priv *priv = netdev_priv(ndev); 3375 - 3376 - if (IS_ENABLED(CONFIG_FSL_ENETC_PTP_CLOCK)) { 3377 - if (cmd == SIOCSHWTSTAMP) 3378 - return enetc_hwtstamp_set(ndev, rq); 3379 - if (cmd == SIOCGHWTSTAMP) 3380 - return enetc_hwtstamp_get(ndev, rq); 3381 - } 3382 3375 3383 3376 if (!priv->phylink) 3384 3377 return -EOPNOTSUPP;
+6
drivers/net/ethernet/freescale/enetc/enetc.h
··· 518 518 int enetc_xdp_xmit(struct net_device *ndev, int num_frames, 519 519 struct xdp_frame **frames, u32 flags); 520 520 521 + int enetc_hwtstamp_get(struct net_device *ndev, 522 + struct kernel_hwtstamp_config *config); 523 + int enetc_hwtstamp_set(struct net_device *ndev, 524 + struct kernel_hwtstamp_config *config, 525 + struct netlink_ext_ack *extack); 526 + 521 527 /* ethtool */ 522 528 extern const struct ethtool_ops enetc_pf_ethtool_ops; 523 529 extern const struct ethtool_ops enetc4_pf_ethtool_ops;
+2
drivers/net/ethernet/freescale/enetc/enetc_pf.c
··· 631 631 .ndo_setup_tc = enetc_pf_setup_tc, 632 632 .ndo_bpf = enetc_setup_bpf, 633 633 .ndo_xdp_xmit = enetc_xdp_xmit, 634 + .ndo_hwtstamp_get = enetc_hwtstamp_get, 635 + .ndo_hwtstamp_set = enetc_hwtstamp_set, 634 636 }; 635 637 636 638 static struct phylink_pcs *
+2
drivers/net/ethernet/freescale/enetc/enetc_vf.c
··· 121 121 .ndo_set_features = enetc_vf_set_features, 122 122 .ndo_eth_ioctl = enetc_ioctl, 123 123 .ndo_setup_tc = enetc_vf_setup_tc, 124 + .ndo_hwtstamp_get = enetc_hwtstamp_get, 125 + .ndo_hwtstamp_set = enetc_hwtstamp_set, 124 126 }; 125 127 126 128 static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev,