mvebu: backport mvneta and comphy from linux 5.x
[openwrt/staging/dedeckeh.git] / target / linux / mvebu / patches-4.19 / 531-net-mvneta-Add-support-for-2500Mbps-SGMII.patch
1 From da58a931f248f423f917c3a0b3c94303aa30a738 Mon Sep 17 00:00:00 2001
2 From: Maxime Chevallier <maxime.chevallier@bootlin.com>
3 Date: Tue, 25 Sep 2018 15:59:39 +0200
4 Subject: [PATCH] net: mvneta: Add support for 2500Mbps SGMII
5
6 The mvneta controller can handle speeds up to 2500Mbps on the SGMII
7 interface. This relies on serdes configuration, the lane must be
8 configured at 3.125Gbps and we can't use in-band autoneg at that speed.
9
10 The main issue when supporting that speed on this particular controller
11 is that the link partner can send ethernet frames with a shortened
12 preamble, which if not explicitly enabled in the controller will cause
13 unexpected behaviours.
14
15 This was tested on Armada 385, with the comphy configuration done in
16 bootloader.
17
18 Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
19 Signed-off-by: David S. Miller <davem@davemloft.net>
20 ---
21 drivers/net/ethernet/marvell/mvneta.c | 27 +++++++++++++++++++++++----
22 1 file changed, 23 insertions(+), 4 deletions(-)
23
24 --- a/drivers/net/ethernet/marvell/mvneta.c
25 +++ b/drivers/net/ethernet/marvell/mvneta.c
26 @@ -221,6 +221,8 @@
27 #define MVNETA_GMAC_AN_FLOW_CTRL_EN BIT(11)
28 #define MVNETA_GMAC_CONFIG_FULL_DUPLEX BIT(12)
29 #define MVNETA_GMAC_AN_DUPLEX_EN BIT(13)
30 +#define MVNETA_GMAC_CTRL_4 0x2c90
31 +#define MVNETA_GMAC4_SHORT_PREAMBLE_ENABLE BIT(1)
32 #define MVNETA_MIB_COUNTERS_BASE 0x3000
33 #define MVNETA_MIB_LATE_COLLISION 0x7c
34 #define MVNETA_DA_FILT_SPEC_MCAST 0x3400
35 @@ -3344,6 +3346,7 @@ static void mvneta_validate(struct net_d
36 if (state->interface != PHY_INTERFACE_MODE_NA &&
37 state->interface != PHY_INTERFACE_MODE_QSGMII &&
38 state->interface != PHY_INTERFACE_MODE_SGMII &&
39 + state->interface != PHY_INTERFACE_MODE_2500BASEX &&
40 !phy_interface_mode_is_8023z(state->interface) &&
41 !phy_interface_mode_is_rgmii(state->interface)) {
42 bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
43 @@ -3356,9 +3359,15 @@ static void mvneta_validate(struct net_d
44
45 /* Asymmetric pause is unsupported */
46 phylink_set(mask, Pause);
47 - /* Half-duplex at speeds higher than 100Mbit is unsupported */
48 - phylink_set(mask, 1000baseT_Full);
49 - phylink_set(mask, 1000baseX_Full);
50 +
51 + /* We cannot use 1Gbps when using the 2.5G interface. */
52 + if (state->interface == PHY_INTERFACE_MODE_2500BASEX) {
53 + phylink_set(mask, 2500baseT_Full);
54 + phylink_set(mask, 2500baseX_Full);
55 + } else {
56 + phylink_set(mask, 1000baseT_Full);
57 + phylink_set(mask, 1000baseX_Full);
58 + }
59
60 if (!phy_interface_mode_is_8023z(state->interface)) {
61 /* 10M and 100M are only supported in non-802.3z mode */
62 @@ -3419,12 +3428,14 @@ static void mvneta_mac_config(struct net
63 struct mvneta_port *pp = netdev_priv(ndev);
64 u32 new_ctrl0, gmac_ctrl0 = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
65 u32 new_ctrl2, gmac_ctrl2 = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
66 + u32 new_ctrl4, gmac_ctrl4 = mvreg_read(pp, MVNETA_GMAC_CTRL_4);
67 u32 new_clk, gmac_clk = mvreg_read(pp, MVNETA_GMAC_CLOCK_DIVIDER);
68 u32 new_an, gmac_an = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
69
70 new_ctrl0 = gmac_ctrl0 & ~MVNETA_GMAC0_PORT_1000BASE_X;
71 new_ctrl2 = gmac_ctrl2 & ~(MVNETA_GMAC2_INBAND_AN_ENABLE |
72 MVNETA_GMAC2_PORT_RESET);
73 + new_ctrl4 = gmac_ctrl4 & ~(MVNETA_GMAC4_SHORT_PREAMBLE_ENABLE);
74 new_clk = gmac_clk & ~MVNETA_GMAC_1MS_CLOCK_ENABLE;
75 new_an = gmac_an & ~(MVNETA_GMAC_INBAND_AN_ENABLE |
76 MVNETA_GMAC_INBAND_RESTART_AN |
77 @@ -3457,7 +3468,7 @@ static void mvneta_mac_config(struct net
78 if (state->duplex)
79 new_an |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
80
81 - if (state->speed == SPEED_1000)
82 + if (state->speed == SPEED_1000 || state->speed == SPEED_2500)
83 new_an |= MVNETA_GMAC_CONFIG_GMII_SPEED;
84 else if (state->speed == SPEED_100)
85 new_an |= MVNETA_GMAC_CONFIG_MII_SPEED;
86 @@ -3496,10 +3507,18 @@ static void mvneta_mac_config(struct net
87 MVNETA_GMAC_FORCE_LINK_DOWN);
88 }
89
90 + /* When at 2.5G, the link partner can send frames with shortened
91 + * preambles.
92 + */
93 + if (state->speed == SPEED_2500)
94 + new_ctrl4 |= MVNETA_GMAC4_SHORT_PREAMBLE_ENABLE;
95 +
96 if (new_ctrl0 != gmac_ctrl0)
97 mvreg_write(pp, MVNETA_GMAC_CTRL_0, new_ctrl0);
98 if (new_ctrl2 != gmac_ctrl2)
99 mvreg_write(pp, MVNETA_GMAC_CTRL_2, new_ctrl2);
100 + if (new_ctrl4 != gmac_ctrl4)
101 + mvreg_write(pp, MVNETA_GMAC_CTRL_4, new_ctrl4);
102 if (new_clk != gmac_clk)
103 mvreg_write(pp, MVNETA_GMAC_CLOCK_DIVIDER, new_clk);
104 if (new_an != gmac_an)