Skip to contentSkip to conversation

net: dsa: qca8k: add a QCA8337 CPU PHY consumer

RFC PATCH Superseded Yongzhao Chen 3 participants 20 messages Sep 23 – Sep 28

Subsystems (9)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover net: dsa: qca8k: add a QCA8337 CPU PHY consumer

The qca83xx PHY driver is already in net-next. This series allows passing PHY flags on DSA shared ports and adds support for a QCA8337 internal CPU PHY. It implements CPU port selection, serializes MAC state across global MTU updates, and proposes disabling SmartSpeed prior to CPU PHY resets.

The first patch extends the DSA core interface; the qca8k patches provide its concrete user. No board-name matching or board-specific DT properties are introduced.

The minimal topology uses a single CPU link: a conduit PHY connects over MDI to QCA8337 PHY4 on switch port 5, with each endpoint having its own phy-handle. A reduced devicetree fixture based on Redmi AX5400 wiring passed dtc and validation against the complete net-next schema set. This is a binding fixture rather than a bootable board description. Because the pinned base tree lacks the IPQ5018 Ethernet MAC driver and RA74 board support, this series has not been boot-tested on RA74 under pure net-next.

On one RA74 board, diagnostic boot logs showed PHY4 advertising 1000BASE-T full duplex after generic config_aneg() succeeded, but a later read found the advertisement missing. No intervening write was found through the instrumented Clause 22 BMCR/CTRL1000 path; other paths were not excluded. The exact trigger remains unknown. Clearing SmartSpeed before the initial reset preserved the 1 Gb/s internal link during the tested boot sequence. Runtime testing did not establish late-peer causality, a broken pair, or successful fallback to 100 Mb/s.

Two scope questions remain for this RFC:

1. Internal CPU port selection currently falls back to ports 1 through 5 only on QCA8337. Dedicated ports 0 and 6 retain priority on all models, including mixed CPU port descriptions. AR8327 documentation describes per-port headers and destination bitmaps, but I have not established its internal CPU link behavior. Should this fallback remain limited to QCA8337, or can maintainers confirm the same support for QCA8327?

2. The proposed SmartSpeed policy applies to QCA8337 internal CPU PHYs. SmartSpeed is the hardware downshift feature, so disabling it removes that fallback behavior. Current hardware evidence is limited to PHY4 on a single RA74 board. Is the internal CPU link role sufficient justification for this policy, or should the quirk be scoped more narrowly?

Changes since v2:
- Patch 2 uses reg_mutex across the MTU pause, frame-size write, and state restoration. Variable declarations now follow reverse Christmas-tree order. This patch precedes topology support so MTU protection is in place when internal CPU ports become available.
- Patch 3 adds internal CPU port fallback while retaining port 0 and 6 priority, leaving QCA8327 support as an explicit RFC question.
- Patch 4 masks the revision before setting the CPU PHY flag, clarifies SmartSpeed downshift behavior, and drops the delayed-conduit causal claim.
- Patch 5 clarifies reset and config_aneg ordering along with hardware evidence limits, keeping generic config_aneg.

This series depends on the separate net patch "net: dsa: qca8k:
propagate MDIO errors":
https://lore.kernel.org/netdev/[email protected]/

Testing:
Fault injection against the actual MDIO/PHY functions and kernel polling macros covered busy-read errors, timeouts and successful transactions. The old polling code reproduced false success on read error; the fixed path blocked SmartSpeed writes and initial/resume resets. Tests with mocked hardware also covered flag scope, CPU-port selection and MDIO-to-MTU error handling.

The changed qca8k-8xxx.o built with W=1 for x86_64 and ARM64 under allyesconfig and allmodconfig, with no compiler diagnostics. Unchanged qca8k-common.o and MTU locking retain the earlier build and concurrency test results. Hardware tests used downstream RA74 firmware. This revision has no full kernel image/modules build, pure net-next RA74 boot or hardware lockdep run.

Original RFC:
https://lore.kernel.org/netdev/[email protected]/

v2:
https://lore.kernel.org/netdev/[email protected]/

Base: net-next 8830e65ed46de41f849eefb8ba227d4852c460f6. Local prerequisite: 3ba847ea54227f704ee3b04f95d4b52d4e22d483.

Yongzhao Chen (4):
net: dsa: pass PHY flags when connecting shared ports
net: dsa: qca8k: serialize CPU MAC pause during MTU changes
net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed
net: phy: qca83xx: disable SmartSpeed before resetting CPU PHYs

Ziyang Huang (1):
net: dsa: qca8k: support QCA8337 internal PHY CPU links

 Documentation/networking/dsa/dsa.rst |  2 +
 MAINTAINERS                          |  1 +
 drivers/net/dsa/bcm_sf2.c            |  4 ++
 drivers/net/dsa/microchip/ksz8.c     |  4 ++
 drivers/net/dsa/qca/qca8k-8xxx.c     | 39 +++++++++-----
 drivers/net/dsa/qca/qca8k-common.c   | 79 ++++++++++++++++++++++------
 drivers/net/phy/qcom/qca83xx.c       | 32 +++++++++--
 include/linux/qca83xx.h              | 11 ++++
 net/dsa/port.c                       |  6 ++-
 9 files changed, 145 insertions(+), 33 deletions(-)
 create mode 100644 include/linux/qca83xx.h
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH v3 1/5 net: dsa: pass PHY flags when connecting shared ports

DSA calls get_phy_flags() for user ports, but passes zero when connecting CPU or DSA port PHYs. Pass the callback result before PHY initialization for shared ports too. Drivers without the callback still pass zero.

Keep bcm_sf2 and ksz88xx shared-port flags at zero, preserving their existing behavior. Document the extended callback scope.

This lets qca8k pass revision information and a SmartSpeed quirk to an internal PHY used as a CPU link. The remaining patches supply that user.

---
 Documentation/networking/dsa/dsa.rst | 2 ++
 drivers/net/dsa/bcm_sf2.c            | 4 ++++
 drivers/net/dsa/microchip/ksz8.c     | 4 ++++
 net/dsa/port.c                       | 6 +++++-
 4 files changed, 15 insertions(+), 1 deletion(-)
Documentation/networking/dsa/dsa.rst +2 -0
index 7edfdd555..647f952e3 100644
@@ -668,6 +668,8 @@ PHY devices and link management
   on its own (e.g.: coming from switch memory mapped registers), this function
   should return a 32-bit bitmask of "flags" that is private between the switch
   driver and the Ethernet PHY driver in ``drivers/net/phy/\*``.
+  It is called when connecting PHYs for user, CPU and DSA ports. Drivers
+  should return zero for ports that do not need switch-specific PHY flags.
 
 - ``phy_read``: Function invoked by the DSA user MDIO bus when attempting to read
   the switch port MDIO registers. If unavailable, return 0xffff for each read.
drivers/net/dsa/bcm_sf2.c +4 -0
index 9e5713015..f516fc396 100644
@@ -709,6 +709,10 @@ static u32 bcm_sf2_sw_get_phy_flags(struct dsa_switch *ds, int port)
 {
 	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
 
+	/* Shared ports previously received no PHY flags. */
+	if (!dsa_is_user_port(ds, port))
+		return 0;
+
 	/* The BCM7xxx PHY driver expects to find the integrated PHY revision
 	 * in bits 15:8 and the patch level in bits 7:0 which is exactly what
 	 * the REG_PHY_REVISION register layout is.
drivers/net/dsa/microchip/ksz8.c +4 -0
index d74981320..be8861a7a 100644
@@ -3076,6 +3076,10 @@ static u32 ksz88xx_get_phy_flags(struct dsa_switch *ds, int port)
 {
 	struct ksz_device *dev = ds->priv;
 
+	/* Shared ports previously received no PHY flags. */
+	if (!dsa_is_user_port(ds, port))
+		return 0;
+
 	switch (dev->chip_id) {
 	case KSZ88X3_CHIP_ID:
 		/* Silicon Errata Sheet (DS80000830A):
net/dsa/port.c +5 -1
index 1f5536c0d..4db7e6f9c 100644
@@ -1666,6 +1666,7 @@ static int dsa_shared_port_phylink_register(struct dsa_port *dp)
 {
 	struct dsa_switch *ds = dp->ds;
 	struct device_node *port_dn = dp->dn;
+	u32 phy_flags = 0;
 	int err;
 
 	dp->pl_config.dev = ds->dev;
@@ -1675,7 +1676,10 @@ static int dsa_shared_port_phylink_register(struct dsa_port *dp)
 	if (err)
 		return err;
 
-	err = phylink_of_phy_connect(dp->pl, port_dn, 0);
+	if (ds->ops->get_phy_flags)
+		phy_flags = ds->ops->get_phy_flags(ds, dp->index);
+
+	err = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
 	if (err && err != -ENODEV) {
 		pr_err("could not attach to PHY: %d\n", err);
 		goto err_phy_connect;
Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH v3 2/5 net: dsa: qca8k: serialize CPU MAC pause during MTU changes

In reply to Yongzhao Chen

The global maximum frame size must be updated with CPU MACs disabled. The previous logic only paused ports 0 and 6, leaving an internal PHY CPU port enabled while modifying the register.

Include enabled internal CPU ports in the pause sequence. Use the existing reg_mutex to serialize the MTU update against port enable, port disable, and phylink link-up and link-down transitions. Read and restore each port's original TXMAC and RXMAC bits, ensuring ports that were down remain down and preserving LINK_AUTO. Retain existing handling for ports 0 and 6.

Abort before updating the frame size if reading port status or pausing the MAC fails. Attempt to restore all ports already modified, and report any restoration failures even if an earlier error occurred.

The standalone qca8k MDIO error-propagation fix is a prerequisite for this series; that error-handling bug predates this locking change.

Assisted-by LLM
---
 drivers/net/dsa/qca/qca8k-8xxx.c   |  2 +
 drivers/net/dsa/qca/qca8k-common.c | 79 ++++++++++++++++++++++++------
 2 files changed, 66 insertions(+), 15 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +2 -0
index f9e2eb0b9..d8564001c 100644
@@ -1488,7 +1488,9 @@ qca8k_phylink_mac_link_up(struct phylink_config *config,
 
 	reg |= QCA8K_PORT_STATUS_TXMAC | QCA8K_PORT_STATUS_RXMAC;
 
+	mutex_lock(&priv->reg_mutex);
 	qca8k_write(priv, QCA8K_REG_PORT_STATUS(port), reg);
+	mutex_unlock(&priv->reg_mutex);
 }
 
 static struct qca8k_pcs *pcs_to_qca8k_pcs(struct phylink_pcs *pcs)
drivers/net/dsa/qca/qca8k-common.c +64 -15

124 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH v3 3/5 net: dsa: qca8k: support QCA8337 internal PHY CPU links

In reply to Yongzhao Chen

From: Ziyang Huang <[email protected]>

A PHY-to-PHY CPU link connects the SoC PHY directly to an internal switch PHY. The QCA8337 supports header mode on these ports, and existing phylink callbacks already handle their internal interfaces.

Allow QCA8337 CPU port selection to fall back to ports 1 through 5 after checking the dedicated MAC-only ports. Preserve the preference for CPU ports 0 and 6 across all switch models, limiting the internal-port fallback to QCA8337. Support for QCA8327 internal CPU links remains an open question in this RFC. Include internal CPU PHYs when selecting the PHY access method, without altering the handling of MAC-only or external user ports.

This enables a single internal CPU PHY configured with an explicit phy-handle and phy-mode = "internal". The conduit interface uses its own PHY on the opposite side of the MDI connection. Existing single-CPU DSA forwarding uses the selected port for default flooding and membership without extra routing changes.

Adapted from the OpenWrt PHY-to-PHY CPU link patch, narrowing the MDIO filter adjustments to preserve handling for external user ports.

[yongzhao: preserve external user-port handling on port 6 and limit
internal CPU PHY support to QCA8337]

---
 drivers/net/dsa/qca/qca8k-8xxx.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +13 -5
index d8564001c..07640ce4a 100644
@@ -1019,7 +1019,8 @@ qca8k_setup_mdio_bus(struct qca8k_priv *priv)
 			return ret;
 		}
 
-		if (!dsa_is_user_port(priv->ds, reg))
+		if (!dsa_is_user_port(priv->ds, reg) &&
+		    !(reg > 0 && reg < 6 && dsa_is_cpu_port(priv->ds, reg)))
 			continue;
 
 		of_get_phy_mode(port, &mode);
@@ -1095,16 +1096,23 @@ qca8k_setup_mac_pwr_sel(struct qca8k_priv *priv)
 static int qca8k_find_cpu_port(struct dsa_switch *ds)
 {
 	struct qca8k_priv *priv = ds->priv;
+	int port;
 
-	/* Find the connected cpu port. Valid port are 0 or 6 */
 	if (dsa_is_cpu_port(ds, 0))
 		return 0;
 
-	dev_dbg(priv->dev, "port 0 is not the CPU port. Checking port 6");
-
 	if (dsa_is_cpu_port(ds, 6))
 		return 6;
 
+	/* Internal PHY CPU port selection is currently enabled for QCA8337. */
+	if (priv->switch_id != QCA8K_ID_QCA8337)
+		return -EINVAL;
+
+	/* An internal PHY can provide a PHY-to-PHY CPU link. */
+	for (port = 1; port < 6; port++)
+		if (dsa_is_cpu_port(ds, port))
+			return port;
+
 	return -EINVAL;
 }
 
@@ -1856,7 +1864,7 @@ qca8k_setup(struct dsa_switch *ds)
 
 	cpu_port = qca8k_find_cpu_port(ds);
 	if (cpu_port < 0) {
-		dev_err(priv->dev, "No cpu port configured in both cpu port0 and port6");
+		dev_err(priv->dev, "No CPU port configured");
 		return cpu_port;
 	}
 
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH v3 4/5 net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

In reply to Yongzhao Chen

Flag QCA8337 internal PHYs used as CPU links for SmartSpeed suppression. SmartSpeed is the Qualcomm PHY driver downshift feature configured in register 0x14. Its enable and bypass-timer bits are cleared by a subsequent patch prior to software reset.

In a diagnostic boot on one RA74, PHY4 initially advertised 1000BASE-T full duplex, but a later read showed that advertisement cleared. Clearing SmartSpeed before the initial reset preserved the 1 Gb/s link on that board. This observation does not establish the root cause of the advertisement loss or prove that a delayed conduit PHY caused it.

Define a shared switch-to-PHY flag while preserving the hardware revision bits consumed by the PHY driver. Mask the revision before setting the flag to prevent revision values from mistakenly enabling the quirk on user ports. Only QCA8337 internal CPU ports 1 through 5 receive this flag. The hardware test covered PHY4 on one RA74; the other ports and boards selected by this code have not been validated.

Assisted-by LLM
---
 MAINTAINERS                      |  1 +
 drivers/net/dsa/qca/qca8k-8xxx.c | 19 ++++++++++---------
 drivers/net/phy/qcom/qca83xx.c   |  3 +--
 include/linux/qca83xx.h          | 11 +++++++++++
 4 files changed, 23 insertions(+), 11 deletions(-)
 create mode 100644 include/linux/qca83xx.h
MAINTAINERS +1 -0
index df8ab9b82..fa1da8031 100644
@@ -22336,6 +22336,7 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/net/dsa/qca8k.yaml
 F:	drivers/net/dsa/qca/qca8k*
+F:	include/linux/qca83xx.h
 F:	net/dsa/tag_qca.c
 
 QUALCOMM ATHEROS QCA7K ETHERNET DRIVER
drivers/net/dsa/qca/qca8k-8xxx.c +10 -9
index 07640ce4a..cd7adb2d9 100644
@@ -8,6 +8,7 @@
 
 #include <linux/module.h>
 #include <linux/phy.h>
+#include <linux/qca83xx.h>
 #include <linux/netdevice.h>
 #include <linux/bitfield.h>
 #include <linux/regmap.h>
@@ -1754,17 +1755,17 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)
 static u32 qca8k_get_phy_flags(struct dsa_switch *ds, int port)
 {
 	struct qca8k_priv *priv = ds->priv;
+	u32 flags;
 
-	/* Communicate to the phy internal driver the switch revision.
-	 * Based on the switch revision different values needs to be
-	 * set to the dbg and mmd reg on the phy.
-	 * The first 2 bit are used to communicate the switch revision
-	 * to the phy driver.
-	 */
-	if (port > 0 && port < 6)
-		return priv->switch_revision;
+	if (port <= 0 || port >= 6)
+		return 0;
 
-	return 0;
+	/* The PHY driver uses the switch revision for analog initialization. */
+	flags = priv->switch_revision & QCA8K_DEVFLAGS_REVISION_MASK;
+	if (priv->switch_id == QCA8K_ID_QCA8337 && dsa_is_cpu_port(ds, port))
+		flags |= QCA8K_DEVFLAGS_NO_SMARTSPEED;
+
+	return flags;
 }
 
 static enum dsa_tag_protocol
drivers/net/phy/qcom/qca83xx.c +1 -2
index bc70ed8ef..0f484cdfe 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include <linux/phy.h>
+#include <linux/qca83xx.h>
 #include <linux/module.h>
 
 #include "qcom.h"
@@ -16,8 +17,6 @@
 #define QCA8327_B_PHY_ID			0x004dd034
 #define QCA8337_PHY_ID				0x004dd036
 
-#define QCA8K_DEVFLAGS_REVISION_MASK		GENMASK(2, 0)
-
 static struct at803x_hw_stat qca83xx_hw_stats[] = {
 	{ "phy_idle_errors", 0xa, GENMASK(7, 0), PHY},
 	{ "phy_receive_errors", 0x15, GENMASK(15, 0), PHY},
include/linux/qca83xx.h new file +11 -0
new file mode 100644
index 000000000..f90ed80fb
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _LINUX_QCA83XX_H
+#define _LINUX_QCA83XX_H
+
+#include <linux/bits.h>
+
+/* QCA8K switch-to-PHY flags, carried through phy_device::dev_flags. */
+#define QCA8K_DEVFLAGS_REVISION_MASK	GENMASK(2, 0)
+#define QCA8K_DEVFLAGS_NO_SMARTSPEED	BIT(3)
+
+#endif
Signature · 1 line
2.43.0
maintainer
#5 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Quoted 3 lines · Yongzhao Chen

Flag QCA8337 internal PHYs used as CPU links for SmartSpeed suppression. SmartSpeed is the Qualcomm PHY driver downshift feature configured in register 0x14.

As far as i can see, nothing configures register 0x14, so this is not very useful.

Please look at other PHYs which support downshift. There is a tunable for it. Also, the read_status is expected to return the real speed, which often is not in BMSR, but in a vendor register.

Is there an errata which covers this?

It would be interesting to know if downshift is broken in general, or only when used in switch integrated PHYs.

What might be possible here it to look at phydev->is_internal, rather than add a flag, to differentiate switch internal PHYs and discrete PHYs.

Andrew

#6 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Hi Andrew,

The register 0x14 configuration is in patch 5. For a QCA8337 CPU PHY marked by patch 4, qca8337_soft_reset() clears SmartSpeed enable and bypass before the software reset. I should have made that relationship explicit in patch 4.

I have a local read_status change for QCA8337, which I plan to include in the next RFC. When autonegotiation is enabled, it reads the resolved speed and duplex from register 0x11, retaining generic link-partner and master/slave handling. It holds the link down until those values are valid; forced mode keeps the generic BMCR handling. Local tests that run the callback and the PHY state machine against a simulated MDIO bus pass, including a case where 0x11 reports 100 Mb/s while the generic path resolves 1 Gb/s. W=1 object builds for x86 and arm64 are clean.

I also tested it on RA74 in an OpenWrt backport on Linux 6.18.52, not the net-next series itself, with the existing CPU SmartSpeed workaround. On normal 100 and 1000 Mb/s LAN links the reported speed matched 0x11, including after renegotiating the 100 Mb/s port and after a warm reboot. These were normal links; I could not force a downshift, so the downshifted case is only covered by the simulated test.

The existing at803x downshift tunable cannot be reused directly here. Its setter calls phy_init_hw() after writing 0x14, which would run qca8337_soft_reset() and clear a requested enable on the flagged CPU PHY. This shared-port PHY also has no net_device->phydev through which ethtool can reach it; ethtool on the conduit or wan addresses a different PHY. I have left tunable support out of this follow-up.

I don't know whether downshift is broken in general or only in switch-integrated PHYs. My only data point is the RA74 CPU link failure, and I have no downshift results from user ports or discrete at803x PHYs. phydev->is_internal is set for every PHY that qca83xx matches, since they are all switch-internal, including user ports and QCA8327, so it cannot select just the CPU link. I have not found a verified erratum for this switch revision.

Thanks,
Yongzhao Chen

maintainer
#7 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Quoted 4 lines

I don't know whether downshift is broken in general or only in switch-integrated PHYs. My only data point is the RA74 CPU link failure, and I have no downshift results from user ports or discrete at803x PHYs.

It is pretty easy to test, if you have a spare Ethernet cable you can sacrifice.

https://en.wikipedia.org/wiki/Ethernet_over_twisted_pair

100Mbps needs pins 1-4, 5-8 are not used. So you can either cover some of those pins with something, maybe nail varnish, or take some of the outer cover off the cable to expose the wires, and if it follows the colour scheme describe cut say the brown cable.

But this is testing the wrong thing. This is testing downshift works. What you are actually interested in is downshift happening when it should not....

So take a closer look at the user ports. phylib should report when a downshift occurs:

https://elixir.bootlin.com/linux/v7.2.7/source/drivers/net/phy/phy-core.c#L359

phydev->advertising should contain what the user configured, even if the hardware has cleared the 1G advertisement. So it should trigger.

Andrew

#8 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Hi Andrew,

Quoted 6 lines

But this is testing the wrong thing. This is testing downshift works. What you are actually interested in is downshift happening when it should not....

So take a closer look at the user ports. phylib should report when a downshift occurs:

Thanks, that is a better test. I ran it on RA74 with the OpenWrt 6.18.52 backport that includes the read_status change, so phy_check_downshift() sees the speed from 0x11. The user ports keep SmartSpeed at its hardware default (enabled). The CPU PHY keeps the existing workaround, so SmartSpeed stays disabled there.

Across 8 boots (1 after flashing, 4 warm reboots, 3 power cycles) and 10 "ethtool -r" on each of wan, lan1, lan2 and lan3, there was no "Downshift occurred" message. CTRL1000 stayed at 0x0600 on all four user PHYs, and each port came up at the speed its link partner supports. The only unexpected event was one link drop on lan3 about 7 seconds after its last renegotiation; it came back at 1 Gb/s after 3 seconds.

I also tried to recreate what the CPU link sees at boot, where the IPQ5018 PHY does not advertise 1000BASE-T at first and adds it a few seconds later. On lan1 I switched the PC NIC 30 times between advertising only up to 100 Mb/s, with autonegotiation still enabled, and full autonegotiation, then restarted it another 10 times. lan1 returned to 1 Gb/s every time. In 741 once-per-second samples CTRL1000 stayed at 0x0600 and 0x11 bit 5 was never set, and there was no downshift warning.

So on this board I have not seen downshift misbehave on the user ports, including when the link partner changes its advertisement in a similar way. This is one board and a limited number of attempts, and the link partner was a PC NIC rather than the IPQ5018 PHY. It also does not show that downshift works on a bad cable, and the CPU link failure itself was not exercised because SmartSpeed stays disabled on that PHY.

Disabling downshift for all qca83xx PHYs would also remove it from the user ports, where I have not seen it misbehave. The CPU link has no cable, only a fixed on-board connection, so disabling it there should cost little. Given this, would you accept keeping the workaround limited to the CPU link, or would you still prefer disabling it in the PHY driver without a flag?

Thanks,
Yongzhao Chen

maintainer
#9 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Quoted 3 lines

Disabling downshift for all qca83xx PHYs would also remove it from the user ports, where I have not seen it misbehave. The CPU link has no cable, only a fixed on-board connection

How are the two ports coupled?

Are there magnetics? Capacitor coupling?

Anything like what Micrel suggests?

https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ApplicationNotes/ApplicationNotes/ANLAN120-UNG.pdf

Andrew

#10 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Hi Andrew,

Quoted 3 lines

How are the two ports coupled?

Are there magnetics? Capacitor coupling?

I don't have a schematic and have not inspected the board closely myself. What I have are third-party photos of the Redmi AX5400 board (board marking M74). A teardown with the shields removed:

https://www.acwifi.net/19451.html

Full board: https://www.acwifi.net/wp-content/uploads/2022/03/DSC_4718.jpg
Close-up:   https://www.acwifi.net/wp-content/uploads/2022/03/DSC_4725.jpg

And a repair forum photo of the same board with the shields on:

https://remont-aud.net/forum/103-124057-1
Photo: https://remont-aud.net/_fr/1240/2027121.jpg

In the full board photo the QCA8337 is under the small shield at the top left and the IPQ5018 is under the diagonal shield in the middle. They are a few centimetres apart, judging from the photo, and I cannot see magnetics or common-mode chokes between them.

Just outside the chamfered corner of the QCA8337 shield, between the two chips, the silkscreen shows eight capacitor positions in pairs, C548 to C555. In the forum photo, parallel traces appear to run from this group towards the IPQ5018 shield. That looks like AC coupling on the four pairs, but from the photos I cannot tell whether they are populated, what their values are, or whether they are capacitors at all rather than 0 ohm links. I also cannot identify any bias or termination parts, so I cannot say whether it matches the arrangement in the Micrel note.

The OpenWrt DTS for this board sets qcom,dac-preset-short-cable on the IPQ5018 GE PHY. The qca,ar803x.yaml binding describes it as adjusting amplitude, bias current and error correction for a PHY connected to another PHY over a short distance. There is no equivalent setting on the QCA8337 side.

Thanks,
Yongzhao Chen

maintainer
#11 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Quoted 5 lines

The OpenWrt DTS for this board sets qcom,dac-preset-short-cable on the IPQ5018 GE PHY. The qca,ar803x.yaml binding describes it as adjusting amplitude, bias current and error correction for a PHY connected to another PHY over a short distance. There is no equivalent setting on the QCA8337 side.

I'm leaning towards the hardware design is broken, not enough attenuation etc, causing the PHY to wrongly detect a broken pair.

The IPQ5018 PHY driver does have cable test support, have you tried it out?

Downshift itself, in the normal setting with a cable, probably does work, otherwise we would of had reports of issues.

Although the PHY on the CPU port is not associated to a Linux interface, it is still probed, and has a phydev. So you should be able to represent it in DT, and add a DT property to disable downshift. This would sometimes run into problems in that DT should describe hardware, not the configuration of the hardware. But in this case, if in the commit message and comments you say downshift needs to be disabled because of a bad hardware design, i expect it will be accepted.

Andrew

#12 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Hi Andrew,

Quoted 2 lines

The IPQ5018 PHY driver does have cable test support, have you tried it out?

Yes. I ran it seven times on the IPQ5018 PHY under OpenWrt 6.18.44 (NSS build). All four pairs reported OK each time. This was a working link, so the result does not show what the QCA8337 sees during a failed boot, or confirm or rule out insufficient attenuation.

I also ran an A/B test on the OpenWrt 6.18.52 backport, using identical kernel and rootfs contents. Before the initial PHY software reset, both paths read register 0x14 once and unconditionally wrote it once:
either the original value, or the value with SmartSpeed disabled.

Across six alternating warm boots on this board:

- Writing back 0x082c failed all three times. PHY4's CTRL1000 read 0x0400, register 0x11 read 0x1030, and the CPU link did not come up.
- Writing 0x080c worked all three times. CTRL1000 read 0x0600 and the CPU link came up at 1 Gb/s.

The pre-reset value was 0x082c in every run; the two written values therefore differed only in the SmartSpeed enable bit. Writing the original value back did not avoid the failure, despite the same MDIO access sequence. This strengthens the case for disabling SmartSpeed on this link, but does not establish the electrical cause.

I'm open to selecting the workaround through DT, so that it is enabled only on boards known to need it. What I can document at this point is the PHY-to-PHY connection, the reproducible boot failure and the effect of disabling SmartSpeed. I have not established whether the cause is the board's electrical design or something else.

Would that be sufficient justification for a DT property, with the underlying cause left open in the commit message? If so, would you prefer a generic PHY property to disable downshift, or a Qualcomm-specific property for this workaround?

Thanks,
Yongzhao Chen

maintainer
#13 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Quoted 5 lines

I'm open to selecting the workaround through DT, so that it is enabled only on boards known to need it. What I can document at this point is the PHY-to-PHY connection, the reproducible boot failure and the effect of disabling SmartSpeed. I have not established whether the cause is the board's electrical design or something else.

This is tricky. I can understand not wanting to say the board design is broken without strong evidence. But a DT property is about hardware. Maybe word it something like ... when the hardware uses an on board PHY-to-PHY connection, without cable, SmartSpeed has been seen to incorrectly performed a downshift. There have not been any reports of a traditional hardware designs, using a cable, having this issue.

Quoted 4 lines

Would that be sufficient justification for a DT property, with the underlying cause left open in the commit message? If so, would you prefer a generic PHY property to disable downshift, or a Qualcomm-specific property for this workaround?

Also tricky. What we don't want is other developers trying to abuse this to turn it into a configuration option, rather than a hardware property. So i don't think it should be a generic property. Lets make it a qualcomm specific property. I would also put 'workaround' in the property name, again making it clear this is not intended to be used for configuration.

Andrew

#14 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Hi Andrew,

Quoted 6 lines

Also tricky. What we don't want is other developers trying to abuse this to turn it into a configuration option, rather than a hardware property. So i don't think it should be a generic property. Lets make it a qualcomm specific property. I would also put 'workaround' in the property name, again making it clear this is not intended to be used for configuration.

Thank you, that makes sense. I'll use a Qualcomm-specific property with "workaround" in its name, and word the commit message around what has been observed, as you suggested: an on-board PHY-to-PHY connection without a cable, where SmartSpeed has been seen to downshift incorrectly. The workaround would then apply only to boards that set the property, rather than to every QCA8337 internal CPU PHY as in v3.

One correction to the data I sent you: as Ziyang pointed out, the IPQ5018 short-cable DAC values were not being applied on this board, because the driver does not shift the field value. My earlier A/B runs were therefore done without them. I have repeated the A/B with the DAC values corrected, and the result is the same. The details are in my reply to Ziyang in this thread.

Before sending the next revision, I would like to check one more thing. In these boots the QCA8337 CPU PHY is reset about 38 s before the IPQ5018 PHY has its DAC values configured. If setting the DAC before the switch-side PHY starts negotiating avoids the downshift, that would suggest fixing the initialisation order rather than adding a DT workaround. I'll report back on what I find before sending the next revision. If the workaround is still needed, I'll propose the property name and binding with it.

Thanks,
Yongzhao Chen

#15 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Hi Andrew,

Following up on the initialisation order, as promised. On this board it was the cause, and the DT workaround is not needed.

The IPQ5018 GE PHY leaves reset in ipq5018_probe() and starts autonegotiating with its reset defaults. Its LDO, EEE, MSE and DAC settings are only written in ipq5018_config_init(), when stmmac attaches the PHY on open, about 39 s later on this board. I sampled both PHYs during that window. They resolved 1000BASE-T every 2.5 to 3 s without getting link, and after about five attempts SmartSpeed downshifted on both sides at the same moment: the IPQ5018 PHY's CTRL1000 went 0x0200 -> 0x0000 and PHY4's 0x0600 -> 0x0400. The soft reset at attach restores the IPQ5018 side, but nothing touches PHY4 again, so the CPU link never came up.

Applying the same analog settings in probe, right after the reset, and restarting autonegotiation, fixed it with SmartSpeed left enabled on the QCA8337: 3 of 3 warm boots came up at 1 Gb/s about 2.5 s after PHY4 was reset, against 0 of 3 without it. Both groups ran the same kernel and rootfs, with the probe-time writes enabled by a private DT property. The final patch was then checked on the same board over a first boot, three reboots, three interface down/up cycles, three renegotiations, a network restart and a 10 minute observation, all at 1 Gb/s with SmartSpeed enabled. It is still one board, and I have not done a power-cycle test on this kernel.

So I will not add the workaround property. I will send the at803x change to net together with the DAC fix, and v4 of this series without patches 4 and 5. George, I've Cc'd you since the at803x change touches the IPQ5018 probe path you added.

Thanks,
Yongzhao

maintainer
#16 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Quoted 2 lines

So I will not add the workaround property. I will send the at803x change to net together with the DAC fix

Thanks for keeping at this. It is always better to understand why something does not work, than try to work around it.

Andrew

#17 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

In reply to Yongzhao Chen
Quoted 5 lines · Yongzhao Chen

In a diagnostic boot on one RA74, PHY4 initially advertised 1000BASE-T full duplex, but a later read showed that advertisement cleared. Clearing SmartSpeed before the initial reset preserved the 1 Gb/s link on that board. This observation does not establish the root cause of the advertisement loss or prove that a delayed conduit PHY caused it.

Have you correct the DAC settings of the IPQ5018 PHY ?

Most of the IPQ5018 devices which use PHY-to-PHY CPU link require to adjust it.

But some don't need. What's more, maybe some need different values.

NOTE: Setting a large value may damage the SoC. Please check the vendor dts.

#18 lore raw

Re: [RFC PATCH net-next v3 4/5] net: dsa: qca8k: flag QCA8337 internal CPU PHYs for SmartSpeed

Hi Ziyang,

Quoted 1 line

Have you correct the DAC settings of the IPQ5018 PHY ?

Thank you for pointing this out. It turned out that the DAC values were not being applied on my board.

The OpenWrt DTS for this board sets qcom,dac-preset-short-cable, but ipq5018_config_init() passes the unshifted value 0x10 to phy_modify_mmd() and at803x_debug_reg_mask() while the mask is GENMASK(15, 8). As a result, the high byte is cleared instead of being set to 0x10, and bit 4 of the low byte is set. The same code is in net-next today. All my earlier A/B runs, including the ones I reported to Andrew, were done with this code. I will send the DAC fix as a separate patch.

With both writes changed to FIELD_PREP(IPQ5018_PHY_DAC_MASK, 0x10), I repeated the A/B on the same board: six alternating warm boots with identical kernel and rootfs contents. The only difference between the two groups was whether SmartSpeed on the QCA8337 CPU PHY was left enabled or disabled before its initial reset. I kept 0x10 and did not try other values, given your warning. In all six boots the read-back after the write was MDAC 0x6868 -> 0x1068 and EDAC 0x7800 -> 0x1000, so the high byte was 0x10 and the low byte was preserved.

The result was the same as before:

- SmartSpeed left enabled: failed 3/3. PHY4's CTRL1000 read 0x0400, register 0x11 read 0x1030, and the CPU link did not come up.
- SmartSpeed disabled: 3/3 came up at 1 Gb/s.

So correcting the DAC values alone did not avoid the failure in this setup. I don't think this rules the DAC out yet, though, because of the ordering. In these boots the QCA8337 CPU PHY (PHY4) was reset at about 2.3 s, while the IPQ5018 PHY's config_init(), which writes the DAC values, ran at about 40 s. For roughly 38 s PHY4 may have been negotiating with an IPQ5018 PHY that still had its reset-default DAC values. I have not yet measured when PHY4 first drops its 1000BASE-T advertisement relative to the DAC write.

Do you know whether the vendor code has an ordering requirement here, for example setting the IPQ5018 DAC before the switch-side PHY starts autonegotiation, or restarting the link after the DAC has been set? Any pointer would be much appreciated.

Thanks,
Yongzhao Chen

#19 lore raw

RFC PATCH v3 5/5 net: phy: qca83xx: disable SmartSpeed before resetting CPU PHYs

In reply to Yongzhao Chen

For flagged QCA8337 CPU PHYs, clear the SmartSpeed enable and bypass-timer bits before invoking genphy_soft_reset(). The register update preserves all other bits, and an MDIO read or write error prevents the reset. Reapply the clear prior to soft reset on system resume. Unflagged QCA8337 PHYs and QCA8327 retain their standard reset sequence.

The quirk flag is set on phydev before phy_init_hw() calls soft_reset(); config_init() executes after the reset completes, and generic config_aneg() remains in use. In the RA74 diagnostic trace, generic config_aneg() preserved CTRL1000 at 0x0600 and returned success, yet a later read returned 0x0400. The trace verified that no intervening writes occurred via the instrumented Clause 22 BMCR and CTRL1000 path, though it did not isolate the precise timing or cause of the change. A read value of 0x0400 reflects the advertised capability rather than an active negotiated link speed.

Disabling SmartSpeed before the initial reset maintained a 1 Gb/s internal link during the tested RA74 boot sequence. The experiment did not establish a broken pair condition or a functional fallback to 100 Mb/s. Board support for the RA74 is not included in this series.

Assisted-by LLM
---
 drivers/net/phy/qcom/qca83xx.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/net/phy/qcom/qca83xx.c +28 -1
index 0f484cdfe..21ab015f6 100644
@@ -91,6 +91,28 @@ static int qca83xx_probe(struct phy_device *phydev)
 	return 0;
 }
 
+static int qca8337_disable_smartspeed(struct phy_device *phydev)
+{
+	if (!(phydev->dev_flags & QCA8K_DEVFLAGS_NO_SMARTSPEED))
+		return 0;
+
+	/* SmartSpeed settings take effect at software reset. */
+	return phy_clear_bits(phydev, AT803X_SMART_SPEED,
+			      AT803X_SMART_SPEED_ENABLE |
+			      AT803X_SMART_SPEED_BYPASS_TIMER);
+}
+
+static int qca8337_soft_reset(struct phy_device *phydev)
+{
+	int ret;
+
+	ret = qca8337_disable_smartspeed(phydev);
+	if (ret)
+		return ret;
+
+	return genphy_soft_reset(phydev);
+}
+
 static int qca83xx_config_init(struct phy_device *phydev)
 {
 	u8 switch_revision;
@@ -160,6 +182,11 @@ static int qca83xx_resume(struct phy_device *phydev)
 	/* Reinit the port, reset values set by suspend */
 	qca83xx_config_init(phydev);
 
+	/* Reapply the CPU PHY quirk before the resume reset. */
+	ret = qca8337_disable_smartspeed(phydev);
+	if (ret)
+		return ret;
+
 	/* Reset the port on port resume */
 	phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
 
@@ -218,7 +245,7 @@ static struct phy_driver qca83xx_driver[] = {
 	.probe			= qca83xx_probe,
 	.flags			= PHY_IS_INTERNAL,
 	.config_init		= qca83xx_config_init,
-	.soft_reset		= genphy_soft_reset,
+	.soft_reset		= qca8337_soft_reset,
 	.get_sset_count		= qca83xx_get_sset_count,
 	.get_strings		= qca83xx_get_strings,
 	.get_stats		= qca83xx_get_stats,
Signature · 1 line
2.43.0