Skip to contentSkip to conversation

net: stmmac: dwc-qos: calibrate tegra with mdio bus idle

PATCH Applied Russell King (Oracle) 4 participants 5 messages Apr 22, 2025 – Apr 23, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: dwc-qos: calibrate tegra with mdio bus idle

Thierry states that there are prerequists for Tegra's calibration that should be met before starting calibration - both the RGMII and MDIO interfaces should be idle.

This commit adds the necessary MII bus locking to ensure that the MDIO interface is idle during calibration.

---
 .../net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c  | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +10 -2
index fa900b4991d0..09ae16e026eb 100644
@@ -136,10 +136,11 @@ static int dwc_qos_probe(struct platform_device *pdev,
 #define AUTO_CAL_STATUS 0x880c
 #define  AUTO_CAL_STATUS_ACTIVE BIT(31)
 
-static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode)
+static void tegra_eqos_fix_speed(void *bsp_priv, int speed, unsigned int mode)
 {
-	struct tegra_eqos *eqos = priv;
+	struct tegra_eqos *eqos = bsp_priv;
 	bool needs_calibration = false;
+	struct stmmac_priv *priv;
 	u32 value;
 	int err;
 
@@ -158,6 +159,11 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode)
 	}
 
 	if (needs_calibration) {
+		priv = netdev_priv(dev_get_drvdata(eqos->dev));
+
+		/* Calibration should be done with the MDIO bus idle */
+		mutex_lock(&priv->mii->mdio_lock);
+
 		/* calibrate */
 		value = readl(eqos->regs + SDMEMCOMPPADCTRL);
 		value |= SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD;
@@ -191,6 +197,8 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode)
 		value = readl(eqos->regs + SDMEMCOMPPADCTRL);
 		value &= ~SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD;
 		writel(value, eqos->regs + SDMEMCOMPPADCTRL);
+
+		mutex_unlock(&priv->mii->mdio_lock);
 	} else {
 		value = readl(eqos->regs + AUTO_CAL_CONFIG);
 		value &= ~AUTO_CAL_CONFIG_ENABLE;
Signature · 1 line
2.30.2
#1 lore raw

Hello Russell,

Quoted 8 lines · On Tue, 22 Apr 2025 15:24:55 +0100 "Russell King (Oracle)"…

Thierry states that there are prerequists for Tegra's calibration that should be met before starting calibration - both the RGMII and MDIO interfaces should be idle.

This commit adds the necessary MII bus locking to ensure that the MDIO interface is idle during calibration.

[...]

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +3 -2
-static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode)
+static void tegra_eqos_fix_speed(void *bsp_priv, int speed, unsigned int mode)
 {
-	struct tegra_eqos *eqos = priv;
+	struct tegra_eqos *eqos = bsp_priv;
 	bool needs_calibration = false;
+	struct stmmac_priv *priv;
 	u32 value;
 	int err;

drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode) · line 165

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +4 -0
@@ -158,6 +159,11 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode)
 	}
 
 	if (needs_calibration) {
+		priv = netdev_priv(dev_get_drvdata(eqos->dev));
+
+		/* Calibration should be done with the MDIO bus idle */
+		mutex_lock(&priv->mii->mdio_lock);

Can't priv->mii be NULL, if the PHY for that MAC is connected to another MDIO bus for instance ?

Maxime

#2 lore raw
Quoted 29 lines · Maxime Chevallier

Hello Russell,

Quoted 8 lines · On Tue, 22 Apr 2025 15:24:55 +0100 "Russell King (Oracle)"…

Thierry states that there are prerequists for Tegra's calibration that should be met before starting calibration - both the RGMII and MDIO interfaces should be idle.

This commit adds the necessary MII bus locking to ensure that the MDIO interface is idle during calibration.

[...]

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +3 -2
-static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode)
+static void tegra_eqos_fix_speed(void *bsp_priv, int speed, unsigned int mode)
 {
-	struct tegra_eqos *eqos = priv;
+	struct tegra_eqos *eqos = bsp_priv;
 	bool needs_calibration = false;
+	struct stmmac_priv *priv;
 	u32 value;
 	int err;
@@ -158,6 +159,11 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode)
 	}
 
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode) · line 165

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +4 -0
 	if (needs_calibration) {
+		priv = netdev_priv(dev_get_drvdata(eqos->dev));
+
+		/* Calibration should be done with the MDIO bus idle */
+		mutex_lock(&priv->mii->mdio_lock);

Can't priv->mii be NULL, if the PHY for that MAC is connected to another MDIO bus for instance ?

Looking at the code, priv->mii will either be valid when mdio_bus_data is non-NULL, or the driver probe will fail. mdio_bus_data depends on the presence of the "mdio" child node in DT (via plat->mdio_node).

As far as I can tell this is always the case on Tegra devices, so I don't think we need to worry about this case. If it ever wasn't valid, I'd probably consider that a bug.

Thierry

Acked-by on v1 1/1
#3 lore raw
In reply to Russell King (Oracle)
Quoted 11 lines · Russell King (Oracle)

Thierry states that there are prerequists for Tegra's calibration that should be met before starting calibration - both the RGMII and MDIO interfaces should be idle.

This commit adds the necessary MII bus locking to ensure that the MDIO interface is idle during calibration.

---
 .../net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c  | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
#4 lore raw
In reply to Russell King (Oracle)
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 22 Apr 2025 15:24:55 +0100 you wrote:

Thierry states that there are prerequists for Tegra's calibration that should be met before starting calibration - both the RGMII and MDIO interfaces should be idle.

This commit adds the necessary MII bus locking to ensure that the MDIO interface is idle during calibration.

[...]

Here is the summary with links:
- [net-next] net: stmmac: dwc-qos: calibrate tegra with mdio bus idle

    https://git.kernel.org/netdev/net-next/c/87f43e6f06a2

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html