lantiq: xrx200: enable use of baby jumbo frames
[openwrt/staging/dedeckeh.git] / target / linux / lantiq / patches-5.10 / 0703-net-lantiq-enable-jumbo-frames-on-GSWIP.patch
1 From 24a43ae2ac0ea06c474b1c80dc75651294d49321 Mon Sep 17 00:00:00 2001
2 From: Thomas Nixon <tom@tomn.co.uk>
3 Date: Sat, 2 Oct 2021 00:48:05 +0100
4 Subject: [PATCH 2/2] net: lantiq: 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.
13
14 Signed-off-by: Thomas Nixon <tom@tomn.co.uk>
15 ---
16 drivers/net/dsa/lantiq_gswip.c | 46 +++++++++++++++++++++++++++++++---
17 1 file changed, 42 insertions(+), 4 deletions(-)
18
19 --- a/drivers/net/dsa/lantiq_gswip.c
20 +++ b/drivers/net/dsa/lantiq_gswip.c
21 @@ -238,6 +238,11 @@
22
23 #define XRX200_GPHY_FW_ALIGN (16 * 1024)
24
25 +/* maximum packet size supported by the switch; in theory this should be 9600,
26 + * but long packets currently cause lock-ups with an MTU of over 2526
27 + */
28 +#define GSWIP_MAX_PACKET_LENGTH 2556
29 +
30 struct gswip_hw_info {
31 int max_ports;
32 int cpu_port;
33 @@ -851,10 +856,6 @@ static int gswip_setup(struct dsa_switch
34 gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_INGRESS,
35 GSWIP_PCE_PCTRL_0p(cpu_port));
36
37 - gswip_switch_mask(priv, 0, GSWIP_MAC_CTRL_2_MLEN,
38 - GSWIP_MAC_CTRL_2p(cpu_port));
39 - gswip_switch_w(priv, VLAN_ETH_FRAME_LEN + 8 + ETH_FCS_LEN,
40 - GSWIP_MAC_FLEN);
41 gswip_switch_mask(priv, 0, GSWIP_BM_QUEUE_GCTRL_GL_MOD,
42 GSWIP_BM_QUEUE_GCTRL);
43
44 @@ -871,6 +872,8 @@ static int gswip_setup(struct dsa_switch
45 return err;
46 }
47
48 + ds->mtu_enforcement_ingress = true;
49 +
50 gswip_port_enable(ds, cpu_port, NULL);
51 return 0;
52 }
53 @@ -1433,6 +1436,39 @@ static int gswip_port_fdb_dump(struct ds
54 return 0;
55 }
56
57 +static int gswip_port_max_mtu(struct dsa_switch *ds, int port)
58 +{
59 + /* includes 8 bytes for special header */
60 + return GSWIP_MAX_PACKET_LENGTH - VLAN_ETH_HLEN - ETH_FCS_LEN;
61 +}
62 +
63 +static int gswip_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
64 +{
65 + struct gswip_priv *priv = ds->priv;
66 + int cpu_port = priv->hw_info->cpu_port;
67 +
68 + /* cpu port always has maximum mtu of user ports, so use it to set
69 + * switch frame size, including 8 byte special header
70 + */
71 + if (port == cpu_port) {
72 + new_mtu += 8;
73 + gswip_switch_w(priv, VLAN_ETH_HLEN + new_mtu + ETH_FCS_LEN,
74 + GSWIP_MAC_FLEN);
75 + }
76 +
77 + /* enable MLEN for ports with non-standard MTUs, including the special
78 + * header on the CPU port added above
79 + */
80 + if (new_mtu != ETH_DATA_LEN)
81 + gswip_switch_mask(priv, 0, GSWIP_MAC_CTRL_2_MLEN,
82 + GSWIP_MAC_CTRL_2p(port));
83 + else
84 + gswip_switch_mask(priv, GSWIP_MAC_CTRL_2_MLEN, 0,
85 + GSWIP_MAC_CTRL_2p(port));
86 +
87 + return 0;
88 +}
89 +
90 static void gswip_phylink_validate(struct dsa_switch *ds, int port,
91 unsigned long *supported,
92 struct phylink_link_state *state)
93 @@ -1776,6 +1812,8 @@ static const struct dsa_switch_ops gswip
94 .port_fdb_add = gswip_port_fdb_add,
95 .port_fdb_del = gswip_port_fdb_del,
96 .port_fdb_dump = gswip_port_fdb_dump,
97 + .port_change_mtu = gswip_port_change_mtu,
98 + .port_max_mtu = gswip_port_max_mtu,
99 .phylink_validate = gswip_phylink_validate,
100 .phylink_mac_config = gswip_phylink_mac_config,
101 .phylink_mac_link_down = gswip_phylink_mac_link_down,