net: sparx5: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 1 Aug 2023 14:28:20 +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 sparx5 driver to the new API before that can be removed.

After removing the timestamping logic from sparx5_port_ioctl(), the rest
is equivalent to phy_do_ioctl().

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>
Link: https://lore.kernel.org/r/20230801142824.1772134-9-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/microchip/sparx5/sparx5_main.h
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c

index 62c8546..89a9a7a 100644 (file)
@@ -205,7 +205,7 @@ enum sparx5_core_clockfreq {
 struct sparx5_phc {
        struct ptp_clock *clock;
        struct ptp_clock_info info;
-       struct hwtstamp_config hwtstamp_config;
+       struct kernel_hwtstamp_config hwtstamp_config;
        struct sparx5 *sparx5;
        u8 index;
 };
@@ -388,8 +388,11 @@ void sparx5_unregister_netdevs(struct sparx5 *sparx5);
 /* sparx5_ptp.c */
 int sparx5_ptp_init(struct sparx5 *sparx5);
 void sparx5_ptp_deinit(struct sparx5 *sparx5);
-int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr);
-int sparx5_ptp_hwtstamp_get(struct sparx5_port *port, struct ifreq *ifr);
+int sparx5_ptp_hwtstamp_set(struct sparx5_port *port,
+                           struct kernel_hwtstamp_config *cfg,
+                           struct netlink_ext_ack *extack);
+void sparx5_ptp_hwtstamp_get(struct sparx5_port *port,
+                            struct kernel_hwtstamp_config *cfg);
 void sparx5_ptp_rxtstamp(struct sparx5 *sparx5, struct sk_buff *skb,
                         u64 timestamp);
 int sparx5_ptp_txtstamp_request(struct sparx5_port *port,
index d078156..e01d3b1 100644 (file)
@@ -210,22 +210,37 @@ static int sparx5_get_port_parent_id(struct net_device *dev,
        return 0;
 }
 
-static int sparx5_port_ioctl(struct net_device *dev, struct ifreq *ifr,
-                            int cmd)
+static int sparx5_port_hwtstamp_get(struct net_device *dev,
+                                   struct kernel_hwtstamp_config *cfg)
 {
        struct sparx5_port *sparx5_port = netdev_priv(dev);
        struct sparx5 *sparx5 = sparx5_port->sparx5;
 
-       if (!phy_has_hwtstamp(dev->phydev) && sparx5->ptp) {
-               switch (cmd) {
-               case SIOCSHWTSTAMP:
-                       return sparx5_ptp_hwtstamp_set(sparx5_port, ifr);
-               case SIOCGHWTSTAMP:
-                       return sparx5_ptp_hwtstamp_get(sparx5_port, ifr);
-               }
-       }
+       if (phy_has_hwtstamp(dev->phydev))
+               return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCGHWTSTAMP);
+
+       if (!sparx5->ptp)
+               return -EOPNOTSUPP;
+
+       sparx5_ptp_hwtstamp_get(sparx5_port, cfg);
+
+       return 0;
+}
+
+static int sparx5_port_hwtstamp_set(struct net_device *dev,
+                                   struct kernel_hwtstamp_config *cfg,
+                                   struct netlink_ext_ack *extack)
+{
+       struct sparx5_port *sparx5_port = netdev_priv(dev);
+       struct sparx5 *sparx5 = sparx5_port->sparx5;
+
+       if (phy_has_hwtstamp(dev->phydev))
+               return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCSHWTSTAMP);
+
+       if (!sparx5->ptp)
+               return -EOPNOTSUPP;
 
-       return phy_mii_ioctl(dev->phydev, ifr, cmd);
+       return sparx5_ptp_hwtstamp_set(sparx5_port, cfg, extack);
 }
 
 static const struct net_device_ops sparx5_port_netdev_ops = {
@@ -238,8 +253,10 @@ static const struct net_device_ops sparx5_port_netdev_ops = {
        .ndo_validate_addr      = eth_validate_addr,
        .ndo_get_stats64        = sparx5_get_stats64,
        .ndo_get_port_parent_id = sparx5_get_port_parent_id,
-       .ndo_eth_ioctl          = sparx5_port_ioctl,
+       .ndo_eth_ioctl          = phy_do_ioctl,
        .ndo_setup_tc           = sparx5_port_setup_tc,
+       .ndo_hwtstamp_get       = sparx5_port_hwtstamp_get,
+       .ndo_hwtstamp_set       = sparx5_port_hwtstamp_set,
 };
 
 bool sparx5_netdevice_check(const struct net_device *dev)
index 0edb98c..5a93246 100644 (file)
@@ -74,10 +74,11 @@ static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5)
        return res;
 }
 
-int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
+int sparx5_ptp_hwtstamp_set(struct sparx5_port *port,
+                           struct kernel_hwtstamp_config *cfg,
+                           struct netlink_ext_ack *extack)
 {
        struct sparx5 *sparx5 = port->sparx5;
-       struct hwtstamp_config cfg;
        struct sparx5_phc *phc;
 
        /* For now don't allow to run ptp on ports that are part of a bridge,
@@ -88,10 +89,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
        if (test_bit(port->portno, sparx5->bridge_mask))
                return -EINVAL;
 
-       if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
-               return -EFAULT;
-
-       switch (cfg.tx_type) {
+       switch (cfg->tx_type) {
        case HWTSTAMP_TX_ON:
                port->ptp_cmd = IFH_REW_OP_TWO_STEP_PTP;
                break;
@@ -105,7 +103,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
                return -ERANGE;
        }
 
-       switch (cfg.rx_filter) {
+       switch (cfg->rx_filter) {
        case HWTSTAMP_FILTER_NONE:
                break;
        case HWTSTAMP_FILTER_ALL:
@@ -122,7 +120,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
        case HWTSTAMP_FILTER_PTP_V2_SYNC:
        case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
        case HWTSTAMP_FILTER_NTP_ALL:
-               cfg.rx_filter = HWTSTAMP_FILTER_ALL;
+               cfg->rx_filter = HWTSTAMP_FILTER_ALL;
                break;
        default:
                return -ERANGE;
@@ -131,20 +129,20 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
        /* Commit back the result & save it */
        mutex_lock(&sparx5->ptp_lock);
        phc = &sparx5->phc[SPARX5_PHC_PORT];
-       memcpy(&phc->hwtstamp_config, &cfg, sizeof(cfg));
+       phc->hwtstamp_config = *cfg;
        mutex_unlock(&sparx5->ptp_lock);
 
-       return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
+       return 0;
 }
 
-int sparx5_ptp_hwtstamp_get(struct sparx5_port *port, struct ifreq *ifr)
+void sparx5_ptp_hwtstamp_get(struct sparx5_port *port,
+                            struct kernel_hwtstamp_config *cfg)
 {
        struct sparx5 *sparx5 = port->sparx5;
        struct sparx5_phc *phc;
 
        phc = &sparx5->phc[SPARX5_PHC_PORT];
-       return copy_to_user(ifr->ifr_data, &phc->hwtstamp_config,
-                           sizeof(phc->hwtstamp_config)) ? -EFAULT : 0;
+       *cfg = phc->hwtstamp_config;
 }
 
 static void sparx5_ptp_classify(struct sparx5_port *port, struct sk_buff *skb,