78444903a8c20b7f1d53ea65dac609c278221f31
[openwrt/staging/hauke.git] / target / linux / generic / backport-5.15 / 704-11-v5.19-net-mtk_eth_soc-correct-802.3z-duplex-setting.patch
1 From a459187390bb221827f9c07866c3a5ffbdf9622b Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Wed, 18 May 2022 15:54:52 +0100
4 Subject: [PATCH 05/12] net: mtk_eth_soc: correct 802.3z duplex setting
5
6 Phylink does not guarantee that state->duplex will be set correctly in
7 the mac_config() call, so it's a bug that the driver makes use of it.
8
9 Move the 802.3z PCS duplex configuration to mac_link_up().
10
11 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
12 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
13 ---
14 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 16 +++++++++++----
15 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 +
16 drivers/net/ethernet/mediatek/mtk_sgmii.c | 22 +++++++++++++++------
17 3 files changed, 29 insertions(+), 10 deletions(-)
18
19 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
21 @@ -533,8 +533,18 @@ static void mtk_mac_link_up(struct phyli
22 {
23 struct mtk_mac *mac = container_of(config, struct mtk_mac,
24 phylink_config);
25 - u32 mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
26 + u32 mcr;
27
28 + if (phy_interface_mode_is_8023z(interface)) {
29 + struct mtk_eth *eth = mac->hw;
30 +
31 + /* Decide how GMAC and SGMIISYS be mapped */
32 + int sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ?
33 + 0 : mac->id;
34 + mtk_sgmii_link_up(eth->sgmii, sid, speed, duplex);
35 + }
36 +
37 + mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
38 mcr &= ~(MAC_MCR_SPEED_100 | MAC_MCR_SPEED_1000 |
39 MAC_MCR_FORCE_DPX | MAC_MCR_FORCE_TX_FC |
40 MAC_MCR_FORCE_RX_FC);
41 @@ -3268,9 +3278,7 @@ static int mtk_add_mac(struct mtk_eth *e
42
43 mac->phylink_config.dev = &eth->netdev[id]->dev;
44 mac->phylink_config.type = PHYLINK_NETDEV;
45 - /* This driver makes use of state->speed/state->duplex in
46 - * mac_config
47 - */
48 + /* This driver makes use of state->speed in mac_config */
49 mac->phylink_config.legacy_pre_march2020 = true;
50 mac->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
51 MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD;
52 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
53 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
54 @@ -1104,6 +1104,7 @@ int mtk_sgmii_init(struct mtk_sgmii *ss,
55 int mtk_sgmii_setup_mode_an(struct mtk_sgmii *ss, int id);
56 int mtk_sgmii_setup_mode_force(struct mtk_sgmii *ss, int id,
57 const struct phylink_link_state *state);
58 +void mtk_sgmii_link_up(struct mtk_sgmii *ss, int id, int speed, int duplex);
59 void mtk_sgmii_restart_an(struct mtk_eth *eth, int mac_id);
60
61 int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
62 --- a/drivers/net/ethernet/mediatek/mtk_sgmii.c
63 +++ b/drivers/net/ethernet/mediatek/mtk_sgmii.c
64 @@ -83,14 +83,10 @@ int mtk_sgmii_setup_mode_force(struct mt
65 val &= ~SGMII_AN_ENABLE;
66 regmap_write(ss->regmap[id], SGMSYS_PCS_CONTROL_1, val);
67
68 - /* SGMII force mode setting */
69 + /* Set the speed etc but leave the duplex unchanged */
70 regmap_read(ss->regmap[id], SGMSYS_SGMII_MODE, &val);
71 - val &= ~SGMII_IF_MODE_MASK;
72 + val &= SGMII_DUPLEX_FULL | ~SGMII_IF_MODE_MASK;
73 val |= SGMII_SPEED_1000;
74 -
75 - if (state->duplex == DUPLEX_FULL)
76 - val |= SGMII_DUPLEX_FULL;
77 -
78 regmap_write(ss->regmap[id], SGMSYS_SGMII_MODE, val);
79
80 /* Release PHYA power down state */
81 @@ -101,6 +97,20 @@ int mtk_sgmii_setup_mode_force(struct mt
82 return 0;
83 }
84
85 +/* For 1000BASE-X and 2500BASE-X interface modes */
86 +void mtk_sgmii_link_up(struct mtk_sgmii *ss, int id, int speed, int duplex)
87 +{
88 + unsigned int val;
89 +
90 + /* SGMII force duplex setting */
91 + regmap_read(ss->regmap[id], SGMSYS_SGMII_MODE, &val);
92 + val &= ~SGMII_DUPLEX_FULL;
93 + if (duplex == DUPLEX_FULL)
94 + val |= SGMII_DUPLEX_FULL;
95 +
96 + regmap_write(ss->regmap[id], SGMSYS_SGMII_MODE, val);
97 +}
98 +
99 void mtk_sgmii_restart_an(struct mtk_eth *eth, int mac_id)
100 {
101 struct mtk_sgmii *ss = eth->sgmii;