Skip to contentSkip to conversation

net: stmmac: dwmac-sophgo: Add phy interface filter

PATCH Superseded Inochi Amaoto 4 participants 9 messages Oct 17, 2025 – Oct 19, 2025

Subsystems (5)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Inochi Amaoto

author maintainer
#0 lore raw

PATCH 1/1 net: stmmac: dwmac-sophgo: Add phy interface filter

As the SG2042 has an internal rx delay, the delay should be remove when init the mac, otherwise the phy will be misconfigurated.

Fixes 543009e2d4cd ("net: stmmac: dwmac-sophgo: Add support for Sophgo SG2042 SoC")
---
 .../ethernet/stmicro/stmmac/dwmac-sophgo.c    | 25 ++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c +24 -1
index 3b7947a7a7ba..b2dee1399eb0 100644
@@ -7,6 +7,7 @@
 
 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/property.h>
 #include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
 
@@ -29,8 +30,23 @@ static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
 	return 0;
 }
 
+static int sophgo_sg2042_set_mode(struct plat_stmmacenet_data *plat_dat)
+{
+	switch (plat_dat->phy_interface) {
+	case PHY_INTERFACE_MODE_RGMII_ID:
+		plat_dat->phy_interface = PHY_INTERFACE_MODE_RGMII_TXID;
+		return 0;
+	case PHY_INTERFACE_MODE_RGMII_RXID:
+		plat_dat->phy_interface = PHY_INTERFACE_MODE_RGMII;
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
 static int sophgo_dwmac_probe(struct platform_device *pdev)
 {
+	int (*plat_set_mode)(struct plat_stmmacenet_data *plat_dat);
 	struct plat_stmmacenet_data *plat_dat;
 	struct stmmac_resources stmmac_res;
 	struct device *dev = &pdev->dev;
@@ -50,11 +66,18 @@ static int sophgo_dwmac_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	plat_set_mode = device_get_match_data(&pdev->dev);
+	if (plat_set_mode) {
+		ret = plat_set_mode(plat_dat);
+		if (ret)
+			return ret;
+	}
+
 	return stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
 }
 
 static const struct of_device_id sophgo_dwmac_match[] = {
-	{ .compatible = "sophgo,sg2042-dwmac" },
+	{ .compatible = "sophgo,sg2042-dwmac", .data = sophgo_sg2042_set_mode },
 	{ .compatible = "sophgo,sg2044-dwmac" },
 	{ /* sentinel */ }
 };

--
2.51.0

#1 lore raw
Quoted 2 lines · Inochi Amaoto

As the SG2042 has an internal rx delay, the delay should be remove when init the mac, otherwise the phy will be misconfigurated.

Are there any in tree DT blobs using invalid phy-modes? In theory, they should not work, but sometimes there is other magic going on. I just want to make sure this is not going to cause a regression.

Also, does the DT binding document list the valid phy-modes?

Andrew

#7 lore raw
In reply to Inochi Amaoto

Hi Inochi,

Quoted 1 line · Inochi Amaoto

As the SG2042 has an internal rx delay, the delay should be remove

s/remove/removed/

Quoted 1 line

when init the mac, otherwise the phy will be misconfigurated.

s/init/initialize/

Quoted 51 lines
Fixes 543009e2d4cd ("net: stmmac: dwmac-sophgo: Add support for Sophgo SG2042 SoC")
---
 .../ethernet/stmicro/stmmac/dwmac-sophgo.c    | 25 ++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c +19 -0
index 3b7947a7a7ba..b2dee1399eb0 100644
@@ -7,6 +7,7 @@
 
 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/property.h>
 #include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
 
@@ -29,8 +30,23 @@ static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
 	return 0;
 }
 
+static int sophgo_sg2042_set_mode(struct plat_stmmacenet_data *plat_dat)
+{
+	switch (plat_dat->phy_interface) {
+	case PHY_INTERFACE_MODE_RGMII_ID:
+		plat_dat->phy_interface = PHY_INTERFACE_MODE_RGMII_TXID;
+		return 0;
+	case PHY_INTERFACE_MODE_RGMII_RXID:
+		plat_dat->phy_interface = PHY_INTERFACE_MODE_RGMII;
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
 static int sophgo_dwmac_probe(struct platform_device *pdev)
 {
+	int (*plat_set_mode)(struct plat_stmmacenet_data *plat_dat);
 	struct plat_stmmacenet_data *plat_dat;
 	struct stmmac_resources stmmac_res;
 	struct device *dev = &pdev->dev;
@@ -50,11 +66,18 @@ static int sophgo_dwmac_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	plat_set_mode = device_get_match_data(&pdev->dev);
+	if (plat_set_mode) {
+		ret = plat_set_mode(plat_dat);

drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c static int sophgo_dwmac_probe(struct platform_device *pdev) · line 80

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c +5 -1
+		if (ret)
+			return ret;
+	}
+
 	return stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
 }
 
 static const struct of_device_id sophgo_dwmac_match[] = {
-	{ .compatible = "sophgo,sg2042-dwmac" },
+	{ .compatible = "sophgo,sg2042-dwmac", .data = sophgo_sg2042_set_mode },

I'd personally prefer to introduce a flag for this, it would be more readable and maintainable, something like

struct sophgo_dwmac_compitable_data {
	bool has_internal_rx_delay;
}

then.

	if (data->has_internal_rx_delay)
		sophgo_sg2042_set_mode(..)
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c +0 -1
 	{ .compatible = "sophgo,sg2044-dwmac" },
 	{ /* sentinel */ }
 };
--

2.51.0

Signature · 1 line
Yixun Lan (dlan)
author maintainer
#2 lore raw
In reply to Andrew Lunn
Quoted 8 lines · Andrew Lunn
Quoted 2 lines · Inochi Amaoto

As the SG2042 has an internal rx delay, the delay should be remove when init the mac, otherwise the phy will be misconfigurated.

Are there any in tree DT blobs using invalid phy-modes? In theory, they should not work, but sometimes there is other magic going on. I just want to make sure this is not going to cause a regression.

I see no SG2042 board using invalid phy-modes. Only rgmii-id is used, which is vaild.

Quoted 2 lines

Also, does the DT binding document list the valid phy-modes?

It does not list. Is it better for me to add a list for it?

Regards,
Inochi

author maintainer
#8 lore raw
In reply to Yixun Lan
Quoted 71 lines · Yixun Lan

Hi Inochi,

Quoted 1 line · Inochi Amaoto

As the SG2042 has an internal rx delay, the delay should be remove

s/remove/removed/

Quoted 1 line

when init the mac, otherwise the phy will be misconfigurated.

s/init/initialize/

Quoted 52 lines
Fixes 543009e2d4cd ("net: stmmac: dwmac-sophgo: Add support for Sophgo SG2042 SoC")
---
 .../ethernet/stmicro/stmmac/dwmac-sophgo.c    | 25 ++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c +20 -0
index 3b7947a7a7ba..b2dee1399eb0 100644
@@ -7,6 +7,7 @@
 
 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/property.h>
 #include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
 
@@ -29,8 +30,23 @@ static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
 	return 0;
 }
 
+static int sophgo_sg2042_set_mode(struct plat_stmmacenet_data *plat_dat)
+{
+	switch (plat_dat->phy_interface) {
+	case PHY_INTERFACE_MODE_RGMII_ID:
+		plat_dat->phy_interface = PHY_INTERFACE_MODE_RGMII_TXID;
+		return 0;
+	case PHY_INTERFACE_MODE_RGMII_RXID:
+		plat_dat->phy_interface = PHY_INTERFACE_MODE_RGMII;
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
 static int sophgo_dwmac_probe(struct platform_device *pdev)
 {
+	int (*plat_set_mode)(struct plat_stmmacenet_data *plat_dat);
 	struct plat_stmmacenet_data *plat_dat;
 	struct stmmac_resources stmmac_res;
 	struct device *dev = &pdev->dev;
@@ -50,11 +66,18 @@ static int sophgo_dwmac_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	plat_set_mode = device_get_match_data(&pdev->dev);
+	if (plat_set_mode) {
+		ret = plat_set_mode(plat_dat);
+		if (ret)

drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c static int sophgo_dwmac_probe(struct platform_device *pdev) · line 81

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c +4 -1
+			return ret;
+	}
+
 	return stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
 }
 
 
 static const struct of_device_id sophgo_dwmac_match[] = {
-	{ .compatible = "sophgo,sg2042-dwmac" },
+	{ .compatible = "sophgo,sg2042-dwmac", .data = sophgo_sg2042_set_mode },

I'd personally prefer to introduce a flag for this, it would be more readable and maintainable, something like

Quoted 12 lines
struct sophgo_dwmac_compitable_data {
	bool has_internal_rx_delay;
}

then.

	if (data->has_internal_rx_delay)
		sophgo_sg2042_set_mode(..)
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c +0 -0
 	{ .compatible = "sophgo,sg2044-dwmac" },
 	{ /* sentinel */ }

};

Yeah, I think this is a good idea, thanks.

Regards,
Inochi

#3 lore raw
In reply to Inochi Amaoto
Quoted 5 lines · Inochi Amaoto
Quoted 4 lines · Andrew Lunn
Quoted 2 lines · Inochi Amaoto

As the SG2042 has an internal rx delay, the delay should be remove when init the mac, otherwise the phy will be misconfigurated.

Quoted 7 lines
Quoted 4 lines

Are there any in tree DT blobs using invalid phy-modes? In theory, they should not work, but sometimes there is other magic going on. I just want to make sure this is not going to cause a regression.

I see no SG2042 board using invalid phy-modes. Only rgmii-id is used, which is vaild.

Great, thanks for checking.

Quoted 5 lines
Quoted 3 lines

Also, does the DT binding document list the valid phy-modes?

It does not list. Is it better for me to add a list for it?

It would be nice to list the valid modes, to match the code.

Andrew

#4 lore raw
Quoted 11 lines · Andrew Lunn
Quoted 10 lines · Inochi Amaoto
Quoted 8 lines · Andrew Lunn
Quoted 2 lines · Inochi Amaoto

As the SG2042 has an internal rx delay, the delay should be remove when init the mac, otherwise the phy will be misconfigurated.

Are there any in tree DT blobs using invalid phy-modes? In theory, they should not work, but sometimes there is other magic going on. I just want to make sure this is not going to cause a regression.

Quoted 4 lines
Quoted 2 lines

I see no SG2042 board using invalid phy-modes. Only rgmii-id is used, which is vaild.

Great, thanks for checking.

Hang on. Is this right?

The commit says that SG2042 has an internal receive delay. This is presumably the MAC side.

To work around that, you map rgmii-id to rgmii-txid for the PHY, to prevent the PHY from enabling its receive-side clock delay.

It seems to me that you're saying that rgmii-rxid and rgmii-id should not be used with these MACs, and you're fixing up to remove the receive-side delay.

"rgmii-id" doesn't mean "there is a delay _somewhere_ in the system". It's supposed to mean that the PHY should add delays on both tx and rx paths.

Confused.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#5 lore raw
Quoted 3 lines

"rgmii-id" doesn't mean "there is a delay _somewhere_ in the system". It's supposed to mean that the PHY should add delays on both tx and rx paths.

When passed to the PHY it means that.

However, DT describes the hardware, the PCB. "rgmii-id" means the PCB does not provide the delays. So the MAC/PHY combination needs to add the delays. We normally have the PHY provide the delays, so the phy-mode is normally passed straight to the PHY. However, if the MAC is adding a delay, which it is in this case, in one direction and cannot be turned off, the value passed to the PHY needs to reflect this, to avoid double delays.

And because the MAC delay cannot be turned off, it means there are PCB designs which don't work, double delays. So it would be nice not to list them in the binding.

Andrew

#6 lore raw
Quoted 14 lines · Andrew Lunn
Quoted 3 lines

"rgmii-id" doesn't mean "there is a delay _somewhere_ in the system". It's supposed to mean that the PHY should add delays on both tx and rx paths.

When passed to the PHY it means that.

However, DT describes the hardware, the PCB. "rgmii-id" means the PCB does not provide the delays. So the MAC/PHY combination needs to add the delays. We normally have the PHY provide the delays, so the phy-mode is normally passed straight to the PHY. However, if the MAC is adding a delay, which it is in this case, in one direction and cannot be turned off, the value passed to the PHY needs to reflect this, to avoid double delays.

Quoted 3 lines

And because the MAC delay cannot be turned off, it means there are PCB designs which don't work, double delays. So it would be nice not to list them in the binding.

Well, I find this confusing. I'd suggest there needs to be common code to deal with it so we can stop thinking about it, and just push everyone towards using the common code.

phy_interface_t phy_fix_phy_mode_for_mac_delays(phy_interface_t interface,
bool mac_txid, bool mac_rxid)

{
	if (!phy_interface_mode_is_rgmii(interface))
		return interface;

	if (mac_txid && mac_rxid) {
		if (interface == PHY_INTERFACE_MODE_RGMII_ID)
			return PHY_INTERFACE_MODE_RGMII;
		return PHY_INTERFACE_MODE_NA;
	}

	if (mac_txid) {
		if (interface == PHY_INTERFACE_MODE_RGMII_ID)
			return PHY_INTERFACE_MODE_RGMII_RXID;
		if (interface == PHY_INTERFACE_MODE_RGMII_TXID)
			return PHY_INTERFACE_MODE_RGMII;
		return PHY_INTERFACE_MODE_NA;
	}

	if (mac_rxid) {
		if (interface == PHY_INTERFACE_MODE_RGMII_ID)
			return PHY_INTERFACE_MODE_RGMII_TXID;
		if (interface == PHY_INTERFACE_MODE_RGMII_RXID)
			return PHY_INTERFACE_MODE_RGMII;
		return PHY_INTERFACE_MODE_NA;
	}

	return interface;
}
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!