44cf60cf1487a6f6a4599a82326a44422223b7cf
[openwrt/staging/blogic.git] /
1 From 856e8954a0a88d1a4d2b43e9002b9249131a156f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <arinc.unal@arinc9.com>
3 Date: Mon, 22 Apr 2024 10:15:08 +0300
4 Subject: [PATCH 01/15] net: dsa: mt7530: disable EEE abilities on failure on
5 MT7531 and MT7988
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 The MT7531_FORCE_EEE1G and MT7531_FORCE_EEE100 bits let the
11 PMCR_FORCE_EEE1G and PMCR_FORCE_EEE100 bits determine the 1G/100 EEE
12 abilities of the MAC. If MT7531_FORCE_EEE1G and MT7531_FORCE_EEE100 are
13 unset, the abilities are left to be determined by PHY auto polling.
14
15 The commit 40b5d2f15c09 ("net: dsa: mt7530: Add support for EEE features")
16 made it so that the PMCR_FORCE_EEE1G and PMCR_FORCE_EEE100 bits are set on
17 mt753x_phylink_mac_link_up(). But it did not set the MT7531_FORCE_EEE1G and
18 MT7531_FORCE_EEE100 bits. Because of this, the EEE abilities will be
19 determined by PHY auto polling, regardless of the result of phy_init_eee().
20
21 Define these bits and add them to the MT7531_FORCE_MODE mask which is set
22 in mt7531_setup_common(). With this, there won't be any EEE abilities set
23 when phy_init_eee() returns a negative value.
24
25 Thanks to Russell for explaining when phy_init_eee() could return a
26 negative value below.
27
28 Looking at phy_init_eee(), it could return a negative value when:
29
30 1. phydev->drv is NULL
31 2. if genphy_c45_eee_is_active() returns negative
32 3. if genphy_c45_eee_is_active() returns zero, it returns -EPROTONOSUPPORT
33 4. if phy_set_bits_mmd() fails (e.g. communication error with the PHY)
34
35 If we then look at genphy_c45_eee_is_active(), then:
36
37 genphy_c45_read_eee_adv() and genphy_c45_read_eee_lpa() propagate their
38 non-zero return values, otherwise this function returns zero or positive
39 integer.
40
41 If we then look at genphy_c45_read_eee_adv(), then a failure of
42 phy_read_mmd() would cause a negative value to be returned.
43
44 Looking at genphy_c45_read_eee_lpa(), the same is true.
45
46 So, it can be summarised as:
47
48 - phydev->drv is NULL
49 - there is a communication error accessing the PHY
50 - EEE is not active
51
52 otherwise, it returns zero on success.
53
54 If one wishes to determine whether an error occurred vs EEE not being
55 supported through negotiation for the negotiated speed, if it returns
56 -EPROTONOSUPPORT in the latter case. Other error codes mean either the
57 driver has been unloaded or communication error.
58
59 In conclusion, determining the EEE abilities by PHY auto polling shouldn't
60 result in having any EEE abilities enabled, when one of the last two
61 situations in the summary happens. And it seems that if phydev->drv is
62 NULL, there would be bigger problems with the device than a broken link. So
63 this is not a bugfix.
64
65 Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
66 ---
67 drivers/net/dsa/mt7530.h | 6 +++++-
68 1 file changed, 5 insertions(+), 1 deletion(-)
69
70 --- a/drivers/net/dsa/mt7530.h
71 +++ b/drivers/net/dsa/mt7530.h
72 @@ -328,11 +328,15 @@ enum mt7530_vlan_port_acc_frm {
73 #define MT7531_FORCE_DPX BIT(29)
74 #define MT7531_FORCE_RX_FC BIT(28)
75 #define MT7531_FORCE_TX_FC BIT(27)
76 +#define MT7531_FORCE_EEE100 BIT(26)
77 +#define MT7531_FORCE_EEE1G BIT(25)
78 #define MT7531_FORCE_MODE (MT7531_FORCE_LNK | \
79 MT7531_FORCE_SPD | \
80 MT7531_FORCE_DPX | \
81 MT7531_FORCE_RX_FC | \
82 - MT7531_FORCE_TX_FC)
83 + MT7531_FORCE_TX_FC | \
84 + MT7531_FORCE_EEE100 | \
85 + MT7531_FORCE_EEE1G)
86 #define PMCR_LINK_SETTINGS_MASK (PMCR_TX_EN | PMCR_FORCE_SPEED_1000 | \
87 PMCR_RX_EN | PMCR_FORCE_SPEED_100 | \
88 PMCR_TX_FC_EN | PMCR_RX_FC_EN | \