Skip to contentSkip to conversation

net: fec: don't save PTP state if PTP is unsupported

PATCH Applied Wei Fang 5 participants 7 messages Oct 8, 2024 – Oct 10, 2024

Subsystems (4)
lore
Share & tools
lore

Wei Fang

author maintainer
#0 lore raw

PATCH 1/1 net: fec: don't save PTP state if PTP is unsupported

Some platforms (such as i.MX25 and i.MX27) do not support PTP, so on these platforms fec_ptp_init() is not called and the related members in fep are not initialized. However, fec_ptp_save_state() is called unconditionally, which causes the kernel to panic. Therefore, add a condition so that fec_ptp_save_state() is not called if PTP is not supported.

Fixes a1477dc87dc4 ("net: fec: Restart PPS after link state change")
---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +4 -2
index 60fb54231ead..1b55047c0237 100644
@@ -1077,7 +1077,8 @@ fec_restart(struct net_device *ndev)
 	u32 rcntl = OPT_FRAME_SIZE | 0x04;
 	u32 ecntl = FEC_ECR_ETHEREN;
 
-	fec_ptp_save_state(fep);
+	if (fep->bufdesc_ex)
+		fec_ptp_save_state(fep);
 
 	/* Whack a reset.  We should wait for this.
 	 * For i.MX6SX SOC, enet use AXI bus, we use disable MAC
@@ -1340,7 +1341,8 @@ fec_stop(struct net_device *ndev)
 			netdev_err(ndev, "Graceful transmit stop did not complete!\n");
 	}
 
-	fec_ptp_save_state(fep);
+	if (fep->bufdesc_ex)
+		fec_ptp_save_state(fep);
 
 	/* Whack a reset.  We should wait for this.
 	 * For i.MX6SX SOC, enet use AXI bus, we use disable MAC
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Wei Fang

Some platforms (such as i.MX25 and i.MX27) do not support PTP, so on these platforms fec_ptp_init() is not called and the related members in fep are not initialized. However, fec_ptp_save_state() is called unconditionally, which causes the kernel to panic. Therefore, add a condition so that fec_ptp_save_state() is not called if PTP is not supported.

Fixes a1477dc87dc4 ("net: fec: Restart PPS after link state change")
---
  drivers/net/ethernet/freescale/fec_main.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +2 -1
index 60fb54231ead..1b55047c0237 100644
@@ -1077,7 +1077,8 @@ fec_restart(struct net_device *ndev)
  	u32 rcntl = OPT_FRAME_SIZE | 0x04;
  	u32 ecntl = FEC_ECR_ETHEREN;
 
-	fec_ptp_save_state(fep);
+	if (fep->bufdesc_ex)
+		fec_ptp_save_state(fep);
 
  	/* Whack a reset.  We should wait for this.
  	 * For i.MX6SX SOC, enet use AXI bus, we use disable MAC

drivers/net/ethernet/freescale/fec_main.c fec_stop(struct net_device *ndev) · line 1348

Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +2 -1
@@ -1340,7 +1341,8 @@ fec_stop(struct net_device *ndev)
  			netdev_err(ndev, "Graceful transmit stop did not complete!\n");
  	}
 
-	fec_ptp_save_state(fep);
+	if (fep->bufdesc_ex)
+		fec_ptp_save_state(fep);
 
  	/* Whack a reset.  We should wait for this.
  	 * For i.MX6SX SOC, enet use AXI bus, we use disable MAC

Thanks, it seems fec_ptp_restore_state() was properly guarded, but save_state() was not. Sorry for that.

reviewer
#2 lore raw
In reply to Wei Fang
Quoted 20 lines · Wei Fang

Some platforms (such as i.MX25 and i.MX27) do not support PTP, so on these platforms fec_ptp_init() is not called and the related members in fep are not initialized. However, fec_ptp_save_state() is called unconditionally, which causes the kernel to panic. Therefore, add a condition so that fec_ptp_save_state() is not called if PTP is not supported.

Fixes a1477dc87dc4 ("net: fec: Restart PPS after link state change")
---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +0 -0
index 60fb54231ead..1b55047c0237 100644

drivers/net/ethernet/freescale/fec_main.c fec_restart(struct net_device *ndev) · line 1081

Quoted 6 lines
drivers/net/ethernet/freescale/fec_main.c +2 -1
@@ -1077,7 +1077,8 @@ fec_restart(struct net_device *ndev)
 	u32 rcntl = OPT_FRAME_SIZE | 0x04;
 	u32 ecntl = FEC_ECR_ETHEREN;
 
-	fec_ptp_save_state(fep);
+	if (fep->bufdesc_ex)
+		fec_ptp_save_state(fep);

Hi,

I am wondering if you considered adding this check to (the top of) fec_ptp_save_state. It seems like it would both lead to a smaller change and be less error-prone to use.

Quoted 17 lines
drivers/net/ethernet/freescale/fec_main.c +2 -1
 	/* Whack a reset.  We should wait for this.
 	 * For i.MX6SX SOC, enet use AXI bus, we use disable MAC
@@ -1340,7 +1341,8 @@ fec_stop(struct net_device *ndev)
 			netdev_err(ndev, "Graceful transmit stop did not complete!\n");
 	}
 
-	fec_ptp_save_state(fep);
+	if (fep->bufdesc_ex)
+		fec_ptp_save_state(fep);
 
 	/* Whack a reset.  We should wait for this.
 	 * For i.MX6SX SOC, enet use AXI bus, we use disable MAC
Signature · 1 line
2.34.1
author maintainer
#3 lore raw
Quoted 49 lines

-----Original Message-----
From: Simon Horman <[email protected]>
Sent: 2024年10月9日 19:55
To: Wei Fang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shenwei Wang <[email protected]>; Clark Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net] net: fec: don't save PTP state if PTP is unsupported

Quoted 10 lines · Wei Fang

Some platforms (such as i.MX25 and i.MX27) do not support PTP, so on these platforms fec_ptp_init() is not called and the related members in fep are not initialized. However, fec_ptp_save_state() is called unconditionally, which causes the kernel to panic. Therefore, add a condition so that fec_ptp_save_state() is not called if PTP is not supported.

Fixes a1477dc87dc4 ("net: fec: Restart PPS after link state change")

Closes:

https://lore.ker/
nel.org%2Flkml%2F353e41fe-6bb4-4ee9-9980-2da2a9c1c508%40roeck-us.net %2F&data=05%7C02%7Cwei.fang%40nxp.com%7Cb10cac9ed8cd43284aae08 dce85930cd%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63864 0716999752935%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLC JQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=1 gxwnxNjk91xX7I%2Foco%2F4OhBbxNCryhDMo72O9Jkr2w%3D&reserved=0

Review

Quoted 6 lines
---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/freescale/fec_main.c

drivers/net/ethernet/freescale/fec_main.c fec_restart(struct net_device *ndev) · line 1081

Quoted 10 lines

index 60fb54231ead..1b55047c0237 100644

drivers/net/ethernet/freescale/fec_main.c +2 -1
@@ -1077,7 +1077,8 @@ fec_restart(struct net_device *ndev)
    u32 rcntl = OPT_FRAME_SIZE | 0x04;
    u32 ecntl = FEC_ECR_ETHEREN;
 
-   fec_ptp_save_state(fep);
+   if (fep->bufdesc_ex)
+           fec_ptp_save_state(fep);

Hi,

Quoted 4 lines

I am wondering if you considered adding this check to (the top of) fec_ptp_save_state. It seems like it would both lead to a smaller change and be less error-prone to use.

Yes, I considered this solution, but when I thought about it, fec_ptp_save_state() and fec_ptp_restore_state() are a pair. If the check is added to fec_ptp_save_state(), it is better to add it to fec_ptp_restore_state(). However, considering that this is not related to the current problem, and there are relatively few calls to fec_ptp_restore_state(), I did not do this. If there are more calls to fec_ptp_restore_state()/fec_ptp_restore_state() in the future, I will consider it.

Thanks.

Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/freescale/fec_main.c +2 -2
    /* Whack a reset.  We should wait for this.
     * For i.MX6SX SOC, enet use AXI bus, we use disable MAC
@@ -1340,7 +1341,8 @@ fec_stop(struct net_device *ndev)
                    netdev_err(ndev, "Graceful transmit stop did not complete!\n");
    }
 
-   fec_ptp_save_state(fep);
+   if (fep->bufdesc_ex)
+           fec_ptp_save_state(fep);
 
    /* Whack a reset.  We should wait for this.
     * For i.MX6SX SOC, enet use AXI bus, we use disable MAC
--

2.34.1

reviewer Reviewed-by
#4 lore raw
Quoted 54 lines · Wei Fang
Quoted 49 lines

-----Original Message-----
From: Simon Horman <[email protected]>
Sent: 2024年10月9日 19:55
To: Wei Fang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shenwei Wang <[email protected]>; Clark Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net] net: fec: don't save PTP state if PTP is unsupported

Quoted 10 lines · Wei Fang

Some platforms (such as i.MX25 and i.MX27) do not support PTP, so on these platforms fec_ptp_init() is not called and the related members in fep are not initialized. However, fec_ptp_save_state() is called unconditionally, which causes the kernel to panic. Therefore, add a condition so that fec_ptp_save_state() is not called if PTP is not supported.

Fixes a1477dc87dc4 ("net: fec: Restart PPS after link state change")

Closes:

https://lore.ker/
nel.org%2Flkml%2F353e41fe-6bb4-4ee9-9980-2da2a9c1c508%40roeck-us.net %2F&data=05%7C02%7Cwei.fang%40nxp.com%7Cb10cac9ed8cd43284aae08 dce85930cd%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63864 0716999752935%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLC JQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=1 gxwnxNjk91xX7I%2Foco%2F4OhBbxNCryhDMo72O9Jkr2w%3D&reserved=0

Review

Quoted 6 lines
---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/freescale/fec_main.c

drivers/net/ethernet/freescale/fec_main.c fec_restart(struct net_device *ndev) · line 1081

Quoted 10 lines

index 60fb54231ead..1b55047c0237 100644

drivers/net/ethernet/freescale/fec_main.c +2 -1
@@ -1077,7 +1077,8 @@ fec_restart(struct net_device *ndev)
    u32 rcntl = OPT_FRAME_SIZE | 0x04;
    u32 ecntl = FEC_ECR_ETHEREN;
 
-   fec_ptp_save_state(fep);
+   if (fep->bufdesc_ex)
+           fec_ptp_save_state(fep);

Hi,

Quoted 4 lines

I am wondering if you considered adding this check to (the top of) fec_ptp_save_state. It seems like it would both lead to a smaller change and be less error-prone to use.

Quoted 8 lines

Yes, I considered this solution, but when I thought about it, fec_ptp_save_state() and fec_ptp_restore_state() are a pair. If the check is added to fec_ptp_save_state(), it is better to add it to fec_ptp_restore_state(). However, considering that this is not related to the current problem, and there are relatively few calls to fec_ptp_restore_state(), I did not do this. If there are more calls to fec_ptp_restore_state()/fec_ptp_restore_state() in the future, I will consider it.

Sure, I agree on your point regarding symmetry, which I had not considered when I wrote my previous email. And I agree that the patch is suitable for net in it's current form.

...

Tested-by on v1 1/1
#5 lore raw
In reply to Wei Fang
Quoted 11 lines · Wei Fang

Some platforms (such as i.MX25 and i.MX27) do not support PTP, so on these platforms fec_ptp_init() is not called and the related members in fep are not initialized. However, fec_ptp_save_state() is called unconditionally, which causes the kernel to panic. Therefore, add a condition so that fec_ptp_save_state() is not called if PTP is not supported.

Fixes a1477dc87dc4 ("net: fec: Restart PPS after link state change")
#6 lore raw
In reply to Wei Fang
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 8 Oct 2024 14:11:53 +0800 you wrote:

Some platforms (such as i.MX25 and i.MX27) do not support PTP, so on these platforms fec_ptp_init() is not called and the related members in fep are not initialized. However, fec_ptp_save_state() is called unconditionally, which causes the kernel to panic. Therefore, add a condition so that fec_ptp_save_state() is not called if PTP is not supported.

[...]

Here is the summary with links:
- [net] net: fec: don't save PTP state if PTP is unsupported

    https://git.kernel.org/netdev/net/c/6be063071a45

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html