Skip to contentSkip to conversation

net: phy: phy_interface_is_rgmii update, drop phy_interface_is_sgmii

PATCH In review Nishanth Menon 3 participants 10 messages Apr 14, 2023 – May 6, 2023

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

v3 cover net: phy: phy_interface_is_rgmii update, drop phy_interface_is_sgmii

Originally reported by Tom[1], turned out to be that recent commit 75d28899e3e9 ("net: phy: Synchronize PHY interface modes with Linux") reordered the enum definitions which in turn broke the range checks.

we are left with two options:
a) check against explicit values to help reuse as much as possible and let compiler optimize where applicable
or
b) be very explicit in phy drivers and drop these helpers.

I have chosen to go with (a) approach.

Tested on am64x, though the dp83867 is used elsewhere as well.

Changes since V2:
* Dropped fixing up sgmii api, instead: just fixup the phy driver, drop the api
* picked reviewed by for the rgmii

V2: https://lore.kernel.org/all/[email protected]/
V1: https://lore.kernel.org/all/[email protected]/

Nishanth Menon (3):
net: phy: dp83867: Explicitly check against sgmii
net: phy: Drop phy_interface_is_sgmii
net: phy: Make phy_interface_is_rgmii a switch statement

 drivers/net/phy/dp83867.c |  2 +-
 include/phy.h             | 23 +++++++++--------------
 2 files changed, 10 insertions(+), 15 deletions(-)
Signature · 1 line
2.40.0
#1 lore raw

PATCH v3 1/3 net: phy: dp83867: Explicitly check against sgmii

dp83867 driver only supports sgmii and not all the newer protocols. Drop the usage of the generic phy_interface_is_sgmii function and just matchup to the specific mode supported.

---
Changes since v2:
* New patch.

 drivers/net/phy/dp83867.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/dp83867.c +1 -1
index b861bf7cef36..7111e36aa0d0 100644
@@ -330,7 +330,7 @@ static int dp83867_config(struct phy_device *phydev)
 			      DP83867_RGMIIDCTL, delay);
 	}
 
-	if (phy_interface_is_sgmii(phydev)) {
+	if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
 		if (dp83867->sgmii_ref_clk_en)
 			phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_SGMIICTL,
 				      DP83867_SGMII_TYPE);
Signature · 1 line
2.40.0
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH V3 1/3] net: phy: dp83867: Explicitly check against sgmii

Quoted 31 lines · Nishanth Menon

dp83867 driver only supports sgmii and not all the newer protocols. Drop the usage of the generic phy_interface_is_sgmii function and just matchup to the specific mode supported.

---
Changes since v2:
* New patch.

 drivers/net/phy/dp83867.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/dp83867.c +1 -2
index b861bf7cef36..7111e36aa0d0 100644
@@ -330,7 +330,7 @@ static int dp83867_config(struct phy_device *phydev)
                              DP83867_RGMIIDCTL, delay);
        }
 
-       if (phy_interface_is_sgmii(phydev)) {
+       if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
                if (dp83867->sgmii_ref_clk_en)
                        phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_SGMIICTL,
                                      DP83867_SGMII_TYPE);
--
Quoted 2 lines

2.40.0

#3 lore raw

Re: [PATCH V3 1/3] net: phy: dp83867: Explicitly check against sgmii

In reply to Nishanth Menon
Quoted 10 lines · Nishanth Menon

dp83867 driver only supports sgmii and not all the newer protocols. Drop the usage of the generic phy_interface_is_sgmii function and just matchup to the specific mode supported.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#4 lore raw

PATCH v3 2/3 net: phy: Drop phy_interface_is_sgmii

In reply to Nishanth Menon

Recent commit 75d28899e3e9 ("net: phy: Synchronize PHY interface modes with Linux") reordered the enum definitions. This caused the range of enums that this api was checking to go bad.

There aren't anymore users of phy_interface_is_sgmii, so, just drop it. Also the protocols are so very different that it makes no sense to provide a helper wrapper in the hope of reuse for phy drivers.

---
Changes Since v2:
* Redone the patch, but original versions below (did'nt make sense to carry reviewed-by)
* Just drop the phy_interface_is_sgmii
V2: https://lore.kernel.org/r/[email protected]
V1: https://lore.kernel.org/r/[email protected]

 include/phy.h | 12 ------------
 1 file changed, 12 deletions(-)
include/phy.h +0 -12
index a837fed72352..cb87d1d4fc95 100644
@@ -365,18 +365,6 @@ static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
 		phydev->interface <= PHY_INTERFACE_MODE_RGMII_TXID;
 }
 
-/**
- * phy_interface_is_sgmii - Convenience function for testing if a PHY interface
- * is SGMII (all variants)
- * @phydev: the phy_device struct
- * @return: true if MII bus is SGMII or false if it is not
- */
-static inline bool phy_interface_is_sgmii(struct phy_device *phydev)
-{
-	return phydev->interface >= PHY_INTERFACE_MODE_SGMII &&
-		phydev->interface <= PHY_INTERFACE_MODE_QSGMII;
-}
-
 bool phy_interface_is_ncsi(void);
 
 /* PHY UIDs for various PHYs that are referenced in external code */
Signature · 1 line
2.40.0
Reviewed-by on v3 2/3
#5 lore raw

Re: [PATCH V3 2/3] net: phy: Drop phy_interface_is_sgmii

Quoted 49 lines · Nishanth Menon

Recent commit 75d28899e3e9 ("net: phy: Synchronize PHY interface modes with Linux") reordered the enum definitions. This caused the range of enums that this api was checking to go bad.

There aren't anymore users of phy_interface_is_sgmii, so, just drop it. Also the protocols are so very different that it makes no sense to provide a helper wrapper in the hope of reuse for phy drivers.

---
Changes Since v2:
* Redone the patch, but original versions below (did'nt make sense to carry reviewed-by)
* Just drop the phy_interface_is_sgmii
V2: https://lore.kernel.org/r/[email protected]
V1: https://lore.kernel.org/r/[email protected]

 include/phy.h | 12 ------------
 1 file changed, 12 deletions(-)
include/phy.h +0 -13
index a837fed72352..cb87d1d4fc95 100644
@@ -365,18 +365,6 @@ static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
                phydev->interface <= PHY_INTERFACE_MODE_RGMII_TXID;
 }
 
-/**
- * phy_interface_is_sgmii - Convenience function for testing if a PHY interface
- * is SGMII (all variants)
- * @phydev: the phy_device struct
- * @return: true if MII bus is SGMII or false if it is not
- */
-static inline bool phy_interface_is_sgmii(struct phy_device *phydev)
-{
-       return phydev->interface >= PHY_INTERFACE_MODE_SGMII &&
-               phydev->interface <= PHY_INTERFACE_MODE_QSGMII;
-}
-
 bool phy_interface_is_ncsi(void);
 
 /* PHY UIDs for various PHYs that are referenced in external code */
--
Quoted 2 lines

2.40.0

#6 lore raw

Re: [PATCH V3 2/3] net: phy: Drop phy_interface_is_sgmii

In reply to Nishanth Menon
Quoted 8 lines · Nishanth Menon

Recent commit 75d28899e3e9 ("net: phy: Synchronize PHY interface modes with Linux") reordered the enum definitions. This caused the range of enums that this api was checking to go bad.

There aren't anymore users of phy_interface_is_sgmii, so, just drop it. Also the protocols are so very different that it makes no sense to provide a helper wrapper in the hope of reuse for phy drivers.

Quoted 6 lines

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#7 lore raw

PATCH v3 3/3 net: phy: Make phy_interface_is_rgmii a switch statement

In reply to Nishanth Menon

Recent commit 75d28899e3e9 ("net: phy: Synchronize PHY interface modes with Linux") reordered the enum definitions. This exposed a problem in range checking functions to identify the interface type. Though this specific api wasn't impacted (all the RGMII definitions remained within range), this experience should be used to never to have to face this kind of challenge again.

While it is possible for the phy drivers to use the enums directly, drivers such as dp83867, dp83869, marvell, micrel_ksz90x1 etc use this api.

---
Changes since V2:
* picked up reviewed-by
* s/was'nt/wasn't/g in commit message, minor rewording.
V2: https://lore.kernel.org/r/[email protected]
V1: https://lore.kernel.org/r/[email protected]

 include/phy.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
include/phy.h +9 -2
index cb87d1d4fc95..247223d92be7 100644
@@ -361,8 +361,15 @@ int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id);
  */
 static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
 {
-	return phydev->interface >= PHY_INTERFACE_MODE_RGMII &&
-		phydev->interface <= PHY_INTERFACE_MODE_RGMII_TXID;
+	switch (phydev->interface) {
+	case PHY_INTERFACE_MODE_RGMII:
+	case PHY_INTERFACE_MODE_RGMII_ID:
+	case PHY_INTERFACE_MODE_RGMII_RXID:
+	case PHY_INTERFACE_MODE_RGMII_TXID:
+		return 1;
+	default:
+		return 0;
+	}
 }
 
 bool phy_interface_is_ncsi(void);
Signature · 1 line
2.40.0
Reviewed-by on v3 3/3
#8 lore raw

Re: [PATCH V3 3/3] net: phy: Make phy_interface_is_rgmii a switch statement

Quoted 48 lines · Nishanth Menon

Recent commit 75d28899e3e9 ("net: phy: Synchronize PHY interface modes with Linux") reordered the enum definitions. This exposed a problem in range checking functions to identify the interface type. Though this specific api wasn't impacted (all the RGMII definitions remained within range), this experience should be used to never to have to face this kind of challenge again.

While it is possible for the phy drivers to use the enums directly, drivers such as dp83867, dp83869, marvell, micrel_ksz90x1 etc use this api.

---
Changes since V2:
* picked up reviewed-by
* s/was'nt/wasn't/g in commit message, minor rewording.
V2: https://lore.kernel.org/r/[email protected]
V1: https://lore.kernel.org/r/[email protected]

 include/phy.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
include/phy.h +9 -3
index cb87d1d4fc95..247223d92be7 100644
@@ -361,8 +361,15 @@ int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id);
  */
 static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
 {
-       return phydev->interface >= PHY_INTERFACE_MODE_RGMII &&
-               phydev->interface <= PHY_INTERFACE_MODE_RGMII_TXID;
+       switch (phydev->interface) {
+       case PHY_INTERFACE_MODE_RGMII:
+       case PHY_INTERFACE_MODE_RGMII_ID:
+       case PHY_INTERFACE_MODE_RGMII_RXID:
+       case PHY_INTERFACE_MODE_RGMII_TXID:
+               return 1;
+       default:
+               return 0;
+       }
 }
 
 bool phy_interface_is_ncsi(void);
--
Quoted 2 lines

2.40.0

#9 lore raw

Re: [PATCH V3 3/3] net: phy: Make phy_interface_is_rgmii a switch statement

In reply to Nishanth Menon
Quoted 11 lines · Nishanth Menon

Recent commit 75d28899e3e9 ("net: phy: Synchronize PHY interface modes with Linux") reordered the enum definitions. This exposed a problem in range checking functions to identify the interface type. Though this specific api wasn't impacted (all the RGMII definitions remained within range), this experience should be used to never to have to face this kind of challenge again.

While it is possible for the phy drivers to use the enums directly, drivers such as dp83867, dp83869, marvell, micrel_ksz90x1 etc use this api.

Quoted 5 lines

Applied to u-boot/master, thanks!

Signature · 1 line
Tom