diff mbox series

[net,1/1] net: stmmac: add check for supported link mode before mode change

Message ID 20221109024329.15805-1-noor.azura.ahmad.tarmizi@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [net,1/1] net: stmmac: add check for supported link mode before mode change | expand

Commit Message

Noor Azura Ahmad Tarmizi Nov. 9, 2022, 2:43 a.m. UTC
From: Noor Azura Ahmad Tarmizi <noor.azura.ahmad.tarmizi@intel.com>

Currently, change for unsupported speed and duplex are sent to the phy,
rendering the link to unknown speed (link state down). Plus, advertising
settings are also passed down directly to the phy. Additional test is
now added to compare new speed and duplex settings and advertising
against current supported settings by attached phy.
Non-supported new settings(speed/duplex and advertising) will be rejected.

Signed-off-by: Noor Azura Ahmad Tarmizi <noor.azura.ahmad.tarmizi@intel.com>
---
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Andrew Lunn Nov. 9, 2022, 4:58 p.m. UTC | #1
On Wed, Nov 09, 2022 at 10:43:29AM +0800, Noor Azura Ahmad Tarmizi wrote:
> From: Noor Azura Ahmad Tarmizi <noor.azura.ahmad.tarmizi@intel.com>
> 
> Currently, change for unsupported speed and duplex are sent to the phy,
> rendering the link to unknown speed (link state down).

Something does not seem correct. See:

https://elixir.bootlin.com/linux/v6.1-rc4/source/drivers/net/phy/phy.c#L816

	/* We make sure that we don't pass unsupported values in to the PHY */
	linkmode_and(advertising, advertising, phydev->supported);

Do you somehow have phydev->supported set wrong?

   Andrew
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index f453b0d09366..d40cf7908eaa 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -390,6 +390,21 @@  stmmac_ethtool_set_link_ksettings(struct net_device *dev,
 				  const struct ethtool_link_ksettings *cmd)
 {
 	struct stmmac_priv *priv = netdev_priv(dev);
+	struct ethtool_link_ksettings link_ks = {};
+
+	/* Get the current link settings */
+	stmmac_ethtool_get_link_ksettings(dev, &link_ks);
+
+	/* Check if the speed and duplex are supported by phy */
+	if (!phy_lookup_setting(cmd->base.speed, cmd->base.duplex,
+				link_ks.link_modes.supported, true))
+		return -EINVAL;
+
+	/* Check if the advertising request is supported */
+	if (!bitmap_subset(cmd->link_modes.advertising,
+			   link_ks.link_modes.supported,
+			   __ETHTOOL_LINK_MODE_MASK_NBITS))
+		return -EINVAL;
 
 	if (priv->hw->pcs & STMMAC_PCS_RGMII ||
 	    priv->hw->pcs & STMMAC_PCS_SGMII) {