net: macb: Convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
authorKory Maincent <kory.maincent@bootlin.com>
Tue, 14 Nov 2023 11:28:32 +0000 (12:28 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sat, 18 Nov 2023 14:52:57 +0000 (14:52 +0000)
The hardware timestamping through ndo_eth_ioctl() is going away.
Convert the macb driver to the new API before that can be removed.

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/cadence/macb.h
drivers/net/ethernet/cadence/macb_main.c
drivers/net/ethernet/cadence/macb_ptp.c

index 78c972bb1d962368ed0c62b5f3d28e47047f1b34..aa5700ac9c00ee79e5003dc60a996dd5c06310b7 100644 (file)
@@ -1165,9 +1165,10 @@ struct macb_ptp_info {
        int (*get_ts_info)(struct net_device *dev,
                           struct ethtool_ts_info *info);
        int (*get_hwtst)(struct net_device *netdev,
-                        struct ifreq *ifr);
+                        struct kernel_hwtstamp_config *tstamp_config);
        int (*set_hwtst)(struct net_device *netdev,
-                        struct ifreq *ifr, int cmd);
+                        struct kernel_hwtstamp_config *tstamp_config,
+                        struct netlink_ext_ack *extack);
 };
 
 struct macb_pm_data {
@@ -1314,7 +1315,7 @@ struct macb {
        struct ptp_clock *ptp_clock;
        struct ptp_clock_info ptp_clock_info;
        struct tsu_incr tsu_incr;
-       struct hwtstamp_config tstamp_config;
+       struct kernel_hwtstamp_config tstamp_config;
 
        /* RX queue filer rule set*/
        struct ethtool_rx_fs_list rx_fs_list;
@@ -1363,8 +1364,12 @@ static inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, stru
 
        gem_ptp_rxstamp(bp, skb, desc);
 }
-int gem_get_hwtst(struct net_device *dev, struct ifreq *rq);
-int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd);
+
+int gem_get_hwtst(struct net_device *dev,
+                 struct kernel_hwtstamp_config *tstamp_config);
+int gem_set_hwtst(struct net_device *dev,
+                 struct kernel_hwtstamp_config *tstamp_config,
+                 struct netlink_ext_ack *extack);
 #else
 static inline void gem_ptp_init(struct net_device *ndev) { }
 static inline void gem_ptp_remove(struct net_device *ndev) { }
index cebae0f418f2f27c1493e4b0ac87b5ec21237799..898debfd4db36ac7792cef5db9e5436ea348c320 100644 (file)
@@ -3773,18 +3773,38 @@ static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        if (!netif_running(dev))
                return -EINVAL;
 
-       if (bp->ptp_info) {
-               switch (cmd) {
-               case SIOCSHWTSTAMP:
-                       return bp->ptp_info->set_hwtst(dev, rq, cmd);
-               case SIOCGHWTSTAMP:
-                       return bp->ptp_info->get_hwtst(dev, rq);
-               }
-       }
-
        return phylink_mii_ioctl(bp->phylink, rq, cmd);
 }
 
+static int macb_hwtstamp_get(struct net_device *dev,
+                            struct kernel_hwtstamp_config *cfg)
+{
+       struct macb *bp = netdev_priv(dev);
+
+       if (!netif_running(dev))
+               return -EINVAL;
+
+       if (!bp->ptp_info)
+               return -EOPNOTSUPP;
+
+       return bp->ptp_info->get_hwtst(dev, cfg);
+}
+
+static int macb_hwtstamp_set(struct net_device *dev,
+                            struct kernel_hwtstamp_config *cfg,
+                            struct netlink_ext_ack *extack)
+{
+       struct macb *bp = netdev_priv(dev);
+
+       if (!netif_running(dev))
+               return -EINVAL;
+
+       if (!bp->ptp_info)
+               return -EOPNOTSUPP;
+
+       return bp->ptp_info->set_hwtst(dev, cfg, extack);
+}
+
 static inline void macb_set_txcsum_feature(struct macb *bp,
                                           netdev_features_t features)
 {
@@ -3884,6 +3904,8 @@ static const struct net_device_ops macb_netdev_ops = {
 #endif
        .ndo_set_features       = macb_set_features,
        .ndo_features_check     = macb_features_check,
+       .ndo_hwtstamp_set       = macb_hwtstamp_set,
+       .ndo_hwtstamp_get       = macb_hwtstamp_get,
 };
 
 /* Configure peripheral capabilities according to device tree
@@ -4539,6 +4561,8 @@ static const struct net_device_ops at91ether_netdev_ops = {
 #ifdef CONFIG_NET_POLL_CONTROLLER
        .ndo_poll_controller    = at91ether_poll_controller,
 #endif
+       .ndo_hwtstamp_set       = macb_hwtstamp_set,
+       .ndo_hwtstamp_get       = macb_hwtstamp_get,
 };
 
 static int at91ether_clk_init(struct platform_device *pdev, struct clk **pclk,
index 51d26fa190d7d1368fb83fd25a5bec5449344580..a63bf29c4fa81b95f10aec8b8fe9918022e196d6 100644 (file)
@@ -374,19 +374,16 @@ static int gem_ptp_set_ts_mode(struct macb *bp,
        return 0;
 }
 
-int gem_get_hwtst(struct net_device *dev, struct ifreq *rq)
+int gem_get_hwtst(struct net_device *dev,
+                 struct kernel_hwtstamp_config *tstamp_config)
 {
-       struct hwtstamp_config *tstamp_config;
        struct macb *bp = netdev_priv(dev);
 
-       tstamp_config = &bp->tstamp_config;
+       *tstamp_config = bp->tstamp_config;
        if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) == 0)
                return -EOPNOTSUPP;
 
-       if (copy_to_user(rq->ifr_data, tstamp_config, sizeof(*tstamp_config)))
-               return -EFAULT;
-       else
-               return 0;
+       return 0;
 }
 
 static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable)
@@ -401,22 +398,18 @@ static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable)
                macb_writel(bp, NCR, reg_val & ~MACB_BIT(OSSMODE));
 }
 
-int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd)
+int gem_set_hwtst(struct net_device *dev,
+                 struct kernel_hwtstamp_config *tstamp_config,
+                 struct netlink_ext_ack *extack)
 {
        enum macb_bd_control tx_bd_control = TSTAMP_DISABLED;
        enum macb_bd_control rx_bd_control = TSTAMP_DISABLED;
-       struct hwtstamp_config *tstamp_config;
        struct macb *bp = netdev_priv(dev);
        u32 regval;
 
-       tstamp_config = &bp->tstamp_config;
        if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) == 0)
                return -EOPNOTSUPP;
 
-       if (copy_from_user(tstamp_config, ifr->ifr_data,
-                          sizeof(*tstamp_config)))
-               return -EFAULT;
-
        switch (tstamp_config->tx_type) {
        case HWTSTAMP_TX_OFF:
                break;
@@ -463,12 +456,11 @@ int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd)
                return -ERANGE;
        }
 
+       bp->tstamp_config = *tstamp_config;
+
        if (gem_ptp_set_ts_mode(bp, tx_bd_control, rx_bd_control) != 0)
                return -ERANGE;
 
-       if (copy_to_user(ifr->ifr_data, tstamp_config, sizeof(*tstamp_config)))
-               return -EFAULT;
-       else
-               return 0;
+       return 0;
 }