All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 1/1] net: stmmac: add check for supported link mode before mode change
@ 2022-11-09  2:43 ` Noor Azura Ahmad Tarmizi
  0 siblings, 0 replies; 4+ messages in thread
From: Noor Azura Ahmad Tarmizi @ 2022-11-09  2:43 UTC (permalink / raw)
  To: David S . Miller, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Muhammad Husaini Zulkifli
  Cc: netdev, linux-stm32, linux-arm-kernel, linux-kernel, Voon Weifeng,
	Tan Tee Min, Looi Hong Aun, Noor Azura Ahmad Tarmizi

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(+)

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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net 1/1] net: stmmac: add check for supported link mode before mode change
@ 2022-11-09  2:43 ` Noor Azura Ahmad Tarmizi
  0 siblings, 0 replies; 4+ messages in thread
From: Noor Azura Ahmad Tarmizi @ 2022-11-09  2:43 UTC (permalink / raw)
  To: David S . Miller, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Muhammad Husaini Zulkifli
  Cc: netdev, linux-stm32, linux-arm-kernel, linux-kernel, Voon Weifeng,
	Tan Tee Min, Looi Hong Aun, Noor Azura Ahmad Tarmizi

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(+)

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net 1/1] net: stmmac: add check for supported link mode before mode change
  2022-11-09  2:43 ` Noor Azura Ahmad Tarmizi
@ 2022-11-09 16:58   ` Andrew Lunn
  -1 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2022-11-09 16:58 UTC (permalink / raw)
  To: Noor Azura Ahmad Tarmizi
  Cc: David S . Miller, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Muhammad Husaini Zulkifli, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, Voon Weifeng, Tan Tee Min,
	Looi Hong Aun, Noor Azura Ahmad Tarmizi

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net 1/1] net: stmmac: add check for supported link mode before mode change
@ 2022-11-09 16:58   ` Andrew Lunn
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2022-11-09 16:58 UTC (permalink / raw)
  To: Noor Azura Ahmad Tarmizi
  Cc: David S . Miller, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Muhammad Husaini Zulkifli, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, Voon Weifeng, Tan Tee Min,
	Looi Hong Aun, Noor Azura Ahmad Tarmizi

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-09 17:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-09  2:43 [PATCH net 1/1] net: stmmac: add check for supported link mode before mode change Noor Azura Ahmad Tarmizi
2022-11-09  2:43 ` Noor Azura Ahmad Tarmizi
2022-11-09 16:58 ` Andrew Lunn
2022-11-09 16:58   ` Andrew Lunn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.