diff mbox series

[resubmit,2] net: fec: Fix FEC_ECR_EN1588 being cleared on link-down

Message ID 20240611080405.673431-1-csokas.bence@prolan.hu (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [resubmit,2] net: fec: Fix FEC_ECR_EN1588 being cleared on link-down | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 850 this patch: 850
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 854 this patch: 854
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: 854 this patch: 854
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-12--09-00 (tests: 644)

Commit Message

Csókás Bence June 11, 2024, 8:04 a.m. UTC
FEC_ECR_EN1588 bit gets cleared after MAC reset in `fec_stop()`, which
makes all 1588 functionality shut down, and all the extended registers
disappear, on link-down, making the adapter fall back to compatibility
"dumb mode". However, some functionality needs to be retained (e.g. PPS)
even without link.

Fixes: 6605b730c061 ("FEC: Add time stamping code and a PTP hardware clock")
Cc: Richard Cochran <richardcochran@gmail.com>

Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Andrew Lunn June 12, 2024, 7:16 p.m. UTC | #1
On Tue, Jun 11, 2024 at 10:04:05AM +0200, Csókás, Bence wrote:
> FEC_ECR_EN1588 bit gets cleared after MAC reset in `fec_stop()`, which
> makes all 1588 functionality shut down, and all the extended registers
> disappear, on link-down, making the adapter fall back to compatibility
> "dumb mode". However, some functionality needs to be retained (e.g. PPS)
> even without link.
> 
> Fixes: 6605b730c061 ("FEC: Add time stamping code and a PTP hardware clock")
> Cc: Richard Cochran <richardcochran@gmail.com>
> 
> Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Jakub Kicinski June 13, 2024, 3:12 p.m. UTC | #2
On Tue, 11 Jun 2024 10:04:05 +0200 Csókás, Bence wrote:
> +	if (fep->bufdesc_ex) {
> +		val = readl(fep->hwp + FEC_ECNTRL);
> +		val |= FEC_ECR_EN1588;
> +		writel(val, fep->hwp + FEC_ECNTRL);

FEC_ECNTRL gets written multiple times in this function,
including with 0, and then you RMW it to add this flag.

Is this intentional? It really seems like you should be
adding this flag more consistently or making sure its
not cleared, rather than appending "add it back" at the 
end of the function...
Csókás Bence June 14, 2024, 7:59 a.m. UTC | #3
On 6/13/24 17:12, Jakub Kicinski wrote:
> On Tue, 11 Jun 2024 10:04:05 +0200 Csókás, Bence wrote:
>> +	if (fep->bufdesc_ex) {
>> +		val = readl(fep->hwp + FEC_ECNTRL);
>> +		val |= FEC_ECR_EN1588;
>> +		writel(val, fep->hwp + FEC_ECNTRL);
> 
> FEC_ECNTRL gets written multiple times in this function,
> including with 0, and then you RMW it to add this flag.
> 
> Is this intentional? It really seems like you should be
> adding this flag more consistently or making sure its
> not cleared, rather than appending "add it back" at the
> end of the function...

It only writes 0 if WOL is disabled AND the device has the MULTI_QUEUES 
quirk. Otherwise, we either write FEC_ECR_RESET, which resets the device 
(and the HW changes ECNTRL to its reset value), OR we RMW set the WOL 
sleep bits. And then, if some more quirks are set, we set ETHEREN.

So I think RMW is the safest route here, instead of trying to keep track 
of all these different branches, re-read ECNTRL after reset etc.

Bence
Jakub Kicinski June 15, 2024, 1:27 a.m. UTC | #4
On Fri, 14 Jun 2024 09:59:16 +0200 Csókás Bence wrote:
> It only writes 0 if WOL is disabled AND the device has the MULTI_QUEUES 
> quirk. Otherwise, we either write FEC_ECR_RESET, which resets the device 
> (and the HW changes ECNTRL to its reset value), OR we RMW set the WOL 
> sleep bits. And then, if some more quirks are set, we set ETHEREN.
> 
> So I think RMW is the safest route here, instead of trying to keep track 
> of all these different branches, re-read ECNTRL after reset etc.

Okay, just resend without the empty line between tags then.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 881ece735dcf..fb19295529a2 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1361,6 +1361,12 @@  fec_stop(struct net_device *ndev)
 		writel(FEC_ECR_ETHEREN, fep->hwp + FEC_ECNTRL);
 		writel(rmii_mode, fep->hwp + FEC_R_CNTRL);
 	}
+
+	if (fep->bufdesc_ex) {
+		val = readl(fep->hwp + FEC_ECNTRL);
+		val |= FEC_ECR_EN1588;
+		writel(val, fep->hwp + FEC_ECNTRL);
+	}
 }
 
 static void