Skip to contentSkip to conversation

net: phy: at803x: stop switching phy delay config needlessly

PATCH Superseded André Draszik 3 participants 7 messages Aug 9, 2019 – Aug 12, 2019

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

PATCH 1/1 net: phy: at803x: stop switching phy delay config needlessly

This driver does a funny dance disabling and re-enabling RX and/or TX delays. In any of the RGMII-ID modes, it first disables the delays, just to re-enable them again right away. This looks like a needless exercise.

Just enable the respective delays when in any of the relevant 'id' modes, and disable them otherwise.

Also, remove comments which don't add anything that can't be seen by looking at the code.

CC Andrew Lunn <[email protected]>
CC Florian Fainelli <[email protected]>
CC Heiner Kallweit <[email protected]>
CC "David S. Miller" <[email protected]>
---
 drivers/net/phy/at803x.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/net/phy/at803x.c +6 -20
index 222ccd9ecfce..2ab51f552e92 100644
@@ -257,35 +257,21 @@ static int at803x_config_init(struct phy_device *phydev)
 	 *   after HW reset: RX delay enabled and TX delay disabled
 	 *   after SW reset: RX delay enabled, while TX delay retains the
 	 *   value before reset.
-	 *
-	 * So let's first disable the RX and TX delays in PHY and enable
-	 * them based on the mode selected (this also takes care of RGMII
-	 * mode where we expect delays to be disabled)
 	 */
-
-	ret = at803x_disable_rx_delay(phydev);
-	if (ret < 0)
-		return ret;
-	ret = at803x_disable_tx_delay(phydev);
-	if (ret < 0)
-		return ret;
-
 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
 	    phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
-		/* If RGMII_ID or RGMII_RXID are specified enable RX delay,
-		 * otherwise keep it disabled
-		 */
 		ret = at803x_enable_rx_delay(phydev);
-		if (ret < 0)
-			return ret;
+	} else {
+		ret = at803x_disable_rx_delay(phydev);
 	}
+	if (ret < 0)
+		return ret;
 
 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
 	    phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
-		/* If RGMII_ID or RGMII_TXID are specified enable TX delay,
-		 * otherwise keep it disabled
-		 */
 		ret = at803x_enable_tx_delay(phydev);
+	} else {
+		ret = at803x_disable_tx_delay(phydev);
 	}
 
 	return ret;
Signature · 1 line
2.20.1
#1 lore raw

Hi Andre,

Quoted 12 lines · André Draszik

This driver does a funny dance disabling and re-enabling RX and/or TX delays. In any of the RGMII-ID modes, it first disables the delays, just to re-enable them again right away. This looks like a needless exercise.

Just enable the respective delays when in any of the relevant 'id' modes, and disable them otherwise.

Also, remove comments which don't add anything that can't be seen by looking at the code.

Quoted 7 lines
CC Andrew Lunn <[email protected]>
CC Florian Fainelli <[email protected]>
CC Heiner Kallweit <[email protected]>
CC "David S. Miller" <[email protected]>

---

Is there any particular problem you're facing? Does this make any difference?

Quoted 50 lines
 drivers/net/phy/at803x.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/net/phy/at803x.c +6 -21
index 222ccd9ecfce..2ab51f552e92 100644
@@ -257,35 +257,21 @@ static int at803x_config_init(struct phy_device *phydev)
         *   after HW reset: RX delay enabled and TX delay disabled
         *   after SW reset: RX delay enabled, while TX delay retains the
         *   value before reset.
-        *
-        * So let's first disable the RX and TX delays in PHY and enable
-        * them based on the mode selected (this also takes care of RGMII
-        * mode where we expect delays to be disabled)
         */
-
-       ret = at803x_disable_rx_delay(phydev);
-       if (ret < 0)
-               return ret;
-       ret = at803x_disable_tx_delay(phydev);
-       if (ret < 0)
-               return ret;
-
        if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
            phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
-               /* If RGMII_ID or RGMII_RXID are specified enable RX delay,
-                * otherwise keep it disabled
-                */
                ret = at803x_enable_rx_delay(phydev);
-               if (ret < 0)
-                       return ret;
+       } else {
+               ret = at803x_disable_rx_delay(phydev);
        }
+       if (ret < 0)
+               return ret;
 
        if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
            phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
-               /* If RGMII_ID or RGMII_TXID are specified enable TX delay,
-                * otherwise keep it disabled
-                */
                ret = at803x_enable_tx_delay(phydev);
+       } else {
+               ret = at803x_disable_tx_delay(phydev);
        }
 
        return ret;
--
Quoted 2 lines

2.20.1

Regards,
-Vladimir

#2 lore raw

Hi Vladimir,

Quoted 22 lines · Vladimir Oltean

Hi Andre,

Quoted 11 lines · André Draszik

This driver does a funny dance disabling and re-enabling RX and/or TX delays. In any of the RGMII-ID modes, it first disables the delays, just to re-enable them again right away. This looks like a needless exercise.

Just enable the respective delays when in any of the relevant 'id' modes, and disable them otherwise.

Also, remove comments which don't add anything that can't be seen by looking at the code.

Quoted 7 lines
CC Andrew Lunn <[email protected]>
CC Florian Fainelli <[email protected]>
CC Heiner Kallweit <[email protected]>
CC "David S. Miller" <[email protected]>

---

Quoted 1 line

Is there any particular problem you're facing? Does this make any difference?

This is a clean-up, reducing the number of lines and if statements by removing unnecessary code paths and comments.

Cheers,
Andre'

Quoted 56 lines
Quoted 51 lines
 drivers/net/phy/at803x.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/net/phy/at803x.c +6 -21
index 222ccd9ecfce..2ab51f552e92 100644
@@ -257,35 +257,21 @@ static int at803x_config_init(struct phy_device *phydev)
         *   after HW reset: RX delay enabled and TX delay disabled
         *   after SW reset: RX delay enabled, while TX delay retains the
         *   value before reset.
-        *
-        * So let's first disable the RX and TX delays in PHY and enable
-        * them based on the mode selected (this also takes care of RGMII
-        * mode where we expect delays to be disabled)
         */
-
-       ret = at803x_disable_rx_delay(phydev);
-       if (ret < 0)
-               return ret;
-       ret = at803x_disable_tx_delay(phydev);
-       if (ret < 0)
-               return ret;
-
        if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
            phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
-               /* If RGMII_ID or RGMII_RXID are specified enable RX delay,
-                * otherwise keep it disabled
-                */
                ret = at803x_enable_rx_delay(phydev);
-               if (ret < 0)
-                       return ret;
+       } else {
+               ret = at803x_disable_rx_delay(phydev);
        }
+       if (ret < 0)
+               return ret;
 
        if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
            phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
-               /* If RGMII_ID or RGMII_TXID are specified enable TX delay,
-                * otherwise keep it disabled
-                */
                ret = at803x_enable_tx_delay(phydev);
+       } else {
+               ret = at803x_disable_tx_delay(phydev);
        }
 
        return ret;
--
Quoted 2 lines

2.20.1

Regards,
-Vladimir

#3 lore raw

Hi Andre,

Quoted 26 lines · André Draszik

Hi Vladimir,

Quoted 22 lines · Vladimir Oltean

Hi Andre,

Quoted 18 lines · André Draszik

This driver does a funny dance disabling and re-enabling RX and/or TX delays. In any of the RGMII-ID modes, it first disables the delays, just to re-enable them again right away. This looks like a needless exercise.

Just enable the respective delays when in any of the relevant 'id' modes, and disable them otherwise.

Also, remove comments which don't add anything that can't be seen by looking at the code.

CC Andrew Lunn <[email protected]>
CC Florian Fainelli <[email protected]>
CC Heiner Kallweit <[email protected]>
CC "David S. Miller" <[email protected]>

---

Quoted 5 lines
Quoted 1 line

Is there any particular problem you're facing? Does this make any difference?

This is a clean-up, reducing the number of lines and if statements by removing unnecessary code paths and comments.

Ok. Did checkpatch not complain about the braces which you left open around a single line?

Quoted 62 lines

Cheers,
Andre'

Quoted 56 lines
Quoted 51 lines
 drivers/net/phy/at803x.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/net/phy/at803x.c +6 -21
index 222ccd9ecfce..2ab51f552e92 100644
@@ -257,35 +257,21 @@ static int at803x_config_init(struct phy_device *phydev)
         *   after HW reset: RX delay enabled and TX delay disabled
         *   after SW reset: RX delay enabled, while TX delay retains the
         *   value before reset.
-        *
-        * So let's first disable the RX and TX delays in PHY and enable
-        * them based on the mode selected (this also takes care of RGMII
-        * mode where we expect delays to be disabled)
         */
-
-       ret = at803x_disable_rx_delay(phydev);
-       if (ret < 0)
-               return ret;
-       ret = at803x_disable_tx_delay(phydev);
-       if (ret < 0)
-               return ret;
-
        if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
            phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
-               /* If RGMII_ID or RGMII_RXID are specified enable RX delay,
-                * otherwise keep it disabled
-                */
                ret = at803x_enable_rx_delay(phydev);
-               if (ret < 0)
-                       return ret;
+       } else {
+               ret = at803x_disable_rx_delay(phydev);
        }
+       if (ret < 0)
+               return ret;
 
        if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
            phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
-               /* If RGMII_ID or RGMII_TXID are specified enable TX delay,
-                * otherwise keep it disabled
-                */
                ret = at803x_enable_tx_delay(phydev);
+       } else {
+               ret = at803x_disable_tx_delay(phydev);
        }
 
        return ret;
--
Quoted 2 lines

2.20.1

Regards,
-Vladimir

Thanks,
-Vladimir

#4 lore raw

Hi,

Quoted 28 lines · Vladimir Oltean

Hi Andre,

Quoted 25 lines · André Draszik

Hi Vladimir,

Quoted 22 lines · Vladimir Oltean

Hi Andre,

Quoted 18 lines · André Draszik

This driver does a funny dance disabling and re-enabling RX and/or TX delays. In any of the RGMII-ID modes, it first disables the delays, just to re-enable them again right away. This looks like a needless exercise.

Just enable the respective delays when in any of the relevant 'id' modes, and disable them otherwise.

Also, remove comments which don't add anything that can't be seen by looking at the code.

CC Andrew Lunn <[email protected]>
CC Florian Fainelli <[email protected]>
CC Heiner Kallweit <[email protected]>
CC "David S. Miller" <[email protected]>

---

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Is there any particular problem you're facing? Does this make any difference?

This is a clean-up, reducing the number of lines and if statements by removing unnecessary code paths and comments.

Ok. Did checkpatch not complain about the braces which you left open around a single line?

It actually doesn't... Should I send a v2?

Cheers,
Andre'

Quoted 63 lines
Quoted 60 lines

Cheers,
Andre'

Quoted 55 lines
Quoted 50 lines
 drivers/net/phy/at803x.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/net/phy/at803x.c +6 -21
index 222ccd9ecfce..2ab51f552e92 100644
@@ -257,35 +257,21 @@ static int at803x_config_init(struct phy_device *phydev)
         *   after HW reset: RX delay enabled and TX delay disabled
         *   after SW reset: RX delay enabled, while TX delay retains the
         *   value before reset.
-        *
-        * So let's first disable the RX and TX delays in PHY and enable
-        * them based on the mode selected (this also takes care of RGMII
-        * mode where we expect delays to be disabled)
         */
-
-       ret = at803x_disable_rx_delay(phydev);
-       if (ret < 0)
-               return ret;
-       ret = at803x_disable_tx_delay(phydev);
-       if (ret < 0)
-               return ret;
-
        if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
            phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
-               /* If RGMII_ID or RGMII_RXID are specified enable RX delay,
-                * otherwise keep it disabled
-                */
                ret = at803x_enable_rx_delay(phydev);
-               if (ret < 0)
-                       return ret;
+       } else {
+               ret = at803x_disable_rx_delay(phydev);
        }
+       if (ret < 0)
+               return ret;
 
        if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
            phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
-               /* If RGMII_ID or RGMII_TXID are specified enable TX delay,
-                * otherwise keep it disabled
-                */
                ret = at803x_enable_tx_delay(phydev);
+       } else {
+               ret = at803x_disable_tx_delay(phydev);
        }
 
        return ret;
--
Quoted 2 lines

2.20.1

Regards,
-Vladimir

Thanks,
-Vladimir

#5 lore raw

PATCH v2 1/1 net: phy: at803x: stop switching phy delay config needlessly

In reply to André Draszik

This driver does a funny dance disabling and re-enabling RX and/or TX delays. In any of the RGMII-ID modes, it first disables the delays, just to re-enable them again right away. This looks like a needless exercise.

Just enable the respective delays when in any of the relevant 'id' modes, and disable them otherwise.

Also, remove comments which don't add anything that can't be seen by looking at the code.

CC Andrew Lunn <[email protected]>
CC Florian Fainelli <[email protected]>
CC Heiner Kallweit <[email protected]>
CC "David S. Miller" <[email protected]>

---
v2: also remove braces around single lines

---
 drivers/net/phy/at803x.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)
drivers/net/phy/at803x.c +8 -24
index 222ccd9ecfce..6ad8b1c63c34 100644
@@ -257,36 +257,20 @@ static int at803x_config_init(struct phy_device *phydev)
 	 *   after HW reset: RX delay enabled and TX delay disabled
 	 *   after SW reset: RX delay enabled, while TX delay retains the
 	 *   value before reset.
-	 *
-	 * So let's first disable the RX and TX delays in PHY and enable
-	 * them based on the mode selected (this also takes care of RGMII
-	 * mode where we expect delays to be disabled)
 	 */
-
-	ret = at803x_disable_rx_delay(phydev);
-	if (ret < 0)
-		return ret;
-	ret = at803x_disable_tx_delay(phydev);
-	if (ret < 0)
-		return ret;
-
 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
-	    phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
-		/* If RGMII_ID or RGMII_RXID are specified enable RX delay,
-		 * otherwise keep it disabled
-		 */
+	    phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
 		ret = at803x_enable_rx_delay(phydev);
-		if (ret < 0)
-			return ret;
-	}
+	else
+		ret = at803x_disable_rx_delay(phydev);
+	if (ret < 0)
+		return ret;
 
 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
-	    phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
-		/* If RGMII_ID or RGMII_TXID are specified enable TX delay,
-		 * otherwise keep it disabled
-		 */
+	    phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
 		ret = at803x_enable_tx_delay(phydev);
-	}
+	else
+		ret = at803x_disable_tx_delay(phydev);
 
 	return ret;
 }
Signature · 1 line
2.20.1
maintainer Applied
#6 lore raw

From: André Draszik <[email protected]>
Date: Fri, 9 Aug 2019 12:20:25 +0100

Quoted 5 lines

This driver does a funny dance disabling and re-enabling RX and/or TX delays. In any of the RGMII-ID modes, it first disables the delays, just to re-enable them again right away. This looks like a needless exercise.

Quoted 7 lines

Just enable the respective delays when in any of the relevant 'id' modes, and disable them otherwise.

Also, remove comments which don't add anything that can't be seen by looking at the code.

Applied.