diff mbox series

[v7,net-next,06/10] net: fec: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()

Message ID 20230713121907.3249291-7-vladimir.oltean@nxp.com (mailing list archive)
State New, archived
Headers show
Series Introduce ndo_hwtstamp_get() and ndo_hwtstamp_set() | expand

Commit Message

Vladimir Oltean July 13, 2023, 12:19 p.m. UTC
The hardware timestamping through ndo_eth_ioctl() is going away.
Convert the FEC driver to the new API before that can be removed.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
Changes in v7:
- Patch is new

 drivers/net/ethernet/freescale/fec.h      |  5 ++-
 drivers/net/ethernet/freescale/fec_main.c | 52 +++++++++++++++++------
 drivers/net/ethernet/freescale/fec_ptp.c  | 31 +++++---------
 3 files changed, 52 insertions(+), 36 deletions(-)

Comments

Wei Fang July 14, 2023, 3:05 a.m. UTC | #1
> -----Original Message-----
> From: Vladimir Oltean <vladimir.oltean@nxp.com>
> Sent: 2023年7月13日 20:19
> To: netdev@vger.kernel.org
> Cc: David S. Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Andrew Lunn <andrew@lunn.ch>; Florian Fainelli
> <f.fainelli@gmail.com>; Maxim Georgiev <glipus@gmail.com>; Horatiu Vultur
> <horatiu.vultur@microchip.com>; Köry Maincent
> <kory.maincent@bootlin.com>; Maxime Chevallier
> <maxime.chevallier@bootlin.com>; Richard Cochran
> <richardcochran@gmail.com>; Vadim Fedorenko
> <vadim.fedorenko@linux.dev>; Gerhard Engleder
> <gerhard@engleder-embedded.com>; Hangbin Liu <liuhangbin@gmail.com>;
> Russell King <linux@armlinux.org.uk>; Heiner Kallweit
> <hkallweit1@gmail.com>; Jacob Keller <jacob.e.keller@intel.com>; Jay
> Vosburgh <j.vosburgh@gmail.com>; Andy Gospodarek <andy@greyhouse.net>;
> Wei Fang <wei.fang@nxp.com>; Shenwei Wang <shenwei.wang@nxp.com>;
> Clark Wang <xiaoning.wang@nxp.com>; dl-linux-imx <linux-imx@nxp.com>;
> UNGLinuxDriver@microchip.com; Lars Povlsen <lars.povlsen@microchip.com>;
> Steen Hegelund <Steen.Hegelund@microchip.com>; Daniel Machon
> <daniel.machon@microchip.com>; Simon Horman
> <simon.horman@corigine.com>; Casper Andersson
> <casper.casan@gmail.com>; Sergey Organov <sorganov@gmail.com>;
> linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org
> Subject: [PATCH v7 net-next 06/10] net: fec: convert to ndo_hwtstamp_get()
> and ndo_hwtstamp_set()
> 
> The hardware timestamping through ndo_eth_ioctl() is going away.
> Convert the FEC driver to the new API before that can be removed.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
> Changes in v7:
> - Patch is new
> 
>  drivers/net/ethernet/freescale/fec.h      |  5 ++-
>  drivers/net/ethernet/freescale/fec_main.c | 52 +++++++++++++++++------
> drivers/net/ethernet/freescale/fec_ptp.c  | 31 +++++---------
>  3 files changed, 52 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/fec.h
> b/drivers/net/ethernet/freescale/fec.h
> index 9939ccafb556..d4ae0e7c0a44 100644
> --- a/drivers/net/ethernet/freescale/fec.h
> +++ b/drivers/net/ethernet/freescale/fec.h
> @@ -691,8 +691,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 */
> diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> index 1280da699fa3..c0b68fc3ec8b 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -3196,7 +3196,6 @@ static const struct ethtool_ops
> fec_enet_ethtool_ops = {
> 
>  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))
> @@ -3205,19 +3204,6 @@ static int fec_enet_ioctl(struct net_device *ndev,
> struct ifreq *rq, int cmd)
>  	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);  }
> 
> @@ -3868,6 +3854,42 @@ 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 (!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 (!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,
> @@ -3884,6 +3906,8 @@ static const struct net_device_ops fec_netdev_ops =
> {
>  	.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[] = { diff --git
> a/drivers/net/ethernet/freescale/fec_ptp.c
> b/drivers/net/ethernet/freescale/fec_ptp.c
> index ab86bb8562ef..3f53b8ae57dd 100644
> --- a/drivers/net/ethernet/freescale/fec_ptp.c
> +++ b/drivers/net/ethernet/freescale/fec_ptp.c
> @@ -618,16 +618,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;
> @@ -638,33 +634,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);
>  }
> 
>  /*
> --
> 2.34.1

Thanks!
Reviewed-by: Wei Fang < wei.fang@nxp.com >
Russell King (Oracle) July 14, 2023, 8:47 a.m. UTC | #2
On Fri, Jul 14, 2023 at 03:05:36AM +0000, Wei Fang wrote:
> Thanks!
> Reviewed-by: Wei Fang < wei.fang@nxp.com >

Please note that correct formatting is:

Reviewed-by: Wei Fang <wei.fang@nxp.com>

No spaces between the <> and the email address itself. It's exactly the
same format used in email headers on the Internet.
Wei Fang July 14, 2023, 9:08 a.m. UTC | #3
> -----Original Message-----
> From: Russell King <linux@armlinux.org.uk>
> Sent: 2023年7月14日 16:48
> To: Wei Fang <wei.fang@nxp.com>
> Cc: Vladimir Oltean <vladimir.oltean@nxp.com>; netdev@vger.kernel.org;
> David S. Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Andrew Lunn <andrew@lunn.ch>; Florian Fainelli
> <f.fainelli@gmail.com>; Maxim Georgiev <glipus@gmail.com>; Horatiu Vultur
> <horatiu.vultur@microchip.com>; Köry Maincent
> <kory.maincent@bootlin.com>; Maxime Chevallier
> <maxime.chevallier@bootlin.com>; Richard Cochran
> <richardcochran@gmail.com>; Vadim Fedorenko
> <vadim.fedorenko@linux.dev>; Gerhard Engleder
> <gerhard@engleder-embedded.com>; Hangbin Liu <liuhangbin@gmail.com>;
> Heiner Kallweit <hkallweit1@gmail.com>; Jacob Keller
> <jacob.e.keller@intel.com>; Jay Vosburgh <j.vosburgh@gmail.com>; Andy
> Gospodarek <andy@greyhouse.net>; Shenwei Wang
> <shenwei.wang@nxp.com>; Clark Wang <xiaoning.wang@nxp.com>;
> dl-linux-imx <linux-imx@nxp.com>; UNGLinuxDriver@microchip.com; Lars
> Povlsen <lars.povlsen@microchip.com>; Steen Hegelund
> <Steen.Hegelund@microchip.com>; Daniel Machon
> <daniel.machon@microchip.com>; Simon Horman
> <simon.horman@corigine.com>; Casper Andersson
> <casper.casan@gmail.com>; Sergey Organov <sorganov@gmail.com>;
> linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v7 net-next 06/10] net: fec: convert to
> ndo_hwtstamp_get() and ndo_hwtstamp_set()
>
> On Fri, Jul 14, 2023 at 03:05:36AM +0000, Wei Fang wrote:
> > Thanks!
> > Reviewed-by: Wei Fang < wei.fang@nxp.com >
>
> Please note that correct formatting is:
>
> Reviewed-by: Wei Fang <wei.fang@nxp.com>
>
> No spaces between the <> and the email address itself. It's exactly the same
> format used in email headers on the Internet.
>
Sorry for the typo, I should check before replying. :(
> --
> RMK's Patch system:
> https://www.ar/
> mlinux.org.uk%2Fdeveloper%2Fpatches%2F&data=05%7C01%7Cwei.fang%40
> nxp.com%7C60545ab70c1248b65d7608db84470e9a%7C686ea1d3bc2b4c6fa
> 92cd99c5c301635%7C0%7C0%7C638249212939844945%7CUnknown%7CT
> WFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJ
> XVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=422jsG%2Bd31ymJvT%2FBkntso
> Q8BI%2B7dzd0Fczwb2Qm4B0%3D&reserved=0
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 9939ccafb556..d4ae0e7c0a44 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -691,8 +691,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 */
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 1280da699fa3..c0b68fc3ec8b 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -3196,7 +3196,6 @@  static const struct ethtool_ops fec_enet_ethtool_ops = {
 
 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))
@@ -3205,19 +3204,6 @@  static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
 	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);
 }
 
@@ -3868,6 +3854,42 @@  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 (!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 (!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,
@@ -3884,6 +3906,8 @@  static const struct net_device_ops fec_netdev_ops = {
 	.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[] = {
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index ab86bb8562ef..3f53b8ae57dd 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -618,16 +618,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;
@@ -638,33 +634,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);
 }
 
 /*