diff mbox series

[net,1/2] net: fec: Restart PPS after link state change

Message ID 20240923092347.2867309-1-csokas.bence@prolan.hu (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net,1/2] net: fec: Restart PPS after link state change | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 45 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 19 this patch: 19
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-24--03-00 (tests: 762)

Commit Message

Csókás, Bence Sept. 23, 2024, 9:23 a.m. UTC
On link state change, the controller gets reset,
causing PPS to drop out. Re-enable PPS if it was
enabled before the controller reset.

Fixes: 6605b730c061 ("FEC: Add time stamping code and a PTP hardware clock")
Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
---
 drivers/net/ethernet/freescale/fec.h      |  1 +
 drivers/net/ethernet/freescale/fec_main.c |  7 ++++++-
 drivers/net/ethernet/freescale/fec_ptp.c  | 12 ++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)

Comments

Wei Fang Sept. 23, 2024, 10:41 a.m. UTC | #1
> -----Original Message-----
> From: Csókás, Bence <csokas.bence@prolan.hu>
> Sent: 2024年9月23日 17:24
> To: David S. Miller <davem@davemloft.net>; Frank Li
> <Frank.Li@freescale.com>; imx@lists.linux.dev; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Cc: Csókás, Bence <csokas.bence@prolan.hu>; Wei Fang <wei.fang@nxp.com>;
> Shenwei Wang <shenwei.wang@nxp.com>; Clark Wang
> <xiaoning.wang@nxp.com>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Richard
> Cochran <richardcochran@gmail.com>
> Subject: [PATCH net 1/2] net: fec: Restart PPS after link state change
> 
> On link state change, the controller gets reset,
> causing PPS to drop out. Re-enable PPS if it was
> enabled before the controller reset.
> 
> Fixes: 6605b730c061 ("FEC: Add time stamping code and a PTP hardware
> clock")
> Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
> ---
>  drivers/net/ethernet/freescale/fec.h      |  1 +
>  drivers/net/ethernet/freescale/fec_main.c |  7 ++++++-
>  drivers/net/ethernet/freescale/fec_ptp.c  | 12 ++++++++++++
>  3 files changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/freescale/fec.h
> b/drivers/net/ethernet/freescale/fec.h
> index a19cb2a786fd..afa0bfb974e6 100644
> --- a/drivers/net/ethernet/freescale/fec.h
> +++ b/drivers/net/ethernet/freescale/fec.h
> @@ -695,6 +695,7 @@ struct fec_enet_private {
>  };
> 
>  void fec_ptp_init(struct platform_device *pdev, int irq_idx);
> +void fec_ptp_restore_state(struct fec_enet_private *fep);
>  void fec_ptp_stop(struct platform_device *pdev);
>  void fec_ptp_start_cyclecounter(struct net_device *ndev);
>  int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config
> *config,
> diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> index acbb627d51bf..6c6dbda26f06 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -1244,8 +1244,10 @@ fec_restart(struct net_device *ndev)
>  	writel(ecntl, fep->hwp + FEC_ECNTRL);
>  	fec_enet_active_rxring(ndev);
> 
> -	if (fep->bufdesc_ex)
> +	if (fep->bufdesc_ex) {
>  		fec_ptp_start_cyclecounter(ndev);
> +		fec_ptp_restore_state(fep);
> +	}
> 
>  	/* Enable interrupts we wish to service */
>  	if (fep->link)
> @@ -1366,6 +1368,9 @@ fec_stop(struct net_device *ndev)
>  		val = readl(fep->hwp + FEC_ECNTRL);
>  		val |= FEC_ECR_EN1588;
>  		writel(val, fep->hwp + FEC_ECNTRL);
> +
> +		fec_ptp_start_cyclecounter(ndev);
> +		fec_ptp_restore_state(fep);
>  	}
>  }
> 
> diff --git a/drivers/net/ethernet/freescale/fec_ptp.c
> b/drivers/net/ethernet/freescale/fec_ptp.c
> index 4cffda363a14..54dc3d0503b2 100644
> --- a/drivers/net/ethernet/freescale/fec_ptp.c
> +++ b/drivers/net/ethernet/freescale/fec_ptp.c
> @@ -764,6 +764,18 @@ void fec_ptp_init(struct platform_device *pdev, int
> irq_idx)
>  	schedule_delayed_work(&fep->time_keep, HZ);
>  }
> 
> +/* Restore PTP functionality after a reset */
> +void fec_ptp_restore_state(struct fec_enet_private *fep)
> +{
> +	/* Restart PPS if needed */
> +	if (fep->pps_enable) {
> +		/* Reset turned it off, so adjust our status flag */
> +		fep->pps_enable = 0;

fep->pps_enable is protected by fep->tmreg_lock, see
fec_ptp_enable_pps(), I'm afraid doing this will lead to potential lock
evasion issue. So it is better to add lock protection to avoid warning
from the Coverity tool.

> +		/* Re-enable PPS */
> +		fec_ptp_enable_pps(fep, 1);
> +	}
> +}
> +
>  void fec_ptp_stop(struct platform_device *pdev)
>  {
>  	struct net_device *ndev = platform_get_drvdata(pdev);
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index a19cb2a786fd..afa0bfb974e6 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -695,6 +695,7 @@  struct fec_enet_private {
 };
 
 void fec_ptp_init(struct platform_device *pdev, int irq_idx);
+void fec_ptp_restore_state(struct fec_enet_private *fep);
 void fec_ptp_stop(struct platform_device *pdev);
 void fec_ptp_start_cyclecounter(struct net_device *ndev);
 int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config,
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index acbb627d51bf..6c6dbda26f06 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1244,8 +1244,10 @@  fec_restart(struct net_device *ndev)
 	writel(ecntl, fep->hwp + FEC_ECNTRL);
 	fec_enet_active_rxring(ndev);
 
-	if (fep->bufdesc_ex)
+	if (fep->bufdesc_ex) {
 		fec_ptp_start_cyclecounter(ndev);
+		fec_ptp_restore_state(fep);
+	}
 
 	/* Enable interrupts we wish to service */
 	if (fep->link)
@@ -1366,6 +1368,9 @@  fec_stop(struct net_device *ndev)
 		val = readl(fep->hwp + FEC_ECNTRL);
 		val |= FEC_ECR_EN1588;
 		writel(val, fep->hwp + FEC_ECNTRL);
+
+		fec_ptp_start_cyclecounter(ndev);
+		fec_ptp_restore_state(fep);
 	}
 }
 
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index 4cffda363a14..54dc3d0503b2 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -764,6 +764,18 @@  void fec_ptp_init(struct platform_device *pdev, int irq_idx)
 	schedule_delayed_work(&fep->time_keep, HZ);
 }
 
+/* Restore PTP functionality after a reset */
+void fec_ptp_restore_state(struct fec_enet_private *fep)
+{
+	/* Restart PPS if needed */
+	if (fep->pps_enable) {
+		/* Reset turned it off, so adjust our status flag */
+		fep->pps_enable = 0;
+		/* Re-enable PPS */
+		fec_ptp_enable_pps(fep, 1);
+	}
+}
+
 void fec_ptp_stop(struct platform_device *pdev)
 {
 	struct net_device *ndev = platform_get_drvdata(pdev);