Skip to contentSkip to conversation

net: dwc_eth_qos: bring PHY up before triggering DMA soft reset

PATCH In review kongchen 2 participants 4 messages Sep 22 – Oct 10 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

kongchen

author
#1 lore raw

PATCH 1/2 net: dwc_eth_qos: bring PHY up before triggering DMA soft reset

DMA_MODE.SWR resets the whole MAC core and only self-clears once all of the MAC's clock domains are running. On SoCs where the RGMII RX clock is sourced by the PHY (e.g. Rockchip RK3568), the RX clock domain stays dead until the PHY has been brought up: PHYs like the Maxio MAE0621A need a vendor-specific init sequence (crystal clock mode plus analog tuning) before they start outputting RXC at all.

eqos_start() asserted SWR before phy_connect()/phy_config(), so with such a PHY the reset never completed, eqos_start() bailed out, and the PHY was never initialized -- a structural deadlock (raising swr_wait only delays the failure).

Move the SWR, together with the us_tic_counter programming which must follow a successful reset, to after the PHY has been connected, configured and its link is up, just before eqos_adjust_link(). This mirrors Linux stmmac_open(), which runs stmmac_init_phy() before stmmac_hw_setup() (containing the DMA reset).

The i.MX8M Plus GPR[1] interface-mode value latched by SWR is written at probe time and is not touched by phy_connect()/phy_config(), so the new order is safe there.

On a Rockchip RK3568 board with two MAE0621A PHYs the old order always fails with "EQOS_DMA_MODE_SWR stuck" and no link; with this change the interfaces come up and pass ping. Moving the SWR block back to its old position reproduces the failure.

---
 drivers/net/dwc_eth_qos.c | 51 +++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 21 deletions(-)
drivers/net/dwc_eth_qos.c +30 -21
index e7cf68d011c..f370593649c 100644
@@ -702,21 +702,11 @@ static int eqos_start(struct udevice *dev)
 	eqos->reg_access_ok = true;
 
 	/*
-	 * Assert the SWR first, the actually reset the MAC and to latch in
-	 * e.g. i.MX8M Plus GPR[1] content, which selects interface mode.
+	 * Bring the PHY up before triggering the DMA soft reset: on SoCs
+	 * where the RGMII RX clock is sourced by the PHY (e.g. Rockchip,
+	 * with PHYs that need a vendor init to start their clock, like the
+	 * Maxio MAE0621A), DMA_MODE_SWR cannot complete until the PHY runs.
 	 */
-	setbits_le32(&eqos->dma_regs->mode, EQOS_DMA_MODE_SWR);
-
-	if (eqos->config->ops->eqos_fix_soc_reset)
-		eqos->config->ops->eqos_fix_soc_reset(dev);
-
-	ret = wait_for_bit_le32(&eqos->dma_regs->mode,
-				EQOS_DMA_MODE_SWR, false,
-				eqos->config->swr_wait, false);
-	if (ret) {
-		pr_err("EQOS_DMA_MODE_SWR stuck\n");
-		goto err_stop_resets;
-	}
 
 	ret = eqos->config->ops->eqos_calibrate_pads(dev);
 	if (ret < 0) {
@@ -724,13 +714,6 @@ static int eqos_start(struct udevice *dev)
 		goto err_stop_resets;
 	}
 
-	if (eqos->config->ops->eqos_get_tick_clk_rate) {
-		rate = eqos->config->ops->eqos_get_tick_clk_rate(dev);
-
-		val = (rate / 1000000) - 1;
-		writel(val, &eqos->mac_regs->us_tic_counter);
-	}
-
 	/*
 	 * if PHY was already connected and configured,
 	 * don't need to reconnect/reconfigure again
@@ -786,6 +769,32 @@ static int eqos_start(struct udevice *dev)
 		goto err_shutdown_phy;
 	}
 
+	/*
+	 * Assert the SWR first, the actually reset the MAC and to latch in
+	 * e.g. i.MX8M Plus GPR[1] content, which selects interface mode.
+	 * The PHY is running by now, so its RX clock keeps the MAC clock
+	 * domains alive and the reset can complete.
+	 */
+	setbits_le32(&eqos->dma_regs->mode, EQOS_DMA_MODE_SWR);
+
+	if (eqos->config->ops->eqos_fix_soc_reset)
+		eqos->config->ops->eqos_fix_soc_reset(dev);
+
+	ret = wait_for_bit_le32(&eqos->dma_regs->mode,
+				EQOS_DMA_MODE_SWR, false,
+				eqos->config->swr_wait, false);
+	if (ret) {
+		pr_err("EQOS_DMA_MODE_SWR stuck\n");
+		goto err_shutdown_phy;
+	}
+
+	if (eqos->config->ops->eqos_get_tick_clk_rate) {
+		rate = eqos->config->ops->eqos_get_tick_clk_rate(dev);
+
+		val = (rate / 1000000) - 1;
+		writel(val, &eqos->mac_regs->us_tic_counter);
+	}
+
 	ret = eqos_adjust_link(dev);
 	if (ret < 0) {
 		pr_err("eqos_adjust_link() failed: %d\n", ret);
Signature · 1 line
2.55.0
#2 lore raw
Quoted 8 lines · kongchen

DMA_MODE.SWR resets the whole MAC core and only self-clears once all of the MAC's clock domains are running. On SoCs where the RGMII RX clock is sourced by the PHY (e.g. Rockchip RK3568), the RX clock domain stays dead until the PHY has been brought up: PHYs like the Maxio MAE0621A need a vendor-specific init sequence (crystal clock mode plus analog tuning) before they start outputting RXC at all.

[...]

Applied to u-boot-net branch for-next, thanks!

[1/2] net: dwc_eth_qos: bring PHY up before triggering DMA soft reset

      commit: 1a5da2d56fbd9027ceb7977599d5d793ffd1eb7f
[2/2] net: phy: add support for Maxio MAE0621A Ethernet PHYs
      commit: 8f3113936ba37844cf39574ea7914e3fbc723172

Best regards,

Signature · 1 line
Jerome Forissier <[email protected]>
author
#3 lore raw
Quoted 6 lines · Jerome Forissier

Applied to u-boot-net branch for-next, thanks!

[1/2] net: dwc_eth_qos: bring PHY up before triggering DMA soft reset

      commit 1a5da2d56fbd9027ceb7977599d5d793ffd1eb7f
[2/2] net: phy: add support for Maxio MAE0621A Ethernet PHYs
      commit 8f3113936ba37844cf39574ea7914e3fbc723172

Thank you for reviewing and applying the series. This is my first contribution to U-Boot and I really appreciate the smooth process. I look forward to contributing more in the future.

Best regards,
kongchen

author
#4 lore raw

PATCH 2/2 net: phy: add support for Maxio MAE0621A Ethernet PHYs

In reply to a message not in the archive

The Maxio MAE0621A(-Q2C / -Q3C(I)) gigabit PHYs ship in a non-functional power-on state: the clock-mode register must be programmed for crystal operation and a set of analog tuning registers applied before the RGMII interface starts toggling (RXC output included). With the generic C22 driver the RX clock never appears, which surfaces as an EQOS DMA_MODE_SWR timeout on MACs sourcing their RX clock from the PHY.

Port the init sequence from the vendor out-of-tree Linux driver (MAXIO_PHY_VER v1.8.1.1): paged register writes selecting crystal clock mode, the analog tuning sequence, and the ADC self-check loop.

Link status is read straight from BMSR (read twice per the IEEE 802.3 latching rules) instead of waiting on the autoneg-complete bit: this PHY reports link before aneg-complete settles, which the vendor Linux driver works around as well.

PHY ID1 has been observed reading 0xffff on a board where the vendor kernel reads 0x7b74, so match on the low 16 ID bits only: Q2C ends in 0x4411, Q3C(I) in 0x4412.

---
 drivers/net/phy/Kconfig  |   8 ++
 drivers/net/phy/Makefile |   1 +
 drivers/net/phy/maxio.c  | 228 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 237 insertions(+)
 create mode 100644 drivers/net/phy/maxio.c
drivers/net/phy/Kconfig +8 -0
index ee438524490..02aeb1db977 100644
@@ -238,6 +238,14 @@ config PHY_MOTORCOMM
 	  Enables support for Motorcomm network PHYs.
 	  Currently supports the YT8511 and YT8531 Gigabit Ethernet PHYs.
 
+config PHY_MAXIO
+	bool "Maxio PHYs"
+	help
+	  Enables support for Maxio network PHYs.
+	  Currently supports the MAE0621A/MAE0621B Gigabit Ethernet PHYs,
+	  which require a vendor init sequence (crystal clock mode plus
+	  analog tuning) before their RGMII interface comes up.
+
 config PHY_MSCC
 	depends on !COMPILE_TEST
 	bool "Microsemi Corp Ethernet PHYs support"
drivers/net/phy/Makefile +1 -0
index 83520de7f1f..bd57fa005b1 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_PHY_ET1011C) += et1011c.o
 obj-$(CONFIG_PHY_LXT) += lxt.o
 obj-$(CONFIG_PHY_MARVELL) += marvell.o
 obj-$(CONFIG_PHY_MARVELL_10G) += marvell10g.o
+obj-$(CONFIG_PHY_MAXIO) += maxio.o
 obj-y += mediatek/
 obj-y += airoha/
 obj-$(CONFIG_PHY_MICREL_KSZ8XXX) += micrel_ksz8xxx.o
drivers/net/phy/maxio.c new file +228 -0

228 lines not on this page · raw message

Signature · 1 line
2.55.0