kernel: backport generic phylink validate
[openwrt/staging/hauke.git] / target / linux / generic / backport-5.15 / 704-15-v5.19-net-mtk_eth_soc-move-MAC_MCR-setting-to-mac_finish.patch
1 From 0e37ad71b2ff772009595002da2860999e98e14e Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Wed, 18 May 2022 15:55:12 +0100
4 Subject: [PATCH 09/12] net: mtk_eth_soc: move MAC_MCR setting to mac_finish()
5
6 Move the setting of the MTK_MAC_MCR register from the end of mac_config
7 into the phylink mac_finish() method, to keep it as the very last write
8 that is done during configuration.
9
10 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
11 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
12 ---
13 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 33 ++++++++++++++-------
14 1 file changed, 22 insertions(+), 11 deletions(-)
15
16 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
17 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
18 @@ -316,8 +316,8 @@ static void mtk_mac_config(struct phylin
19 struct mtk_mac *mac = container_of(config, struct mtk_mac,
20 phylink_config);
21 struct mtk_eth *eth = mac->hw;
22 - u32 mcr_cur, mcr_new, sid, i;
23 int val, ge_mode, err = 0;
24 + u32 sid, i;
25
26 /* MT76x8 has no hardware settings between for the MAC */
27 if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628) &&
28 @@ -455,16 +455,6 @@ static void mtk_mac_config(struct phylin
29 return;
30 }
31
32 - /* Setup gmac */
33 - mcr_cur = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
34 - mcr_new = mcr_cur;
35 - mcr_new |= MAC_MCR_IPG_CFG | MAC_MCR_FORCE_MODE |
36 - MAC_MCR_BACKOFF_EN | MAC_MCR_BACKPR_EN | MAC_MCR_FORCE_LINK;
37 -
38 - /* Only update control register when needed! */
39 - if (mcr_new != mcr_cur)
40 - mtk_w32(mac->hw, mcr_new, MTK_MAC_MCR(mac->id));
41 -
42 return;
43
44 err_phy:
45 @@ -477,6 +467,26 @@ init_err:
46 mac->id, phy_modes(state->interface), err);
47 }
48
49 +static int mtk_mac_finish(struct phylink_config *config, unsigned int mode,
50 + phy_interface_t interface)
51 +{
52 + struct mtk_mac *mac = container_of(config, struct mtk_mac,
53 + phylink_config);
54 + u32 mcr_cur, mcr_new;
55 +
56 + /* Setup gmac */
57 + mcr_cur = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
58 + mcr_new = mcr_cur;
59 + mcr_new |= MAC_MCR_IPG_CFG | MAC_MCR_FORCE_MODE |
60 + MAC_MCR_BACKOFF_EN | MAC_MCR_BACKPR_EN | MAC_MCR_FORCE_LINK;
61 +
62 + /* Only update control register when needed! */
63 + if (mcr_new != mcr_cur)
64 + mtk_w32(mac->hw, mcr_new, MTK_MAC_MCR(mac->id));
65 +
66 + return 0;
67 +}
68 +
69 static void mtk_mac_pcs_get_state(struct phylink_config *config,
70 struct phylink_link_state *state)
71 {
72 @@ -581,6 +591,7 @@ static const struct phylink_mac_ops mtk_
73 .mac_pcs_get_state = mtk_mac_pcs_get_state,
74 .mac_an_restart = mtk_mac_an_restart,
75 .mac_config = mtk_mac_config,
76 + .mac_finish = mtk_mac_finish,
77 .mac_link_down = mtk_mac_link_down,
78 .mac_link_up = mtk_mac_link_up,
79 };