netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell King <rmk+kernel@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Ioana Ciornei <ioana.ciornei@nxp.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	Alexandru Marginean <alexandru.marginean@nxp.com>,
	"michael@walle.cc" <michael@walle.cc>,
	"olteanv@gmail.com" <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH RFC net-next 08/13] net: phylink: simplify phy case for ksettings_set method
Date: Tue, 30 Jun 2020 15:29:11 +0100	[thread overview]
Message-ID: <E1jqHG3-0006PX-UZ@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <20200630142754.GC1551@shell.armlinux.org.uk>

When we have a PHY attached, an ethtool ksettings_set() call only
really needs to call through to the phylib equivalent; phylib will
call back to us when the link changes so we can update our state.
Therefore, we can bypass most of our ksettings_set() call for this
case.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/phylink.c | 104 +++++++++++++++++---------------------
 1 file changed, 47 insertions(+), 57 deletions(-)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 103d2a550415..967c068d16c8 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -1312,13 +1312,33 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
 				  const struct ethtool_link_ksettings *kset)
 {
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(support);
-	struct ethtool_link_ksettings our_kset;
 	struct phylink_link_state config;
 	const struct phy_setting *s;
-	int ret;
 
 	ASSERT_RTNL();
 
+	if (pl->phydev) {
+		/* We can rely on phylib for this update; we also do not need
+		 * to update the pl->link_config settings:
+		 * - the configuration returned via ksettings_get() will come
+		 *   from phylib whenever a PHY is present.
+		 * - link_config.interface will be updated by the PHY calling
+		 *   back via phylink_phy_change() and a subsequent resolve.
+		 * - initial link configuration for PHY mode comes from the
+		 *   last phy state updated via phylink_phy_change().
+		 * - other configuration changes (e.g. pause modes) are
+		 *   performed directly via phylib.
+		 * - if in in-band mode with a PHY, the link configuration
+		 *   is passed on the link from the PHY, and all of
+		 *   link_config.{speed,duplex,an_enabled,pause} are not used.
+		 * - the only possible use would be link_config.advertising
+		 *   pause modes when in 1000base-X mode with a PHY, but in
+		 *   the presence of a PHY, this should not be changed as that
+		 *   should be determined from the media side advertisement.
+		 */
+		return phy_ethtool_ksettings_set(pl->phydev, kset);
+	}
+
 	linkmode_copy(support, pl->supported);
 	config = pl->link_config;
 	config.an_enabled = kset->base.autoneg == AUTONEG_ENABLE;
@@ -1365,65 +1385,35 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
 		return -EINVAL;
 	}
 
-	if (pl->phydev) {
-		/* If we have a PHY, we process the kset change via phylib.
-		 * phylib will call our link state function if the PHY
-		 * parameters have changed, which will trigger a resolve
-		 * and update the MAC configuration.
-		 */
-		our_kset = *kset;
-		linkmode_copy(our_kset.link_modes.advertising,
-			      config.advertising);
-		our_kset.base.speed = config.speed;
-		our_kset.base.duplex = config.duplex;
+	/* For a fixed link, this isn't able to change any parameters,
+	 * which just leaves inband mode.
+	 */
+	if (phylink_validate(pl, support, &config))
+		return -EINVAL;
 
-		ret = phy_ethtool_ksettings_set(pl->phydev, &our_kset);
-		if (ret)
-			return ret;
+	/* If autonegotiation is enabled, we must have an advertisement */
+	if (config.an_enabled && phylink_is_empty_linkmode(config.advertising))
+		return -EINVAL;
 
-		mutex_lock(&pl->state_mutex);
-		/* Save the new configuration */
-		linkmode_copy(pl->link_config.advertising,
-			      our_kset.link_modes.advertising);
-		pl->link_config.interface = config.interface;
-		pl->link_config.speed = our_kset.base.speed;
-		pl->link_config.duplex = our_kset.base.duplex;
-		pl->link_config.an_enabled = our_kset.base.autoneg !=
-					     AUTONEG_DISABLE;
-		mutex_unlock(&pl->state_mutex);
-	} else {
-		/* For a fixed link, this isn't able to change any parameters,
-		 * which just leaves inband mode.
+	mutex_lock(&pl->state_mutex);
+	linkmode_copy(pl->link_config.advertising, config.advertising);
+	pl->link_config.interface = config.interface;
+	pl->link_config.speed = config.speed;
+	pl->link_config.duplex = config.duplex;
+	pl->link_config.an_enabled = kset->base.autoneg !=
+				     AUTONEG_DISABLE;
+
+	if (pl->cur_link_an_mode == MLO_AN_INBAND &&
+	    !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) {
+		/* If in 802.3z mode, this updates the advertisement.
+		 *
+		 * If we are in SGMII mode without a PHY, there is no
+		 * advertisement; the only thing we have is the pause
+		 * modes which can only come from a PHY.
 		 */
-		if (phylink_validate(pl, support, &config))
-			return -EINVAL;
-
-		/* If autonegotiation is enabled, we must have an advertisement */
-		if (config.an_enabled &&
-		    phylink_is_empty_linkmode(config.advertising))
-			return -EINVAL;
-
-		mutex_lock(&pl->state_mutex);
-		linkmode_copy(pl->link_config.advertising, config.advertising);
-		pl->link_config.interface = config.interface;
-		pl->link_config.speed = config.speed;
-		pl->link_config.duplex = config.duplex;
-		pl->link_config.an_enabled = kset->base.autoneg !=
-					     AUTONEG_DISABLE;
-
-		if (pl->cur_link_an_mode == MLO_AN_INBAND &&
-		    !test_bit(PHYLINK_DISABLE_STOPPED,
-			      &pl->phylink_disable_state)) {
-			/* If in 802.3z mode, this updates the advertisement.
-			 *
-			 * If we are in SGMII mode without a PHY, there is no
-			 * advertisement; the only thing we have is the pause
-			 * modes which can only come from a PHY.
-			 */
-			phylink_pcs_config(pl, true, &pl->link_config);
-		}
-		mutex_unlock(&pl->state_mutex);
+		phylink_pcs_config(pl, true, &pl->link_config);
 	}
+	mutex_unlock(&pl->state_mutex);
 
 	return 0;
 }
-- 
2.20.1


  parent reply	other threads:[~2020-06-30 14:29 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30 14:27 [PATCH RFC net-next 00/13] Phylink PCS updates Russell King - ARM Linux admin
2020-06-30 14:28 ` [PATCH RFC net-next 01/13] net: phylink: update ethtool reporting for fixed-link modes Russell King
2020-06-30 18:15   ` Florian Fainelli
2020-06-30 14:28 ` [PATCH RFC net-next 02/13] net: phylink: rejig link state tracking Russell King
2020-06-30 18:15   ` Florian Fainelli
2020-06-30 14:28 ` [PATCH RFC net-next 03/13] net: phylink: rearrange resolve mac_config() call Russell King
2020-06-30 18:32   ` Florian Fainelli
2020-06-30 14:28 ` [PATCH RFC net-next 04/13] net: phylink: ensure link is down when changing interface Russell King
2020-06-30 18:32   ` Florian Fainelli
2020-06-30 14:28 ` [PATCH RFC net-next 05/13] net: phylink: update PCS when changing interface during resolution Russell King
2020-06-30 18:33   ` Florian Fainelli
2020-06-30 14:29 ` [PATCH RFC net-next 06/13] net: phylink: avoid mac_config calls Russell King
2020-06-30 19:04   ` Florian Fainelli
2020-06-30 14:29 ` [PATCH RFC net-next 07/13] net: phylink: simplify ksettings_set() implementation Russell King
2020-07-20 10:24   ` Ioana Ciornei
2020-06-30 14:29 ` Russell King [this message]
2020-07-20 10:44   ` [PATCH RFC net-next 08/13] net: phylink: simplify phy case for ksettings_set method Ioana Ciornei
2020-07-20 12:45     ` Russell King - ARM Linux admin
2020-06-30 14:29 ` [PATCH RFC net-next 09/13] net: phylink: simplify fixed-link " Russell King
2020-07-20 10:52   ` Ioana Ciornei
2020-06-30 14:29 ` [PATCH RFC net-next 10/13] net: phylink: in-band pause mode advertisement update for PCS Russell King
2020-06-30 16:19   ` Jakub Kicinski
2020-06-30 14:29 ` [PATCH RFC net-next 11/13] net: phylink: re-implement interface configuration with PCS Russell King
2020-07-20 11:40   ` Ioana Ciornei
2020-07-20 12:44     ` Russell King - ARM Linux admin
2020-07-20 13:02       ` Ioana Ciornei
2020-07-20 14:19         ` Russell King - ARM Linux admin
2020-06-30 14:29 ` [PATCH RFC net-next 12/13] net: phylink: add struct phylink_pcs Russell King
2020-07-01 10:47   ` Vladimir Oltean
2020-07-01 11:16     ` Russell King - ARM Linux admin
2020-07-01 11:24       ` Vladimir Oltean
2020-07-20 15:50   ` Ioana Ciornei
2020-07-20 16:26     ` Russell King - ARM Linux admin
2020-07-20 16:59       ` Ioana Ciornei
2020-07-20 18:16         ` Russell King - ARM Linux admin
2020-06-30 14:29 ` [PATCH RFC net-next 13/13] net: phylink: add interface to configure clause 22 PCS PHY Russell King
2020-07-01 10:52   ` Ioana Ciornei
2020-07-14  8:49 ` [PATCH RFC net-next 00/13] Phylink PCS updates Vladimir Oltean
2020-07-14 13:18   ` Russell King - ARM Linux admin
2020-07-14 21:22     ` Florian Fainelli
2020-07-15  9:53       ` Russell King - ARM Linux admin
2020-07-14 23:46     ` Vladimir Oltean
2020-07-15 11:21       ` Russell King - ARM Linux admin
2020-07-15 11:34         ` Russell King - ARM Linux admin
2020-07-15 12:31           ` Vladimir Oltean
2020-07-15 14:20             ` Andrew Lunn
2020-07-15 17:02             ` Russell King - ARM Linux admin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1jqHG3-0006PX-UZ@rmk-PC.armlinux.org.uk \
    --to=rmk+kernel@armlinux.org.uk \
    --cc=alexandru.marginean@nxp.com \
    --cc=andrew@lunn.ch \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=ioana.ciornei@nxp.com \
    --cc=kuba@kernel.org \
    --cc=michael@walle.cc \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).