]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: fec: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 1 Aug 2023 14:28:18 +0000 (17:28 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 3 Aug 2023 02:11:06 +0000 (19:11 -0700)
The hardware timestamping through ndo_eth_ioctl() is going away.
Convert the FEC driver to the new API before that can be removed.

After removing the timestamping logic from fec_enet_ioctl(), the rest
is equivalent to phy_do_ioctl_running().

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Wei Fang <wei.fang@nxp.com>
Link: https://lore.kernel.org/r/20230801142824.1772134-7-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/freescale/fec.h
drivers/net/ethernet/freescale/fec_main.c
drivers/net/ethernet/freescale/fec_ptp.c

index 8f1edcca96c49a86dd09cef756240c2adee6491d..ec64067ca782e1638f8fccc46b2f061392ee2b02 100644 (file)
@@ -699,8 +699,9 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx);
 void fec_ptp_stop(struct platform_device *pdev);
 void fec_ptp_start_cyclecounter(struct net_device *ndev);
 void fec_ptp_disable_hwts(struct net_device *ndev);
-int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr);
-int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr);
+int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config,
+               struct netlink_ext_ack *extack);
+void fec_ptp_get(struct net_device *ndev, struct kernel_hwtstamp_config *config);
 
 /****************************************************************************/
 #endif /* FEC_H */
index 14d0dc7ba3c9895dd38b4c59869189cd85942835..bbd0cc97905a0ada3c90d95c65d56c6f17f3dc2d 100644 (file)
@@ -3203,33 +3203,6 @@ static const struct ethtool_ops fec_enet_ethtool_ops = {
        .self_test              = net_selftest,
 };
 
-static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
-{
-       struct fec_enet_private *fep = netdev_priv(ndev);
-       struct phy_device *phydev = ndev->phydev;
-
-       if (!netif_running(ndev))
-               return -EINVAL;
-
-       if (!phydev)
-               return -ENODEV;
-
-       if (fep->bufdesc_ex) {
-               bool use_fec_hwts = !phy_has_hwtstamp(phydev);
-
-               if (cmd == SIOCSHWTSTAMP) {
-                       if (use_fec_hwts)
-                               return fec_ptp_set(ndev, rq);
-                       fec_ptp_disable_hwts(ndev);
-               } else if (cmd == SIOCGHWTSTAMP) {
-                       if (use_fec_hwts)
-                               return fec_ptp_get(ndev, rq);
-               }
-       }
-
-       return phy_mii_ioctl(phydev, rq, cmd);
-}
-
 static void fec_enet_free_buffers(struct net_device *ndev)
 {
        struct fec_enet_private *fep = netdev_priv(ndev);
@@ -3895,6 +3868,48 @@ static int fec_enet_xdp_xmit(struct net_device *dev,
        return sent_frames;
 }
 
+static int fec_hwtstamp_get(struct net_device *ndev,
+                           struct kernel_hwtstamp_config *config)
+{
+       struct fec_enet_private *fep = netdev_priv(ndev);
+       struct phy_device *phydev = ndev->phydev;
+
+       if (phy_has_hwtstamp(phydev))
+               return phy_mii_ioctl(phydev, config->ifr, SIOCGHWTSTAMP);
+
+       if (!netif_running(ndev))
+               return -EINVAL;
+
+       if (!fep->bufdesc_ex)
+               return -EOPNOTSUPP;
+
+       fec_ptp_get(ndev, config);
+
+       return 0;
+}
+
+static int fec_hwtstamp_set(struct net_device *ndev,
+                           struct kernel_hwtstamp_config *config,
+                           struct netlink_ext_ack *extack)
+{
+       struct fec_enet_private *fep = netdev_priv(ndev);
+       struct phy_device *phydev = ndev->phydev;
+
+       if (phy_has_hwtstamp(phydev)) {
+               fec_ptp_disable_hwts(ndev);
+
+               return phy_mii_ioctl(phydev, config->ifr, SIOCSHWTSTAMP);
+       }
+
+       if (!netif_running(ndev))
+               return -EINVAL;
+
+       if (!fep->bufdesc_ex)
+               return -EOPNOTSUPP;
+
+       return fec_ptp_set(ndev, config, extack);
+}
+
 static const struct net_device_ops fec_netdev_ops = {
        .ndo_open               = fec_enet_open,
        .ndo_stop               = fec_enet_close,
@@ -3904,13 +3919,15 @@ static const struct net_device_ops fec_netdev_ops = {
        .ndo_validate_addr      = eth_validate_addr,
        .ndo_tx_timeout         = fec_timeout,
        .ndo_set_mac_address    = fec_set_mac_address,
-       .ndo_eth_ioctl          = fec_enet_ioctl,
+       .ndo_eth_ioctl          = phy_do_ioctl_running,
 #ifdef CONFIG_NET_POLL_CONTROLLER
        .ndo_poll_controller    = fec_poll_controller,
 #endif
        .ndo_set_features       = fec_set_features,
        .ndo_bpf                = fec_enet_bpf,
        .ndo_xdp_xmit           = fec_enet_xdp_xmit,
+       .ndo_hwtstamp_get       = fec_hwtstamp_get,
+       .ndo_hwtstamp_set       = fec_hwtstamp_set,
 };
 
 static const unsigned short offset_des_active_rxq[] = {
index fc4674cb65be50b7520303ddefe4361b67a9a944..befd49b8bd718a32fb0aed021d83964e75c08ec0 100644 (file)
@@ -617,16 +617,12 @@ void fec_ptp_disable_hwts(struct net_device *ndev)
        fep->hwts_rx_en = 0;
 }
 
-int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr)
+int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config,
+               struct netlink_ext_ack *extack)
 {
        struct fec_enet_private *fep = netdev_priv(ndev);
 
-       struct hwtstamp_config config;
-
-       if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
-               return -EFAULT;
-
-       switch (config.tx_type) {
+       switch (config->tx_type) {
        case HWTSTAMP_TX_OFF:
                fep->hwts_tx_en = 0;
                break;
@@ -637,33 +633,28 @@ int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr)
                return -ERANGE;
        }
 
-       switch (config.rx_filter) {
+       switch (config->rx_filter) {
        case HWTSTAMP_FILTER_NONE:
                fep->hwts_rx_en = 0;
                break;
 
        default:
                fep->hwts_rx_en = 1;
-               config.rx_filter = HWTSTAMP_FILTER_ALL;
+               config->rx_filter = HWTSTAMP_FILTER_ALL;
                break;
        }
 
-       return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
-           -EFAULT : 0;
+       return 0;
 }
 
-int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr)
+void fec_ptp_get(struct net_device *ndev, struct kernel_hwtstamp_config *config)
 {
        struct fec_enet_private *fep = netdev_priv(ndev);
-       struct hwtstamp_config config;
-
-       config.flags = 0;
-       config.tx_type = fep->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
-       config.rx_filter = (fep->hwts_rx_en ?
-                           HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
 
-       return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
-               -EFAULT : 0;
+       config->flags = 0;
+       config->tx_type = fep->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
+       config->rx_filter = (fep->hwts_rx_en ?
+                            HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
 }
 
 /*