Skip to content

Commit 523e1f5

Browse files
committed
Merge branch 'net-at803x-cleanups'
Christian Marangi says: ==================== net: phy: at803x: additional cleanup for qca808x This small series is a preparation for the big code split. While the qca808x code is waiting to be reviwed and merged, we can further cleanup and generalize shared functions between at803x and qca808x. With these last 2 patch everything is ready to move the driver to a dedicated directory and split the code by creating a library module for the few shared functions between the 2 driver. Eventually at803x can be further cleaned and generalized but everything will be already self contained and related only to at803x family of PHYs. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 6da0bcb + 38eb804 commit 523e1f5

File tree

1 file changed

+58
-34
lines changed

1 file changed

+58
-34
lines changed

drivers/net/phy/at803x.c

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ static struct at803x_hw_stat qca83xx_hw_stats[] = {
301301
{ "eee_wake_errors", 0x16, GENMASK(15, 0), MMD},
302302
};
303303

304+
struct at803x_ss_mask {
305+
u16 speed_mask;
306+
u8 speed_shift;
307+
};
308+
304309
struct at803x_priv {
305310
int flags;
306311
u16 clk_25m_reg;
@@ -921,7 +926,8 @@ static void at803x_link_change_notify(struct phy_device *phydev)
921926
}
922927
}
923928

924-
static int at803x_read_specific_status(struct phy_device *phydev)
929+
static int at803x_read_specific_status(struct phy_device *phydev,
930+
struct at803x_ss_mask ss_mask)
925931
{
926932
int ss;
927933

@@ -940,11 +946,8 @@ static int at803x_read_specific_status(struct phy_device *phydev)
940946
if (sfc < 0)
941947
return sfc;
942948

943-
/* qca8081 takes the different bits for speed value from at803x */
944-
if (phydev->drv->phy_id == QCA8081_PHY_ID)
945-
speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss);
946-
else
947-
speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss);
949+
speed = ss & ss_mask.speed_mask;
950+
speed >>= ss_mask.speed_shift;
948951

949952
switch (speed) {
950953
case AT803X_SS_SPEED_10:
@@ -989,6 +992,7 @@ static int at803x_read_specific_status(struct phy_device *phydev)
989992
static int at803x_read_status(struct phy_device *phydev)
990993
{
991994
struct at803x_priv *priv = phydev->priv;
995+
struct at803x_ss_mask ss_mask = { 0 };
992996
int err, old_link = phydev->link;
993997

994998
if (priv->is_1000basex)
@@ -1012,7 +1016,9 @@ static int at803x_read_status(struct phy_device *phydev)
10121016
if (err < 0)
10131017
return err;
10141018

1015-
err = at803x_read_specific_status(phydev);
1019+
ss_mask.speed_mask = AT803X_SS_SPEED_MASK;
1020+
ss_mask.speed_shift = __bf_shf(AT803X_SS_SPEED_MASK);
1021+
err = at803x_read_specific_status(phydev, ss_mask);
10161022
if (err < 0)
10171023
return err;
10181024

@@ -1045,9 +1051,8 @@ static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl)
10451051
FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val));
10461052
}
10471053

1048-
static int at803x_config_aneg(struct phy_device *phydev)
1054+
static int at803x_prepare_config_aneg(struct phy_device *phydev)
10491055
{
1050-
struct at803x_priv *priv = phydev->priv;
10511056
int ret;
10521057

10531058
ret = at803x_config_mdix(phydev, phydev->mdix_ctrl);
@@ -1064,33 +1069,22 @@ static int at803x_config_aneg(struct phy_device *phydev)
10641069
return ret;
10651070
}
10661071

1067-
if (priv->is_1000basex)
1068-
return genphy_c37_config_aneg(phydev);
1069-
1070-
/* Do not restart auto-negotiation by setting ret to 0 defautly,
1071-
* when calling __genphy_config_aneg later.
1072-
*/
1073-
ret = 0;
1074-
1075-
if (phydev->drv->phy_id == QCA8081_PHY_ID) {
1076-
int phy_ctrl = 0;
1072+
return 0;
1073+
}
10771074

1078-
/* The reg MII_BMCR also needs to be configured for force mode, the
1079-
* genphy_config_aneg is also needed.
1080-
*/
1081-
if (phydev->autoneg == AUTONEG_DISABLE)
1082-
genphy_c45_pma_setup_forced(phydev);
1075+
static int at803x_config_aneg(struct phy_device *phydev)
1076+
{
1077+
struct at803x_priv *priv = phydev->priv;
1078+
int ret;
10831079

1084-
if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising))
1085-
phy_ctrl = MDIO_AN_10GBT_CTRL_ADV2_5G;
1080+
ret = at803x_prepare_config_aneg(phydev);
1081+
if (ret)
1082+
return ret;
10861083

1087-
ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
1088-
MDIO_AN_10GBT_CTRL_ADV2_5G, phy_ctrl);
1089-
if (ret < 0)
1090-
return ret;
1091-
}
1084+
if (priv->is_1000basex)
1085+
return genphy_c37_config_aneg(phydev);
10921086

1093-
return __genphy_config_aneg(phydev, ret);
1087+
return genphy_config_aneg(phydev);
10941088
}
10951089

10961090
static int at803x_get_downshift(struct phy_device *phydev, u8 *d)
@@ -1881,6 +1875,7 @@ static int qca808x_config_init(struct phy_device *phydev)
18811875

18821876
static int qca808x_read_status(struct phy_device *phydev)
18831877
{
1878+
struct at803x_ss_mask ss_mask = { 0 };
18841879
int ret;
18851880

18861881
ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
@@ -1894,7 +1889,10 @@ static int qca808x_read_status(struct phy_device *phydev)
18941889
if (ret)
18951890
return ret;
18961891

1897-
ret = at803x_read_specific_status(phydev);
1892+
/* qca8081 takes the different bits for speed value from at803x */
1893+
ss_mask.speed_mask = QCA808X_SS_SPEED_MASK;
1894+
ss_mask.speed_shift = __bf_shf(QCA808X_SS_SPEED_MASK);
1895+
ret = at803x_read_specific_status(phydev, ss_mask);
18981896
if (ret < 0)
18991897
return ret;
19001898

@@ -2118,6 +2116,32 @@ static int qca808x_get_features(struct phy_device *phydev)
21182116
return 0;
21192117
}
21202118

2119+
static int qca808x_config_aneg(struct phy_device *phydev)
2120+
{
2121+
int phy_ctrl = 0;
2122+
int ret;
2123+
2124+
ret = at803x_prepare_config_aneg(phydev);
2125+
if (ret)
2126+
return ret;
2127+
2128+
/* The reg MII_BMCR also needs to be configured for force mode, the
2129+
* genphy_config_aneg is also needed.
2130+
*/
2131+
if (phydev->autoneg == AUTONEG_DISABLE)
2132+
genphy_c45_pma_setup_forced(phydev);
2133+
2134+
if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising))
2135+
phy_ctrl = MDIO_AN_10GBT_CTRL_ADV2_5G;
2136+
2137+
ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
2138+
MDIO_AN_10GBT_CTRL_ADV2_5G, phy_ctrl);
2139+
if (ret < 0)
2140+
return ret;
2141+
2142+
return __genphy_config_aneg(phydev, ret);
2143+
}
2144+
21212145
static void qca808x_link_change_notify(struct phy_device *phydev)
21222146
{
21232147
/* Assert interface sgmii fifo on link down, deassert it on link up,
@@ -2295,7 +2319,7 @@ static struct phy_driver at803x_driver[] = {
22952319
.set_wol = at803x_set_wol,
22962320
.get_wol = at803x_get_wol,
22972321
.get_features = qca808x_get_features,
2298-
.config_aneg = at803x_config_aneg,
2322+
.config_aneg = qca808x_config_aneg,
22992323
.suspend = genphy_suspend,
23002324
.resume = genphy_resume,
23012325
.read_status = qca808x_read_status,

0 commit comments

Comments
 (0)