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

Noor Azura Ahmad Tarmizi noor.azura.ahmad.tarmizi at linux.intel.com
Tue Nov 8 18:43:29 PST 2022


From: Noor Azura Ahmad Tarmizi <noor.azura.ahmad.tarmizi at 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 at intel.com>
---
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

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) {
-- 
2.17.1




More information about the linux-arm-kernel mailing list