Skip to contentSkip to conversation

highly rfc macb usrio/tsu patches

RFC Superseded Conor Dooley 1 participant 9 messages Nov 20, 2025

Subsystems (6)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover highly rfc macb usrio/tsu patches

From: Conor Dooley <[email protected]>

Hey folks,

After doing some debugging of broken tsu/ptp support on mpfs, I've come up with some very rfc patches that I'd like opinions on - particularly because they impact a bunch of platforms that I have no access to at all and have no idea how they work. The at91 platforms I can just ask Nicolas about (and he already provided some info directly, so I'm not super worried at least about the usrio portion there) but the others my gut says are likely incorrect in the driver at the moment.

These patches *are* fairly opinionated and not necessarily technically correct or w/e. The only thing I am confident in saying that they are is more deliberate than what's being done at the moment.

At the very least, it'd be good of the soc vendor folks could check their platforms and see if their usrio stuff actually lines up with what the driver currently calls "macb_default_usrio". Ours didn't and it was a nasty surprise.

Cheers,
Conor.

CC Andrew Lunn <[email protected]>
CC David S. Miller <[email protected]>
CC Eric Dumazet <[email protected]>
CC Jakub Kicinski <[email protected]>
CC Paolo Abeni <[email protected]>
CC Rob Herring <[email protected]>
CC Krzysztof Kozlowski <[email protected]>
CC Conor Dooley <[email protected]>
CC Daire McNamara <[email protected]>
CC Paul Walmsley <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Albert Ou <[email protected]>
CC Alexandre Ghiti <[email protected]>
CC Nicolas Ferre <[email protected]>
CC Claudiu Beznea <[email protected]>
CC Richard Cochran <[email protected]>
CC Samuel Holland <[email protected]>
CC Neil Armstrong <[email protected]>
CC Dave Stevenson <[email protected]>
CC Sean Anderson <[email protected]>
CC Vineeth Karumanchi <[email protected]>
CC Abin Joseph <[email protected]>

Conor Dooley (7):
riscv: dts: microchip: add tsu clock to macb on mpfs
net: macb: warn on pclk use as a tsu_clk fallback
net: macb: rename macb_default_usrio to at91_default_usrio as not all
platforms have mii mode control in usrio
net: macb: np4 doesn't need a usrio pointer
dt-bindings: net: macb: add property indicating timer adjust mode
net: macb: afaict, the driver doesn't support tsu timer adjust mode
net: macb: add mpfs specific usrio configuration

 .../devicetree/bindings/net/cdns,macb.yaml    |  15 +++
 arch/riscv/boot/dts/microchip/Makefile.orig   |  26 ++++
 arch/riscv/boot/dts/microchip/mpfs.dtsi       |   8 +-
 drivers/net/ethernet/cadence/macb.h           |   3 +
 drivers/net/ethernet/cadence/macb_main.c      | 123 +++++++++++-------
 5 files changed, 125 insertions(+), 50 deletions(-)
 create mode 100644 arch/riscv/boot/dts/microchip/Makefile.orig
Signature · 1 line
2.51.0
#1 lore raw

RFC 1/7 riscv: dts: microchip: add tsu clock to macb on mpfs

From: Conor Dooley <[email protected]>

In increment mode, the tsu clock for the macb is provided separately to the pck, usually the same clock as the reference to the rtc provided by an off-chip oscillator. pclk is 150 MHz typically, and the reference is either 100 MHz or 125 MHz, so having the tsu clock is required for correct rate selection.

---
 arch/riscv/boot/dts/microchip/Makefile.orig | 26 +++++++++++++++++++++
 arch/riscv/boot/dts/microchip/mpfs.dtsi     |  8 +++----
 2 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 arch/riscv/boot/dts/microchip/Makefile.orig
arch/riscv/boot/dts/microchip/Makefile.orig new file +26 -0
new file mode 100644
index 000000000000..e94f4096fd40
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: GPL-2.0
+<<<<<<< HEAD
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-beaglev-fire.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-disco-kit.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-icicle-kit.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-icicle-kit-prod.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-m100pfsevp.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-polarberry.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-sev-kit.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-tysom-m.dtb
+||||||| constructed fake ancestor
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-beaglev-fire.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-icicle-kit.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-m100pfsevp.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-polarberry.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-sev-kit.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP_POLARFIRE) += mpfs-tysom-m.dtb
+=======
+dtb-$(CONFIG_ARCH_MICROCHIP) += mpfs-beaglev-fire.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP) += mpfs-icicle-kit.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP) += mpfs-m100pfsevp.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP) += mpfs-polarberry.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP) += mpfs-sev-kit.dtb
+dtb-$(CONFIG_ARCH_MICROCHIP) += mpfs-tysom-m.dtb
+>>>>>>> riscv: dts: microchip: remove POLARFIRE mention in Makefile
+dtb-$(CONFIG_ARCH_MICROCHIP) += pic64gx-curiosity-kit.dtb
arch/riscv/boot/dts/microchip/mpfs.dtsi +4 -4
index 9883ca3554c5..68e130550130 100644
@@ -445,8 +445,8 @@ mac0: ethernet@20110000 {
 			interrupt-parent = <&plic>;
 			interrupts = <64>, <65>, <66>, <67>, <68>, <69>;
 			local-mac-address = [00 00 00 00 00 00];
-			clocks = <&clkcfg CLK_MAC0>, <&clkcfg CLK_AHB>;
-			clock-names = "pclk", "hclk";
+			clocks = <&clkcfg CLK_MAC0>, <&clkcfg CLK_AHB>, <&refclk>;
+			clock-names = "pclk", "hclk", "tsu_clk";
 			resets = <&clkcfg CLK_MAC0>;
 			status = "disabled";
 		};
@@ -459,8 +459,8 @@ mac1: ethernet@20112000 {
 			interrupt-parent = <&plic>;
 			interrupts = <70>, <71>, <72>, <73>, <74>, <75>;
 			local-mac-address = [00 00 00 00 00 00];
-			clocks = <&clkcfg CLK_MAC1>, <&clkcfg CLK_AHB>;
-			clock-names = "pclk", "hclk";
+			clocks = <&clkcfg CLK_MAC1>, <&clkcfg CLK_AHB>, <&refclk>;
+			clock-names = "pclk", "hclk", "tsu_clk";
 			resets = <&clkcfg CLK_MAC1>;
 			status = "disabled";
 		};
Signature · 1 line
2.51.0
#2 lore raw

RFC 2/7 net: macb: warn on pclk use as a tsu_clk fallback

In reply to Conor Dooley

From: Conor Dooley <[email protected]>

Not a serious patch as-is, but I think this pclk fallback code is not really a good idea.

I think the reason that it exists is that there is a parameter for the IP that will make the hardware use the pclk to clock the timestamper, but from a devicetree and driver point of view I don't think this is actually really relevant and this code is just bug prone.

It makes more sense for the binding/driver if the tsu_clk clock represents whatever clock is clocking the timestamper, not specifically the tsu_clk input to the IP block, because what it does at the moment will register the ptp clock with an incorrect clock in the "right" (or wrong I guess) circumstances. This can happen when the capability MACB_CAPS_GEM_HAS_PTP is set for the integration, MACB_USE_HWSTAMP is set (which a multiplatform kernel would) but the devicetree does not provide a tsu_clk. Sure, that probably means the devicetree is wrong, but there's no per-compatible clocks enforcement in the binding so getting it right might not be so easy!

It's my opinion that, regardless of the way the parameter is set, it makes sense for the binding/driver if the "tsu_clk" clock actually represents the clock being used by the timestamper, not strictly the clock provided to the tsu_clk input to the IP block. That's because there appears to be nothing done differently between the two cases w.r.t. configuring the hardware at runtime and it allows us to be sure the ptp clock will not be registered with the wrong clock. Obviously, for compatibility reasons I can't just delete this fallback though, because there are devices using it, so just warn in the hopes that the devices that actually use pclk for the timestamper can be updated to explicitly provide it.

Out of the devices that claim MACB_CAPS_GEM_HAS_PTP the fu540, mpfs, sama5d2 and sama7g5-emac (but not sama7g5-gem) are at risk of having this problem. It may be that these platforms actually do use the pclk for the timestamper (either by supplying pclk to the tsu_clk input of the IP, or by having the IP block configured to use pclk instead of the tsu_clk input). mpfs is wrong though, it does not use pclk for the tsu_clk, so the driver is registering the ptp clock incorrectly.

---
As I say, not a serious patch at the moment, but I'd like to know what folks think here. All of the Xilinx platforms I looked at explicitly provide the tsu_clk, so aren't impacted.
I know this changes the meaning of the dt-binding, but I don't think it is harmful to do so, as it is a nop for any existing devices that provide tsu_clk.

---
 drivers/net/ethernet/cadence/macb_main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/cadence/macb_main.c +1 -0
index ca2386b83473..b9248f52dd5b 100644
@@ -3567,6 +3567,7 @@ static unsigned int gem_get_tsu_rate(struct macb *bp)
 	else if (!IS_ERR(bp->pclk)) {
 		tsu_clk = bp->pclk;
 		tsu_rate = clk_get_rate(tsu_clk);
+		dev_warn(&bp->pdev->dev, "devicetree missing tsu_clk, using pclk as fallback\n");
 	} else
 		return -ENOTSUPP;
 	return tsu_rate;
Signature · 1 line
2.51.0
#3 lore raw

RFC 3/7 net: macb: rename macb_default_usrio to at91_default_usrio as not all platforms have mii mode control in usrio

In reply to Conor Dooley

From: Conor Dooley <[email protected]>

Calling this structure macb_default_usrio is misleading, I believe, as it implies that it should be used if your platform has nothing special to do in usrio. Since usrio is platform dependant, the default here is probably for each usrio to do nothing, with the macb documentation I have access to prescribing no standard behaviour here. We noticed that this was problematic because on mpfs, a bit that macb_default_usrio sets to deal with the MII mode actually changes the source for the tsu_clk to something with how the majority of mpfs devices are actually configured!

Rename it to at91_default_usrio, since that's where the values actually come from for these. I have no idea if any of the other platforms that use the default actually copied at91's usrio configuration or if they have usrio configurations where what the driver does has no impact.

Gate touching these bits behind a capability, like the clken refclock usrio knob, so that platforms without the MII mode stuff can avoid running this code.

---
 drivers/net/ethernet/cadence/macb.h      |   1 +
 drivers/net/ethernet/cadence/macb_main.c | 106 +++++++++++++----------
 2 files changed, 62 insertions(+), 45 deletions(-)
drivers/net/ethernet/cadence/macb.h +1 -0
index 0830c48973aa..59881c48485b 100644
@@ -769,6 +769,7 @@
 #define MACB_CAPS_NEED_TSUCLK			0x00000400
 #define MACB_CAPS_QUEUE_DISABLE			0x00000800
 #define MACB_CAPS_QBV				0x00001000
+#define MACB_CAPS_USRIO_HAS_MII			0x00002000
 #define MACB_CAPS_PCS				0x01000000
 #define MACB_CAPS_HIGH_SPEED			0x02000000
 #define MACB_CAPS_CLK_HW_CHG			0x04000000
drivers/net/ethernet/cadence/macb_main.c +61 -45

247 lines not on this page · raw message

Signature · 1 line
2.51.0
#4 lore raw

RFC 4/7 net: macb: np4 doesn't need a usrio pointer

In reply to Conor Dooley

From: Conor Dooley <[email protected]>

USRIO is disabled on this platform, having a pointer to a usrio config structure doesn't actually do anything other than look weird.

---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +1 -1
index 888a72c40f26..21045575f19c 100644
@@ -5314,7 +5314,7 @@ static const struct macb_config np4_config = {
 	.caps = MACB_CAPS_USRIO_DISABLED,
 	.clk_init = macb_clk_init,
 	.init = macb_init,
-	.usrio = &at91_default_usrio,
+	.usrio = NULL,
 };
 
 static const struct macb_config zynqmp_config = {
Signature · 1 line
2.51.0
#5 lore raw

RFC 5/7 dt-bindings: net: macb: add property indicating timer adjust mode

In reply to Conor Dooley

From: Conor Dooley <[email protected]>

---
 .../devicetree/bindings/net/cdns,macb.yaml        | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
Documentation/devicetree/bindings/net/cdns,macb.yaml +15 -0
index 1029786a855c..4cea288412b5 100644
@@ -116,6 +116,12 @@ properties:
   power-domains:
     maxItems: 1
 
+  cdns,timer-adjust:
+    type: boolean
+    description:
+      Set when the hardware is operating in timer-adjust mode, where the timer
+      is controlled by the gem_tsu_inc_ctrl and gem_tsu_ms inputs.
+
   cdns,refclk-ext:
     type: boolean
     description:
@@ -182,6 +188,15 @@ allOf:
       properties:
         reg:
           maxItems: 1
+  - if:
+      not:
+        properties:
+          compatible:
+            contains:
+              const: microchip,mpfs-macb
+    then:
+      properties:
+        cdns,timer-adjust: false
 
 unevaluatedProperties: false
 
Signature · 1 line
2.51.0
#6 lore raw

RFC 6/7 net: macb: afaict, the driver doesn't support tsu timer adjust mode

In reply to Conor Dooley

From: Conor Dooley <[email protected]>

The ptp portion of this driver controls the tsu's timer, which is not compatible with the hardware trying to control it via the gem_tsu_inc_ctrl and gem_tsu_ms inputs afaict. Abort probe if someone tries to use it.

---
 drivers/net/ethernet/cadence/macb_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/cadence/macb_main.c +6 -0
index 21045575f19c..4ad1409dab63 100644
@@ -5531,6 +5531,12 @@ static int macb_probe(struct platform_device *pdev)
 
 	bp->usrio = macb_config->usrio;
 
+	if (of_property_read_bool(bp->pdev->dev.of_node, "cdns,timer-adjust") &&
+			IS_ENABLED(CONFIG_MACB_USE_HWSTAMP)) {
+		dev_err(&pdev->dev, "Timer adjust mode is not supported\n");
+		goto err_out_free_netdev;
+	}
+
 	/* By default we set to partial store and forward mode for zynqmp.
 	 * Disable if not set in devicetree.
 	 */
Signature · 1 line
2.51.0
#7 lore raw

RFC 7/7 net: macb: add mpfs specific usrio configuration

In reply to Conor Dooley

From: Conor Dooley <[email protected]>

On mpfs the driver needs to make sure the tsu clock source is not the fabric, as this requires that the hardware is in Timer Adjust mode, which is not compatible with the linux driver trying to control the hardware AFAICT.

---
This may actually be a waste of time, since a) the peripheral is reset by the driver during probe which zeroes it, b) the timer-adjust mode is not permitted, so setting a 1 here is not ever done and c) the value written by the driver to the usrio register starts as zero, so would clear this bit anyway, were it to be set somehow.
The alternative would be just setting the usrio struct pointer to NULL since none of the caps that would cause it to be accessed are set on this platform.

---
 drivers/net/ethernet/cadence/macb.h      |  2 ++
 drivers/net/ethernet/cadence/macb_main.c | 12 ++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/net/ethernet/cadence/macb.h +2 -0
index 59881c48485b..d30682db410a 100644
@@ -770,6 +770,7 @@
 #define MACB_CAPS_QUEUE_DISABLE			0x00000800
 #define MACB_CAPS_QBV				0x00001000
 #define MACB_CAPS_USRIO_HAS_MII			0x00002000
+#define MACB_CAPS_USRIO_TSUCLK_SOURCE		0x00004000
 #define MACB_CAPS_PCS				0x01000000
 #define MACB_CAPS_HIGH_SPEED			0x02000000
 #define MACB_CAPS_CLK_HW_CHG			0x04000000
@@ -1217,6 +1218,7 @@ struct macb_usrio_config {
 	u32 rgmii;
 	u32 refclk;
 	u32 hdfctlen;
+	u32 tsu_source;
 };
 
 struct macb_config {
drivers/net/ethernet/cadence/macb_main.c +10 -2
index 4ad1409dab63..dd14bb4c9e26 100644
@@ -4649,6 +4649,9 @@ static int macb_init(struct platform_device *pdev)
 		if (bp->caps & MACB_CAPS_USRIO_HAS_CLKEN)
 			val |= bp->usrio->refclk;
 
+		if (bp->caps & MACB_CAPS_USRIO_TSUCLK_SOURCE)
+			val |= bp->usrio->tsu_source;
+
 		macb_or_gem_writel(bp, USRIO, val);
 	}
 
@@ -5219,6 +5222,10 @@ static const struct macb_usrio_config at91_default_usrio = {
 	.refclk = MACB_BIT(CLKEN),
 };
 
+static const struct macb_usrio_config mpfs_usrio = {
+	.tsu_source = 0,
+};
+
 static const struct macb_usrio_config sama7g5_usrio = {
 	.mii = 0,
 	.rmii = 1,
@@ -5342,11 +5349,12 @@ static const struct macb_config zynq_config = {
 static const struct macb_config mpfs_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE |
 		MACB_CAPS_JUMBO |
-		MACB_CAPS_GEM_HAS_PTP,
+		MACB_CAPS_GEM_HAS_PTP |
+		MACB_CAPS_USRIO_TSUCLK_SOURCE,
 	.dma_burst_length = 16,
 	.clk_init = macb_clk_init,
 	.init = init_reset_optional,
-	.usrio = &at91_default_usrio,
+	.usrio = &mpfs_usrio,
 	.max_tx_length = 4040, /* Cadence Erratum 1686 */
 	.jumbo_max_len = 4040,
 };
Signature · 1 line
2.51.0
#8 lore raw
In reply to Conor Dooley
Quoted 39 lines · Conor Dooley

From: Conor Dooley <[email protected]>

Hey folks,

After doing some debugging of broken tsu/ptp support on mpfs, I've come up with some very rfc patches that I'd like opinions on - particularly because they impact a bunch of platforms that I have no access to at all and have no idea how they work. The at91 platforms I can just ask Nicolas about (and he already provided some info directly, so I'm not super worried at least about the usrio portion there) but the others my gut says are likely incorrect in the driver at the moment.

These patches *are* fairly opinionated and not necessarily technically correct or w/e. The only thing I am confident in saying that they are is more deliberate than what's being done at the moment.

At the very least, it'd be good of the soc vendor folks could check their platforms and see if their usrio stuff actually lines up with what the driver currently calls "macb_default_usrio". Ours didn't and it was a nasty surprise.

Cheers,
Conor.

CC Andrew Lunn <[email protected]>
CC David S. Miller <[email protected]>
CC Eric Dumazet <[email protected]>
CC Jakub Kicinski <[email protected]>
CC Paolo Abeni <[email protected]>
CC Rob Herring <[email protected]>
CC Krzysztof Kozlowski <[email protected]>
CC Conor Dooley <[email protected]>
CC Daire McNamara <[email protected]>
CC Paul Walmsley <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Albert Ou <[email protected]>
CC Alexandre Ghiti <[email protected]>
CC Nicolas Ferre <[email protected]>
Quoted 8 lines

The perils of grabbing addresses from git blame..
+CC Neil @ linaro.

Quoted 26 lines
CC Dave Stevenson <[email protected]>
CC Sean Anderson <[email protected]>
CC Vineeth Karumanchi <[email protected]>
CC Abin Joseph <[email protected]>

Conor Dooley (7):
riscv: dts: microchip: add tsu clock to macb on mpfs
net: macb: warn on pclk use as a tsu_clk fallback
net: macb: rename macb_default_usrio to at91_default_usrio as not all
platforms have mii mode control in usrio
net: macb: np4 doesn't need a usrio pointer
dt-bindings: net: macb: add property indicating timer adjust mode
net: macb: afaict, the driver doesn't support tsu timer adjust mode
net: macb: add mpfs specific usrio configuration

 .../devicetree/bindings/net/cdns,macb.yaml    |  15 +++
 arch/riscv/boot/dts/microchip/Makefile.orig   |  26 ++++
 arch/riscv/boot/dts/microchip/mpfs.dtsi       |   8 +-
 drivers/net/ethernet/cadence/macb.h           |   3 +
 drivers/net/ethernet/cadence/macb_main.c      | 123 +++++++++++-------
 5 files changed, 125 insertions(+), 50 deletions(-)
 create mode 100644 arch/riscv/boot/dts/microchip/Makefile.orig
Signature · 1 line
2.51.0