2022-11-09 03:38:39

by Noor Azura Ahmad Tarmizi

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

From: Noor Azura Ahmad Tarmizi <[email protected]>

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 <[email protected]>
---
.../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



2022-11-09 17:26:23

by Andrew Lunn

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

On Wed, Nov 09, 2022 at 10:43:29AM +0800, Noor Azura Ahmad Tarmizi wrote:
> From: Noor Azura Ahmad Tarmizi <[email protected]>
>
> 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