kernel: bump 5.10 to 5.10.145
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 731-v5.13-net-dsa-mt7530-Add-support-for-EEE-features.patch
1 From 40b5d2f15c091fa9c854acde91ad2acb504027d7 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Ren=C3=A9=20van=20Dorst?= <opensource@vdorst.com>
3 Date: Mon, 12 Apr 2021 08:50:31 +0200
4 Subject: [PATCH] net: dsa: mt7530: Add support for EEE features
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This patch adds EEE support.
10
11 Signed-off-by: René van Dorst <opensource@vdorst.com>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 ---
14 drivers/net/dsa/mt7530.c | 43 ++++++++++++++++++++++++++++++++++++++++
15 drivers/net/dsa/mt7530.h | 14 ++++++++++++-
16 2 files changed, 56 insertions(+), 1 deletion(-)
17
18 --- a/drivers/net/dsa/mt7530.c
19 +++ b/drivers/net/dsa/mt7530.c
20 @@ -2366,6 +2366,17 @@ static void mt753x_phylink_mac_link_up(s
21 mcr |= PMCR_RX_FC_EN;
22 }
23
24 + if (mode == MLO_AN_PHY && phydev && phy_init_eee(phydev, 0) >= 0) {
25 + switch (speed) {
26 + case SPEED_1000:
27 + mcr |= PMCR_FORCE_EEE1G;
28 + break;
29 + case SPEED_100:
30 + mcr |= PMCR_FORCE_EEE100;
31 + break;
32 + }
33 + }
34 +
35 mt7530_set(priv, MT7530_PMCR_P(port), mcr);
36 }
37
38 @@ -2596,6 +2607,36 @@ mt753x_phy_write(struct dsa_switch *ds,
39 return priv->info->phy_write(ds, port, regnum, val);
40 }
41
42 +static int mt753x_get_mac_eee(struct dsa_switch *ds, int port,
43 + struct ethtool_eee *e)
44 +{
45 + struct mt7530_priv *priv = ds->priv;
46 + u32 eeecr = mt7530_read(priv, MT7530_PMEEECR_P(port));
47 +
48 + e->tx_lpi_enabled = !(eeecr & LPI_MODE_EN);
49 + e->tx_lpi_timer = GET_LPI_THRESH(eeecr);
50 +
51 + return 0;
52 +}
53 +
54 +static int mt753x_set_mac_eee(struct dsa_switch *ds, int port,
55 + struct ethtool_eee *e)
56 +{
57 + struct mt7530_priv *priv = ds->priv;
58 + u32 set, mask = LPI_THRESH_MASK | LPI_MODE_EN;
59 +
60 + if (e->tx_lpi_timer > 0xFFF)
61 + return -EINVAL;
62 +
63 + set = SET_LPI_THRESH(e->tx_lpi_timer);
64 + if (!e->tx_lpi_enabled)
65 + /* Force LPI Mode without a delay */
66 + set |= LPI_MODE_EN;
67 + mt7530_rmw(priv, MT7530_PMEEECR_P(port), mask, set);
68 +
69 + return 0;
70 +}
71 +
72 static const struct dsa_switch_ops mt7530_switch_ops = {
73 .get_tag_protocol = mtk_get_tag_protocol,
74 .setup = mt753x_setup,
75 @@ -2624,6 +2665,8 @@ static const struct dsa_switch_ops mt753
76 .phylink_mac_an_restart = mt753x_phylink_mac_an_restart,
77 .phylink_mac_link_down = mt753x_phylink_mac_link_down,
78 .phylink_mac_link_up = mt753x_phylink_mac_link_up,
79 + .get_mac_eee = mt753x_get_mac_eee,
80 + .set_mac_eee = mt753x_set_mac_eee,
81 };
82
83 static const struct mt753x_info mt753x_table[] = {
84 --- a/drivers/net/dsa/mt7530.h
85 +++ b/drivers/net/dsa/mt7530.h
86 @@ -240,6 +240,8 @@ enum mt7530_vlan_port_attr {
87 #define PMCR_RX_EN BIT(13)
88 #define PMCR_BACKOFF_EN BIT(9)
89 #define PMCR_BACKPR_EN BIT(8)
90 +#define PMCR_FORCE_EEE1G BIT(7)
91 +#define PMCR_FORCE_EEE100 BIT(6)
92 #define PMCR_TX_FC_EN BIT(5)
93 #define PMCR_RX_FC_EN BIT(4)
94 #define PMCR_FORCE_SPEED_1000 BIT(3)
95 @@ -264,7 +266,8 @@ enum mt7530_vlan_port_attr {
96 #define PMCR_LINK_SETTINGS_MASK (PMCR_TX_EN | PMCR_FORCE_SPEED_1000 | \
97 PMCR_RX_EN | PMCR_FORCE_SPEED_100 | \
98 PMCR_TX_FC_EN | PMCR_RX_FC_EN | \
99 - PMCR_FORCE_FDX | PMCR_FORCE_LNK)
100 + PMCR_FORCE_FDX | PMCR_FORCE_LNK | \
101 + PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100)
102 #define PMCR_CPU_PORT_SETTING(id) (PMCR_FORCE_MODE_ID((id)) | \
103 PMCR_IFG_XMIT(1) | PMCR_MAC_MODE | \
104 PMCR_BACKOFF_EN | PMCR_BACKPR_EN | \
105 @@ -273,6 +276,15 @@ enum mt7530_vlan_port_attr {
106 PMCR_FORCE_SPEED_1000 | \
107 PMCR_FORCE_FDX | PMCR_FORCE_LNK)
108
109 +#define MT7530_PMEEECR_P(x) (0x3004 + (x) * 0x100)
110 +#define WAKEUP_TIME_1000(x) (((x) & 0xFF) << 24)
111 +#define WAKEUP_TIME_100(x) (((x) & 0xFF) << 16)
112 +#define LPI_THRESH_MASK GENMASK(15, 4)
113 +#define LPI_THRESH_SHT 4
114 +#define SET_LPI_THRESH(x) (((x) << LPI_THRESH_SHT) & LPI_THRESH_MASK)
115 +#define GET_LPI_THRESH(x) (((x) & LPI_THRESH_MASK) >> LPI_THRESH_SHT)
116 +#define LPI_MODE_EN BIT(0)
117 +
118 #define MT7530_PMSR_P(x) (0x3008 + (x) * 0x100)
119 #define PMSR_EEE1G BIT(7)
120 #define PMSR_EEE100M BIT(6)