ath25: switch default kernel to 5.15
[openwrt/openwrt.git] / target / linux / lantiq / patches-5.10 / 0706-v5.18-net-lantiq-enable-jumbo-frames-on-GSWIP.patch
1 From c40bb4fedcd6b8b6a714da5dd466eb88ed2652d1 Mon Sep 17 00:00:00 2001
2 From: Aleksander Jan Bajkowski <olek2@wp.pl>
3 Date: Wed, 9 Mar 2022 00:04:57 +0100
4 Subject: net: dsa: lantiq_gswip: enable jumbo frames on GSWIP
5
6 This enables non-standard MTUs on a per-port basis, with the overall
7 frame size set based on the CPU port.
8
9 When the MTU is not changed, this should have no effect.
10
11 Long packets crash the switch with MTUs of greater than 2526, so the
12 maximum is limited for now. Medium packets are sometimes dropped (e.g.
13 TCP over 2477, UDP over 2516-2519, ICMP over 2526), Hence an MTU value
14 of 2400 seems safe.
15
16 Signed-off-by: Thomas Nixon <tom@tomn.co.uk>
17 Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
18 Link: https://lore.kernel.org/r/20220308230457.1599237-1-olek2@wp.pl
19 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
20 ---
21 drivers/net/dsa/lantiq_gswip.c | 53 ++++++++++++++++++++++++++++++++++++++----
22 1 file changed, 49 insertions(+), 4 deletions(-)
23
24 --- a/drivers/net/dsa/lantiq_gswip.c
25 +++ b/drivers/net/dsa/lantiq_gswip.c
26 @@ -213,6 +213,7 @@
27 #define GSWIP_MAC_CTRL_0_GMII_MII 0x0001
28 #define GSWIP_MAC_CTRL_0_GMII_RGMII 0x0002
29 #define GSWIP_MAC_CTRL_2p(p) (0x905 + ((p) * 0xC))
30 +#define GSWIP_MAC_CTRL_2_LCHKL BIT(2) /* Frame Length Check Long Enable */
31 #define GSWIP_MAC_CTRL_2_MLEN BIT(3) /* Maximum Untagged Frame Lnegth */
32
33 /* Ethernet Switch Fetch DMA Port Control Register */
34 @@ -239,6 +240,15 @@
35
36 #define XRX200_GPHY_FW_ALIGN (16 * 1024)
37
38 +/* Maximum packet size supported by the switch. In theory this should be 10240,
39 + * but long packets currently cause lock-ups with an MTU of over 2526. Medium
40 + * packets are sometimes dropped (e.g. TCP over 2477, UDP over 2516-2519, ICMP
41 + * over 2526), hence an MTU value of 2400 seems safe. This issue only affects
42 + * packet reception. This is probably caused by the PPA engine, which is on the
43 + * RX part of the device. Packet transmission works properly up to 10240.
44 + */
45 +#define GSWIP_MAX_PACKET_LENGTH 2400
46 +
47 struct gswip_hw_info {
48 int max_ports;
49 int cpu_port;
50 @@ -858,10 +868,6 @@ static int gswip_setup(struct dsa_switch
51 gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_INGRESS,
52 GSWIP_PCE_PCTRL_0p(cpu_port));
53
54 - gswip_switch_mask(priv, 0, GSWIP_MAC_CTRL_2_MLEN,
55 - GSWIP_MAC_CTRL_2p(cpu_port));
56 - gswip_switch_w(priv, VLAN_ETH_FRAME_LEN + 8 + ETH_FCS_LEN,
57 - GSWIP_MAC_FLEN);
58 gswip_switch_mask(priv, 0, GSWIP_BM_QUEUE_GCTRL_GL_MOD,
59 GSWIP_BM_QUEUE_GCTRL);
60
61 @@ -878,6 +884,8 @@ static int gswip_setup(struct dsa_switch
62 return err;
63 }
64
65 + ds->mtu_enforcement_ingress = true;
66 +
67 gswip_port_enable(ds, cpu_port, NULL);
68 return 0;
69 }
70 @@ -1472,6 +1480,39 @@ static void gswip_phylink_set_capab(unsi
71 __ETHTOOL_LINK_MODE_MASK_NBITS);
72 }
73
74 +static int gswip_port_max_mtu(struct dsa_switch *ds, int port)
75 +{
76 + /* Includes 8 bytes for special header. */
77 + return GSWIP_MAX_PACKET_LENGTH - VLAN_ETH_HLEN - ETH_FCS_LEN;
78 +}
79 +
80 +static int gswip_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
81 +{
82 + struct gswip_priv *priv = ds->priv;
83 + int cpu_port = priv->hw_info->cpu_port;
84 +
85 + /* CPU port always has maximum mtu of user ports, so use it to set
86 + * switch frame size, including 8 byte special header.
87 + */
88 + if (port == cpu_port) {
89 + new_mtu += 8;
90 + gswip_switch_w(priv, VLAN_ETH_HLEN + new_mtu + ETH_FCS_LEN,
91 + GSWIP_MAC_FLEN);
92 + }
93 +
94 + /* Enable MLEN for ports with non-standard MTUs, including the special
95 + * header on the CPU port added above.
96 + */
97 + if (new_mtu != ETH_DATA_LEN)
98 + gswip_switch_mask(priv, 0, GSWIP_MAC_CTRL_2_MLEN,
99 + GSWIP_MAC_CTRL_2p(port));
100 + else
101 + gswip_switch_mask(priv, GSWIP_MAC_CTRL_2_MLEN, 0,
102 + GSWIP_MAC_CTRL_2p(port));
103 +
104 + return 0;
105 +}
106 +
107 static void gswip_xrx200_phylink_validate(struct dsa_switch *ds, int port,
108 unsigned long *supported,
109 struct phylink_link_state *state)
110 @@ -1829,6 +1870,8 @@ static const struct dsa_switch_ops gswip
111 .port_fdb_add = gswip_port_fdb_add,
112 .port_fdb_del = gswip_port_fdb_del,
113 .port_fdb_dump = gswip_port_fdb_dump,
114 + .port_change_mtu = gswip_port_change_mtu,
115 + .port_max_mtu = gswip_port_max_mtu,
116 .phylink_validate = gswip_xrx200_phylink_validate,
117 .phylink_mac_config = gswip_phylink_mac_config,
118 .phylink_mac_link_down = gswip_phylink_mac_link_down,
119 @@ -1853,6 +1896,8 @@ static const struct dsa_switch_ops gswip
120 .port_fdb_add = gswip_port_fdb_add,
121 .port_fdb_del = gswip_port_fdb_del,
122 .port_fdb_dump = gswip_port_fdb_dump,
123 + .port_change_mtu = gswip_port_change_mtu,
124 + .port_max_mtu = gswip_port_max_mtu,
125 .phylink_validate = gswip_xrx300_phylink_validate,
126 .phylink_mac_config = gswip_phylink_mac_config,
127 .phylink_mac_link_down = gswip_phylink_mac_link_down,