Skip to contentSkip to conversation

net: dwc_eth_qos_rockchip: Fix disable of delay for RK356x and RK3588

PATCH In review Jonas Karlman 3 participants 8 messages Feb 9, 2025 – Feb 19, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover net: dwc_eth_qos_rockchip: Fix disable of delay for RK356x and RK3588

When rgmii-rxid/txid/id phy-mode is used the MAC should not add RX and/or TX delay. Currently RX/TX delay is configured as enabled using zero as delay value for the rgmii-rxid/txid/id modes.

This series change to disable RX and/or TX delay and using zero as delay value for RK356x and RK3588.

Jonas Karlman (2):
net: dwc_eth_qos_rockchip: Fix disable of RX/TX delay for RK356x
net: dwc_eth_qos_rockchip: Fix disable of RX/TX delay for RK3588

 drivers/net/dwc_eth_qos_rockchip.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.48.1
#1 lore raw

PATCH 1/2 net: dwc_eth_qos_rockchip: Fix disable of RX/TX delay for RK356x

When rgmii-rxid/txid/id phy-mode is used the MAC should not add RX and/or TX delay. Currently RX/TX delay is configured as enabled using zero as delay value for the rgmii-rxid/txid/id modes.

Change to disable RX and/or TX delay and using zero as delay value.

---
 drivers/net/dwc_eth_qos_rockchip.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/dwc_eth_qos_rockchip.c +5 -2
index 9fc8c686b889..3e10e07403c1 100644
@@ -46,6 +46,10 @@ struct rockchip_platform_data {
 #define GRF_BIT(nr)	(BIT(nr) | BIT((nr) + 16))
 #define GRF_CLR_BIT(nr)	(BIT((nr) + 16))
 
+#define DELAY_ENABLE(soc, tx, rx) \
+	(((tx) ? soc##_GMAC_TXCLK_DLY_ENABLE : soc##_GMAC_TXCLK_DLY_DISABLE) | \
+	 ((rx) ? soc##_GMAC_RXCLK_DLY_ENABLE : soc##_GMAC_RXCLK_DLY_DISABLE))
+
 #define RK3568_GRF_GMAC0_CON0		0x0380
 #define RK3568_GRF_GMAC0_CON1		0x0384
 #define RK3568_GRF_GMAC1_CON0		0x0388
@@ -85,8 +89,7 @@ static int rk3568_set_to_rgmii(struct udevice *dev,
 
 	regmap_write(data->grf, con1,
 		     RK3568_GMAC_PHY_INTF_SEL_RGMII |
-		     RK3568_GMAC_RXCLK_DLY_ENABLE |
-		     RK3568_GMAC_TXCLK_DLY_ENABLE);
+		     DELAY_ENABLE(RK3568, tx_delay, rx_delay));
 
 	return 0;
 }
Signature · 1 line
2.48.1
#2 lore raw

Re: [PATCH 1/2] net: dwc_eth_qos_rockchip: Fix disable of RX/TX delay for RK356x

Hi Jonas,

Quoted 16 lines · Jonas Karlman

When rgmii-rxid/txid/id phy-mode is used the MAC should not add RX and/or TX delay. Currently RX/TX delay is configured as enabled using zero as delay value for the rgmii-rxid/txid/id modes.

Change to disable RX and/or TX delay and using zero as delay value.

---
  drivers/net/dwc_eth_qos_rockchip.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/dwc_eth_qos_rockchip.c +0 -0
index 9fc8c686b889..3e10e07403c1 100644

drivers/net/dwc_eth_qos_rockchip.c struct rockchip_platform_data { · line 52

Quoted 7 lines
drivers/net/dwc_eth_qos_rockchip.c +4 -0
@@ -46,6 +46,10 @@ struct rockchip_platform_data {
  #define GRF_BIT(nr)	(BIT(nr) | BIT((nr) + 16))
  #define GRF_CLR_BIT(nr)	(BIT((nr) + 16))
 
+#define DELAY_ENABLE(soc, tx, rx) \
+	(((tx) ? soc##_GMAC_TXCLK_DLY_ENABLE : soc##_GMAC_TXCLK_DLY_DISABLE) | \
+	 ((rx) ? soc##_GMAC_RXCLK_DLY_ENABLE : soc##_GMAC_RXCLK_DLY_DISABLE))
+

Considering this won't be used for RK3588 in the next patch and that I found it obfuscating the constants that are used, can't we simply do...

drivers/net/dwc_eth_qos_rockchip.c static int rk3568_set_to_rgmii(struct udevice *dev, · line 92

Quoted 10 lines
drivers/net/dwc_eth_qos_rockchip.c +1 -2
  #define RK3568_GRF_GMAC0_CON0		0x0380
  #define RK3568_GRF_GMAC0_CON1		0x0384
  #define RK3568_GRF_GMAC1_CON0		0x0388
@@ -85,8 +89,7 @@ static int rk3568_set_to_rgmii(struct udevice *dev,
 
  	regmap_write(data->grf, con1,
  		     RK3568_GMAC_PHY_INTF_SEL_RGMII |
-		     RK3568_GMAC_RXCLK_DLY_ENABLE |
-		     RK3568_GMAC_TXCLK_DLY_ENABLE);
+		     DELAY_ENABLE(RK3568, tx_delay, rx_delay));

(tx_delay ? RK3568_GMAC_TXCLK_DLY_ENABLE : RK3568_GMAC_TXCLK_DLY_DISABLE) | (rx_delay ? RK3568_GMAC_RXCLK_DLY_ENABLE : RK3568_GMAC_RXCLK_DLY_DISABLE));

instead?

Also, if tx_delay or rx_delay is 0, does it actually make sense to write the delay config in there? (so the regmap_write before this one).

Note that the config is set before the enable on rk3568, but the opposite on rk3588 which I find quite odd, you usually want to configure something before it's enabled?

The change itself looks fine though!

Cheers,
Quentin

#3 lore raw

Re: [PATCH 1/2] net: dwc_eth_qos_rockchip: Fix disable of RX/TX delay for RK356x

Hi Quentin,

Quoted 44 lines · Quentin Schulz

Hi Jonas,

Quoted 16 lines · Jonas Karlman

When rgmii-rxid/txid/id phy-mode is used the MAC should not add RX and/or TX delay. Currently RX/TX delay is configured as enabled using zero as delay value for the rgmii-rxid/txid/id modes.

Change to disable RX and/or TX delay and using zero as delay value.

---
  drivers/net/dwc_eth_qos_rockchip.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/dwc_eth_qos_rockchip.c +0 -0
index 9fc8c686b889..3e10e07403c1 100644

drivers/net/dwc_eth_qos_rockchip.c struct rockchip_platform_data { · line 52

Quoted 7 lines
drivers/net/dwc_eth_qos_rockchip.c +4 -0
@@ -46,6 +46,10 @@ struct rockchip_platform_data {
  #define GRF_BIT(nr)	(BIT(nr) | BIT((nr) + 16))
  #define GRF_CLR_BIT(nr)	(BIT((nr) + 16))
 
+#define DELAY_ENABLE(soc, tx, rx) \
+	(((tx) ? soc##_GMAC_TXCLK_DLY_ENABLE : soc##_GMAC_TXCLK_DLY_DISABLE) | \
+	 ((rx) ? soc##_GMAC_RXCLK_DLY_ENABLE : soc##_GMAC_RXCLK_DLY_DISABLE))
+

Considering this won't be used for RK3588 in the next patch and that I found it obfuscating the constants that are used, can't we simply do...

drivers/net/dwc_eth_qos_rockchip.c static int rk3568_set_to_rgmii(struct udevice *dev, · line 92

Quoted 10 lines
drivers/net/dwc_eth_qos_rockchip.c +1 -2
  #define RK3568_GRF_GMAC0_CON0		0x0380
  #define RK3568_GRF_GMAC0_CON1		0x0384
  #define RK3568_GRF_GMAC1_CON0		0x0388
@@ -85,8 +89,7 @@ static int rk3568_set_to_rgmii(struct udevice *dev,
 
  	regmap_write(data->grf, con1,
  		     RK3568_GMAC_PHY_INTF_SEL_RGMII |
-		     RK3568_GMAC_RXCLK_DLY_ENABLE |
-		     RK3568_GMAC_TXCLK_DLY_ENABLE);
+		     DELAY_ENABLE(RK3568, tx_delay, rx_delay));

(tx_delay ? RK3568_GMAC_TXCLK_DLY_ENABLE : RK3568_GMAC_TXCLK_DLY_DISABLE) | (rx_delay ? RK3568_GMAC_RXCLK_DLY_ENABLE : RK3568_GMAC_RXCLK_DLY_DISABLE));

Quoted 1 line

instead?

Sorry for not being clear in the cover letter or in commit message. The DELAY_ENABLE macro match a similar macro in gmac_rockchip.c and in the mainline Linux driver and will/should be used by pending RK3528 and RK3576 support.

Quoted 3 lines

Also, if tx_delay or rx_delay is 0, does it actually make sense to write the delay config in there? (so the regmap_write before this one).

It seem to be what is done for the other SoCs GMAC in both mainline and vendor U-Boot. Not sure we should deviate too much from what seem to be working.

Quoted 4 lines

Note that the config is set before the enable on rk3568, but the opposite on rk3588 which I find quite odd, you usually want to configure something before it's enabled?

I also think this look a bit strange, however it is what is also done for the other SoCs GMAC in both mainline and vendor U-Boot. Hopefully the reg write order does not matter for the hw.

Regards,
Jonas

Quoted 5 lines

The change itself looks fine though!

Cheers,
Quentin

Reviewed-by
#4 lore raw

Re: [PATCH 1/2] net: dwc_eth_qos_rockchip: Fix disable of RX/TX delay for RK356x

Hi Jonas,

Quoted 47 lines · Jonas Karlman

Hi Quentin,

Quoted 44 lines · Quentin Schulz

Hi Jonas,

Quoted 16 lines · Jonas Karlman

When rgmii-rxid/txid/id phy-mode is used the MAC should not add RX and/or TX delay. Currently RX/TX delay is configured as enabled using zero as delay value for the rgmii-rxid/txid/id modes.

Change to disable RX and/or TX delay and using zero as delay value.

---
   drivers/net/dwc_eth_qos_rockchip.c | 7 +++++--
   1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/dwc_eth_qos_rockchip.c +0 -0
index 9fc8c686b889..3e10e07403c1 100644

drivers/net/dwc_eth_qos_rockchip.c struct rockchip_platform_data { · line 52

Quoted 7 lines
drivers/net/dwc_eth_qos_rockchip.c +4 -0
@@ -46,6 +46,10 @@ struct rockchip_platform_data {
   #define GRF_BIT(nr)	(BIT(nr) | BIT((nr) + 16))
   #define GRF_CLR_BIT(nr)	(BIT((nr) + 16))
 
+#define DELAY_ENABLE(soc, tx, rx) \
+	(((tx) ? soc##_GMAC_TXCLK_DLY_ENABLE : soc##_GMAC_TXCLK_DLY_DISABLE) | \
+	 ((rx) ? soc##_GMAC_RXCLK_DLY_ENABLE : soc##_GMAC_RXCLK_DLY_DISABLE))
+

Considering this won't be used for RK3588 in the next patch and that I found it obfuscating the constants that are used, can't we simply do...

drivers/net/dwc_eth_qos_rockchip.c static int rk3568_set_to_rgmii(struct udevice *dev, · line 92

Quoted 10 lines
drivers/net/dwc_eth_qos_rockchip.c +1 -2
   #define RK3568_GRF_GMAC0_CON0		0x0380
   #define RK3568_GRF_GMAC0_CON1		0x0384
   #define RK3568_GRF_GMAC1_CON0		0x0388
@@ -85,8 +89,7 @@ static int rk3568_set_to_rgmii(struct udevice *dev,
 
   	regmap_write(data->grf, con1,
   		     RK3568_GMAC_PHY_INTF_SEL_RGMII |
-		     RK3568_GMAC_RXCLK_DLY_ENABLE |
-		     RK3568_GMAC_TXCLK_DLY_ENABLE);
+		     DELAY_ENABLE(RK3568, tx_delay, rx_delay));

(tx_delay ? RK3568_GMAC_TXCLK_DLY_ENABLE : RK3568_GMAC_TXCLK_DLY_DISABLE) | (rx_delay ? RK3568_GMAC_RXCLK_DLY_ENABLE : RK3568_GMAC_RXCLK_DLY_DISABLE));

Quoted 7 lines
Quoted 1 line

instead?

Sorry for not being clear in the cover letter or in commit message. The DELAY_ENABLE macro match a similar macro in gmac_rockchip.c and in the mainline Linux driver and will/should be used by pending RK3528 and RK3576 support.

Ah, this is what I was missing :)

The commit in Linux seems to be eaf70ad14cbb ("net: stmmac: dwmac-rk: Add handling for RGMII_ID/RXID/TXID"). Maybe add this to the commit log?

Quoted 8 lines
Quoted 3 lines

Also, if tx_delay or rx_delay is 0, does it actually make sense to write the delay config in there? (so the regmap_write before this one).

It seem to be what is done for the other SoCs GMAC in both mainline and vendor U-Boot. Not sure we should deviate too much from what seem to be working.

Didn't know there was a reference, thanks for the pointer.

Quoted 9 lines
Quoted 4 lines

Note that the config is set before the enable on rk3568, but the opposite on rk3588 which I find quite odd, you usually want to configure something before it's enabled?

I also think this look a bit strange, however it is what is also done for the other SoCs GMAC in both mainline and vendor U-Boot. Hopefully the reg write order does not matter for the hw.

/me shrugs.

Maybe update the commit log to point at the change from the Linux kernel as reference in a v2 if you don't mind?

Thanks!
Quentin

Reviewed-by on v1 1/2
#5 lore raw

Re: [PATCH 1/2] net: dwc_eth_qos_rockchip: Fix disable of RX/TX delay for RK356x

In reply to Jonas Karlman
Quoted 7 lines · Jonas Karlman

When rgmii-rxid/txid/id phy-mode is used the MAC should not add RX and/or TX delay. Currently RX/TX delay is configured as enabled using zero as delay value for the rgmii-rxid/txid/id modes.

Change to disable RX and/or TX delay and using zero as delay value.

Thanks,
- Kever

Quoted 29 lines
---
  drivers/net/dwc_eth_qos_rockchip.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/dwc_eth_qos_rockchip.c +5 -2
index 9fc8c686b889..3e10e07403c1 100644
@@ -46,6 +46,10 @@ struct rockchip_platform_data {
  #define GRF_BIT(nr)	(BIT(nr) | BIT((nr) + 16))
  #define GRF_CLR_BIT(nr)	(BIT((nr) + 16))
 
+#define DELAY_ENABLE(soc, tx, rx) \
+	(((tx) ? soc##_GMAC_TXCLK_DLY_ENABLE : soc##_GMAC_TXCLK_DLY_DISABLE) | \
+	 ((rx) ? soc##_GMAC_RXCLK_DLY_ENABLE : soc##_GMAC_RXCLK_DLY_DISABLE))
+
  #define RK3568_GRF_GMAC0_CON0		0x0380
  #define RK3568_GRF_GMAC0_CON1		0x0384
  #define RK3568_GRF_GMAC1_CON0		0x0388
@@ -85,8 +89,7 @@ static int rk3568_set_to_rgmii(struct udevice *dev,
 
  	regmap_write(data->grf, con1,
  		     RK3568_GMAC_PHY_INTF_SEL_RGMII |
-		     RK3568_GMAC_RXCLK_DLY_ENABLE |
-		     RK3568_GMAC_TXCLK_DLY_ENABLE);
+		     DELAY_ENABLE(RK3568, tx_delay, rx_delay));
 
  	return 0;
  }
#6 lore raw

PATCH 2/2 net: dwc_eth_qos_rockchip: Fix disable of RX/TX delay for RK3588

In reply to Jonas Karlman

When rgmii-rxid/txid/id phy-mode is used the MAC should not add RX and/or TX delay. Currently RX/TX delay is configured as enabled using zero as delay value for the rgmii-rxid/txid/id modes.

Change to disable RX and/or TX delay and using zero as delay value.

---
 drivers/net/dwc_eth_qos_rockchip.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/dwc_eth_qos_rockchip.c +5 -2
index 3e10e07403c1..f3a0f63003ea 100644
@@ -134,6 +134,10 @@ static int rk3568_set_gmac_speed(struct udevice *dev)
 	return 0;
 }
 
+#define RK3588_DELAY_ENABLE(id, tx, rx) \
+	(((tx) ? RK3588_GMAC_TXCLK_DLY_ENABLE(id) : RK3588_GMAC_TXCLK_DLY_DISABLE(id)) | \
+	 ((rx) ? RK3588_GMAC_RXCLK_DLY_ENABLE(id) : RK3588_GMAC_RXCLK_DLY_DISABLE(id)))
+
 /* sys_grf */
 #define RK3588_GRF_GMAC_CON7			0x031c
 #define RK3588_GRF_GMAC_CON8			0x0320
@@ -192,8 +196,7 @@ static int rk3588_set_to_rgmii(struct udevice *dev,
 		     RK3588_GMAC_CLK_RGMII_MODE(id));
 
 	regmap_write(data->grf, RK3588_GRF_GMAC_CON7,
-		     RK3588_GMAC_RXCLK_DLY_ENABLE(id) |
-		     RK3588_GMAC_TXCLK_DLY_ENABLE(id));
+		     RK3588_DELAY_ENABLE(id, tx_delay, rx_delay));
 
 	regmap_write(data->grf, offset_con,
 		     RK3588_GMAC_CLK_RX_DL_CFG(rx_delay) |
Signature · 1 line
2.48.1
Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] net: dwc_eth_qos_rockchip: Fix disable of RX/TX delay for RK3588

Quoted 7 lines · Jonas Karlman

When rgmii-rxid/txid/id phy-mode is used the MAC should not add RX and/or TX delay. Currently RX/TX delay is configured as enabled using zero as delay value for the rgmii-rxid/txid/id modes.

Change to disable RX and/or TX delay and using zero as delay value.

Thanks,
- Kever

Quoted 29 lines
---
  drivers/net/dwc_eth_qos_rockchip.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/dwc_eth_qos_rockchip.c +5 -2
index 3e10e07403c1..f3a0f63003ea 100644
@@ -134,6 +134,10 @@ static int rk3568_set_gmac_speed(struct udevice *dev)
  	return 0;
  }
 
+#define RK3588_DELAY_ENABLE(id, tx, rx) \
+	(((tx) ? RK3588_GMAC_TXCLK_DLY_ENABLE(id) : RK3588_GMAC_TXCLK_DLY_DISABLE(id)) | \
+	 ((rx) ? RK3588_GMAC_RXCLK_DLY_ENABLE(id) : RK3588_GMAC_RXCLK_DLY_DISABLE(id)))
+
  /* sys_grf */
  #define RK3588_GRF_GMAC_CON7			0x031c
  #define RK3588_GRF_GMAC_CON8			0x0320
@@ -192,8 +196,7 @@ static int rk3588_set_to_rgmii(struct udevice *dev,
  		     RK3588_GMAC_CLK_RGMII_MODE(id));
 
  	regmap_write(data->grf, RK3588_GRF_GMAC_CON7,
-		     RK3588_GMAC_RXCLK_DLY_ENABLE(id) |
-		     RK3588_GMAC_TXCLK_DLY_ENABLE(id));
+		     RK3588_DELAY_ENABLE(id, tx_delay, rx_delay));
 
  	regmap_write(data->grf, offset_con,
  		     RK3588_GMAC_CLK_RX_DL_CFG(rx_delay) |