kernel: bump 5.4 to 5.4.124
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 752-v5.8-net-dsa-provide-an-option-for-drivers-to-always-rece.patch
1 From 54a0ed0df49609f4e3f098f8943e38e389dc2e15 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Tue, 12 May 2020 20:20:25 +0300
4 Subject: net: dsa: provide an option for drivers to always receive bridge
5 VLANs
6
7 DSA assumes that a bridge which has vlan filtering disabled is not
8 vlan aware, and ignores all vlan configuration. However, the kernel
9 software bridge code allows configuration in this state.
10
11 This causes the kernel's idea of the bridge vlan state and the
12 hardware state to disagree, so "bridge vlan show" indicates a correct
13 configuration but the hardware lacks all configuration. Even worse,
14 enabling vlan filtering on a DSA bridge immediately blocks all traffic
15 which, given the output of "bridge vlan show", is very confusing.
16
17 Provide an option that drivers can set to indicate they want to receive
18 vlan configuration even when vlan filtering is disabled. At the very
19 least, this is safe for Marvell DSA bridges, which do not look up
20 ingress traffic in the VTU if the port is in 8021Q disabled state. It is
21 also safe for the Ocelot switch family. Whether this change is suitable
22 for all DSA bridges is not known.
23
24 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
25 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
26 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
27 Signed-off-by: David S. Miller <davem@davemloft.net>
28 ---
29 include/net/dsa.h | 7 +++++++
30 net/dsa/dsa_priv.h | 1 +
31 net/dsa/port.c | 14 ++++++++++++++
32 net/dsa/slave.c | 8 ++++----
33 4 files changed, 26 insertions(+), 4 deletions(-)
34
35 --- a/include/net/dsa.h
36 +++ b/include/net/dsa.h
37 @@ -270,6 +270,13 @@ struct dsa_switch {
38 */
39 bool vlan_filtering_is_global;
40
41 + /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges
42 + * that have vlan_filtering=0. All drivers should ideally set this (and
43 + * then the option would get removed), but it is unknown whether this
44 + * would break things or not.
45 + */
46 + bool configure_vlan_while_not_filtering;
47 +
48 /* In case vlan_filtering_is_global is set, the VLAN awareness state
49 * should be retrieved from here and not from the per-port settings.
50 */
51 --- a/net/dsa/dsa_priv.h
52 +++ b/net/dsa/dsa_priv.h
53 @@ -139,6 +139,7 @@ int dsa_port_bridge_join(struct dsa_port
54 void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
55 int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
56 struct switchdev_trans *trans);
57 +bool dsa_port_skip_vlan_configuration(struct dsa_port *dp);
58 int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock,
59 struct switchdev_trans *trans);
60 int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
61 --- a/net/dsa/port.c
62 +++ b/net/dsa/port.c
63 @@ -238,6 +238,20 @@ int dsa_port_vlan_filtering(struct dsa_p
64 return 0;
65 }
66
67 +/* This enforces legacy behavior for switch drivers which assume they can't
68 + * receive VLAN configuration when enslaved to a bridge with vlan_filtering=0
69 + */
70 +bool dsa_port_skip_vlan_configuration(struct dsa_port *dp)
71 +{
72 + struct dsa_switch *ds = dp->ds;
73 +
74 + if (!dp->bridge_dev)
75 + return false;
76 +
77 + return (!ds->configure_vlan_while_not_filtering &&
78 + !br_vlan_enabled(dp->bridge_dev));
79 +}
80 +
81 int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock,
82 struct switchdev_trans *trans)
83 {
84 --- a/net/dsa/slave.c
85 +++ b/net/dsa/slave.c
86 @@ -319,7 +319,7 @@ static int dsa_slave_vlan_add(struct net
87 if (obj->orig_dev != dev)
88 return -EOPNOTSUPP;
89
90 - if (dp->bridge_dev && !br_vlan_enabled(dp->bridge_dev))
91 + if (dsa_port_skip_vlan_configuration(dp))
92 return 0;
93
94 vlan = *SWITCHDEV_OBJ_PORT_VLAN(obj);
95 @@ -386,7 +386,7 @@ static int dsa_slave_vlan_del(struct net
96 if (obj->orig_dev != dev)
97 return -EOPNOTSUPP;
98
99 - if (dp->bridge_dev && !br_vlan_enabled(dp->bridge_dev))
100 + if (dsa_port_skip_vlan_configuration(dp))
101 return 0;
102
103 /* Do not deprogram the CPU port as it may be shared with other user
104 @@ -1120,7 +1120,7 @@ static int dsa_slave_vlan_rx_add_vid(str
105 * need to emulate the switchdev prepare + commit phase.
106 */
107 if (dp->bridge_dev) {
108 - if (!br_vlan_enabled(dp->bridge_dev))
109 + if (dsa_port_skip_vlan_configuration(dp))
110 return 0;
111
112 /* br_vlan_get_info() returns -EINVAL or -ENOENT if the
113 @@ -1154,7 +1154,7 @@ static int dsa_slave_vlan_rx_kill_vid(st
114 * need to emulate the switchdev prepare + commit phase.
115 */
116 if (dp->bridge_dev) {
117 - if (!br_vlan_enabled(dp->bridge_dev))
118 + if (dsa_port_skip_vlan_configuration(dp))
119 return 0;
120
121 /* br_vlan_get_info() returns -EINVAL or -ENOENT if the