Skip to contentSkip to conversation

net: phy: realtek: complete 5Gbps support and replace private constants

PATCH Applied Heiner Kallweit 3 participants 13 messages Feb 4, 2024 – Feb 8, 2024

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

cover net: phy: realtek: complete 5Gbps support and replace private constants

Realtek maps standard C45 registers to vendor-specific registers which can be accessed via C22 w/o MMD. For an unknown reason C22 MMD access to C45 registers isn't supported for integrated PHY's. However the vendor-specific registers preserve the format of the C45 registers, so we can use standard constants. First two patches are cherry-picked from a series posted by Marek some time ago.

RTL8126 supports 5Gbps, therefore add the missing 5Gbps support to rtl822x_config_aneg().

Heiner Kallweit (1):
net: phy: realtek: add 5Gbps support to rtl822x_config_aneg()

Marek Behún (2):
net: mdio: add 2.5g and 5g related PMA speed constants
net: phy: realtek: use generic MDIO constants

 drivers/net/phy/realtek.c | 36 ++++++++++++++++++------------------
 include/uapi/linux/mdio.h |  2 ++
 2 files changed, 20 insertions(+), 18 deletions(-)
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/3 net: mdio: add 2.5g and 5g related PMA speed constants

From: Marek Behún <[email protected]>

Add constants indicating 2.5g and 5g ability in the MMD PMA speed register.

---
 include/uapi/linux/mdio.h | 2 ++
 1 file changed, 2 insertions(+)
include/uapi/linux/mdio.h +2 -0
index d03863da1..3c9097502 100644
@@ -138,6 +138,8 @@
 #define MDIO_PMA_SPEED_1000		0x0010	/* 1000M capable */
 #define MDIO_PMA_SPEED_100		0x0020	/* 100M capable */
 #define MDIO_PMA_SPEED_10		0x0040	/* 10M capable */
+#define MDIO_PMA_SPEED_2_5G		0x2000	/* 2.5G capable */
+#define MDIO_PMA_SPEED_5G		0x4000	/* 5G capable */
 #define MDIO_PCS_SPEED_10P2B		0x0002	/* 10PASS-TS/2BASE-TL capable */
 #define MDIO_PCS_SPEED_2_5G		0x0040	/* 2.5G capable */
 #define MDIO_PCS_SPEED_5G		0x0080	/* 5G capable */
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 2/3 net: phy: realtek: use generic MDIO constants

In reply to Heiner Kallweit

From: Marek Behún <[email protected]>

Drop the ad-hoc MDIO constants used in the driver and use generic constants instead.

---
 drivers/net/phy/realtek.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/net/phy/realtek.c +13 -17
index 894172a3e..ffc13c495 100644
@@ -57,14 +57,6 @@
 #define RTL8366RB_POWER_SAVE			0x15
 #define RTL8366RB_POWER_SAVE_ON			BIT(12)
 
-#define RTL_SUPPORTS_5000FULL			BIT(14)
-#define RTL_SUPPORTS_2500FULL			BIT(13)
-#define RTL_SUPPORTS_10000FULL			BIT(0)
-#define RTL_ADV_2500FULL			BIT(7)
-#define RTL_LPADV_10000FULL			BIT(11)
-#define RTL_LPADV_5000FULL			BIT(6)
-#define RTL_LPADV_2500FULL			BIT(5)
-
 #define RTL9000A_GINMR				0x14
 #define RTL9000A_GINMR_LINK_STATUS		BIT(4)
 
@@ -674,11 +666,11 @@ static int rtl822x_get_features(struct phy_device *phydev)
 		return val;
 
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_2500FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_2_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_5000FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_10000FULL);
+			 phydev->supported, val & MDIO_SPEED_10G);
 
 	return genphy_read_abilities(phydev);
 }
@@ -692,10 +684,11 @@ static int rtl822x_config_aneg(struct phy_device *phydev)
 
 		if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
 				      phydev->advertising))
-			adv2500 = RTL_ADV_2500FULL;
+			adv2500 = MDIO_AN_10GBT_CTRL_ADV2_5G;
 
 		ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12,
-					       RTL_ADV_2500FULL, adv2500);
+					       MDIO_AN_10GBT_CTRL_ADV2_5G,
+					       adv2500);
 		if (ret < 0)
 			return ret;
 	}
@@ -714,11 +707,14 @@ static int rtl822x_read_status(struct phy_device *phydev)
 			return lpadv;
 
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_10000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP10G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_5000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP5G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_2500FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP2_5G);
 	}
 
 	ret = genphy_read_status(phydev);
@@ -736,7 +732,7 @@ static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
 	val = phy_read(phydev, 0x13);
 	phy_write(phydev, RTL821x_PAGE_SELECT, 0);
 
-	return val >= 0 && val & RTL_SUPPORTS_2500FULL;
+	return val >= 0 && val & MDIO_PMA_SPEED_2_5G;
 }
 
 static int rtlgen_match_phy_device(struct phy_device *phydev)
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH net-next 2/3] net: phy: realtek: use generic MDIO constants

Quoted 32 lines · Heiner Kallweit

From: Marek Behún <[email protected]>

Drop the ad-hoc MDIO constants used in the driver and use generic constants instead.

---
 drivers/net/phy/realtek.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/net/phy/realtek.c +0 -8
index 894172a3e..ffc13c495 100644
@@ -57,14 +57,6 @@
 #define RTL8366RB_POWER_SAVE			0x15
 #define RTL8366RB_POWER_SAVE_ON			BIT(12)
 
-#define RTL_SUPPORTS_5000FULL			BIT(14)
-#define RTL_SUPPORTS_2500FULL			BIT(13)
-#define RTL_SUPPORTS_10000FULL			BIT(0)
-#define RTL_ADV_2500FULL			BIT(7)
-#define RTL_LPADV_10000FULL			BIT(11)
-#define RTL_LPADV_5000FULL			BIT(6)
-#define RTL_LPADV_2500FULL			BIT(5)
-
 #define RTL9000A_GINMR				0x14
 #define RTL9000A_GINMR_LINK_STATUS		BIT(4)
 
@@ -674,11 +666,11 @@ static int rtl822x_get_features(struct phy_device *phydev)
 		return val;

drivers/net/phy/realtek.c static int rtl822x_get_features(struct phy_device *phydev) · line 673

Quoted 10 lines
drivers/net/phy/realtek.c +3 -3
 
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_2500FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_2_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_5000FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_10000FULL);
+			 phydev->supported, val & MDIO_SPEED_10G);

Now that this only using generic constants, should it move into mdio.h as a shared helper? Is this a standard register defined in 802.3, just at a different address?

Quoted 22 lines
drivers/net/phy/realtek.c +3 -3
 	return genphy_read_abilities(phydev);
 }
@@ -692,10 +684,11 @@ static int rtl822x_config_aneg(struct phy_device *phydev)
 
 		if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
 				      phydev->advertising))
-			adv2500 = RTL_ADV_2500FULL;
+			adv2500 = MDIO_AN_10GBT_CTRL_ADV2_5G;
 
 		ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12,
-					       RTL_ADV_2500FULL, adv2500);
+					       MDIO_AN_10GBT_CTRL_ADV2_5G,
+					       adv2500);
 		if (ret < 0)
 			return ret;
 	}
@@ -714,11 +707,14 @@ static int rtl822x_read_status(struct phy_device *phydev)
 			return lpadv;
 
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_10000FULL);

drivers/net/phy/realtek.c static int rtl822x_read_status(struct phy_device *phydev) · line 717

Quoted 10 lines
drivers/net/phy/realtek.c +6 -2
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP10G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_5000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP5G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_2500FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP2_5G);

Is this mii_10gbt_stat_mod_linkmode_lpa_t() ?

Something i've done in the past is to do this sort of conversion to standard macros, and the followed up with a patch which says that function X is now clearly the same as helper Y, so delete the function and use the helper...

Andrew

author maintainer
#4 lore raw

Re: [PATCH net-next 2/3] net: phy: realtek: use generic MDIO constants

Quoted 34 lines · Andrew Lunn
Quoted 33 lines · Heiner Kallweit

From: Marek Behún <[email protected]>

Drop the ad-hoc MDIO constants used in the driver and use generic constants instead.

---
 drivers/net/phy/realtek.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/net/phy/realtek.c +0 -8
index 894172a3e..ffc13c495 100644
@@ -57,14 +57,6 @@
 #define RTL8366RB_POWER_SAVE			0x15
 #define RTL8366RB_POWER_SAVE_ON			BIT(12)
 
-#define RTL_SUPPORTS_5000FULL			BIT(14)
-#define RTL_SUPPORTS_2500FULL			BIT(13)
-#define RTL_SUPPORTS_10000FULL			BIT(0)
-#define RTL_ADV_2500FULL			BIT(7)
-#define RTL_LPADV_10000FULL			BIT(11)
-#define RTL_LPADV_5000FULL			BIT(6)
-#define RTL_LPADV_2500FULL			BIT(5)
-
 #define RTL9000A_GINMR				0x14
 #define RTL9000A_GINMR_LINK_STATUS		BIT(4)
 
@@ -674,11 +666,11 @@ static int rtl822x_get_features(struct phy_device *phydev)
 		return val;
 
Quoted 14 lines

drivers/net/phy/realtek.c static int rtl822x_get_features(struct phy_device *phydev) · line 673

Quoted 9 lines
drivers/net/phy/realtek.c +3 -3
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_2500FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_2_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_5000FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_10000FULL);
+			 phydev->supported, val & MDIO_SPEED_10G);

Now that this only using generic constants, should it move into mdio.h as a shared helper? Is this a standard register defined in 802.3, just at a different address?

This is register 1.4 (PMA/PMD speed ability), mapped to a vendor-specific register. There's very few users of this register, and nothing where such a helper could be reused.

Quoted 20 lines
Quoted 20 lines
drivers/net/phy/realtek.c +3 -2
 	return genphy_read_abilities(phydev);
 }
@@ -692,10 +684,11 @@ static int rtl822x_config_aneg(struct phy_device *phydev)
 
 		if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
 				      phydev->advertising))
-			adv2500 = RTL_ADV_2500FULL;
+			adv2500 = MDIO_AN_10GBT_CTRL_ADV2_5G;
 
 		ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12,
-					       RTL_ADV_2500FULL, adv2500);
+					       MDIO_AN_10GBT_CTRL_ADV2_5G,
+					       adv2500);
 		if (ret < 0)
 			return ret;
 	}
@@ -714,11 +707,14 @@ static int rtl822x_read_status(struct phy_device *phydev)
 			return lpadv;
 
Quoted 15 lines

drivers/net/phy/realtek.c static int rtl822x_read_status(struct phy_device *phydev) · line 717

Quoted 12 lines
drivers/net/phy/realtek.c +6 -3
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_10000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP10G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_5000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP5G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_2500FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP2_5G);

Is this mii_10gbt_stat_mod_linkmode_lpa_t() ?

Indeed, it is. Thanks for the hint. I'd prefer to submit the patch making use of this helper as a follow-up patch. Then it's obvious that the helper is the same as the replaced code.

Quoted 6 lines

Something i've done in the past is to do this sort of conversion to standard macros, and the followed up with a patch which says that function X is now clearly the same as helper Y, so delete the function and use the helper...

Andrew

Heiner

author maintainer
#5 lore raw

Re: [PATCH net-next 2/3] net: phy: realtek: use generic MDIO constants

Quoted 58 lines · Heiner Kallweit
Quoted 34 lines · Andrew Lunn
Quoted 33 lines · Heiner Kallweit

From: Marek Behún <[email protected]>

Drop the ad-hoc MDIO constants used in the driver and use generic constants instead.

---
 drivers/net/phy/realtek.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/net/phy/realtek.c +0 -8
index 894172a3e..ffc13c495 100644
@@ -57,14 +57,6 @@
 #define RTL8366RB_POWER_SAVE			0x15
 #define RTL8366RB_POWER_SAVE_ON			BIT(12)
 
-#define RTL_SUPPORTS_5000FULL			BIT(14)
-#define RTL_SUPPORTS_2500FULL			BIT(13)
-#define RTL_SUPPORTS_10000FULL			BIT(0)
-#define RTL_ADV_2500FULL			BIT(7)
-#define RTL_LPADV_10000FULL			BIT(11)
-#define RTL_LPADV_5000FULL			BIT(6)
-#define RTL_LPADV_2500FULL			BIT(5)
-
 #define RTL9000A_GINMR				0x14
 #define RTL9000A_GINMR_LINK_STATUS		BIT(4)
 
@@ -674,11 +666,11 @@ static int rtl822x_get_features(struct phy_device *phydev)
 		return val;
 
Quoted 14 lines

drivers/net/phy/realtek.c static int rtl822x_get_features(struct phy_device *phydev) · line 673

Quoted 9 lines
drivers/net/phy/realtek.c +3 -3
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_2500FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_2_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_5000FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_10000FULL);
+			 phydev->supported, val & MDIO_SPEED_10G);

Now that this only using generic constants, should it move into mdio.h as a shared helper? Is this a standard register defined in 802.3, just at a different address?

This is register 1.4 (PMA/PMD speed ability), mapped to a vendor-specific register. There's very few users of this register, and nothing where such a helper could be reused.

Quoted 5 lines
Quoted 5 lines
drivers/net/phy/realtek.c +0 -0
 	return genphy_read_abilities(phydev);
 }
@@ -692,10 +684,11 @@ static int rtl822x_config_aneg(struct phy_device *phydev)
 
Quoted 5 lines
Quoted 5 lines

drivers/net/phy/realtek.c static int rtl822x_config_aneg(struct phy_device *phydev) · line 688

Quoted 5 lines
drivers/net/phy/realtek.c +1 -1
 		if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
 				      phydev->advertising))
-			adv2500 = RTL_ADV_2500FULL;
+			adv2500 = MDIO_AN_10GBT_CTRL_ADV2_5G;
 

Similarly linkmode_adv_to_mii_10gbt_adv_t() can be used here.

Quoted 36 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/phy/realtek.c +2 -1
 		ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12,
-					       RTL_ADV_2500FULL, adv2500);
+					       MDIO_AN_10GBT_CTRL_ADV2_5G,
+					       adv2500);
 		if (ret < 0)
 			return ret;
 	}
@@ -714,11 +707,14 @@ static int rtl822x_read_status(struct phy_device *phydev)
 			return lpadv;
 
Quoted 15 lines

drivers/net/phy/realtek.c static int rtl822x_read_status(struct phy_device *phydev) · line 717

Quoted 12 lines
drivers/net/phy/realtek.c +6 -3
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_10000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP10G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_5000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP5G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_2500FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP2_5G);

Is this mii_10gbt_stat_mod_linkmode_lpa_t() ?

Indeed, it is. Thanks for the hint. I'd prefer to submit the patch making use of this helper as a follow-up patch. Then it's obvious that the helper is the same as the replaced code.

Quoted 6 lines

Something i've done in the past is to do this sort of conversion to standard macros, and the followed up with a patch which says that function X is now clearly the same as helper Y, so delete the function and use the helper...

Andrew

Heiner

author maintainer
#6 lore raw

Re: [PATCH net-next 2/3] net: phy: realtek: use generic MDIO constants

Hi Andrew,

Quoted 59 lines · Heiner Kallweit
Quoted 58 lines · Heiner Kallweit
Quoted 34 lines · Andrew Lunn
Quoted 33 lines · Heiner Kallweit

From: Marek Behún <[email protected]>

Drop the ad-hoc MDIO constants used in the driver and use generic constants instead.

---
 drivers/net/phy/realtek.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/net/phy/realtek.c +0 -8
index 894172a3e..ffc13c495 100644
@@ -57,14 +57,6 @@
 #define RTL8366RB_POWER_SAVE			0x15
 #define RTL8366RB_POWER_SAVE_ON			BIT(12)
 
-#define RTL_SUPPORTS_5000FULL			BIT(14)
-#define RTL_SUPPORTS_2500FULL			BIT(13)
-#define RTL_SUPPORTS_10000FULL			BIT(0)
-#define RTL_ADV_2500FULL			BIT(7)
-#define RTL_LPADV_10000FULL			BIT(11)
-#define RTL_LPADV_5000FULL			BIT(6)
-#define RTL_LPADV_2500FULL			BIT(5)
-
 #define RTL9000A_GINMR				0x14
 #define RTL9000A_GINMR_LINK_STATUS		BIT(4)
 
@@ -674,11 +666,11 @@ static int rtl822x_get_features(struct phy_device *phydev)
 		return val;
 
Quoted 14 lines

drivers/net/phy/realtek.c static int rtl822x_get_features(struct phy_device *phydev) · line 673

Quoted 9 lines
drivers/net/phy/realtek.c +3 -3
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_2500FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_2_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_5000FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_10000FULL);
+			 phydev->supported, val & MDIO_SPEED_10G);

Now that this only using generic constants, should it move into mdio.h as a shared helper? Is this a standard register defined in 802.3, just at a different address?

This is register 1.4 (PMA/PMD speed ability), mapped to a vendor-specific register. There's very few users of this register, and nothing where such a helper could be reused.

Quoted 5 lines
Quoted 5 lines
drivers/net/phy/realtek.c +0 -0
 	return genphy_read_abilities(phydev);
 }
@@ -692,10 +684,11 @@ static int rtl822x_config_aneg(struct phy_device *phydev)
 
Quoted 37 lines
Quoted 5 lines
Quoted 5 lines

drivers/net/phy/realtek.c static int rtl822x_config_aneg(struct phy_device *phydev) · line 688

Quoted 5 lines
drivers/net/phy/realtek.c +1 -1
 		if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
 				      phydev->advertising))
-			adv2500 = RTL_ADV_2500FULL;
+			adv2500 = MDIO_AN_10GBT_CTRL_ADV2_5G;
 

Similarly linkmode_adv_to_mii_10gbt_adv_t() can be used here.

Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/phy/realtek.c +2 -1
 		ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12,
-					       RTL_ADV_2500FULL, adv2500);
+					       MDIO_AN_10GBT_CTRL_ADV2_5G,
+					       adv2500);
 		if (ret < 0)
 			return ret;
 	}
@@ -714,11 +707,14 @@ static int rtl822x_read_status(struct phy_device *phydev)
 			return lpadv;
 
Quoted 15 lines

drivers/net/phy/realtek.c static int rtl822x_read_status(struct phy_device *phydev) · line 717

Quoted 12 lines
drivers/net/phy/realtek.c +6 -3
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_10000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP10G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_5000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP5G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_2500FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP2_5G);

Is this mii_10gbt_stat_mod_linkmode_lpa_t() ?

Indeed, it is. Thanks for the hint. I'd prefer to submit the patch making use of this helper as a follow-up patch. Then it's obvious that the helper is the same as the replaced code.

Is it fine with you to do this in a follow-up patch?
The series is marked "under review", so Jakub seems to wait for an outcome of our discussion.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

Something i've done in the past is to do this sort of conversion to standard macros, and the followed up with a patch which says that function X is now clearly the same as helper Y, so delete the function and use the helper...

Andrew

Heiner

Heiner

maintainer Reviewed-by
#7 lore raw

Re: [PATCH net-next 2/3] net: phy: realtek: use generic MDIO constants

Quoted 56 lines · Heiner Kallweit

Hi Andrew,

Quoted 53 lines · Heiner Kallweit
Quoted 52 lines · Heiner Kallweit
Quoted 34 lines · Andrew Lunn
Quoted 33 lines · Heiner Kallweit

From: Marek Behún <[email protected]>

Drop the ad-hoc MDIO constants used in the driver and use generic constants instead.

---
 drivers/net/phy/realtek.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/net/phy/realtek.c +0 -8
index 894172a3e..ffc13c495 100644
@@ -57,14 +57,6 @@
 #define RTL8366RB_POWER_SAVE			0x15
 #define RTL8366RB_POWER_SAVE_ON			BIT(12)
 
-#define RTL_SUPPORTS_5000FULL			BIT(14)
-#define RTL_SUPPORTS_2500FULL			BIT(13)
-#define RTL_SUPPORTS_10000FULL			BIT(0)
-#define RTL_ADV_2500FULL			BIT(7)
-#define RTL_LPADV_10000FULL			BIT(11)
-#define RTL_LPADV_5000FULL			BIT(6)
-#define RTL_LPADV_2500FULL			BIT(5)
-
 #define RTL9000A_GINMR				0x14
 #define RTL9000A_GINMR_LINK_STATUS		BIT(4)
 
@@ -674,11 +666,11 @@ static int rtl822x_get_features(struct phy_device *phydev)
 		return val;
 
Quoted 14 lines

drivers/net/phy/realtek.c static int rtl822x_get_features(struct phy_device *phydev) · line 673

Quoted 9 lines
drivers/net/phy/realtek.c +3 -3
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_2500FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_2_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_5000FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_10000FULL);
+			 phydev->supported, val & MDIO_SPEED_10G);

Now that this only using generic constants, should it move into mdio.h as a shared helper? Is this a standard register defined in 802.3, just at a different address?

This is register 1.4 (PMA/PMD speed ability), mapped to a vendor-specific register. There's very few users of this register, and nothing where such a helper could be reused.

Nothing at the moment. If ixgbe ever gets converted to phylib, or at least converted to link modes, it could use it. But i think it should be in mdio.h. That is where people will look for such a helper, and might overlook it here. We want to encourage such helpers and there use.

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Is this mii_10gbt_stat_mod_linkmode_lpa_t() ?

Indeed, it is. Thanks for the hint. I'd prefer to submit the patch making use of this helper as a follow-up patch. Then it's obvious that the helper is the same as the replaced code.

Is it fine with you to do this in a follow-up patch?
The series is marked "under review", so Jakub seems to wait for an outcome of our discussion.

Converting to use the standard helps can be a follow-up patch. And moving the helper into mdio.h as well.

Andrew

author maintainer
#8 lore raw

Re: [PATCH net-next 2/3] net: phy: realtek: use generic MDIO constants

In reply to Heiner Kallweit
Quoted 57 lines · Heiner Kallweit

Hi Andrew,

Quoted 54 lines · Heiner Kallweit
Quoted 53 lines · Heiner Kallweit
Quoted 34 lines · Andrew Lunn
Quoted 33 lines · Heiner Kallweit

From: Marek Behún <[email protected]>

Drop the ad-hoc MDIO constants used in the driver and use generic constants instead.

---
 drivers/net/phy/realtek.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/net/phy/realtek.c +0 -8
index 894172a3e..ffc13c495 100644
@@ -57,14 +57,6 @@
 #define RTL8366RB_POWER_SAVE			0x15
 #define RTL8366RB_POWER_SAVE_ON			BIT(12)
 
-#define RTL_SUPPORTS_5000FULL			BIT(14)
-#define RTL_SUPPORTS_2500FULL			BIT(13)
-#define RTL_SUPPORTS_10000FULL			BIT(0)
-#define RTL_ADV_2500FULL			BIT(7)
-#define RTL_LPADV_10000FULL			BIT(11)
-#define RTL_LPADV_5000FULL			BIT(6)
-#define RTL_LPADV_2500FULL			BIT(5)
-
 #define RTL9000A_GINMR				0x14
 #define RTL9000A_GINMR_LINK_STATUS		BIT(4)
 
@@ -674,11 +666,11 @@ static int rtl822x_get_features(struct phy_device *phydev)
 		return val;
 
Quoted 14 lines

drivers/net/phy/realtek.c static int rtl822x_get_features(struct phy_device *phydev) · line 673

Quoted 9 lines
drivers/net/phy/realtek.c +3 -3
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_2500FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_2_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_5000FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_10000FULL);
+			 phydev->supported, val & MDIO_SPEED_10G);

Now that this only using generic constants, should it move into mdio.h as a shared helper? Is this a standard register defined in 802.3, just at a different address?

This is register 1.4 (PMA/PMD speed ability), mapped to a vendor-specific register. There's very few users of this register, and nothing where such a helper could be reused.

When looking a little closer at creating a helper for it, I stumbled across the following. This register just states that the PHY can operate at a certain speed, it leaves open which mode(s) are supported at that speed. I see e.g. 10 different modes for 200Gbps. So it may not be possible to create a generic helper. A translation to linkmodes is only possible if the PHY supports just one mode per speed.

Quoted 55 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/phy/realtek.c +0 -0
 	return genphy_read_abilities(phydev);
 }
@@ -692,10 +684,11 @@ static int rtl822x_config_aneg(struct phy_device *phydev)
 
Quoted 37 lines
Quoted 5 lines
Quoted 5 lines

drivers/net/phy/realtek.c static int rtl822x_config_aneg(struct phy_device *phydev) · line 688

Quoted 5 lines
drivers/net/phy/realtek.c +1 -1
 		if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
 				      phydev->advertising))
-			adv2500 = RTL_ADV_2500FULL;
+			adv2500 = MDIO_AN_10GBT_CTRL_ADV2_5G;
 

Similarly linkmode_adv_to_mii_10gbt_adv_t() can be used here.

Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/phy/realtek.c +2 -1
 		ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12,
-					       RTL_ADV_2500FULL, adv2500);
+					       MDIO_AN_10GBT_CTRL_ADV2_5G,
+					       adv2500);
 		if (ret < 0)
 			return ret;
 	}
@@ -714,11 +707,14 @@ static int rtl822x_read_status(struct phy_device *phydev)
 			return lpadv;
 
Quoted 15 lines

drivers/net/phy/realtek.c static int rtl822x_read_status(struct phy_device *phydev) · line 717

Quoted 12 lines
drivers/net/phy/realtek.c +6 -3
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_10000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP10G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_5000FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP5G);
 		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			phydev->lp_advertising, lpadv & RTL_LPADV_2500FULL);
+				 phydev->lp_advertising,
+				 lpadv & MDIO_AN_10GBT_STAT_LP2_5G);

Is this mii_10gbt_stat_mod_linkmode_lpa_t() ?

Indeed, it is. Thanks for the hint. I'd prefer to submit the patch making use of this helper as a follow-up patch. Then it's obvious that the helper is the same as the replaced code.

Is it fine with you to do this in a follow-up patch?
The series is marked "under review", so Jakub seems to wait for an outcome of our discussion.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

Something i've done in the past is to do this sort of conversion to standard macros, and the followed up with a patch which says that function X is now clearly the same as helper Y, so delete the function and use the helper...

Andrew

Heiner

Heiner

maintainer
#9 lore raw

Re: [PATCH net-next 2/3] net: phy: realtek: use generic MDIO constants

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

drivers/net/phy/realtek.c static int rtl822x_get_features(struct phy_device *phydev) · line 673

Quoted 12 lines
drivers/net/phy/realtek.c +3 -3
@@ -674,11 +666,11 @@ static int rtl822x_get_features(struct phy_device *phydev)
 		return val;
 
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_2500FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_2_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_5000FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_10000FULL);
+			 phydev->supported, val & MDIO_SPEED_10G);

Now that this only using generic constants, should it move into mdio.h as a shared helper? Is this a standard register defined in 802.3, just at a different address?

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This is register 1.4 (PMA/PMD speed ability), mapped to a vendor-specific register. There's very few users of this register, and nothing where such a helper could be reused.

When looking a little closer at creating a helper for it, I stumbled across the following. This register just states that the PHY can operate at a certain speed, it leaves open which mode(s) are supported at that speed.

O.K, yes, i agree. All it says is speed, nothing more.

But that also means this driver should not really be doing this. Is there a full list of registers which are implemented? Is there a way to implement genphy_c45_pma_read_abilities(), or at least the subset needed for this device? That appears to be MDIO_MMD_PMAPMD:MDIO_PMA_NG_EXTABLE and MDIO_MMD_PMAPMD:MDIO_PMA_EXTABLE?

Andrew

author maintainer
#10 lore raw

Re: [PATCH net-next 2/3] net: phy: realtek: use generic MDIO constants

Quoted 26 lines · Andrew Lunn
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

Review static int rtl822x_get_features(struct phy_device *phydev) · line 673

Quoted 12 lines
(quoted diff) +3 -3
@@ -674,11 +666,11 @@ static int rtl822x_get_features(struct phy_device *phydev)
 		return val;
 
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_2500FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_2_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_5000FULL);
+			 phydev->supported, val & MDIO_PMA_SPEED_5G);
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
-			 phydev->supported, val & RTL_SUPPORTS_10000FULL);
+			 phydev->supported, val & MDIO_SPEED_10G);

Now that this only using generic constants, should it move into mdio.h as a shared helper? Is this a standard register defined in 802.3, just at a different address?

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This is register 1.4 (PMA/PMD speed ability), mapped to a vendor-specific register. There's very few users of this register, and nothing where such a helper could be reused.

When looking a little closer at creating a helper for it, I stumbled across the following. This register just states that the PHY can operate at a certain speed, it leaves open which mode(s) are supported at that speed.

Quoted 8 lines

O.K, yes, i agree. All it says is speed, nothing more.

But that also means this driver should not really be doing this. Is there a full list of registers which are implemented? Is there a way to implement genphy_c45_pma_read_abilities(), or at least the subset needed for this device? That appears to be MDIO_MMD_PMAPMD:MDIO_PMA_NG_EXTABLE and MDIO_MMD_PMAPMD:MDIO_PMA_EXTABLE?

I don't have access to Realtek datasheets, and AFAIK the datasheets don't document the mapping of c45 standard registers to vendor-specific registers. But let me check with my contact at Realtek.

Quoted 1 line

Andrew

Heiner

author maintainer
#11 lore raw

PATCH 3/3 net: phy: realtek: add 5Gbps support to rtl822x_config_aneg()

In reply to Heiner Kallweit

RTL8126 as an evolution of RTL8125 supports 5Gbps. rtl822x_config_aneg() is used by the PHY driver for the integrated PHY, therefore add 5Gbps support to it.

---
 drivers/net/phy/realtek.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/phy/realtek.c +8 -4
index ffc13c495..06f6672a4 100644
@@ -680,15 +680,19 @@ static int rtl822x_config_aneg(struct phy_device *phydev)
 	int ret = 0;
 
 	if (phydev->autoneg == AUTONEG_ENABLE) {
-		u16 adv2500 = 0;
+		u16 adv = 0;
 
 		if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
 				      phydev->advertising))
-			adv2500 = MDIO_AN_10GBT_CTRL_ADV2_5G;
+			adv |= MDIO_AN_10GBT_CTRL_ADV2_5G;
+		if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
+				      phydev->advertising))
+			adv |= MDIO_AN_10GBT_CTRL_ADV5G;
 
 		ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12,
-					       MDIO_AN_10GBT_CTRL_ADV2_5G,
-					       adv2500);
+					       MDIO_AN_10GBT_CTRL_ADV2_5G |
+					       MDIO_AN_10GBT_CTRL_ADV5G,
+					       adv);
 		if (ret < 0)
 			return ret;
 	}
Signature · 1 line
2.43.0
#12 lore raw
In reply to Heiner Kallweit
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Sun, 4 Feb 2024 15:15:00 +0100 you wrote:

Realtek maps standard C45 registers to vendor-specific registers which can be accessed via C22 w/o MMD. For an unknown reason C22 MMD access to C45 registers isn't supported for integrated PHY's. However the vendor-specific registers preserve the format of the C45 registers, so we can use standard constants. First two patches are cherry-picked from a series posted by Marek some time ago.

[...]

Here is the summary with links:
- [net-next,1/3] net: mdio: add 2.5g and 5g related PMA speed constants

    https://git.kernel.org/netdev/net-next/c/6c06c88fa838
  - [net-next,2/3] net: phy: realtek: use generic MDIO constants
    https://git.kernel.org/netdev/net-next/c/2b9ec5dfb825
  - [net-next,3/3] net: phy: realtek: add 5Gbps support to rtl822x_config_aneg()
    https://git.kernel.org/netdev/net-next/c/db1bb7741ff2

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html