diff mbox series

[net-next,5/9] net: stmmac: use phylink_limit_mac_speed()

Message ID E1qYWSO-005fXx-6w@rmk-PC.armlinux.org.uk (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series stmmac cleanups | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
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 fail Errors and warnings before: 18 this patch: 1330
netdev/cc_maintainers success CCed 13 of 13 maintainers
netdev/build_clang fail Errors and warnings before: 19 this patch: 1353
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 fail Errors and warnings before: 18 this patch: 1353
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 67 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Russell King (Oracle) Aug. 22, 2023, 6:50 p.m. UTC
Use phylink_limit_mac_speed() to limit the MAC capabilities rather
than coding this for each speed.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 35 ++++++++-----------
 drivers/net/phy/phylink.c                     |  2 +-
 2 files changed, 15 insertions(+), 22 deletions(-)

Comments

Jakub Kicinski Aug. 24, 2023, 2:34 a.m. UTC | #1
On Tue, 22 Aug 2023 19:50:24 +0100 Russell King (Oracle) wrote:
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index b51cf92392d2..0d7354955d62 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -440,7 +440,7 @@ void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed)
>  
>  	for (i = 0; i < ARRAY_SIZE(phylink_caps_params) &&
>  		    phylink_caps_params[i].speed > max_speed; i++)
> -		config->mac_speed &= ~phylink_caps_params.mask;
> +		config->mac_capabilities &= ~phylink_caps_params[i].mask;
>  }
>  EXPORT_SYMBOL_GPL(phylink_limit_mac_speed);

This chunk belongs to patch 1?
Russell King (Oracle) Aug. 24, 2023, 10:38 a.m. UTC | #2
On Wed, Aug 23, 2023 at 07:34:57PM -0700, Jakub Kicinski wrote:
> On Tue, 22 Aug 2023 19:50:24 +0100 Russell King (Oracle) wrote:
> > diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> > index b51cf92392d2..0d7354955d62 100644
> > --- a/drivers/net/phy/phylink.c
> > +++ b/drivers/net/phy/phylink.c
> > @@ -440,7 +440,7 @@ void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed)
> >  
> >  	for (i = 0; i < ARRAY_SIZE(phylink_caps_params) &&
> >  		    phylink_caps_params[i].speed > max_speed; i++)
> > -		config->mac_speed &= ~phylink_caps_params.mask;
> > +		config->mac_capabilities &= ~phylink_caps_params[i].mask;
> >  }
> >  EXPORT_SYMBOL_GPL(phylink_limit_mac_speed);
> 
> This chunk belongs to patch 1?

Thanks for spotting that, you're absolutely right. I wonder why I didn't
merge that fix into the correct patch...

In any case, I added a 10th patch to the patch set which converts the
half-duplex capabilities to be positive logic. I'll resend it later
today.

I also have a raft of other stmmac cleanup patches which are steadily
growing at the moment!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index fe733a9f5fe4..30a085f2b8fa 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1200,10 +1200,10 @@  static int stmmac_init_phy(struct net_device *dev)
 static int stmmac_phy_setup(struct stmmac_priv *priv)
 {
 	struct stmmac_mdio_bus_data *mdio_bus_data;
-	int max_speed = priv->plat->max_speed;
 	int mode = priv->plat->phy_interface;
 	struct fwnode_handle *fwnode;
 	struct phylink *phylink;
+	int max_speed;
 
 	priv->phylink_config.dev = &priv->dev->dev;
 	priv->phylink_config.type = PHYLINK_NETDEV;
@@ -1222,29 +1222,18 @@  static int stmmac_phy_setup(struct stmmac_priv *priv)
 				    priv->phylink_config.supported_interfaces);
 
 	priv->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
-		MAC_10 | MAC_100;
-
-	if (!max_speed || max_speed >= 1000)
-		priv->phylink_config.mac_capabilities |= MAC_1000;
+		MAC_10 | MAC_100 | MAC_1000;
 
 	if (priv->plat->has_gmac4) {
-		if (!max_speed || max_speed >= 2500)
-			priv->phylink_config.mac_capabilities |= MAC_2500FD;
+		priv->phylink_config.mac_capabilities |= MAC_2500FD;
 	} else if (priv->plat->has_xgmac) {
-		if (!max_speed || max_speed >= 2500)
-			priv->phylink_config.mac_capabilities |= MAC_2500FD;
-		if (!max_speed || max_speed >= 5000)
-			priv->phylink_config.mac_capabilities |= MAC_5000FD;
-		if (!max_speed || max_speed >= 10000)
-			priv->phylink_config.mac_capabilities |= MAC_10000FD;
-		if (!max_speed || max_speed >= 25000)
-			priv->phylink_config.mac_capabilities |= MAC_25000FD;
-		if (!max_speed || max_speed >= 40000)
-			priv->phylink_config.mac_capabilities |= MAC_40000FD;
-		if (!max_speed || max_speed >= 50000)
-			priv->phylink_config.mac_capabilities |= MAC_50000FD;
-		if (!max_speed || max_speed >= 100000)
-			priv->phylink_config.mac_capabilities |= MAC_100000FD;
+		priv->phylink_config.mac_capabilities |= MAC_2500FD;
+		priv->phylink_config.mac_capabilities |= MAC_5000FD;
+		priv->phylink_config.mac_capabilities |= MAC_10000FD;
+		priv->phylink_config.mac_capabilities |= MAC_25000FD;
+		priv->phylink_config.mac_capabilities |= MAC_40000FD;
+		priv->phylink_config.mac_capabilities |= MAC_50000FD;
+		priv->phylink_config.mac_capabilities |= MAC_100000FD;
 	}
 
 	/* Half-Duplex can only work with single queue */
@@ -1253,6 +1242,10 @@  static int stmmac_phy_setup(struct stmmac_priv *priv)
 			~(MAC_10HD | MAC_100HD | MAC_1000HD);
 	priv->phylink_config.mac_managed_pm = true;
 
+	max_speed = priv->plat->max_speed;
+	if (max_speed)
+		phylink_limit_mac_speed(&priv->phylink_config, max_speed);
+
 	fwnode = priv->plat->port_node;
 	if (!fwnode)
 		fwnode = dev_fwnode(priv->device);
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index b51cf92392d2..0d7354955d62 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -440,7 +440,7 @@  void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed)
 
 	for (i = 0; i < ARRAY_SIZE(phylink_caps_params) &&
 		    phylink_caps_params[i].speed > max_speed; i++)
-		config->mac_speed &= ~phylink_caps_params.mask;
+		config->mac_capabilities &= ~phylink_caps_params[i].mask;
 }
 EXPORT_SYMBOL_GPL(phylink_limit_mac_speed);