]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: enetc: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Mon, 12 May 2025 11:24:02 +0000 (14:24 +0300)
committerJakub Kicinski <kuba@kernel.org>
Tue, 13 May 2025 22:38:53 +0000 (15:38 -0700)
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>
drivers/net/ethernet/freescale/enetc/enetc.c
drivers/net/ethernet/freescale/enetc/enetc.h
drivers/net/ethernet/freescale/enetc/enetc_pf.c
drivers/net/ethernet/freescale/enetc/enetc_vf.c

index 7e92dc0a9a4974906c471f1dd6d677a7d6a83cd8..dcc3fbac3481fa3790226d6f217f69742564e5fb 100644 (file)
@@ -3296,16 +3296,17 @@ void enetc_set_features(struct net_device *ndev, netdev_features_t features)
 }
 EXPORT_SYMBOL_GPL(enetc_set_features);
 
-static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr)
+int enetc_hwtstamp_set(struct net_device *ndev,
+                      struct kernel_hwtstamp_config *config,
+                      struct netlink_ext_ack *extack)
 {
        struct enetc_ndev_priv *priv = netdev_priv(ndev);
        int err, new_offloads = priv->active_offloads;
-       struct hwtstamp_config config;
 
-       if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
-               return -EFAULT;
+       if (!IS_ENABLED(CONFIG_FSL_ENETC_PTP_CLOCK))
+               return -EOPNOTSUPP;
 
-       switch (config.tx_type) {
+       switch (config->tx_type) {
        case HWTSTAMP_TX_OFF:
                new_offloads &= ~ENETC_F_TX_TSTAMP_MASK;
                break;
@@ -3324,13 +3325,13 @@ static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr)
                return -ERANGE;
        }
 
-       switch (config.rx_filter) {
+       switch (config->rx_filter) {
        case HWTSTAMP_FILTER_NONE:
                new_offloads &= ~ENETC_F_RX_TSTAMP;
                break;
        default:
                new_offloads |= ENETC_F_RX_TSTAMP;
-               config.rx_filter = HWTSTAMP_FILTER_ALL;
+               config->rx_filter = HWTSTAMP_FILTER_ALL;
        }
 
        if ((new_offloads ^ priv->active_offloads) & ENETC_F_RX_TSTAMP) {
@@ -3343,42 +3344,36 @@ static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr)
 
        priv->active_offloads = new_offloads;
 
-       return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
-              -EFAULT : 0;
+       return 0;
 }
+EXPORT_SYMBOL_GPL(enetc_hwtstamp_set);
 
-static int enetc_hwtstamp_get(struct net_device *ndev, struct ifreq *ifr)
+int enetc_hwtstamp_get(struct net_device *ndev,
+                      struct kernel_hwtstamp_config *config)
 {
        struct enetc_ndev_priv *priv = netdev_priv(ndev);
-       struct hwtstamp_config config;
 
-       config.flags = 0;
+       if (!IS_ENABLED(CONFIG_FSL_ENETC_PTP_CLOCK))
+               return -EOPNOTSUPP;
 
        if (priv->active_offloads & ENETC_F_TX_ONESTEP_SYNC_TSTAMP)
-               config.tx_type = HWTSTAMP_TX_ONESTEP_SYNC;
+               config->tx_type = HWTSTAMP_TX_ONESTEP_SYNC;
        else if (priv->active_offloads & ENETC_F_TX_TSTAMP)
-               config.tx_type = HWTSTAMP_TX_ON;
+               config->tx_type = HWTSTAMP_TX_ON;
        else
-               config.tx_type = HWTSTAMP_TX_OFF;
+               config->tx_type = HWTSTAMP_TX_OFF;
 
-       config.rx_filter = (priv->active_offloads & ENETC_F_RX_TSTAMP) ?
-                           HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE;
+       config->rx_filter = (priv->active_offloads & ENETC_F_RX_TSTAMP) ?
+                            HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE;
 
-       return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
-              -EFAULT : 0;
+       return 0;
 }
+EXPORT_SYMBOL_GPL(enetc_hwtstamp_get);
 
 int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
 {
        struct enetc_ndev_priv *priv = netdev_priv(ndev);
 
-       if (IS_ENABLED(CONFIG_FSL_ENETC_PTP_CLOCK)) {
-               if (cmd == SIOCSHWTSTAMP)
-                       return enetc_hwtstamp_set(ndev, rq);
-               if (cmd == SIOCGHWTSTAMP)
-                       return enetc_hwtstamp_get(ndev, rq);
-       }
-
        if (!priv->phylink)
                return -EOPNOTSUPP;
 
index 7b24f1a5969aa85631d65cb25716b24d14c664f2..872d2cbd088b191661bb499eb4b5fd61e57a152f 100644 (file)
@@ -518,6 +518,12 @@ int enetc_setup_bpf(struct net_device *ndev, struct netdev_bpf *bpf);
 int enetc_xdp_xmit(struct net_device *ndev, int num_frames,
                   struct xdp_frame **frames, u32 flags);
 
+int enetc_hwtstamp_get(struct net_device *ndev,
+                      struct kernel_hwtstamp_config *config);
+int enetc_hwtstamp_set(struct net_device *ndev,
+                      struct kernel_hwtstamp_config *config,
+                      struct netlink_ext_ack *extack);
+
 /* ethtool */
 extern const struct ethtool_ops enetc_pf_ethtool_ops;
 extern const struct ethtool_ops enetc4_pf_ethtool_ops;
index 6560bdbff287cba64b80a2252c89122d461ce55e..f63a29e2e0311dbb4eadb99ed19102f341e6b327 100644 (file)
@@ -631,6 +631,8 @@ static const struct net_device_ops enetc_ndev_ops = {
        .ndo_setup_tc           = enetc_pf_setup_tc,
        .ndo_bpf                = enetc_setup_bpf,
        .ndo_xdp_xmit           = enetc_xdp_xmit,
+       .ndo_hwtstamp_get       = enetc_hwtstamp_get,
+       .ndo_hwtstamp_set       = enetc_hwtstamp_set,
 };
 
 static struct phylink_pcs *
index f6aed0a1ad1e24fe1665d14556734c2b0cac419a..6c4b374bcb0ef14284d2ea153d8bd4112fe5309a 100644 (file)
@@ -121,6 +121,8 @@ static const struct net_device_ops enetc_ndev_ops = {
        .ndo_set_features       = enetc_vf_set_features,
        .ndo_eth_ioctl          = enetc_ioctl,
        .ndo_setup_tc           = enetc_vf_setup_tc,
+       .ndo_hwtstamp_get       = enetc_hwtstamp_get,
+       .ndo_hwtstamp_set       = enetc_hwtstamp_set,
 };
 
 static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev,