]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: mvpp2: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Thu, 8 May 2025 14:46:30 +0000 (17:46 +0300)
committerJakub Kicinski <kuba@kernel.org>
Fri, 9 May 2025 23:43:41 +0000 (16:43 -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 mvpp2 driver to the new API, so that the
ndo_eth_ioctl() path can be removed completely.

Note that on the !port->hwtstamp condition, the old code used to fall
through in mvpp2_ioctl(), and return either -ENOTSUPP if !port->phylink,
or -EOPNOTSUPP, in phylink_mii_ioctl(). Keep the test for port->hwtstamp
in the newly introduced net_device_ops, but consolidate the error code
to just -EOPNOTSUPP. The other one is documented as NFS-specific, it's
best to avoid it anyway.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Link: https://patch.msgid.link/20250508144630.1979215-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c

index 416a926a8281760cf87a2a53204448740ae68bcd..a7872d14a49d60af0c4474962536f136051b2a6c 100644 (file)
@@ -5173,38 +5173,40 @@ mvpp2_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
        stats->tx_dropped       = dev->stats.tx_dropped;
 }
 
-static int mvpp2_set_ts_config(struct mvpp2_port *port, struct ifreq *ifr)
+static int mvpp2_hwtstamp_set(struct net_device *dev,
+                             struct kernel_hwtstamp_config *config,
+                             struct netlink_ext_ack *extack)
 {
-       struct hwtstamp_config config;
+       struct mvpp2_port *port = netdev_priv(dev);
        void __iomem *ptp;
        u32 gcr, int_mask;
 
-       if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
-               return -EFAULT;
+       if (!port->hwtstamp)
+               return -EOPNOTSUPP;
 
-       if (config.tx_type != HWTSTAMP_TX_OFF &&
-           config.tx_type != HWTSTAMP_TX_ON)
+       if (config->tx_type != HWTSTAMP_TX_OFF &&
+           config->tx_type != HWTSTAMP_TX_ON)
                return -ERANGE;
 
        ptp = port->priv->iface_base + MVPP22_PTP_BASE(port->gop_id);
 
        int_mask = gcr = 0;
-       if (config.tx_type != HWTSTAMP_TX_OFF) {
+       if (config->tx_type != HWTSTAMP_TX_OFF) {
                gcr |= MVPP22_PTP_GCR_TSU_ENABLE | MVPP22_PTP_GCR_TX_RESET;
                int_mask |= MVPP22_PTP_INT_MASK_QUEUE1 |
                            MVPP22_PTP_INT_MASK_QUEUE0;
        }
 
        /* It seems we must also release the TX reset when enabling the TSU */
-       if (config.rx_filter != HWTSTAMP_FILTER_NONE)
+       if (config->rx_filter != HWTSTAMP_FILTER_NONE)
                gcr |= MVPP22_PTP_GCR_TSU_ENABLE | MVPP22_PTP_GCR_RX_RESET |
                       MVPP22_PTP_GCR_TX_RESET;
 
        if (gcr & MVPP22_PTP_GCR_TSU_ENABLE)
                mvpp22_tai_start(port->priv->tai);
 
-       if (config.rx_filter != HWTSTAMP_FILTER_NONE) {
-               config.rx_filter = HWTSTAMP_FILTER_ALL;
+       if (config->rx_filter != HWTSTAMP_FILTER_NONE) {
+               config->rx_filter = HWTSTAMP_FILTER_ALL;
                mvpp2_modify(ptp + MVPP22_PTP_GCR,
                             MVPP22_PTP_GCR_RX_RESET |
                             MVPP22_PTP_GCR_TX_RESET |
@@ -5225,26 +5227,22 @@ static int mvpp2_set_ts_config(struct mvpp2_port *port, struct ifreq *ifr)
        if (!(gcr & MVPP22_PTP_GCR_TSU_ENABLE))
                mvpp22_tai_stop(port->priv->tai);
 
-       port->tx_hwtstamp_type = config.tx_type;
-
-       if (copy_to_user(ifr->ifr_data, &config, sizeof(config)))
-               return -EFAULT;
+       port->tx_hwtstamp_type = config->tx_type;
 
        return 0;
 }
 
-static int mvpp2_get_ts_config(struct mvpp2_port *port, struct ifreq *ifr)
+static int mvpp2_hwtstamp_get(struct net_device *dev,
+                             struct kernel_hwtstamp_config *config)
 {
-       struct hwtstamp_config config;
-
-       memset(&config, 0, sizeof(config));
+       struct mvpp2_port *port = netdev_priv(dev);
 
-       config.tx_type = port->tx_hwtstamp_type;
-       config.rx_filter = port->rx_hwtstamp ?
-               HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE;
+       if (!port->hwtstamp)
+               return -EOPNOTSUPP;
 
-       if (copy_to_user(ifr->ifr_data, &config, sizeof(config)))
-               return -EFAULT;
+       config->tx_type = port->tx_hwtstamp_type;
+       config->rx_filter = port->rx_hwtstamp ? HWTSTAMP_FILTER_ALL :
+                           HWTSTAMP_FILTER_NONE;
 
        return 0;
 }
@@ -5274,18 +5272,6 @@ static int mvpp2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
        struct mvpp2_port *port = netdev_priv(dev);
 
-       switch (cmd) {
-       case SIOCSHWTSTAMP:
-               if (port->hwtstamp)
-                       return mvpp2_set_ts_config(port, ifr);
-               break;
-
-       case SIOCGHWTSTAMP:
-               if (port->hwtstamp)
-                       return mvpp2_get_ts_config(port, ifr);
-               break;
-       }
-
        if (!port->phylink)
                return -ENOTSUPP;
 
@@ -5799,6 +5785,8 @@ static const struct net_device_ops mvpp2_netdev_ops = {
        .ndo_set_features       = mvpp2_set_features,
        .ndo_bpf                = mvpp2_xdp,
        .ndo_xdp_xmit           = mvpp2_xdp_xmit,
+       .ndo_hwtstamp_get       = mvpp2_hwtstamp_get,
+       .ndo_hwtstamp_set       = mvpp2_hwtstamp_set,
 };
 
 static const struct ethtool_ops mvpp2_eth_tool_ops = {