diff mbox series

[net-next,v3,4/8] net: ethernet: fs_enet: only protect the .restart() call in .adjust_link

Message ID 20240904171822.64652-5-maxime.chevallier@bootlin.com (mailing list archive)
State Accepted
Commit aa3672be731d473f65619ad198664a90771ab3d5
Delegated to: Netdev Maintainers
Headers show
Series net: ethernet: fs_enet: Cleanup and phylink conversion | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
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: 7 this patch: 7
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 40 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-09-07--06-00 (tests: 722)

Commit Message

Maxime Chevallier Sept. 4, 2024, 5:18 p.m. UTC
When .adjust_link() gets called, it runs in thread context, with the
phydev->lock held. We only need to protect the fep->fecp/fccp/sccp
register that are accessed within the .restart() function from
concurrent access from the interrupts.

These registers are being protected by the fep->lock spinlock, so we can
move the spinlock protection around the .restart() call instead of the
entire adjust_link() call. By doing so, we can simplify further the
.adjust_link() callback and avoid the intermediate helper.

Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 .../ethernet/freescale/fs_enet/fs_enet-main.c  | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

Comments

Russell King (Oracle) Sept. 16, 2024, 5:49 p.m. UTC | #1
On Wed, Sep 04, 2024 at 07:18:17PM +0200, Maxime Chevallier wrote:
>  /* generic link-change handler - should be sufficient for most cases */
> -static void generic_adjust_link(struct  net_device *dev)
> +static void fs_adjust_link(struct  net_device *dev)

As you're changing the function name, I think getting rid of the double
space in 'struct  net_device' would be worthwhile.

Thanks.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
index caca81b3ccb6..b320e55dcb81 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
@@ -607,10 +607,11 @@  static void fs_timeout(struct net_device *dev, unsigned int txqueue)
 }
 
 /* generic link-change handler - should be sufficient for most cases */
-static void generic_adjust_link(struct  net_device *dev)
+static void fs_adjust_link(struct  net_device *dev)
 {
 	struct fs_enet_private *fep = netdev_priv(dev);
 	struct phy_device *phydev = dev->phydev;
+	unsigned long flags;
 	int new_state = 0;
 
 	if (phydev->link) {
@@ -630,8 +631,11 @@  static void generic_adjust_link(struct  net_device *dev)
 			fep->oldlink = 1;
 		}
 
-		if (new_state)
+		if (new_state) {
+			spin_lock_irqsave(&fep->lock, flags);
 			fep->ops->restart(dev);
+			spin_unlock_irqrestore(&fep->lock, flags);
+		}
 	} else if (fep->oldlink) {
 		new_state = 1;
 		fep->oldlink = 0;
@@ -643,16 +647,6 @@  static void generic_adjust_link(struct  net_device *dev)
 		phy_print_status(phydev);
 }
 
-static void fs_adjust_link(struct net_device *dev)
-{
-	struct fs_enet_private *fep = netdev_priv(dev);
-	unsigned long flags;
-
-	spin_lock_irqsave(&fep->lock, flags);
-	generic_adjust_link(dev);
-	spin_unlock_irqrestore(&fep->lock, flags);
-}
-
 static int fs_init_phy(struct net_device *dev)
 {
 	struct fs_enet_private *fep = netdev_priv(dev);