generic: 6.1: move stmmac backport fix patches to generic
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 706-v6.6-03-net-phy-at803x-enable-qca8081-slave-seed-conditional.patch
1 From 7cc3209558002d95c0d45a1276ba4f5f741eec42 Mon Sep 17 00:00:00 2001
2 From: Luo Jie <quic_luoj@quicinc.com>
3 Date: Sun, 16 Jul 2023 16:49:21 +0800
4 Subject: [PATCH 3/6] net: phy: at803x: enable qca8081 slave seed conditionally
5
6 qca8081 is the single port PHY, the slave prefer mode is used
7 by default.
8
9 if the phy master perfer mode is configured, the slave seed
10 configuration should not be enabled, since the slave seed
11 enablement is for making PHY linked as slave mode easily.
12
13 disable slave seed if the master mode is preferred.
14
15 Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
16 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
18 ---
19 drivers/net/phy/at803x.c | 25 ++++++++++++++++++++-----
20 1 file changed, 20 insertions(+), 5 deletions(-)
21
22 --- a/drivers/net/phy/at803x.c
23 +++ b/drivers/net/phy/at803x.c
24 @@ -1745,6 +1745,12 @@ static int qca808x_phy_ms_seed_enable(st
25 QCA808X_MASTER_SLAVE_SEED_ENABLE);
26 }
27
28 +static bool qca808x_is_prefer_master(struct phy_device *phydev)
29 +{
30 + return (phydev->master_slave_get == MASTER_SLAVE_CFG_MASTER_FORCE) ||
31 + (phydev->master_slave_get == MASTER_SLAVE_CFG_MASTER_PREFERRED);
32 +}
33 +
34 static int qca808x_config_init(struct phy_device *phydev)
35 {
36 int ret;
37 @@ -1766,11 +1772,17 @@ static int qca808x_config_init(struct ph
38 if (ret)
39 return ret;
40
41 - /* Enable seed and configure lower ramdom seed to make phy linked as slave mode */
42 - ret = qca808x_phy_ms_seed_enable(phydev, true);
43 - if (ret)
44 + ret = genphy_read_master_slave(phydev);
45 + if (ret < 0)
46 return ret;
47
48 + if (!qca808x_is_prefer_master(phydev)) {
49 + /* Enable seed and configure lower ramdom seed to make phy linked as slave mode */
50 + ret = qca808x_phy_ms_seed_enable(phydev, true);
51 + if (ret)
52 + return ret;
53 + }
54 +
55 /* Configure adc threshold as 100mv for the link 10M */
56 return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_ADC_THRESHOLD,
57 QCA808X_ADC_THRESHOLD_MASK, QCA808X_ADC_THRESHOLD_100MV);
58 @@ -1802,13 +1814,16 @@ static int qca808x_read_status(struct ph
59 phydev->interface = PHY_INTERFACE_MODE_SGMII;
60 } else {
61 /* generate seed as a lower random value to make PHY linked as SLAVE easily,
62 - * except for master/slave configuration fault detected.
63 + * except for master/slave configuration fault detected or the master mode
64 + * preferred.
65 + *
66 * the reason for not putting this code into the function link_change_notify is
67 * the corner case where the link partner is also the qca8081 PHY and the seed
68 * value is configured as the same value, the link can't be up and no link change
69 * occurs.
70 */
71 - if (phydev->master_slave_state == MASTER_SLAVE_STATE_ERR) {
72 + if (phydev->master_slave_state == MASTER_SLAVE_STATE_ERR ||
73 + qca808x_is_prefer_master(phydev)) {
74 qca808x_phy_ms_seed_enable(phydev, false);
75 } else {
76 qca808x_phy_ms_seed_enable(phydev, true);