Skip to content

Commit ad5ce74

Browse files
elkablodavem330
authored andcommitted
net: phy: realtek: Add driver instances for rtl8221b via Clause 45
Collected from several commits in [PATCH net-next] "Realtek RTL822x PHY rework to c45 and SerDes interface switching" The instances are used by Clause 45 only accessible PHY's on several sfp modules, which are using RollBall protocol. Signed-off-by: Marek Behún <[email protected]> [ Added matching functions to differentiate C45 instances ] Signed-off-by: Eric Woudstra <[email protected]> Reviewed-by: Russell King (Oracle) <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c189dbd commit ad5ce74

File tree

1 file changed

+131
-4
lines changed

1 file changed

+131
-4
lines changed

drivers/net/phy/realtek.c

Lines changed: 131 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464
#define RTL822X_VND1_SERDES_CTRL3_MODE_SGMII 0x02
6565
#define RTL822X_VND1_SERDES_CTRL3_MODE_2500BASEX 0x16
6666

67+
/* RTL822X_VND2_XXXXX registers are only accessible when phydev->is_c45
68+
* is set, they cannot be accessed by C45-over-C22.
69+
*/
70+
#define RTL822X_VND2_GBCR 0xa412
71+
72+
#define RTL822X_VND2_GANLPAR 0xa414
73+
6774
#define RTL8366RB_POWER_SAVE 0x15
6875
#define RTL8366RB_POWER_SAVE_ON BIT(12)
6976

@@ -74,6 +81,9 @@
7481

7582
#define RTL_GENERIC_PHYID 0x001cc800
7683
#define RTL_8211FVD_PHYID 0x001cc878
84+
#define RTL_8221B_VB_CG 0x001cc849
85+
#define RTL_8221B_VN_CG 0x001cc84a
86+
#define RTL_8251B 0x001cc862
7787

7888
MODULE_DESCRIPTION("Realtek PHY driver");
7989
MODULE_AUTHOR("Johnson Leung");
@@ -839,6 +849,67 @@ static int rtl822xb_read_status(struct phy_device *phydev)
839849
return 0;
840850
}
841851

852+
static int rtl822x_c45_config_aneg(struct phy_device *phydev)
853+
{
854+
bool changed = false;
855+
int ret, val;
856+
857+
if (phydev->autoneg == AUTONEG_DISABLE)
858+
return genphy_c45_pma_setup_forced(phydev);
859+
860+
ret = genphy_c45_an_config_aneg(phydev);
861+
if (ret < 0)
862+
return ret;
863+
if (ret > 0)
864+
changed = true;
865+
866+
val = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
867+
868+
/* Vendor register as C45 has no standardized support for 1000BaseT */
869+
ret = phy_modify_mmd_changed(phydev, MDIO_MMD_VEND2, RTL822X_VND2_GBCR,
870+
ADVERTISE_1000FULL, val);
871+
if (ret < 0)
872+
return ret;
873+
if (ret > 0)
874+
changed = true;
875+
876+
return genphy_c45_check_and_restart_aneg(phydev, changed);
877+
}
878+
879+
static int rtl822x_c45_read_status(struct phy_device *phydev)
880+
{
881+
int ret, val;
882+
883+
ret = genphy_c45_read_status(phydev);
884+
if (ret < 0)
885+
return ret;
886+
887+
/* Vendor register as C45 has no standardized support for 1000BaseT */
888+
if (phydev->autoneg == AUTONEG_ENABLE) {
889+
val = phy_read_mmd(phydev, MDIO_MMD_VEND2,
890+
RTL822X_VND2_GANLPAR);
891+
if (val < 0)
892+
return val;
893+
894+
mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val);
895+
}
896+
897+
return 0;
898+
}
899+
900+
static int rtl822xb_c45_read_status(struct phy_device *phydev)
901+
{
902+
int ret;
903+
904+
ret = rtl822x_c45_read_status(phydev);
905+
if (ret < 0)
906+
return ret;
907+
908+
rtl822xb_update_interface(phydev);
909+
910+
return 0;
911+
}
912+
842913
static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
843914
{
844915
int val;
@@ -862,6 +933,35 @@ static int rtl8226_match_phy_device(struct phy_device *phydev)
862933
rtlgen_supports_2_5gbps(phydev);
863934
}
864935

936+
static int rtlgen_is_c45_match(struct phy_device *phydev, unsigned int id,
937+
bool is_c45)
938+
{
939+
if (phydev->is_c45)
940+
return is_c45 && (id == phydev->c45_ids.device_ids[1]);
941+
else
942+
return !is_c45 && (id == phydev->phy_id);
943+
}
944+
945+
static int rtl8221b_vb_cg_c22_match_phy_device(struct phy_device *phydev)
946+
{
947+
return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, false);
948+
}
949+
950+
static int rtl8221b_vb_cg_c45_match_phy_device(struct phy_device *phydev)
951+
{
952+
return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, true);
953+
}
954+
955+
static int rtl8221b_vn_cg_c22_match_phy_device(struct phy_device *phydev)
956+
{
957+
return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, false);
958+
}
959+
960+
static int rtl8221b_vn_cg_c45_match_phy_device(struct phy_device *phydev)
961+
{
962+
return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, true);
963+
}
964+
865965
static int rtlgen_resume(struct phy_device *phydev)
866966
{
867967
int ret = genphy_resume(phydev);
@@ -872,6 +972,15 @@ static int rtlgen_resume(struct phy_device *phydev)
872972
return ret;
873973
}
874974

975+
static int rtlgen_c45_resume(struct phy_device *phydev)
976+
{
977+
int ret = genphy_c45_pma_resume(phydev);
978+
979+
msleep(20);
980+
981+
return ret;
982+
}
983+
875984
static int rtl9000a_config_init(struct phy_device *phydev)
876985
{
877986
phydev->autoneg = AUTONEG_DISABLE;
@@ -1143,8 +1252,8 @@ static struct phy_driver realtek_drvs[] = {
11431252
.read_page = rtl821x_read_page,
11441253
.write_page = rtl821x_write_page,
11451254
}, {
1146-
PHY_ID_MATCH_EXACT(0x001cc849),
1147-
.name = "RTL8221B-VB-CG 2.5Gbps PHY",
1255+
.match_phy_device = rtl8221b_vb_cg_c22_match_phy_device,
1256+
.name = "RTL8221B-VB-CG 2.5Gbps PHY (C22)",
11481257
.get_features = rtl822x_get_features,
11491258
.config_aneg = rtl822x_config_aneg,
11501259
.config_init = rtl822xb_config_init,
@@ -1155,8 +1264,17 @@ static struct phy_driver realtek_drvs[] = {
11551264
.read_page = rtl821x_read_page,
11561265
.write_page = rtl821x_write_page,
11571266
}, {
1158-
PHY_ID_MATCH_EXACT(0x001cc84a),
1159-
.name = "RTL8221B-VM-CG 2.5Gbps PHY",
1267+
.match_phy_device = rtl8221b_vb_cg_c45_match_phy_device,
1268+
.name = "RTL8221B-VB-CG 2.5Gbps PHY (C45)",
1269+
.config_init = rtl822xb_config_init,
1270+
.get_rate_matching = rtl822xb_get_rate_matching,
1271+
.config_aneg = rtl822x_c45_config_aneg,
1272+
.read_status = rtl822xb_c45_read_status,
1273+
.suspend = genphy_c45_pma_suspend,
1274+
.resume = rtlgen_c45_resume,
1275+
}, {
1276+
.match_phy_device = rtl8221b_vn_cg_c22_match_phy_device,
1277+
.name = "RTL8221B-VM-CG 2.5Gbps PHY (C22)",
11601278
.get_features = rtl822x_get_features,
11611279
.config_aneg = rtl822x_config_aneg,
11621280
.config_init = rtl822xb_config_init,
@@ -1166,6 +1284,15 @@ static struct phy_driver realtek_drvs[] = {
11661284
.resume = rtlgen_resume,
11671285
.read_page = rtl821x_read_page,
11681286
.write_page = rtl821x_write_page,
1287+
}, {
1288+
.match_phy_device = rtl8221b_vn_cg_c45_match_phy_device,
1289+
.name = "RTL8221B-VN-CG 2.5Gbps PHY (C45)",
1290+
.config_init = rtl822xb_config_init,
1291+
.get_rate_matching = rtl822xb_get_rate_matching,
1292+
.config_aneg = rtl822x_c45_config_aneg,
1293+
.read_status = rtl822xb_c45_read_status,
1294+
.suspend = genphy_c45_pma_suspend,
1295+
.resume = rtlgen_c45_resume,
11691296
}, {
11701297
PHY_ID_MATCH_EXACT(0x001cc862),
11711298
.name = "RTL8251B 5Gbps PHY",

0 commit comments

Comments
 (0)