devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] net: stmmac: dwmac-sophgo: Add phy interface filter
@ 2025-10-20  9:54 Inochi Amaoto
  2025-10-20  9:54 ` [PATCH v2 1/3] dt-bindings: net: sophgo,sg2044-dwmac: add phy mode restriction Inochi Amaoto
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Inochi Amaoto @ 2025-10-20  9:54 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Inochi Amaoto, Maxime Coquelin, Alexandre Torgue,
	Heiner Kallweit, Russell King, Russell King (Oracle), Han Gao,
	Icenowy Zheng, Vivian Wang, Yao Zi
  Cc: netdev, devicetree, sophgo, linux-kernel, linux-stm32,
	linux-arm-kernel, Yixun Lan, Longbin Li

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

Since this delay fix is common for other MACs, add a common helper
for it. And use it to fix SG2042.

Change from v1:
- https://lore.kernel.org/all/20251017011802.523140-1-inochiama@gmail.com
1. Add phy-mode property to dt-bindings of sophgo,sg2044-dwmac
2. Add common helper for fixing RGMII phy mode
3. Use struct to hold the compatiable data.

Inochi Amaoto (3):
  dt-bindings: net: sophgo,sg2044-dwmac: add phy mode restriction
  net: phy: Add helper for fixing RGMII PHY mode based on internal mac
    delay
  net: stmmac: dwmac-sophgo: Add phy interface filter

 .../bindings/net/sophgo,sg2044-dwmac.yaml     | 17 ++++++++
 .../ethernet/stmicro/stmmac/dwmac-sophgo.c    | 17 +++++++-
 drivers/net/phy/phy-core.c                    | 43 +++++++++++++++++++
 include/linux/phy.h                           |  3 ++
 4 files changed, 79 insertions(+), 1 deletion(-)

--
2.51.1.dirty


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/3] dt-bindings: net: sophgo,sg2044-dwmac: add phy mode restriction
  2025-10-20  9:54 [PATCH v2 0/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
@ 2025-10-20  9:54 ` Inochi Amaoto
  2025-10-20 12:05   ` Rob Herring (Arm)
  2025-10-20  9:54 ` [PATCH v2 2/3] net: phy: Add helper for fixing RGMII PHY mode based on internal mac delay Inochi Amaoto
  2025-10-20  9:54 ` [PATCH v2 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
  2 siblings, 1 reply; 9+ messages in thread
From: Inochi Amaoto @ 2025-10-20  9:54 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Inochi Amaoto, Maxime Coquelin, Alexandre Torgue,
	Heiner Kallweit, Russell King, Russell King (Oracle), Han Gao,
	Icenowy Zheng, Vivian Wang, Yao Zi
  Cc: netdev, devicetree, sophgo, linux-kernel, linux-stm32,
	linux-arm-kernel, Yixun Lan, Longbin Li

As the ethernet controller of SG2044 and SG2042 only supports
RGMII phy. Add phy-mode property to restrict the value.

Also, since SG2042 has internal rx delay in its mac, make
only "rgmii-txid" and "rgmii-id" valid for phy-mode.

Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
 .../bindings/net/sophgo,sg2044-dwmac.yaml       | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml b/Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml
index ce21979a2d9a..0f1523dc0e36 100644
--- a/Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml
+++ b/Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml
@@ -52,6 +52,13 @@ properties:
   interrupt-names:
     maxItems: 1

+  phy-mode:
+    enum:
+      - rgmii
+      - rgmii-rxid
+      - rgmii-txid
+      - rgmii-id
+
   resets:
     maxItems: 1

@@ -70,6 +77,16 @@ required:

 allOf:
   - $ref: snps,dwmac.yaml#
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: sophgo,sg2042-dwmac
+    then:
+      phy-mode:
+        enum:
+          - rgmii-txid
+          - rgmii-id

 unevaluatedProperties: false

--
2.51.1.dirty


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/3] net: phy: Add helper for fixing RGMII PHY mode based on internal mac delay
  2025-10-20  9:54 [PATCH v2 0/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
  2025-10-20  9:54 ` [PATCH v2 1/3] dt-bindings: net: sophgo,sg2044-dwmac: add phy mode restriction Inochi Amaoto
@ 2025-10-20  9:54 ` Inochi Amaoto
  2025-10-20 18:51   ` Andrew Lunn
  2025-10-20  9:54 ` [PATCH v2 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
  2 siblings, 1 reply; 9+ messages in thread
From: Inochi Amaoto @ 2025-10-20  9:54 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Inochi Amaoto, Maxime Coquelin, Alexandre Torgue,
	Heiner Kallweit, Russell King, Russell King (Oracle), Han Gao,
	Icenowy Zheng, Vivian Wang, Yao Zi
  Cc: netdev, devicetree, sophgo, linux-kernel, linux-stm32,
	linux-arm-kernel, Yixun Lan, Longbin Li

The "phy-mode" property of devicetree indicates whether the PCB has
delay now, which means the mac needs to modify the PHY mode based
on whether there is an internal delay in the mac.

This modification is similar for many ethernet drivers. To simplify
code, define the helper phy_fix_phy_mode_for_mac_delays(speed, mac_txid,
mac_rxid) to fix PHY mode based on whether mac adds internal delay.

Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
 drivers/net/phy/phy-core.c | 43 ++++++++++++++++++++++++++++++++++++++
 include/linux/phy.h        |  3 +++
 2 files changed, 46 insertions(+)

diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index 605ca20ae192..4f258fb409da 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -101,6 +101,49 @@ const char *phy_rate_matching_to_str(int rate_matching)
 }
 EXPORT_SYMBOL_GPL(phy_rate_matching_to_str);

+/**
+ * phy_fix_phy_mode_for_mac_delays - Convenience function for fixing PHY
+ * mode based on whether mac adds internal delay
+ *
+ * @interface: The current interface mode of the port
+ * @mac_txid: True if the mac adds internal tx delay
+ * @mac_rxid: True if the mac adds internal rx delay
+ *
+ * Return fixed PHY mode, or PHY_INTERFACE_MODE_NA if the interface can
+ * not apply the internal delay
+ */
+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;
+}
+EXPORT_SYMBOL_GPL(phy_fix_phy_mode_for_mac_delays);
+
 /**
  * phy_interface_num_ports - Return the number of links that can be carried by
  *			     a given MAC-PHY physical link. Returns 0 if this is
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 3c7634482356..0bc00a4cceb2 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1813,6 +1813,9 @@ static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev)
 	return phydev->is_pseudo_fixed_link;
 }

+phy_interface_t phy_fix_phy_mode_for_mac_delays(phy_interface_t interface,
+						bool mac_txid, bool mac_rxid);
+
 int phy_save_page(struct phy_device *phydev);
 int phy_select_page(struct phy_device *phydev, int page);
 int phy_restore_page(struct phy_device *phydev, int oldpage, int ret);
--
2.51.1.dirty


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter
  2025-10-20  9:54 [PATCH v2 0/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
  2025-10-20  9:54 ` [PATCH v2 1/3] dt-bindings: net: sophgo,sg2044-dwmac: add phy mode restriction Inochi Amaoto
  2025-10-20  9:54 ` [PATCH v2 2/3] net: phy: Add helper for fixing RGMII PHY mode based on internal mac delay Inochi Amaoto
@ 2025-10-20  9:54 ` Inochi Amaoto
  2025-10-20 11:02   ` Yixun Lan
  2025-10-20 18:52   ` Andrew Lunn
  2 siblings, 2 replies; 9+ messages in thread
From: Inochi Amaoto @ 2025-10-20  9:54 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Inochi Amaoto, Maxime Coquelin, Alexandre Torgue,
	Heiner Kallweit, Russell King, Russell King (Oracle), Han Gao,
	Icenowy Zheng, Vivian Wang, Yao Zi
  Cc: netdev, devicetree, sophgo, linux-kernel, linux-stm32,
	linux-arm-kernel, Yixun Lan, Longbin Li

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")
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
Tested-by: Han Gao <rabenda.cn@gmail.com>
---
 .../net/ethernet/stmicro/stmmac/dwmac-sophgo.c  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
index 3b7947a7a7ba..960357d6e282 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
@@ -7,11 +7,16 @@

 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/property.h>
 #include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>

 #include "stmmac_platform.h"

+struct sophgo_dwmac_data {
+	bool has_internal_rx_delay;
+};
+
 static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
 				    struct plat_stmmacenet_data *plat_dat,
 				    struct stmmac_resources *stmmac_res)
@@ -32,6 +37,7 @@ static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
 static int sophgo_dwmac_probe(struct platform_device *pdev)
 {
 	struct plat_stmmacenet_data *plat_dat;
+	const struct sophgo_dwmac_data *data;
 	struct stmmac_resources stmmac_res;
 	struct device *dev = &pdev->dev;
 	int ret;
@@ -50,11 +56,20 @@ static int sophgo_dwmac_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;

+	data = device_get_match_data(&pdev->dev);
+	if (data && data->has_internal_rx_delay)
+		plat_dat->phy_interface = phy_fix_phy_mode_for_mac_delays(plat_dat->phy_interface,
+									  false, true);
+
 	return stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
 }

+static struct sophgo_dwmac_data sg2042_dwmac_data = {
+	.has_internal_rx_delay = true,
+};
+
 static const struct of_device_id sophgo_dwmac_match[] = {
-	{ .compatible = "sophgo,sg2042-dwmac" },
+	{ .compatible = "sophgo,sg2042-dwmac", .data = &sg2042_dwmac_data },
 	{ .compatible = "sophgo,sg2044-dwmac" },
 	{ /* sentinel */ }
 };
--
2.51.1.dirty


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter
  2025-10-20  9:54 ` [PATCH v2 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
@ 2025-10-20 11:02   ` Yixun Lan
  2025-10-20 11:24     ` Inochi Amaoto
  2025-10-20 18:52   ` Andrew Lunn
  1 sibling, 1 reply; 9+ messages in thread
From: Yixun Lan @ 2025-10-20 11:02 UTC (permalink / raw)
  To: Inochi Amaoto
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Maxime Coquelin, Alexandre Torgue, Heiner Kallweit,
	Russell King, Russell King (Oracle), Han Gao, Icenowy Zheng,
	Vivian Wang, Yao Zi, netdev, devicetree, sophgo, linux-kernel,
	linux-stm32, linux-arm-kernel, Longbin Li

Hi Inochi,

On 17:54 Mon 20 Oct     , Inochi Amaoto wrote:
> As the SG2042 has an internal rx delay, the delay should be remove
missed my comment in v1?

> when init the mac, otherwise the phy will be misconfigurated.
> 
> Fixes: 543009e2d4cd ("net: stmmac: dwmac-sophgo: Add support for Sophgo SG2042 SoC")
> Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
> Tested-by: Han Gao <rabenda.cn@gmail.com>
> ---
>  .../net/ethernet/stmicro/stmmac/dwmac-sophgo.c  | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
> index 3b7947a7a7ba..960357d6e282 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
> @@ -7,11 +7,16 @@
> 
>  #include <linux/clk.h>
>  #include <linux/module.h>
> +#include <linux/property.h>
>  #include <linux/mod_devicetable.h>
>  #include <linux/platform_device.h>
> 
>  #include "stmmac_platform.h"
> 
> +struct sophgo_dwmac_data {
> +	bool has_internal_rx_delay;
> +};
> +
>  static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
>  				    struct plat_stmmacenet_data *plat_dat,
>  				    struct stmmac_resources *stmmac_res)
> @@ -32,6 +37,7 @@ static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
>  static int sophgo_dwmac_probe(struct platform_device *pdev)
>  {
>  	struct plat_stmmacenet_data *plat_dat;
> +	const struct sophgo_dwmac_data *data;
>  	struct stmmac_resources stmmac_res;
>  	struct device *dev = &pdev->dev;
>  	int ret;
> @@ -50,11 +56,20 @@ static int sophgo_dwmac_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
> 
> +	data = device_get_match_data(&pdev->dev);
> +	if (data && data->has_internal_rx_delay)
> +		plat_dat->phy_interface = phy_fix_phy_mode_for_mac_delays(plat_dat->phy_interface,
> +									  false, true);
> +
>  	return stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
>  }
> 
> +static struct sophgo_dwmac_data sg2042_dwmac_data = {
static const?
> +	.has_internal_rx_delay = true,
> +};
> +
>  static const struct of_device_id sophgo_dwmac_match[] = {
> -	{ .compatible = "sophgo,sg2042-dwmac" },
> +	{ .compatible = "sophgo,sg2042-dwmac", .data = &sg2042_dwmac_data },
>  	{ .compatible = "sophgo,sg2044-dwmac" },
>  	{ /* sentinel */ }
>  };
> --
> 2.51.1.dirty
> 

-- 
Yixun Lan (dlan)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter
  2025-10-20 11:02   ` Yixun Lan
@ 2025-10-20 11:24     ` Inochi Amaoto
  0 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2025-10-20 11:24 UTC (permalink / raw)
  To: Yixun Lan, Inochi Amaoto
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Maxime Coquelin, Alexandre Torgue, Heiner Kallweit,
	Russell King, Russell King (Oracle), Han Gao, Icenowy Zheng,
	Vivian Wang, Yao Zi, netdev, devicetree, sophgo, linux-kernel,
	linux-stm32, linux-arm-kernel, Longbin Li

On Mon, Oct 20, 2025 at 07:02:19PM +0800, Yixun Lan wrote:
> Hi Inochi,
> 
> On 17:54 Mon 20 Oct     , Inochi Amaoto wrote:
> > As the SG2042 has an internal rx delay, the delay should be remove
> missed my comment in v1?
> 

My fault, I forgot to fix here

> > when init the mac, otherwise the phy will be misconfigurated.
> > 
> > Fixes: 543009e2d4cd ("net: stmmac: dwmac-sophgo: Add support for Sophgo SG2042 SoC")
> > Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
> > Tested-by: Han Gao <rabenda.cn@gmail.com>
> > ---
> >  .../net/ethernet/stmicro/stmmac/dwmac-sophgo.c  | 17 ++++++++++++++++-
> >  1 file changed, 16 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
> > index 3b7947a7a7ba..960357d6e282 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
> > @@ -7,11 +7,16 @@
> > 
> >  #include <linux/clk.h>
> >  #include <linux/module.h>
> > +#include <linux/property.h>
> >  #include <linux/mod_devicetable.h>
> >  #include <linux/platform_device.h>
> > 
> >  #include "stmmac_platform.h"
> > 
> > +struct sophgo_dwmac_data {
> > +	bool has_internal_rx_delay;
> > +};
> > +
> >  static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
> >  				    struct plat_stmmacenet_data *plat_dat,
> >  				    struct stmmac_resources *stmmac_res)
> > @@ -32,6 +37,7 @@ static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
> >  static int sophgo_dwmac_probe(struct platform_device *pdev)
> >  {
> >  	struct plat_stmmacenet_data *plat_dat;
> > +	const struct sophgo_dwmac_data *data;
> >  	struct stmmac_resources stmmac_res;
> >  	struct device *dev = &pdev->dev;
> >  	int ret;
> > @@ -50,11 +56,20 @@ static int sophgo_dwmac_probe(struct platform_device *pdev)
> >  	if (ret)
> >  		return ret;
> > 
> > +	data = device_get_match_data(&pdev->dev);
> > +	if (data && data->has_internal_rx_delay)
> > +		plat_dat->phy_interface = phy_fix_phy_mode_for_mac_delays(plat_dat->phy_interface,
> > +									  false, true);
> > +
> >  	return stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
> >  }
> > 
> > +static struct sophgo_dwmac_data sg2042_dwmac_data = {
> static const?

Right.

> > +	.has_internal_rx_delay = true,
> > +};
> > +
> >  static const struct of_device_id sophgo_dwmac_match[] = {
> > -	{ .compatible = "sophgo,sg2042-dwmac" },
> > +	{ .compatible = "sophgo,sg2042-dwmac", .data = &sg2042_dwmac_data },
> >  	{ .compatible = "sophgo,sg2044-dwmac" },
> >  	{ /* sentinel */ }
> >  };
> > --
> > 2.51.1.dirty
> > 
> 
> -- 
> Yixun Lan (dlan)

Regards,
Inochi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/3] dt-bindings: net: sophgo,sg2044-dwmac: add phy mode restriction
  2025-10-20  9:54 ` [PATCH v2 1/3] dt-bindings: net: sophgo,sg2044-dwmac: add phy mode restriction Inochi Amaoto
@ 2025-10-20 12:05   ` Rob Herring (Arm)
  0 siblings, 0 replies; 9+ messages in thread
From: Rob Herring (Arm) @ 2025-10-20 12:05 UTC (permalink / raw)
  To: Inochi Amaoto
  Cc: Icenowy Zheng, Han Gao, Yao Zi, linux-kernel, Alexandre Torgue,
	Chen Wang, sophgo, Vivian Wang, Conor Dooley, Maxime Coquelin,
	Eric Dumazet, Russell King, Krzysztof Kozlowski, netdev,
	Yixun Lan, Russell King (Oracle), devicetree, linux-arm-kernel,
	Andrew Lunn, linux-stm32, Longbin Li, Jakub Kicinski, Paolo Abeni,
	Heiner Kallweit, David S. Miller


On Mon, 20 Oct 2025 17:54:57 +0800, Inochi Amaoto wrote:
> As the ethernet controller of SG2044 and SG2042 only supports
> RGMII phy. Add phy-mode property to restrict the value.
> 
> Also, since SG2042 has internal rx delay in its mac, make
> only "rgmii-txid" and "rgmii-id" valid for phy-mode.
> 
> Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
> ---
>  .../bindings/net/sophgo,sg2044-dwmac.yaml       | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml: allOf:1:then: 'anyOf' conditional failed, one must be fixed:
	'phy-mode' is not one of ['$ref', 'additionalItems', 'additionalProperties', 'allOf', 'anyOf', 'const', 'contains', 'default', 'dependencies', 'dependentRequired', 'dependentSchemas', 'deprecated', 'description', 'else', 'enum', 'exclusiveMaximum', 'exclusiveMinimum', 'items', 'if', 'minItems', 'minimum', 'maxItems', 'maximum', 'multipleOf', 'not', 'oneOf', 'pattern', 'patternProperties', 'properties', 'required', 'then', 'typeSize', 'unevaluatedProperties', 'uniqueItems']
	'type' was expected
	from schema $id: http://devicetree.org/meta-schemas/keywords.yaml#

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20251020095500.1330057-2-inochiama@gmail.com

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/3] net: phy: Add helper for fixing RGMII PHY mode based on internal mac delay
  2025-10-20  9:54 ` [PATCH v2 2/3] net: phy: Add helper for fixing RGMII PHY mode based on internal mac delay Inochi Amaoto
@ 2025-10-20 18:51   ` Andrew Lunn
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Lunn @ 2025-10-20 18:51 UTC (permalink / raw)
  To: Inochi Amaoto
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Maxime Coquelin, Alexandre Torgue, Heiner Kallweit,
	Russell King, Russell King (Oracle), Han Gao, Icenowy Zheng,
	Vivian Wang, Yao Zi, netdev, devicetree, sophgo, linux-kernel,
	linux-stm32, linux-arm-kernel, Yixun Lan, Longbin Li

On Mon, Oct 20, 2025 at 05:54:58PM +0800, Inochi Amaoto wrote:
> The "phy-mode" property of devicetree indicates whether the PCB has
> delay now, which means the mac needs to modify the PHY mode based
> on whether there is an internal delay in the mac.
> 
> This modification is similar for many ethernet drivers. To simplify
> code, define the helper phy_fix_phy_mode_for_mac_delays(speed, mac_txid,
> mac_rxid) to fix PHY mode based on whether mac adds internal delay.
> 
> Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
> ---
>  drivers/net/phy/phy-core.c | 43 ++++++++++++++++++++++++++++++++++++++
>  include/linux/phy.h        |  3 +++
>  2 files changed, 46 insertions(+)
> 
> diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
> index 605ca20ae192..4f258fb409da 100644
> --- a/drivers/net/phy/phy-core.c
> +++ b/drivers/net/phy/phy-core.c
> @@ -101,6 +101,49 @@ const char *phy_rate_matching_to_str(int rate_matching)
>  }
>  EXPORT_SYMBOL_GPL(phy_rate_matching_to_str);
> 
> +/**
> + * phy_fix_phy_mode_for_mac_delays - Convenience function for fixing PHY
> + * mode based on whether mac adds internal delay
> + *
> + * @interface: The current interface mode of the port
> + * @mac_txid: True if the mac adds internal tx delay
> + * @mac_rxid: True if the mac adds internal rx delay
> + *
> + * Return fixed PHY mode, or PHY_INTERFACE_MODE_NA if the interface can
> + * not apply the internal delay
> + */

I think a helper like this is a good idea. But there are a couple of
things i don't like about this implementation.

I don't like returning PHY_INTERFACE_MODE_NA on error. I would prefer
-EINVAL.  of_get_phy_mode() passed a phy_interface_t *, and returns an
errno. The same would be good here.

I find:

phy_fix_phy_mode_for_mac_delays(interface, true, false)

hard to read. You cannot see what these true/false mean. Which is Rx
and which is Tx?

Rather than true false, how about passing an
PHY_INTERFACE_MODE_RGMII_* values?

PHY_INTERFACE_MODE_RGMII_ID would indicate the MAC is doing both
delays.  PHY_INTERFACE_MODE_RGMII_RXID the MAC is implementing the RX
delay? I'm open to other ideas here.

	Andrew

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter
  2025-10-20  9:54 ` [PATCH v2 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
  2025-10-20 11:02   ` Yixun Lan
@ 2025-10-20 18:52   ` Andrew Lunn
  1 sibling, 0 replies; 9+ messages in thread
From: Andrew Lunn @ 2025-10-20 18:52 UTC (permalink / raw)
  To: Inochi Amaoto
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Maxime Coquelin, Alexandre Torgue, Heiner Kallweit,
	Russell King, Russell King (Oracle), Han Gao, Icenowy Zheng,
	Vivian Wang, Yao Zi, netdev, devicetree, sophgo, linux-kernel,
	linux-stm32, linux-arm-kernel, Yixun Lan, Longbin Li

> +	data = device_get_match_data(&pdev->dev);
> +	if (data && data->has_internal_rx_delay)
> +		plat_dat->phy_interface = phy_fix_phy_mode_for_mac_delays(plat_dat->phy_interface,
> +									  false, true);

You should check the return value and if it is _NA, return -EIVAL.

    Andrew

---
pw-bot: cr

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-10-20 18:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20  9:54 [PATCH v2 0/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
2025-10-20  9:54 ` [PATCH v2 1/3] dt-bindings: net: sophgo,sg2044-dwmac: add phy mode restriction Inochi Amaoto
2025-10-20 12:05   ` Rob Herring (Arm)
2025-10-20  9:54 ` [PATCH v2 2/3] net: phy: Add helper for fixing RGMII PHY mode based on internal mac delay Inochi Amaoto
2025-10-20 18:51   ` Andrew Lunn
2025-10-20  9:54 ` [PATCH v2 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
2025-10-20 11:02   ` Yixun Lan
2025-10-20 11:24     ` Inochi Amaoto
2025-10-20 18:52   ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).