diff mbox series

[net-next,v2,3/7] net: ethernet: fs_enet: drop the .adjust_link custom fs_ops

Message ID 20240829161531.610874-4-maxime.chevallier@bootlin.com (mailing list archive)
State Superseded
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
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, 20 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-08-31--15-00 (tests: 714)

Commit Message

Maxime Chevallier Aug. 29, 2024, 4:15 p.m. UTC
There's no in-tree user for the fs_ops .adjust_link() function, so we
can always use the generic one in fe_enet-main.

Acked-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 7 +------
 drivers/net/ethernet/freescale/fs_enet/fs_enet.h      | 1 -
 2 files changed, 1 insertion(+), 7 deletions(-)

Comments

Andrew Lunn Aug. 30, 2024, 9:06 p.m. UTC | #1
> --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> @@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev)
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(&fep->lock, flags);
> -
> -	if (fep->ops->adjust_link)
> -		fep->ops->adjust_link(dev);
> -	else
> -		generic_adjust_link(dev);
> -
> +	generic_adjust_link(dev);
>  	spin_unlock_irqrestore(&fep->lock, flags);

Holding a spinlock is pretty unusual. We are in thread context, and
the phydev mutex is held. Looking at generic_adjust_link, do any of
the fep->foo variables actually need protecting, particularly from
changes in interrupts context?

	Andrew
Maxime Chevallier Sept. 4, 2024, 8:27 a.m. UTC | #2
Hi Andrew,

On Fri, 30 Aug 2024 23:06:08 +0200
Andrew Lunn <andrew@lunn.ch> wrote:

> > --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> > +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> > @@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev)
> >  	unsigned long flags;
> >  
> >  	spin_lock_irqsave(&fep->lock, flags);
> > -
> > -	if (fep->ops->adjust_link)
> > -		fep->ops->adjust_link(dev);
> > -	else
> > -		generic_adjust_link(dev);
> > -
> > +	generic_adjust_link(dev);
> >  	spin_unlock_irqrestore(&fep->lock, flags);  
> 
> Holding a spinlock is pretty unusual. We are in thread context, and
> the phydev mutex is held. Looking at generic_adjust_link, do any of
> the fep->foo variables actually need protecting, particularly from
> changes in interrupts context?

Yes there are, the interrupt mask/event registers are being accessed
from the interrupt handler and the ->restart() hook. I can try to
rework this a bit for a cleaner interrupt handling, but I don't have
means to test this on all mac flavors (fec/fcc/scc) :(

Thanks for reviewing this,

Maxime
Andrew Lunn Sept. 4, 2024, 12:36 p.m. UTC | #3
On Wed, Sep 04, 2024 at 10:27:11AM +0200, Maxime Chevallier wrote:
> Hi Andrew,
> 
> On Fri, 30 Aug 2024 23:06:08 +0200
> Andrew Lunn <andrew@lunn.ch> wrote:
> 
> > > --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> > > +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> > > @@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev)
> > >  	unsigned long flags;
> > >  
> > >  	spin_lock_irqsave(&fep->lock, flags);
> > > -
> > > -	if (fep->ops->adjust_link)
> > > -		fep->ops->adjust_link(dev);
> > > -	else
> > > -		generic_adjust_link(dev);
> > > -
> > > +	generic_adjust_link(dev);
> > >  	spin_unlock_irqrestore(&fep->lock, flags);  
> > 
> > Holding a spinlock is pretty unusual. We are in thread context, and
> > the phydev mutex is held. Looking at generic_adjust_link, do any of
> > the fep->foo variables actually need protecting, particularly from
> > changes in interrupts context?
> 
> Yes there are, the interrupt mask/event registers are being accessed
> from the interrupt handler and the ->restart() hook. I can try to
> rework this a bit for a cleaner interrupt handling, but I don't have
> means to test this on all mac flavors (fec/fcc/scc) :(

As far as i can see, none of the fep->old* members are accessed
outside of fs_enet-main.c. There values are not important for the
restart call. So the spinlock has nothing to do with adjust_link as
such, but restart. So maybe narrow down the lock to just the restart
call? But it is not a big issues, just unusual.

	Andrew
Maxime Chevallier Sept. 4, 2024, 3:50 p.m. UTC | #4
On Wed, 4 Sep 2024 14:36:58 +0200
Andrew Lunn <andrew@lunn.ch> wrote:

> On Wed, Sep 04, 2024 at 10:27:11AM +0200, Maxime Chevallier wrote:
> > Hi Andrew,
> > 
> > On Fri, 30 Aug 2024 23:06:08 +0200
> > Andrew Lunn <andrew@lunn.ch> wrote:
> >   
> > > > --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> > > > +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> > > > @@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev)
> > > >  	unsigned long flags;
> > > >  
> > > >  	spin_lock_irqsave(&fep->lock, flags);
> > > > -
> > > > -	if (fep->ops->adjust_link)
> > > > -		fep->ops->adjust_link(dev);
> > > > -	else
> > > > -		generic_adjust_link(dev);
> > > > -
> > > > +	generic_adjust_link(dev);
> > > >  	spin_unlock_irqrestore(&fep->lock, flags);    
> > > 
> > > Holding a spinlock is pretty unusual. We are in thread context, and
> > > the phydev mutex is held. Looking at generic_adjust_link, do any of
> > > the fep->foo variables actually need protecting, particularly from
> > > changes in interrupts context?  
> > 
> > Yes there are, the interrupt mask/event registers are being accessed
> > from the interrupt handler and the ->restart() hook. I can try to
> > rework this a bit for a cleaner interrupt handling, but I don't have
> > means to test this on all mac flavors (fec/fcc/scc) :(  
> 
> As far as i can see, none of the fep->old* members are accessed
> outside of fs_enet-main.c. There values are not important for the
> restart call. So the spinlock has nothing to do with adjust_link as
> such, but restart. So maybe narrow down the lock to just the restart
> call? But it is not a big issues, just unusual.

I agree with you on that, and this is actually what end-up happening in
the final phylink conversion patch (only the restart() call gets called
wthin the spinlock).

I'll however include a patch that does exactly what you suggest as part
of the phylink conversion, both to make the big port-to-phylink patch
smaller, but also to better document why we only need to care about the
restart() part, if that's ok :)

Thanks,

Maxime
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 2b48a2a5e32d..caca81b3ccb6 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
@@ -649,12 +649,7 @@  static void fs_adjust_link(struct net_device *dev)
 	unsigned long flags;
 
 	spin_lock_irqsave(&fep->lock, flags);
-
-	if (fep->ops->adjust_link)
-		fep->ops->adjust_link(dev);
-	else
-		generic_adjust_link(dev);
-
+	generic_adjust_link(dev);
 	spin_unlock_irqrestore(&fep->lock, flags);
 }
 
diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h
index 21c07ac05225..abe4dc97e52a 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h
@@ -77,7 +77,6 @@  struct fs_ops {
 	void (*free_bd)(struct net_device *dev);
 	void (*cleanup_data)(struct net_device *dev);
 	void (*set_multicast_list)(struct net_device *dev);
-	void (*adjust_link)(struct net_device *dev);
 	void (*restart)(struct net_device *dev);
 	void (*stop)(struct net_device *dev);
 	void (*napi_clear_event)(struct net_device *dev);