Skip to contentSkip to conversation

net: sun8i-emac: Add support for fixed-link phy

PATCH Superseded Maxim Kiselev 3 participants 8 messages Jun 14, 2023 – Jan 19, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: sun8i-emac: Add support for fixed-link phy

From: Maksim Kiselev <[email protected]>

Based on dt-specs fixed-link doesn't require phy-handle to be used. Fix driver to only read phy related setting when phy-handle is found.

---
 drivers/net/sun8i_emac.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/sun8i_emac.c +2 -5
index 04c3274fbe..0e339d69e0 100644
@@ -834,11 +834,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
 	priv->use_internal_phy = false;
 
 	offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
-	if (offset < 0) {
-		debug("%s: Cannot find PHY address\n", __func__);
-		return -EINVAL;
-	}
-	priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
+	if (offset >= 0)
+		priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
 
 	pdata->phy_interface = dev_read_phy_mode(dev);
 	debug("phy interface %d\n", pdata->phy_interface);
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Maxim Kiselev

From: Maksim Kiselev <[email protected]>

Based on dt-specs fixed-link doesn't require phy-handle to be used. Fix driver to only read phy related setting when phy-handle is found.

---
 drivers/net/sun8i_emac.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/sun8i_emac.c +2 -6
index 04c3274fbe..0e339d69e0 100644
@@ -834,11 +834,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
        priv->use_internal_phy = false;
 
        offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
-       if (offset < 0) {
-               debug("%s: Cannot find PHY address\n", __func__);
-               return -EINVAL;
-       }
-       priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
+       if (offset >= 0)
+               priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
 
        pdata->phy_interface = dev_read_phy_mode(dev);
        debug("phy interface %d\n", pdata->phy_interface);
--
Quoted 2 lines

2.39.2

#2 lore raw
In reply to Maxim Kiselev

On Thu, 15 Jun 2023 00:44:06 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 3 lines

From: Maksim Kiselev <[email protected]>

Based on dt-specs fixed-link doesn't require phy-handle to be used.

Do you have such a board? And where is that written down? I don't see it explicitly mentioned as optional in ethernet-controller.yaml or in the DT spec PDF. The sun8i EMAC binding lists phy-handle as required, so that would need to be relaxed there then.

Quoted 1 line

Fix driver to only read phy related setting when phy-handle is found.

The patch itself looks fine, we already specify -1 as the default when the PHY DT node does not contain a reg property, so that looks like it would work.

Cheers,
Andre

Quoted 23 lines
---
 drivers/net/sun8i_emac.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/sun8i_emac.c +2 -5
index 04c3274fbe..0e339d69e0 100644
@@ -834,11 +834,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
 	priv->use_internal_phy = false;
 
 	offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
-	if (offset < 0) {
-		debug("%s: Cannot find PHY address\n", __func__);
-		return -EINVAL;
-	}
-	priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
+	if (offset >= 0)
+		priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
 
 	pdata->phy_interface = dev_read_phy_mode(dev);
 	debug("phy interface %d\n", pdata->phy_interface);
#3 lore raw

вт, 16 янв. 2024 г. в 03:18, Andre Przywara <[email protected]>:

Quoted 11 lines

On Thu, 15 Jun 2023 00:44:06 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 3 lines

From: Maksim Kiselev <[email protected]>

Based on dt-specs fixed-link doesn't require phy-handle to be used.

Do you have such a board?

Yes, I had a custom board with T113 SoC which has fixed phy eth.

Quoted 3 lines

And where is that written down? I don't see
it explicitly mentioned as optional in ethernet-controller.yaml or in the DT spec PDF.

Sorry for that commit description. I just found the similar commit, that fixes the same problem for zynq_gem 3888c8d1979289efe685fe29276aed4d4b685975 ("net: zynq_gem: Add support for fixed-link phy") and copied the description from there.

Quoted 2 lines

The sun8i EMAC binding lists phy-handle as required, so that would need to be relaxed there then.

Oh, indeed. So it will require to send dt-binding changes to Linux first...

Therefore, I think we can live without fixed-phy support for sun8i EMAC. At least until some device with such a configuration appears on the market :)

Quoted 30 lines
Quoted 1 line

Fix driver to only read phy related setting when phy-handle is found.

The patch itself looks fine, we already specify -1 as the default when the PHY DT node does not contain a reg property, so that looks like it would work.

Cheers,
Andre

Quoted 21 lines
---
 drivers/net/sun8i_emac.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/sun8i_emac.c +2 -5
index 04c3274fbe..0e339d69e0 100644
@@ -834,11 +834,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
      priv->use_internal_phy = false;
 
      offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
-     if (offset < 0) {
-             debug("%s: Cannot find PHY address\n", __func__);
-             return -EINVAL;
-     }
-     priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
+     if (offset >= 0)
+             priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
 
Quoted 3 lines

drivers/net/sun8i_emac.c static int sun8i_emac_eth_of_to_plat(struct udevice *dev) · line 841

Quoted 2 lines
drivers/net/sun8i_emac.c +0 -0
      pdata->phy_interface = dev_read_phy_mode(dev);
      debug("phy interface %d\n", pdata->phy_interface);

Best wishes,
Maksim

#4 lore raw

On Tue, 16 Jan 2024 19:58:56 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 24 lines

вт, 16 янв. 2024 г. в 03:18, Andre Przywara <[email protected]>:

Quoted 11 lines

On Thu, 15 Jun 2023 00:44:06 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 3 lines

From: Maksim Kiselev <[email protected]>

Based on dt-specs fixed-link doesn't require phy-handle to be used.

Do you have such a board?

Yes, I had a custom board with T113 SoC which has fixed phy eth.

Quoted 3 lines

And where is that written down? I don't see
it explicitly mentioned as optional in ethernet-controller.yaml or in the DT spec PDF.

Sorry for that commit description. I just found the similar commit, that fixes the same problem for zynq_gem 3888c8d1979289efe685fe29276aed4d4b685975 ("net: zynq_gem: Add support for fixed-link phy") and copied the description from there.

Quoted 4 lines
Quoted 2 lines

The sun8i EMAC binding lists phy-handle as required, so that would need to be relaxed there then.

Oh, indeed. So it will require to send dt-binding changes to Linux first...

Well, in the long run yes, but this doesn't mean that this patch needs to wait - if that fixes a problem for you. I think in general that rationale is probably true and phy-handle should be optional, especially since the code can already cope with it.

I would just like to have this documented in the commit message.

Cheers,
Andre

Quoted 40 lines

Therefore, I think we can live without fixed-phy support for sun8i EMAC. At least until some device with such a configuration appears on the market :)

Quoted 30 lines
Quoted 1 line

Fix driver to only read phy related setting when phy-handle is found.

The patch itself looks fine, we already specify -1 as the default when the PHY DT node does not contain a reg property, so that looks like it would work.

Cheers,
Andre

Quoted 21 lines
---
 drivers/net/sun8i_emac.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/sun8i_emac.c +2 -5
index 04c3274fbe..0e339d69e0 100644
@@ -834,11 +834,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
      priv->use_internal_phy = false;
 
      offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
-     if (offset < 0) {
-             debug("%s: Cannot find PHY address\n", __func__);
-             return -EINVAL;
-     }
-     priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
+     if (offset >= 0)
+             priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
 
Quoted 3 lines

drivers/net/sun8i_emac.c static int sun8i_emac_eth_of_to_plat(struct udevice *dev) · line 841

Quoted 2 lines
drivers/net/sun8i_emac.c +0 -0
      pdata->phy_interface = dev_read_phy_mode(dev);
      debug("phy interface %d\n", pdata->phy_interface);  

Best wishes,
Maksim

#5 lore raw
In reply to Maxim Kiselev

On Tue, 16 Jan 2024 19:58:56 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 7 lines

вт, 16 янв. 2024 г. в 03:18, Andre Przywara <[email protected]>:

Quoted 6 lines

On Thu, 15 Jun 2023 00:44:06 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

From: Maksim Kiselev <[email protected]>

Based on dt-specs fixed-link doesn't require phy-handle to be used.

Do you have such a board?

Yes, I had a custom board with T113 SoC which has fixed phy eth.

So just to clarify: this board connected something like a switch directly to the MAC, just using RMII/RGMII? And then you have a fixed-phy node in the DT, detailing the speed and duplex parameters? Matching the fixed-phy node description in ethernet-controller.yaml? And drivers/net/phy/fixed.c takes care of parsing that?

Quoted 9 lines
Quoted 3 lines

And where is that written down? I don't see
it explicitly mentioned as optional in ethernet-controller.yaml or in the DT spec PDF.

Sorry for that commit description. I just found the similar commit, that fixes the same problem for zynq_gem 3888c8d1979289efe685fe29276aed4d4b685975 ("net: zynq_gem: Add support for fixed-link phy") and copied the description from there.

Quoted 8 lines
Quoted 2 lines

The sun8i EMAC binding lists phy-handle as required, so that would need to be relaxed there then.

Oh, indeed. So it will require to send dt-binding changes to Linux first...

Therefore, I think we can live without fixed-phy support for sun8i EMAC. At least until some device with such a configuration appears on the market :)

Well, I am fine with that patch if it fixes a problem for you. It looks like requiring the phy-handle property is too strict, and just needs to be relaxed in the binding. If I see this correctly, the driver would still accept every valid DT, by today's and future bindings?

If you could just confirm my above assumptions, and maybe send a v2 with an amended commit message, I would be happy to merge that patch.

Cheers,
Andre

Quoted 36 lines
Quoted 30 lines
Quoted 1 line

Fix driver to only read phy related setting when phy-handle is found.

The patch itself looks fine, we already specify -1 as the default when the PHY DT node does not contain a reg property, so that looks like it would work.

Cheers,
Andre

Quoted 21 lines
---
 drivers/net/sun8i_emac.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/sun8i_emac.c +2 -5
index 04c3274fbe..0e339d69e0 100644
@@ -834,11 +834,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
      priv->use_internal_phy = false;
 
      offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
-     if (offset < 0) {
-             debug("%s: Cannot find PHY address\n", __func__);
-             return -EINVAL;
-     }
-     priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
+     if (offset >= 0)
+             priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
 
Quoted 3 lines

drivers/net/sun8i_emac.c static int sun8i_emac_eth_of_to_plat(struct udevice *dev) · line 841

Quoted 2 lines
drivers/net/sun8i_emac.c +0 -0
      pdata->phy_interface = dev_read_phy_mode(dev);
      debug("phy interface %d\n", pdata->phy_interface);  

Best wishes,
Maksim

#6 lore raw

Hi Andre,

пт, 19 янв. 2024 г. в 20:35, Andre Przywara <[email protected]>:

Quoted 19 lines

On Tue, 16 Jan 2024 19:58:56 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 13 lines

вт, 16 янв. 2024 г. в 03:18, Andre Przywara <[email protected]>:

Quoted 11 lines

On Thu, 15 Jun 2023 00:44:06 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 3 lines

From: Maksim Kiselev <[email protected]>

Based on dt-specs fixed-link doesn't require phy-handle to be used.

Do you have such a board?

Quoted 7 lines
Quoted 1 line

Yes, I had a custom board with T113 SoC which has fixed phy eth.

So just to clarify: this board connected something like a switch directly to the MAC, just using RMII/RGMII? And then you have a fixed-phy node in the DT, detailing the speed and duplex parameters? Matching the fixed-phy node description in ethernet-controller.yaml? And drivers/net/phy/fixed.c takes care of parsing that?

Yes, you are absolutely right. The T113s connected directly to the switch port via RMII interface. Here is the part of DT, that describes that configuration

&emac {
       pinctrl-names = "default";
       pinctrl-0 = <&rmii_pg_pins>;
       phy-mode = "rmii";
       snps,reset-gpio = <&pio 4 12 GPIO_ACTIVE_LOW>; /* PE12 */
       allwinner,tx-delay-ps = <700>;
       allwinner,rx-delay-ps = <3100>;

       fixed-link {
               speed = <100>;
               full-duplex;
       };
};
Quoted 19 lines
Quoted 10 lines
Quoted 4 lines

And where is that written down? I don't see
it explicitly mentioned as optional in ethernet-controller.yaml or in the DT spec PDF.

Sorry for that commit description. I just found the similar commit, that fixes the same problem for zynq_gem 3888c8d1979289efe685fe29276aed4d4b685975 ("net: zynq_gem: Add support for fixed-link phy") and copied the description from there.

Quoted 8 lines
Quoted 2 lines

The sun8i EMAC binding lists phy-handle as required, so that would need to be relaxed there then.

Oh, indeed. So it will require to send dt-binding changes to Linux first...

Therefore, I think we can live without fixed-phy support for sun8i EMAC. At least until some device with such a configuration appears on the market :)

Quoted 7 lines

Well, I am fine with that patch if it fixes a problem for you. It looks like requiring the phy-handle property is too strict, and just needs to be relaxed in the binding. If I see this correctly, the driver would still accept every valid DT, by today's and future bindings?

If you could just confirm my above assumptions, and maybe send a v2 with an amended commit message, I would be happy to merge that patch.

Sure, I'll fix the commit description and send v2 asap.

Quoted 40 lines

Cheers,
Andre

Quoted 36 lines
Quoted 30 lines
Quoted 1 line

Fix driver to only read phy related setting when phy-handle is found.

The patch itself looks fine, we already specify -1 as the default when the PHY DT node does not contain a reg property, so that looks like it would work.

Cheers,
Andre

Quoted 21 lines
---
 drivers/net/sun8i_emac.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/sun8i_emac.c +2 -5
index 04c3274fbe..0e339d69e0 100644
@@ -834,11 +834,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
      priv->use_internal_phy = false;
 
      offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
-     if (offset < 0) {
-             debug("%s: Cannot find PHY address\n", __func__);
-             return -EINVAL;
-     }
-     priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
+     if (offset >= 0)
+             priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
 
Quoted 3 lines

drivers/net/sun8i_emac.c static int sun8i_emac_eth_of_to_plat(struct udevice *dev) · line 841

Quoted 2 lines
drivers/net/sun8i_emac.c +0 -0
      pdata->phy_interface = dev_read_phy_mode(dev);
      debug("phy interface %d\n", pdata->phy_interface);

Best wishes,
Maksim

Best wishes,
Maksim

#7 lore raw

On Fri, 19 Jan 2024 21:11:07 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 22 lines

пт, 19 янв. 2024 г. в 20:35, Andre Przywara <[email protected]>:

Quoted 21 lines

On Tue, 16 Jan 2024 19:58:56 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 14 lines

вт, 16 янв. 2024 г. в 03:18, Andre Przywara <[email protected]>:

Quoted 11 lines

On Thu, 15 Jun 2023 00:44:06 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

Quoted 3 lines

From: Maksim Kiselev <[email protected]>

Based on dt-specs fixed-link doesn't require phy-handle to be used.

Do you have such a board?

Yes, I had a custom board with T113 SoC which has fixed phy eth.

Quoted 8 lines
Quoted 5 lines

So just to clarify: this board connected something like a switch directly to the MAC, just using RMII/RGMII? And then you have a fixed-phy node in the DT, detailing the speed and duplex parameters? Matching the fixed-phy node description in ethernet-controller.yaml? And drivers/net/phy/fixed.c takes care of parsing that?

Yes, you are absolutely right. The T113s connected directly to the switch port via RMII interface. Here is the part of DT, that describes that configuration

Excellent, thanks for the confirmation!

Looking forward to v2!

Cheers,
Andre

Quoted 86 lines
&emac {
       pinctrl-names = "default";
       pinctrl-0 = <&rmii_pg_pins>;
       phy-mode = "rmii";
       snps,reset-gpio = <&pio 4 12 GPIO_ACTIVE_LOW>; /* PE12 */
       allwinner,tx-delay-ps = <700>;
       allwinner,rx-delay-ps = <3100>;

       fixed-link {
               speed = <100>;
               full-duplex;
       };
};
Quoted 19 lines
Quoted 10 lines
Quoted 4 lines

And where is that written down? I don't see
it explicitly mentioned as optional in ethernet-controller.yaml or in the DT spec PDF.

Sorry for that commit description. I just found the similar commit, that fixes the same problem for zynq_gem 3888c8d1979289efe685fe29276aed4d4b685975 ("net: zynq_gem: Add support for fixed-link phy") and copied the description from there.

Quoted 8 lines
Quoted 2 lines

The sun8i EMAC binding lists phy-handle as required, so that would need to be relaxed there then.

Oh, indeed. So it will require to send dt-binding changes to Linux first...

Therefore, I think we can live without fixed-phy support for sun8i EMAC. At least until some device with such a configuration appears on the market :)

Quoted 7 lines

Well, I am fine with that patch if it fixes a problem for you. It looks like requiring the phy-handle property is too strict, and just needs to be relaxed in the binding. If I see this correctly, the driver would still accept every valid DT, by today's and future bindings?

If you could just confirm my above assumptions, and maybe send a v2 with an amended commit message, I would be happy to merge that patch.

Sure, I'll fix the commit description and send v2 asap.

Quoted 40 lines

Cheers,
Andre

Quoted 36 lines
Quoted 30 lines
Quoted 1 line

Fix driver to only read phy related setting when phy-handle is found.

The patch itself looks fine, we already specify -1 as the default when the PHY DT node does not contain a reg property, so that looks like it would work.

Cheers,
Andre

Quoted 21 lines
---
 drivers/net/sun8i_emac.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/sun8i_emac.c +2 -5
index 04c3274fbe..0e339d69e0 100644
@@ -834,11 +834,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
      priv->use_internal_phy = false;
 
      offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
-     if (offset < 0) {
-             debug("%s: Cannot find PHY address\n", __func__);
-             return -EINVAL;
-     }
-     priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
+     if (offset >= 0)
+             priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
 
Quoted 3 lines

drivers/net/sun8i_emac.c static int sun8i_emac_eth_of_to_plat(struct udevice *dev) · line 841

Quoted 2 lines
drivers/net/sun8i_emac.c +0 -0
      pdata->phy_interface = dev_read_phy_mode(dev);
      debug("phy interface %d\n", pdata->phy_interface);  

Best wishes,
Maksim

Best wishes,
Maksim