54ca3bdfc8258c768aa092af3f9e321edf449c5d
[openwrt/staging/wigyori.git] /
1 From 38eb804e8458ba181a03a0498ce4bf84eebd1931 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 14 Dec 2023 01:44:32 +0100
4 Subject: [PATCH 2/2] net: phy: at803x: make read specific status function more
5 generic
6
7 Rework read specific status function to be more generic. The function
8 apply different speed mask based on the PHY ID. Make it more generic by
9 adding an additional arg to pass the specific speed (ss) mask and use
10 the provided mask to parse the speed value.
11
12 This is needed to permit an easier deatch of qca808x code from the
13 at803x driver.
14
15 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
17 ---
18 drivers/net/phy/at803x.c | 26 ++++++++++++++++++--------
19 1 file changed, 18 insertions(+), 8 deletions(-)
20
21 --- a/drivers/net/phy/at803x.c
22 +++ b/drivers/net/phy/at803x.c
23 @@ -301,6 +301,11 @@ static struct at803x_hw_stat qca83xx_hw_
24 { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD},
25 };
26
27 +struct at803x_ss_mask {
28 + u16 speed_mask;
29 + u8 speed_shift;
30 +};
31 +
32 struct at803x_priv {
33 int flags;
34 u16 clk_25m_reg;
35 @@ -921,7 +926,8 @@ static void at803x_link_change_notify(st
36 }
37 }
38
39 -static int at803x_read_specific_status(struct phy_device *phydev)
40 +static int at803x_read_specific_status(struct phy_device *phydev,
41 + struct at803x_ss_mask ss_mask)
42 {
43 int ss;
44
45 @@ -940,11 +946,8 @@ static int at803x_read_specific_status(s
46 if (sfc < 0)
47 return sfc;
48
49 - /* qca8081 takes the different bits for speed value from at803x */
50 - if (phydev->drv->phy_id == QCA8081_PHY_ID)
51 - speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss);
52 - else
53 - speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss);
54 + speed = ss & ss_mask.speed_mask;
55 + speed >>= ss_mask.speed_shift;
56
57 switch (speed) {
58 case AT803X_SS_SPEED_10:
59 @@ -989,6 +992,7 @@ static int at803x_read_specific_status(s
60 static int at803x_read_status(struct phy_device *phydev)
61 {
62 struct at803x_priv *priv = phydev->priv;
63 + struct at803x_ss_mask ss_mask = { 0 };
64 int err, old_link = phydev->link;
65
66 if (priv->is_1000basex)
67 @@ -1012,7 +1016,9 @@ static int at803x_read_status(struct phy
68 if (err < 0)
69 return err;
70
71 - err = at803x_read_specific_status(phydev);
72 + ss_mask.speed_mask = AT803X_SS_SPEED_MASK;
73 + ss_mask.speed_shift = __bf_shf(AT803X_SS_SPEED_MASK);
74 + err = at803x_read_specific_status(phydev, ss_mask);
75 if (err < 0)
76 return err;
77
78 @@ -1869,6 +1875,7 @@ static int qca808x_config_init(struct ph
79
80 static int qca808x_read_status(struct phy_device *phydev)
81 {
82 + struct at803x_ss_mask ss_mask = { 0 };
83 int ret;
84
85 ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
86 @@ -1882,7 +1889,10 @@ static int qca808x_read_status(struct ph
87 if (ret)
88 return ret;
89
90 - ret = at803x_read_specific_status(phydev);
91 + /* qca8081 takes the different bits for speed value from at803x */
92 + ss_mask.speed_mask = QCA808X_SS_SPEED_MASK;
93 + ss_mask.speed_shift = __bf_shf(QCA808X_SS_SPEED_MASK);
94 + ret = at803x_read_specific_status(phydev, ss_mask);
95 if (ret < 0)
96 return ret;
97