linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/2] net: ethernet: mtk_eth_soc: minor SGMII fixes
@ 2023-03-14  0:34 Daniel Golle
  2023-03-14  0:34 ` [PATCH 1/2] net: ethernet: mtk_eth_soc: reset PCS state Daniel Golle
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Daniel Golle @ 2023-03-14  0:34 UTC (permalink / raw)
  To: devicetree, Rob Herring, Krzysztof Kozlowski, netdev,
	linux-mediatek, linux-arm-kernel, linux-kernel, Russell King,
	Heiner Kallweit, Lorenzo Bianconi, Mark Lee, John Crispin,
	Felix Fietkau, AngeloGioacchino Del Regno, Matthias Brugger,
	DENG Qingfang, Landen Chao, Sean Wang, Paolo Abeni,
	Jakub Kicinski, Eric Dumazet, David S. Miller, Vladimir Oltean,
	Florian Fainelli, Andrew Lunn, Vladimir Oltean
  Cc: Bjørn Mork, Frank Wunderlich, Alexander Couzens

This small series brings two minor fixes for the SGMII unit found in
MediaTek's router SoCs.

The first patch resets the PCS internal state machine on major
configuration changes, just like it is also done in MediaTek's SDK.

The second patch makes sure we only write values and restart AN if
actually needed, thus preventing unnesseray loss of an existing link
in some cases.

Both patches have previously been submitted as part of the series
"net: ethernet: mtk_eth_soc: various enhancements" which grew a bit
too big and it has correctly been criticized that some of the patches
should rather go as fixes to net-next.

This new series tries to address this.

Daniel Golle (2):
  net: ethernet: mtk_eth_soc: reset PCS state
  net: ethernet: mtk_eth_soc: only write values if needed

 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  4 +++
 drivers/net/ethernet/mediatek/mtk_sgmii.c   | 28 ++++++++++++---------
 2 files changed, 20 insertions(+), 12 deletions(-)


base-commit: 512dd354718b98c60d4ff6017ff8c9f66c10d03f
-- 
2.39.2

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

* [PATCH 1/2] net: ethernet: mtk_eth_soc: reset PCS state
  2023-03-14  0:34 [PATCH net 0/2] net: ethernet: mtk_eth_soc: minor SGMII fixes Daniel Golle
@ 2023-03-14  0:34 ` Daniel Golle
  2023-03-14  0:34 ` [PATCH 2/2] net: ethernet: mtk_eth_soc: only write values if needed Daniel Golle
  2023-03-15  9:00 ` [PATCH net 0/2] net: ethernet: mtk_eth_soc: minor SGMII fixes patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Golle @ 2023-03-14  0:34 UTC (permalink / raw)
  To: devicetree, Rob Herring, Krzysztof Kozlowski, netdev,
	linux-mediatek, linux-arm-kernel, linux-kernel, Russell King,
	Heiner Kallweit, Lorenzo Bianconi, Mark Lee, John Crispin,
	Felix Fietkau, AngeloGioacchino Del Regno, Matthias Brugger,
	DENG Qingfang, Landen Chao, Sean Wang, Paolo Abeni,
	Jakub Kicinski, Eric Dumazet, David S. Miller, Vladimir Oltean,
	Florian Fainelli, Andrew Lunn, Vladimir Oltean
  Cc: Bjørn Mork, Frank Wunderlich, Alexander Couzens

Reset the internal PCS state machine when changing interface mode.
This prevents confusing the state machine when changing interface
modes, e.g. from SGMII to 2500Base-X or vice-versa.

Fixes: 7e538372694b ("net: ethernet: mediatek: Re-add support SGMII")
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Tested-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 4 ++++
 drivers/net/ethernet/mediatek/mtk_sgmii.c   | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
index b65de174c3d9..084a6badef6d 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -542,6 +542,10 @@
 #define SGMII_SEND_AN_ERROR_EN		BIT(11)
 #define SGMII_IF_MODE_MASK		GENMASK(5, 1)
 
+/* Register to reset SGMII design */
+#define SGMII_RESERVED_0	0x34
+#define SGMII_SW_RESET		BIT(0)
+
 /* Register to set SGMII speed, ANA RG_ Control Signals III*/
 #define SGMSYS_ANA_RG_CS3	0x2028
 #define RG_PHY_SPEED_MASK	(BIT(2) | BIT(3))
diff --git a/drivers/net/ethernet/mediatek/mtk_sgmii.c b/drivers/net/ethernet/mediatek/mtk_sgmii.c
index bb00de1003ac..612f65bb0345 100644
--- a/drivers/net/ethernet/mediatek/mtk_sgmii.c
+++ b/drivers/net/ethernet/mediatek/mtk_sgmii.c
@@ -88,6 +88,10 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
 		regmap_update_bits(mpcs->regmap, SGMSYS_QPHY_PWR_STATE_CTRL,
 				   SGMII_PHYA_PWD, SGMII_PHYA_PWD);
 
+		/* Reset SGMII PCS state */
+		regmap_update_bits(mpcs->regmap, SGMII_RESERVED_0,
+				   SGMII_SW_RESET, SGMII_SW_RESET);
+
 		if (interface == PHY_INTERFACE_MODE_2500BASEX)
 			rgc3 = RG_PHY_SPEED_3_125G;
 		else
-- 
2.39.2


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

* [PATCH 2/2] net: ethernet: mtk_eth_soc: only write values if needed
  2023-03-14  0:34 [PATCH net 0/2] net: ethernet: mtk_eth_soc: minor SGMII fixes Daniel Golle
  2023-03-14  0:34 ` [PATCH 1/2] net: ethernet: mtk_eth_soc: reset PCS state Daniel Golle
@ 2023-03-14  0:34 ` Daniel Golle
  2023-03-15  9:00 ` [PATCH net 0/2] net: ethernet: mtk_eth_soc: minor SGMII fixes patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Golle @ 2023-03-14  0:34 UTC (permalink / raw)
  To: devicetree, Rob Herring, Krzysztof Kozlowski, netdev,
	linux-mediatek, linux-arm-kernel, linux-kernel, Russell King,
	Heiner Kallweit, Lorenzo Bianconi, Mark Lee, John Crispin,
	Felix Fietkau, AngeloGioacchino Del Regno, Matthias Brugger,
	DENG Qingfang, Landen Chao, Sean Wang, Paolo Abeni,
	Jakub Kicinski, Eric Dumazet, David S. Miller, Vladimir Oltean,
	Florian Fainelli, Andrew Lunn, Vladimir Oltean
  Cc: Bjørn Mork, Frank Wunderlich, Alexander Couzens

Only restart auto-negotiation and write link timer if actually
necessary. This prevents losing the link in case of minor
changes.

Fixes: 7e538372694b ("net: ethernet: mediatek: Re-add support SGMII")
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Tested-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/net/ethernet/mediatek/mtk_sgmii.c | 24 +++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_sgmii.c b/drivers/net/ethernet/mediatek/mtk_sgmii.c
index 612f65bb0345..83976dc86887 100644
--- a/drivers/net/ethernet/mediatek/mtk_sgmii.c
+++ b/drivers/net/ethernet/mediatek/mtk_sgmii.c
@@ -38,20 +38,16 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
 			  const unsigned long *advertising,
 			  bool permit_pause_to_mac)
 {
+	bool mode_changed = false, changed, use_an;
 	struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs);
 	unsigned int rgc3, sgm_mode, bmcr;
 	int advertise, link_timer;
-	bool changed, use_an;
 
 	advertise = phylink_mii_c22_pcs_encode_advertisement(interface,
 							     advertising);
 	if (advertise < 0)
 		return advertise;
 
-	link_timer = phylink_get_link_timer_ns(interface);
-	if (link_timer < 0)
-		return link_timer;
-
 	/* Clearing IF_MODE_BIT0 switches the PCS to BASE-X mode, and
 	 * we assume that fixes it's speed at bitrate = line rate (in
 	 * other words, 1000Mbps or 2500Mbps).
@@ -77,13 +73,16 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
 	}
 
 	if (use_an) {
-		/* FIXME: Do we need to set AN_RESTART here? */
-		bmcr = SGMII_AN_RESTART | SGMII_AN_ENABLE;
+		bmcr = SGMII_AN_ENABLE;
 	} else {
 		bmcr = 0;
 	}
 
 	if (mpcs->interface != interface) {
+		link_timer = phylink_get_link_timer_ns(interface);
+		if (link_timer < 0)
+			return link_timer;
+
 		/* PHYA power down */
 		regmap_update_bits(mpcs->regmap, SGMSYS_QPHY_PWR_STATE_CTRL,
 				   SGMII_PHYA_PWD, SGMII_PHYA_PWD);
@@ -101,16 +100,17 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
 		regmap_update_bits(mpcs->regmap, mpcs->ana_rgc3,
 				   RG_PHY_SPEED_3_125G, rgc3);
 
+		/* Setup the link timer */
+		regmap_write(mpcs->regmap, SGMSYS_PCS_LINK_TIMER, link_timer / 2 / 8);
+
 		mpcs->interface = interface;
+		mode_changed = true;
 	}
 
 	/* Update the advertisement, noting whether it has changed */
 	regmap_update_bits_check(mpcs->regmap, SGMSYS_PCS_ADVERTISE,
 				 SGMII_ADVERTISE, advertise, &changed);
 
-	/* Setup the link timer and QPHY power up inside SGMIISYS */
-	regmap_write(mpcs->regmap, SGMSYS_PCS_LINK_TIMER, link_timer / 2 / 8);
-
 	/* Update the sgmsys mode register */
 	regmap_update_bits(mpcs->regmap, SGMSYS_SGMII_MODE,
 			   SGMII_REMOTE_FAULT_DIS | SGMII_SPEED_DUPLEX_AN |
@@ -118,7 +118,7 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
 
 	/* Update the BMCR */
 	regmap_update_bits(mpcs->regmap, SGMSYS_PCS_CONTROL_1,
-			   SGMII_AN_RESTART | SGMII_AN_ENABLE, bmcr);
+			   SGMII_AN_ENABLE, bmcr);
 
 	/* Release PHYA power down state
 	 * Only removing bit SGMII_PHYA_PWD isn't enough.
@@ -132,7 +132,7 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
 	usleep_range(50, 100);
 	regmap_write(mpcs->regmap, SGMSYS_QPHY_PWR_STATE_CTRL, 0);
 
-	return changed;
+	return changed || mode_changed;
 }
 
 static void mtk_pcs_restart_an(struct phylink_pcs *pcs)
-- 
2.39.2


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

* Re: [PATCH net 0/2] net: ethernet: mtk_eth_soc: minor SGMII fixes
  2023-03-14  0:34 [PATCH net 0/2] net: ethernet: mtk_eth_soc: minor SGMII fixes Daniel Golle
  2023-03-14  0:34 ` [PATCH 1/2] net: ethernet: mtk_eth_soc: reset PCS state Daniel Golle
  2023-03-14  0:34 ` [PATCH 2/2] net: ethernet: mtk_eth_soc: only write values if needed Daniel Golle
@ 2023-03-15  9:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-15  9:00 UTC (permalink / raw)
  To: Daniel Golle
  Cc: devicetree, robh+dt, krzysztof.kozlowski+dt, netdev,
	linux-mediatek, linux-arm-kernel, linux-kernel, linux,
	hkallweit1, lorenzo, Mark-MC.Lee, john, nbd,
	angelogioacchino.delregno, matthias.bgg, dqfext, Landen.Chao,
	sean.wang, pabeni, kuba, edumazet, davem, olteanv, f.fainelli,
	andrew, vladimir.oltean, bjorn, frank-w, lynxis

Hello:

This series was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Tue, 14 Mar 2023 00:34:05 +0000 you wrote:
> This small series brings two minor fixes for the SGMII unit found in
> MediaTek's router SoCs.
> 
> The first patch resets the PCS internal state machine on major
> configuration changes, just like it is also done in MediaTek's SDK.
> 
> The second patch makes sure we only write values and restart AN if
> actually needed, thus preventing unnesseray loss of an existing link
> in some cases.
> 
> [...]

Here is the summary with links:
  - [1/2] net: ethernet: mtk_eth_soc: reset PCS state
    https://git.kernel.org/netdev/net/c/611e2dabb4b3
  - [2/2] net: ethernet: mtk_eth_soc: only write values if needed
    https://git.kernel.org/netdev/net/c/6e933a804c7d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-03-15  9:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14  0:34 [PATCH net 0/2] net: ethernet: mtk_eth_soc: minor SGMII fixes Daniel Golle
2023-03-14  0:34 ` [PATCH 1/2] net: ethernet: mtk_eth_soc: reset PCS state Daniel Golle
2023-03-14  0:34 ` [PATCH 2/2] net: ethernet: mtk_eth_soc: only write values if needed Daniel Golle
2023-03-15  9:00 ` [PATCH net 0/2] net: ethernet: mtk_eth_soc: minor SGMII fixes patchwork-bot+netdevbpf

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).