net: bridge: Multiple Spanning Trees
Subsystems (6)
v3 cover net: bridge: Multiple Spanning Trees
The bridge has had per-VLAN STP support for a while now, since:
https://lore.kernel.org/netdev/[email protected]/
The current implementation has some problems:
- The mapping from VLAN to STP state is fixed as 1:1, i.e. each VLAN is managed independently. This is awkward from an MSTP (802.1Q-2018, Clause 13.5) point of view, where the model is that multiple VLANs are grouped into MST instances.
Because of the way that the standard is written, presumably, this is also reflected in hardware implementations. It is not uncommon for a switch to support the full 4k range of VIDs, but that the pool of MST instances is much smaller. Some examples:
Marvell LinkStreet (mv88e6xxx): 4k VLANs, but only 64 MSTIs Marvell Prestera: 4k VLANs, but only 128 MSTIs Microchip SparX-5i: 4k VLANs, but only 128 MSTIs
- By default, the feature is enabled, and there is no way to disable it. This makes it hard to add offloading in a backwards compatible way, since any underlying switchdevs have no way to refuse the function if the hardware does not support it
- The port-global STP state has precedence over per-VLAN states. In MSTP, as far as I understand it, all VLANs will use the common spanning tree (CST) by default - through traffic engineering you can then optimize your network to group subsets of VLANs to use different trees (MSTI). To my understanding, the way this is typically managed in silicon is roughly:
Incoming packet:
.----.----.--------------.----.-------------
| DA | SA | 802.1Q VID=X | ET | Payload ...
'----'----'--------------'----'-------------
|
'->|\ .----------------------------.
| +--> | VID | Members | ... | MSTI |
PVID -->|/ |-----|---------|-----|------|
| 1 | 0001001 | ... | 0 |
| 2 | 0001010 | ... | 10 |
| 3 | 0001100 | ... | 10 |
'----------------------------'
|
.-----------------------------'
| .------------------------.
'->| MSTI | Fwding | Lrning |
|------|--------|--------|
| 0 | 111110 | 111110 |
| 10 | 110111 | 110111 |
'------------------------'What this is trying to show is that the STP state (whether MSTP is used, or ye olde STP) is always accessed via the VLAN table. If STP is running, all MSTI pointers in that table will reference the same index in the STP stable - if MSTP is running, some VLANs may point to other trees (like in this example).
The fact that in the Linux bridge, the global state (think: index 0 in most hardware implementations) is supposed to override the per-VLAN state, is very awkward to offload. In effect, this means that when the global state changes to blocking, drivers will have to iterate over all MSTIs in use, and alter them all to match. This also means that you have to cache whether the hardware state is currently tracking the global state or the per-VLAN state. In the first case, you also have to cache the per-VLAN state so that you can restore it if the global state transitions back to forwarding.
This series adds a new mst_enable bridge setting (as suggested by Nik) that can only be changed when no VLANs are configured on the bridge. Enabling this mode has the following effect:
- The port-global STP state is used to represent the CST (Common Spanning Tree) (1/14)
- Ingress STP filtering is deferred until the frame's VLAN has been resolved (1/14)
- The preexisting per-VLAN states can no longer be controlled directly (1/14). They are instead placed under the MST module's control, which is managed using a new netlink interface (described in 3/14)
- VLANs can br mapped to MSTIs in an arbitrary M:N fashion, using a new global VLAN option (2/14)
Switchdev notifications are added so that a driver can track:
- MST enabled state
- VID to MSTI mappings
- MST port states
An offloading implementation is this provided for mv88e6xxx.
A proposal for the corresponding iproute2 interface is available here:
https://github.com/wkz/iproute2/tree/mst
v2 -> v3:
Bridge:
- Use new boolopt API to enable/disable the MST mode (Nik)
- Mark br_mst_vlan_set_state as static (Vladimir)
- Avoid updates/notifications on repeated VLAN to MSTI mapping configurations (Vladimir)
- Configure MSTI states via the existing RTM_GET/SETLINK interface
(Roopa)
- Refactor switchdev replay logic (Vladimir)
- Send switchdev notifications when enabling/disabling MST (Vladimir)
DSA:
- Align VLAN MSTI callback with existing APIs (Vladimir)
- Only flush entries in the affected VLANs when changing an MST state (Vladimir)
- Refuse offloading, unless all required ops are implemented (Vladimir)
mv88e6xxx:
- Always keep the driver's MST state in sync with hardware (Vladimir)
- Fix SID leaks (Vladimir)
- Only flush entries in the affected VLANs when changing an MST state (Vladimir)
v1 (RFC) -> v2:
- Add a separate MST mode that is distinct from the exiting per-VLAN state functionality
- Control MSTI states explicitly, rather than via an associated VLAN
Tobias Waldekranz (14):
net: bridge: mst: Multiple Spanning Tree (MST) mode
net: bridge: mst: Allow changing a VLAN's MSTI
net: bridge: mst: Support setting and reporting MST port states
net: bridge: mst: Notify switchdev drivers of MST mode changes
net: bridge: mst: Notify switchdev drivers of VLAN MSTI migrations
net: bridge: mst: Notify switchdev drivers of MST state changes
net: bridge: mst: Add helper to map an MSTI to a VID set
net: bridge: mst: Add helper to check if MST is enabled
net: dsa: Validate hardware support for MST
net: dsa: Pass VLAN MSTI migration notifications to driver
net: dsa: Handle MST state changes
net: dsa: mv88e6xxx: Disentangle STU from VTU
net: dsa: mv88e6xxx: Export STU as devlink region
net: dsa: mv88e6xxx: MST Offloading
drivers/net/dsa/mv88e6xxx/chip.c | 305 ++++++++++++++++++++++- drivers/net/dsa/mv88e6xxx/chip.h | 38 +++ drivers/net/dsa/mv88e6xxx/devlink.c | 94 +++++++ drivers/net/dsa/mv88e6xxx/global1.h | 10 + drivers/net/dsa/mv88e6xxx/global1_vtu.c | 311 ++++++++++++++---------- include/linux/if_bridge.h | 11 + include/net/dsa.h | 6 + include/net/switchdev.h | 16 ++ include/uapi/linux/if_bridge.h | 19 ++ include/uapi/linux/rtnetlink.h | 1 + net/bridge/Makefile | 2 +- net/bridge/br.c | 5 + net/bridge/br_input.c | 17 +- net/bridge/br_mst.c | 310 +++++++++++++++++++++++ net/bridge/br_netlink.c | 32 ++- net/bridge/br_private.h | 43 ++++ net/bridge/br_stp.c | 3 + net/bridge/br_switchdev.c | 46 ++++ net/bridge/br_vlan.c | 20 +- net/bridge/br_vlan_options.c | 20 ++ net/dsa/dsa_priv.h | 6 + net/dsa/port.c | 99 +++++++- net/dsa/slave.c | 18 ++ 23 files changed, 1281 insertions(+), 151 deletions(-) create mode 100644 net/bridge/br_mst.c
Signature · 1 line
2.25.1
PATCH v3 1/14 net: bridge: mst: Multiple Spanning Tree (MST) mode
Allow the user to switch from the current per-VLAN STP mode to an MST mode.
Up to this point, per-VLAN STP states where always isolated from each other. This is in contrast to the MSTP standard (802.1Q-2018, Clause 13.5), where VLANs are grouped into MST instances (MSTIs), and the state is managed on a per-MSTI level, rather that at the per-VLAN level.
Perhaps due to the prevalence of the standard, many switching ASICs are built after the same model. Therefore, add a corresponding MST mode to the bridge, which we can later add offloading support for in a straight-forward way.
For now, all VLANs are fixed to MSTI 0, also called the Common Spanning Tree (CST). That is, all VLANs will follow the port-global state.
Upcoming changes will make this actually useful by allowing VLANs to be mapped to arbitrary MSTIs and allow individual MSTI states to be changed.
--- include/uapi/linux/if_bridge.h | 1 + net/bridge/Makefile | 2 +- net/bridge/br.c | 5 ++ net/bridge/br_input.c | 17 ++++++- net/bridge/br_mst.c | 84 ++++++++++++++++++++++++++++++++++ net/bridge/br_private.h | 27 +++++++++++ net/bridge/br_stp.c | 3 ++ net/bridge/br_vlan.c | 20 +++++++- net/bridge/br_vlan_options.c | 5 ++ 9 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 net/bridge/br_mst.c
include/uapi/linux/if_bridge.h +1 -0
@@ -759,6 +759,7 @@ struct br_mcast_stats {enum br_boolopt_id {BR_BOOLOPT_NO_LL_LEARN ,BR_BOOLOPT_MCAST_VLAN_SNOOPING , +BR_BOOLOPT_MST_ENABLE ,BR_BOOLOPT_MAX };
net/bridge/Makefile +1 -1
@@ -20,7 +20,7 @@ obj-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o br_multicast_eht.o -bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o br_vlan_tunnel.o br_vlan_options.o +bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o br_vlan_tunnel.o br_vlan_options.o br_mst.o bridge-$(CONFIG_NET_SWITCHDEV) += br_switchdev.o
net/bridge/br.c +5 -0
@@ -265,6 +265,9 @@ int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,case BR_BOOLOPT_MCAST_VLAN_SNOOPING : err =br_multicast_toggle_vlan_snooping (br, on, extack);break ; +case BR_BOOLOPT_MST_ENABLE : + err =br_mst_set_enabled (br, on, extack); +break ;default :/* shouldn't be called with unsupported options */ WARN_ON (1 );
@@ -281,6 +284,8 @@ int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt)return br_opt_get (br,BROPT_NO_LL_LEARN );case BR_BOOLOPT_MCAST_VLAN_SNOOPING :return br_opt_get (br,BROPT_MCAST_VLAN_SNOOPING_ENABLED ); +case BR_BOOLOPT_MST_ENABLE : +return br_opt_get (br,BROPT_MST_ENABLED );default :/* shouldn't be called with unsupported options */ WARN_ON (1 );
net/bridge/br_input.c +15 -2
@@ -78,13 +78,22 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skbu16 vid =0 ;u8 state; -if (!p || p->state ==BR_STATE_DISABLED ) +if (!p) goto drop; br = p->br; + +if (br_mst_is_enabled (br)) { + state =BR_STATE_FORWARDING ; + }else { +if (p->state ==BR_STATE_DISABLED ) + goto drop; + + state = p->state; + } + brmctx = &p->br->multicast_ctx; pmctx = &p->multicast_ctx; - state = p->state;if (!br_allowed_ingress (p->br,nbp_vlan_group_rcu (p), skb, &vid, &state, &vlan)) goto out;
@@ -370,9 +379,13 @@ static rx_handler_result_t br_handle_frame(struct sk_buff **pskb)return RX_HANDLER_PASS ; forward: +if (br_mst_is_enabled (p->br)) + goto defer_stp_filtering; +switch (p->state) {case BR_STATE_FORWARDING :case BR_STATE_LEARNING : +defer_stp_filtering:if (ether_addr_equal (p->br->dev->dev_addr, dest)) skb->pkt_type =PACKET_HOST ;
net/bridge/br_mst.c new file +84 -0
84 lines not on this page · raw message
net/bridge/br_private.h +27 -0
@@ -178,6 +178,7 @@ enum {* @br_mcast_ctx: if MASTER flag set, this is the global vlan multicast context * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast * context +* @msti: if MASTER flag set, this holds the VLANs MST instance * @vlist: sorted list of VLAN entries * @rcu: used for entry destruction *
@@ -210,6 +211,8 @@ struct net_bridge_vlan {struct net_bridge_mcast_port port_mcast_ctx; }; +u16 msti; +struct list_head vlist;struct rcu_head rcu;
@@ -445,6 +448,7 @@ enum net_bridge_opts {BROPT_NO_LL_LEARN ,BROPT_VLAN_BRIDGE_BINDING ,BROPT_MCAST_VLAN_SNOOPING_ENABLED , + BROPT_MST_ENABLED, }; struct net_bridge {
@@ -1765,6 +1769,29 @@ static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) }#endif +/* br_mst.c */ +#ifdef CONFIG_BRIDGE_VLAN_FILTERING +DECLARE_STATIC_KEY_FALSE (br_mst_used); +static inline bool br_mst_is_enabled (struct net_bridge *br) +{ +return static_branch_unlikely (&br_mst_used) && +br_opt_get (br,BROPT_MST_ENABLED ); +} + +void br_mst_set_state (struct net_bridge_port *p,u16 msti,u8 state); +void br_mst_vlan_init_state (struct net_bridge_vlan *v); +int br_mst_set_enabled (struct net_bridge *br,bool on, +struct netlink_ext_ack *extack); +#else +static inline bool br_mst_is_enabled (struct net_bridge *br) +{ +return false; +} + +static inline void br_mst_set_state (struct net_bridge_port *p, +u16 msti,u8 state) {} +#endif +struct nf_br_ops {int (*br_dev_xmit_hook)(struct sk_buff *skb); };
net/bridge/br_stp.c +3 -0
@@ -43,6 +43,9 @@ void br_set_state(struct net_bridge_port *p, unsigned int state)return ; p->state = state; +if (br_opt_get (p->br,BROPT_MST_ENABLED )) +br_mst_set_state (p,0 , state); + err =switchdev_port_attr_set (p->dev, &attr,NULL );if (err && err != -EOPNOTSUPP ) br_warn(p->br, "error setting offload STP state on port %u(%s)\n",
net/bridge/br_vlan.c +19 -1
@@ -226,6 +226,24 @@ static void nbp_vlan_rcu_free(struct rcu_head *rcu)kfree (v); } +static void br_vlan_init_state (struct net_bridge_vlan *v) +{ +struct net_bridge *br; + +if (br_vlan_is_master (v)) + br = v->br; +else + br = v->port->br; + +if (br_opt_get (br,BROPT_MST_ENABLED )) { +br_mst_vlan_init_state (v); +return ; + } + + v->state =BR_STATE_FORWARDING ; + v->msti =0 ; +} +/* This is the shared VLAN add function which works for both ports and bridge * devices. There are four possible calls to this function in terms of the * vlan entry type:
@@ -322,7 +340,7 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags, }/* set the state before publishing */ - v->state =BR_STATE_FORWARDING ; +br_vlan_init_state (v); err =rhashtable_lookup_insert_fast (&vg->vlan_hash, &v->vnode, br_vlan_rht_params);
net/bridge/br_vlan_options.c +5 -0
@@ -99,6 +99,11 @@ static int br_vlan_modify_state(struct net_bridge_vlan_group *vg,return -EBUSY ; } +if (br_opt_get (br,BROPT_MST_ENABLED )) { +NL_SET_ERR_MSG_MOD (extack,"Can't modify vlan state directly when MST is enabled" ); +return -EBUSY ; + } +if (v->state == state)return 0 ;
Signature · 1 line
2.25.1
Nikolay Aleksandrov
maintainerRe: [PATCH v3 net-next 01/14] net: bridge: mst: Multiple Spanning Tree (MST) mode
Quoted 24 lines · Tobias Waldekranz
Allow the user to switch from the current per-VLAN STP mode to an MST mode.
Up to this point, per-VLAN STP states where always isolated from each other. This is in contrast to the MSTP standard (802.1Q-2018, Clause 13.5), where VLANs are grouped into MST instances (MSTIs), and the state is managed on a per-MSTI level, rather that at the per-VLAN level.
Perhaps due to the prevalence of the standard, many switching ASICs are built after the same model. Therefore, add a corresponding MST mode to the bridge, which we can later add offloading support for in a straight-forward way.
For now, all VLANs are fixed to MSTI 0, also called the Common Spanning Tree (CST). That is, all VLANs will follow the port-global state.
Upcoming changes will make this actually useful by allowing VLANs to be mapped to arbitrary MSTIs and allow individual MSTI states to be changed.
Signed-off-by Tobias Waldekranz <[email protected]>---
[snip]
Quoted 30 lines
net/bridge/br_private.h +4
-0@@ -178,6 +178,7 @@ enum {* @br_mcast_ctx: if MASTER flag set, this is the global vlan multicast context * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast * context +* @msti: if MASTER flag set, this holds the VLANs MST instance * @vlist: sorted list of VLAN entries * @rcu: used for entry destruction * @@ -210,6 +211,8 @@ struct net_bridge_vlan {struct net_bridge_mcast_port port_mcast_ctx; }; +u16 msti; +struct list_head vlist;struct rcu_head rcu;@@ -445,6 +448,7 @@ enum net_bridge_opts {BROPT_NO_LL_LEARN ,BROPT_VLAN_BRIDGE_BINDING ,BROPT_MCAST_VLAN_SNOOPING_ENABLED , + BROPT_MST_ENABLED, }; struct net_bridge {
net/bridge/br_private.h static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) · line 1773
Quoted 5 lines
net/bridge/br_private.h +2
-0@@ -1765,6 +1769,29 @@ static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) }#endif +/* br_mst.c */ +#ifdef CONFIG_BRIDGE_VLAN_FILTERING
There is already such ifdef, you can embed all MST code inside it.
Quoted 92 lines
net/bridge/br_private.h +21
-0+DECLARE_STATIC_KEY_FALSE (br_mst_used); +static inline bool br_mst_is_enabled (struct net_bridge *br) +{ +return static_branch_unlikely (&br_mst_used) && +br_opt_get (br,BROPT_MST_ENABLED ); +} + +void br_mst_set_state (struct net_bridge_port *p,u16 msti,u8 state); +void br_mst_vlan_init_state (struct net_bridge_vlan *v); +int br_mst_set_enabled (struct net_bridge *br,bool on, +struct netlink_ext_ack *extack); +#else +static inline bool br_mst_is_enabled (struct net_bridge *br) +{ +return false; +} + +static inline void br_mst_set_state (struct net_bridge_port *p, +u16 msti,u8 state) {} +#endif +struct nf_br_ops {int (*br_dev_xmit_hook)(struct sk_buff *skb); };net/bridge/br_stp.c +3
-0@@ -43,6 +43,9 @@ void br_set_state(struct net_bridge_port *p, unsigned int state)return ; p->state = state; +if (br_opt_get (p->br,BROPT_MST_ENABLED )) +br_mst_set_state (p,0 , state); + err =switchdev_port_attr_set (p->dev, &attr,NULL );if (err && err != -EOPNOTSUPP ) br_warn(p->br, "error setting offload STP state on port %u(%s)\n",net/bridge/br_vlan.c +19
-1@@ -226,6 +226,24 @@ static void nbp_vlan_rcu_free(struct rcu_head *rcu)kfree (v); } +static void br_vlan_init_state (struct net_bridge_vlan *v) +{ +struct net_bridge *br; + +if (br_vlan_is_master (v)) + br = v->br; +else + br = v->port->br; + +if (br_opt_get (br,BROPT_MST_ENABLED )) { +br_mst_vlan_init_state (v); +return ; + } + + v->state =BR_STATE_FORWARDING ; + v->msti =0 ; +} +/* This is the shared VLAN add function which works for both ports and bridge * devices. There are four possible calls to this function in terms of the * vlan entry type: @@ -322,7 +340,7 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags, }/* set the state before publishing */ - v->state =BR_STATE_FORWARDING ; +br_vlan_init_state (v); err =rhashtable_lookup_insert_fast (&vg->vlan_hash, &v->vnode, br_vlan_rht_params);net/bridge/br_vlan_options.c +5
-0@@ -99,6 +99,11 @@ static int br_vlan_modify_state(struct net_bridge_vlan_group *vg,return -EBUSY ; } +if (br_opt_get (br,BROPT_MST_ENABLED )) { +NL_SET_ERR_MSG_MOD (extack,"Can't modify vlan state directly when MST is enabled" ); +return -EBUSY ; + } +if (v->state == state)return 0 ;
Re: [PATCH v3 net-next 01/14] net: bridge: mst: Multiple Spanning Tree (MST) mode
Quoted 59 lines · Nikolay Aleksandrov
Quoted 24 lines · Tobias Waldekranz
Allow the user to switch from the current per-VLAN STP mode to an MST mode.
Up to this point, per-VLAN STP states where always isolated from each other. This is in contrast to the MSTP standard (802.1Q-2018, Clause 13.5), where VLANs are grouped into MST instances (MSTIs), and the state is managed on a per-MSTI level, rather that at the per-VLAN level.
Perhaps due to the prevalence of the standard, many switching ASICs are built after the same model. Therefore, add a corresponding MST mode to the bridge, which we can later add offloading support for in a straight-forward way.
For now, all VLANs are fixed to MSTI 0, also called the Common Spanning Tree (CST). That is, all VLANs will follow the port-global state.
Upcoming changes will make this actually useful by allowing VLANs to be mapped to arbitrary MSTIs and allow individual MSTI states to be changed.
Signed-off-by Tobias Waldekranz <[email protected]>---
[snip]
Quoted 33 lines
net/bridge/br_private.h +4
-0@@ -178,6 +178,7 @@ enum {* @br_mcast_ctx: if MASTER flag set, this is the global vlan multicast context * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast * context +* @msti: if MASTER flag set, this holds the VLANs MST instance * @vlist: sorted list of VLAN entries * @rcu: used for entry destruction * @@ -210,6 +211,8 @@ struct net_bridge_vlan {struct net_bridge_mcast_port port_mcast_ctx; }; +u16 msti; +struct list_head vlist;struct rcu_head rcu;@@ -445,6 +448,7 @@ enum net_bridge_opts {BROPT_NO_LL_LEARN ,BROPT_VLAN_BRIDGE_BINDING ,BROPT_MCAST_VLAN_SNOOPING_ENABLED , + BROPT_MST_ENABLED, }; struct net_bridge {@@ -1765,6 +1769,29 @@ static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) }#endif
Quoted 5 lines
net/bridge/br_private.h static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) · line 1773
Quoted 2 lines
net/bridge/br_private.h +2
-0+/* br_mst.c */ +#ifdef CONFIG_BRIDGE_VLAN_FILTERING There is already such ifdef, you can embed all MST code inside it.
My bad, I somehow confused the function placement. This is good. :)
kernel test robot
build botRe: [PATCH v3 net-next 01/14] net: bridge: mst: Multiple Spanning Tree (MST) mode
In reply to Tobias WaldekranzI love your patch! Yet something to improve:
Hi Tobias,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Tobias-Waldekranz/net-bridge-Multiple-Spanning-Trees/20220314-175717 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git de29aff976d3216e7f3ab41fcd7af46fa8f7eab7 config: xtensa-randconfig-m031-20220313 (https://download.01.org/0day-ci/archive/20220314/[email protected]/config) compiler: xtensa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/702c502efb27c12860bc55fc8d9b1bfd99466623
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Tobias-Waldekranz/net-bridge-Multiple-Spanning-Trees/20220314-175717 git checkout 702c502efb27c12860bc55fc8d9b1bfd99466623
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=xtensa SHELL=/bin/bash net/bridge/
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
net/bridge/br.c: In function 'br_boolopt_toggle':
>> net/bridge/br.c:269:23: error: implicit declaration of function 'br_mst_set_enabled'; did you mean 'br_stp_set_enabled'? [-Werror=implicit-function-declaration]
269 | err = br_mst_set_enabled(br, on, extack);
| ^~~~~~~~~~~~~~~~~~
| br_stp_set_enabledcc1: some warnings being treated as errors
vim +269 net/bridge/br.c
245
246 /* br_boolopt_toggle - change user-controlled boolean option
247 *
248 * @br: bridge device
249 * @opt: id of the option to change
250 * @on: new option value
251 * @extack: extack for error messages
252 *
253 * Changes the value of the respective boolean option to @on taking care of
254 * any internal option value mapping and configuration.
255 */
256 int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
257 struct netlink_ext_ack *extack)
258 {
259 int err = 0;
260
261 switch (opt) {
262 case BR_BOOLOPT_NO_LL_LEARN:
263 br_opt_toggle(br, BROPT_NO_LL_LEARN, on);
264 break;
265 case BR_BOOLOPT_MCAST_VLAN_SNOOPING:
266 err = br_multicast_toggle_vlan_snooping(br, on, extack);
267 break;
268 case BR_BOOLOPT_MST_ENABLE:
> 269 err = br_mst_set_enabled(br, on, extack);
270 break;
271 default:
272 /* shouldn't be called with unsupported options */
273 WARN_ON(1);
274 break;
275 }
276
277 return err;
278 }
279
---
0-DAY CI Kernel Test Service
https://lists.01.org/hyperkitty/list/[email protected]
kernel test robot
build botRe: [PATCH v3 net-next 01/14] net: bridge: mst: Multiple Spanning Tree (MST) mode
In reply to Tobias WaldekranzI love your patch! Yet something to improve:
Hi Tobias,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Tobias-Waldekranz/net-bridge-Multiple-Spanning-Trees/20220314-175717 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git de29aff976d3216e7f3ab41fcd7af46fa8f7eab7 config: hexagon-randconfig-r041-20220314 (https://download.01.org/0day-ci/archive/20220315/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 3e4950d7fa78ac83f33bbf1658e2f49a73719236)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/702c502efb27c12860bc55fc8d9b1bfd99466623
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Tobias-Waldekranz/net-bridge-Multiple-Spanning-Trees/20220314-175717 git checkout 702c502efb27c12860bc55fc8d9b1bfd99466623
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash net/bridge/
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> net/bridge/br.c:269:9: error: implicit declaration of function 'br_mst_set_enabled' [-Werror,-Wimplicit-function-declaration]
err = br_mst_set_enabled(br, on, extack);
^
net/bridge/br.c:269:9: note: did you mean 'br_stp_set_enabled'?
net/bridge/br_private.h:1828:5: note: 'br_stp_set_enabled' declared here
int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
^1 error generated.
vim +/br_mst_set_enabled +269 net/bridge/br.c
245
246 /* br_boolopt_toggle - change user-controlled boolean option
247 *
248 * @br: bridge device
249 * @opt: id of the option to change
250 * @on: new option value
251 * @extack: extack for error messages
252 *
253 * Changes the value of the respective boolean option to @on taking care of
254 * any internal option value mapping and configuration.
255 */
256 int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
257 struct netlink_ext_ack *extack)
258 {
259 int err = 0;
260
261 switch (opt) {
262 case BR_BOOLOPT_NO_LL_LEARN:
263 br_opt_toggle(br, BROPT_NO_LL_LEARN, on);
264 break;
265 case BR_BOOLOPT_MCAST_VLAN_SNOOPING:
266 err = br_multicast_toggle_vlan_snooping(br, on, extack);
267 break;
268 case BR_BOOLOPT_MST_ENABLE:
> 269 err = br_mst_set_enabled(br, on, extack);
270 break;
271 default:
272 /* shouldn't be called with unsupported options */
273 WARN_ON(1);
274 break;
275 }
276
277 return err;
278 }
279
---
0-DAY CI Kernel Test Service
https://lists.01.org/hyperkitty/list/[email protected]
PATCH v3 2/14 net: bridge: mst: Allow changing a VLAN's MSTI
In reply to Tobias WaldekranzAllow a VLAN to move out of the CST (MSTI 0), to an independent tree.
The user manages the VID to MSTI mappings via a global VLAN setting. The proposed iproute2 interface would be:
bridge vlan global set dev br0 vid <VID> msti <MSTI>
Changing the state in non-zero MSTIs is still not supported, but will be addressed in upcoming changes.
--- include/uapi/linux/if_bridge.h | 1 + net/bridge/br_mst.c | 42 ++++++++++++++++++++++++++++++++++ net/bridge/br_private.h | 1 + net/bridge/br_vlan_options.c | 15 ++++++++++++ 4 files changed, 59 insertions(+)
include/uapi/linux/if_bridge.h +1 -0
@@ -564,6 +564,7 @@ enum {BRIDGE_VLANDB_GOPTS_MCAST_QUERIER ,BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS ,BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_STATE , +BRIDGE_VLANDB_GOPTS_MSTI , __BRIDGE_VLANDB_GOPTS_MAX };#define BRIDGE_VLANDB_GOPTS_MAX (__BRIDGE_VLANDB_GOPTS_MAX - 1)
net/bridge/br_mst.c +42 -0
48 lines not on this page · raw message
net/bridge/br_private.h +1 -0
@@ -1779,6 +1779,7 @@ static inline bool br_mst_is_enabled(struct net_bridge *br) }void br_mst_set_state (struct net_bridge_port *p,u16 msti,u8 state); +int br_mst_vlan_set_msti (struct net_bridge_vlan *v,u16 msti);void br_mst_vlan_init_state (struct net_bridge_vlan *v);int br_mst_set_enabled (struct net_bridge *br,bool on,struct netlink_ext_ack *extack);
net/bridge/br_vlan_options.c +15 -0
@@ -296,6 +296,7 @@ bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr, const struct net_bridge_vlan *r_end) {return v_curr->vid - r_end->vid ==1 && + v_curr->msti == r_end->msti && ((v_curr->priv_flags ^ r_end->priv_flags) &BR_VLFLAG_GLOBAL_MCAST_ENABLED ) ==0 && br_multicast_ctx_options_equal(&v_curr->br_mcast_ctx,
@@ -384,6 +385,9 @@ bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range,#endif #endif +if (nla_put_u16 (skb,BRIDGE_VLANDB_GOPTS_MSTI , v_opts->msti)) + goto out_err; +nla_nest_end (skb, nest);return true;
@@ -415,6 +419,7 @@ static size_t rtnl_vlan_global_opts_nlmsg_size(const struct net_bridge_vlan *v) +nla_total_size (0 )/* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */ + br_rports_size(&v->br_mcast_ctx) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */#endif + +nla_total_size (sizeof (u16))/* BRIDGE_VLANDB_GOPTS_MSTI */ +nla_total_size (sizeof (u16));/* BRIDGE_VLANDB_GOPTS_RANGE */ }
@@ -564,6 +569,15 @@ static int br_vlan_process_global_one_opts(const struct net_bridge *br, }#endif #endif +if (tb[BRIDGE_VLANDB_GOPTS_MSTI ]) { +u16 msti; + + msti =nla_get_u16 (tb[BRIDGE_VLANDB_GOPTS_MSTI ]); + err =br_mst_vlan_set_msti (v, msti); +if (err) +return err; + *changed = true; + }return 0 ; }
@@ -583,6 +597,7 @@ static const struct nla_policy br_vlan_db_gpol[BRIDGE_VLANDB_GOPTS_MAX + 1] = { [BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL] = { .type = NLA_U64 }, [BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL] = { .type = NLA_U64 }, [BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL] = { .type = NLA_U64 }, + [BRIDGE_VLANDB_GOPTS_MSTI] = NLA_POLICY_MAX(NLA_U16, VLAN_N_VID - 1), }; int br_vlan_rtm_process_global_options(struct net_device *dev,
Signature · 1 line
2.25.1
Re: [PATCH v3 net-next 02/14] net: bridge: mst: Allow changing a VLAN's MSTI
Quoted 10 lines · Tobias Waldekranz
Allow a VLAN to move out of the CST (MSTI 0), to an independent tree.
The user manages the VID to MSTI mappings via a global VLAN setting. The proposed iproute2 interface would be:
bridge vlan global set dev br0 vid <VID> msti <MSTI>
Changing the state in non-zero MSTIs is still not supported, but will be addressed in upcoming changes.
Quoted 8 lines
Signed-off-by Tobias Waldekranz <[email protected]>--- include/uapi/linux/if_bridge.h | 1 + net/bridge/br_mst.c | 42 ++++++++++++++++++++++++++++++++++ net/bridge/br_private.h | 1 + net/bridge/br_vlan_options.c | 15 ++++++++++++ 4 files changed, 59 insertions(+)
PATCH v3 3/14 net: bridge: mst: Support setting and reporting MST port states
In reply to Tobias WaldekranzMake it possible to change the port state in a given MSTI by extending the bridge port netlink interface (RTM_SETLINK on PF_BRIDGE).The proposed iproute2 interface would be:
bridge mst set dev <PORT> msti <MSTI> state <STATE>
Current states in all applicable MSTIs can also be dumped via a corresponding RTM_GETLINK. The proposed iproute interface looks like this:
$ bridge mst port msti vb1 0 state forwarding 100 state disabled vb2 0 state forwarding 100 state forwarding
The preexisting per-VLAN states are still valid in the MST mode (although they are read-only), and can be queried as usual if one is interested in knowing a particular VLAN's state without having to care about the VID to MSTI mapping (in this example VLAN 20 and 30 are bound to MSTI 100):
$ bridge -d vlan port vlan-id vb1 10 state forwarding mcast_router 1 20 state disabled mcast_router 1 30 state disabled mcast_router 1 40 state forwarding mcast_router 1 vb2 10 state forwarding mcast_router 1 20 state forwarding mcast_router 1 30 state forwarding mcast_router 1 40 state forwarding mcast_router 1
--- include/uapi/linux/if_bridge.h | 17 ++++++ include/uapi/linux/rtnetlink.h | 1 + net/bridge/br_mst.c | 105 +++++++++++++++++++++++++++++++++ net/bridge/br_netlink.c | 32 +++++++++- net/bridge/br_private.h | 15 +++++ 5 files changed, 169 insertions(+), 1 deletion(-)
include/uapi/linux/if_bridge.h +17 -0
@@ -122,6 +122,7 @@ enum {IFLA_BRIDGE_VLAN_TUNNEL_INFO ,IFLA_BRIDGE_MRP ,IFLA_BRIDGE_CFM , +IFLA_BRIDGE_MST , __IFLA_BRIDGE_MAX, };#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
@@ -453,6 +454,21 @@ enum {#define IFLA_BRIDGE_CFM_CC_PEER_STATUS_MAX (__IFLA_BRIDGE_CFM_CC_PEER_STATUS_MAX - 1) +enum { +IFLA_BRIDGE_MST_UNSPEC , +IFLA_BRIDGE_MST_ENTRY , + __IFLA_BRIDGE_MST_MAX, +}; +#define IFLA_BRIDGE_MST_MAX (__IFLA_BRIDGE_MST_MAX - 1) + +enum { +IFLA_BRIDGE_MST_ENTRY_UNSPEC , +IFLA_BRIDGE_MST_ENTRY_MSTI , +IFLA_BRIDGE_MST_ENTRY_STATE , + __IFLA_BRIDGE_MST_ENTRY_MAX, +}; +#define IFLA_BRIDGE_MST_ENTRY_MAX (__IFLA_BRIDGE_MST_ENTRY_MAX - 1) +struct bridge_stp_xstats {__u64 transition_blk;__u64 transition_fwd;
@@ -786,4 +802,5 @@ enum {__BRIDGE_QUERIER_MAX };#define BRIDGE_QUERIER_MAX (__BRIDGE_QUERIER_MAX - 1) +#endif /* _UAPI_LINUX_IF_BRIDGE_H */
include/uapi/linux/rtnetlink.h +1 -0
@@ -817,6 +817,7 @@ enum {#define RTEXT_FILTER_MRP (1 << 4)#define RTEXT_FILTER_CFM_CONFIG (1 << 5)#define RTEXT_FILTER_CFM_STATUS (1 << 6) +#define RTEXT_FILTER_MST (1 << 7)/* End of information exported to user level */
net/bridge/br_mst.c +105 -0
108 lines not on this page · raw message
net/bridge/br_netlink.c +31 -1
@@ -485,7 +485,8 @@ static int br_fill_ifinfo(struct sk_buff *skb, RTEXT_FILTER_BRVLAN_COMPRESSED | RTEXT_FILTER_MRP | RTEXT_FILTER_CFM_CONFIG | - RTEXT_FILTER_CFM_STATUS)) { + RTEXT_FILTER_CFM_STATUS | + RTEXT_FILTER_MST)) { af =nla_nest_start_noflag (skb,IFLA_AF_SPEC );if (!af) goto nla_put_failure;
@@ -564,7 +565,28 @@ static int br_fill_ifinfo(struct sk_buff *skb,nla_nest_end (skb, cfm_nest); } +if ((filter_mask &RTEXT_FILTER_MST ) && +br_opt_get (br,BROPT_MST_ENABLED ) && port) { +struct net_bridge_vlan_group *vg =nbp_vlan_group (port); +struct nlattr *mst_nest; +int err; + +if (!vg || !vg->num_vlans) + goto done; + + mst_nest =nla_nest_start (skb,IFLA_BRIDGE_MST ); +if (!mst_nest) + goto nla_put_failure; + + err =br_mst_fill_info (skb, vg); +if (err) + goto nla_put_failure; + +nla_nest_end (skb, mst_nest); + } + done: +if (af)nla_nest_end (skb, af);nlmsg_end (skb, nlh);
@@ -803,6 +825,14 @@ static int br_afspec(struct net_bridge *br,if (err)return err;break ; +case IFLA_BRIDGE_MST : +if (cmd !=RTM_SETLINK || !p) +return -EINVAL ; + + err =br_mst_parse (p, attr, extack); +if (err) +return err; +break ; } }
net/bridge/br_private.h +15 -0
@@ -1783,6 +1783,9 @@ int br_mst_vlan_set_msti(struct net_bridge_vlan *v, u16 msti);void br_mst_vlan_init_state (struct net_bridge_vlan *v);int br_mst_set_enabled (struct net_bridge *br,bool on,struct netlink_ext_ack *extack); +int br_mst_fill_info (struct sk_buff *skb,struct net_bridge_vlan_group *vg); +int br_mst_parse (struct net_bridge_port *p,struct nlattr *mst_attr, +struct netlink_ext_ack *extack);#else static inline bool br_mst_is_enabled (struct net_bridge *br) {
@@ -1791,6 +1794,18 @@ static inline bool br_mst_is_enabled(struct net_bridge *br)static inline void br_mst_set_state (struct net_bridge_port *p,u16 msti,u8 state) {} +static inline int br_mst_fill_info (struct sk_buff *skb, +struct net_bridge_vlan_group *vg) +{ +return -EOPNOTSUPP ; +} + +static inline int br_mst_parse (struct net_bridge_port *p, +struct nlattr *mst_attr, +struct netlink_ext_ack *extack) +{ +return -EOPNOTSUPP ; +}#endif struct nf_br_ops {
Signature · 1 line
2.25.1
Nikolay Aleksandrov
maintainerRe: [PATCH v3 net-next 03/14] net: bridge: mst: Support setting and reporting MST port states
Quoted 46 lines · Tobias Waldekranz
Make it possible to change the port state in a given MSTI by extending the bridge port netlink interface (
RTM_SETLINKon PF_BRIDGE).The proposed iproute2 interface would be:bridge mst set dev <PORT> msti <MSTI> state <STATE>
Current states in all applicable MSTIs can also be dumped via a corresponding
RTM_GETLINK. The proposed iproute interface looks like this:$ bridge mst port msti vb1 0 state forwarding 100 state disabled vb2 0 state forwarding 100 state forwardingThe preexisting per-VLAN states are still valid in the MST mode (although they are read-only), and can be queried as usual if one is interested in knowing a particular VLAN's state without having to care about the VID to MSTI mapping (in this example VLAN 20 and 30 are bound to MSTI 100):
$ bridge -d vlan port vlan-id vb1 10 state forwarding mcast_router 1 20 state disabled mcast_router 1 30 state disabled mcast_router 1 40 state forwarding mcast_router 1 vb2 10 state forwarding mcast_router 1 20 state forwarding mcast_router 1 30 state forwarding mcast_router 1 40 state forwarding mcast_router 1
Quoted 2 lines
Signed-off-by Tobias Waldekranz <[email protected]>---
Hi Tobias,
A few comments below..
Quoted 42 lines
include/uapi/linux/if_bridge.h | 17 ++++++ include/uapi/linux/rtnetlink.h | 1 + net/bridge/br_mst.c | 105 +++++++++++++++++++++++++++++++++ net/bridge/br_netlink.c | 32 +++++++++- net/bridge/br_private.h | 15 +++++ 5 files changed, 169 insertions(+), 1 deletion(-)include/uapi/linux/if_bridge.h +16
-0@@ -122,6 +122,7 @@ enum {IFLA_BRIDGE_VLAN_TUNNEL_INFO ,IFLA_BRIDGE_MRP ,IFLA_BRIDGE_CFM , +IFLA_BRIDGE_MST , __IFLA_BRIDGE_MAX, };#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)@@ -453,6 +454,21 @@ enum {#define IFLA_BRIDGE_CFM_CC_PEER_STATUS_MAX (__IFLA_BRIDGE_CFM_CC_PEER_STATUS_MAX - 1) +enum { +IFLA_BRIDGE_MST_UNSPEC , +IFLA_BRIDGE_MST_ENTRY , + __IFLA_BRIDGE_MST_MAX, +}; +#define IFLA_BRIDGE_MST_MAX (__IFLA_BRIDGE_MST_MAX - 1) + +enum { +IFLA_BRIDGE_MST_ENTRY_UNSPEC , +IFLA_BRIDGE_MST_ENTRY_MSTI , +IFLA_BRIDGE_MST_ENTRY_STATE , + __IFLA_BRIDGE_MST_ENTRY_MAX, +}; +#define IFLA_BRIDGE_MST_ENTRY_MAX (__IFLA_BRIDGE_MST_ENTRY_MAX - 1) +struct bridge_stp_xstats {__u64 transition_blk;__u64 transition_fwd;
include/uapi/linux/if_bridge.h enum { · line 805
Quoted 4 lines
include/uapi/linux/if_bridge.h +1
-0@@ -786,4 +802,5 @@ enum { __BRIDGE_QUERIER_MAX };#define BRIDGE_QUERIER_MAX (__BRIDGE_QUERIER_MAX - 1) +
stray new line
Quoted 18 lines
include/uapi/linux/if_bridge.h +0
-0#endif /* _UAPI_LINUX_IF_BRIDGE_H */ include/uapi/linux/rtnetlink.h +1
-0@@ -817,6 +817,7 @@ enum {#define RTEXT_FILTER_MRP (1 << 4)#define RTEXT_FILTER_CFM_CONFIG (1 << 5)#define RTEXT_FILTER_CFM_STATUS (1 << 6) +#define RTEXT_FILTER_MST (1 << 7)/* End of information exported to user level */ net/bridge/br_mst.c +0
-0
net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 128
Quoted 5 lines
net/bridge/br_mst.c +2
-0@@ -124,3 +124,108 @@ int br_mst_set_enabled(struct net_bridge *br, bool on,br_opt_toggle (br,BROPT_MST_ENABLED , on);return 0 ; } + +int br_mst_fill_info (struct sk_buff *skb,struct net_bridge_vlan_group *vg)
const vg
net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 130
Quoted 2 lines
net/bridge/br_mst.c +2
-0+{ +struct net_bridge_vlan *v;
const v
Quoted 12 lines
net/bridge/br_mst.c +12
-0+struct nlattr *nest; +unsigned long *seen; +int err =0 ; + + seen =bitmap_zalloc (VLAN_N_VID ,0 ); +if (!seen) +return -ENOMEM ; + +list_for_each_entry (v, &vg->vlan_list, vlist) { +if (test_bit (v->brvlan->msti, seen)) +continue ; +
net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 152
Quoted 10 lines
net/bridge/br_mst.c +10
-0+ nest =nla_nest_start_noflag (skb,IFLA_BRIDGE_MST_ENTRY ); +if (!nest || +nla_put_u16 (skb,IFLA_BRIDGE_MST_ENTRY_MSTI , v->brvlan->msti) || +nla_put_u8 (skb,IFLA_BRIDGE_MST_ENTRY_STATE , v->state)) { + err = -EMSGSIZE ; +break ; + } +nla_nest_end (skb, nest); + +set_bit (v->brvlan->msti, seen);
__set_bit()
Quoted 9 lines
net/bridge/br_mst.c +9
-0+ } + +kfree (seen); +return err; +} + +static const struct nla_policy br_mst_nl_policy[IFLA_BRIDGE_MST_ENTRY_MAX +1 ] = { + [IFLA_BRIDGE_MST_ENTRY_MSTI] = NLA_POLICY_RANGE(NLA_U16, + 1, /* 0 reserved for CST */
net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 171
Quoted 10 lines
net/bridge/br_mst.c +10
-0+ VLAN_N_VID - 1), + [IFLA_BRIDGE_MST_ENTRY_STATE ] =NLA_POLICY_RANGE (NLA_U8 , +BR_STATE_DISABLED , + BR_STATE_BLOCKING), +}; + +static int br_mst_parse_one (struct net_bridge_port *p, +const struct nlattr *attr, +struct netlink_ext_ack *extack) +{
I'd either set the state after parsing, so this function just does what it says (parse) or I'd rename it.
Quoted 19 lines
net/bridge/br_mst.c +19
-0+struct nlattr *tb[IFLA_BRIDGE_MST_ENTRY_MAX +1 ]; +u16 msti; +u8 state; +int err; + + err =nla_parse_nested (tb,IFLA_BRIDGE_MST_ENTRY_MAX , attr, + br_mst_nl_policy, extack); +if (err) +return err; + +if (!tb[IFLA_BRIDGE_MST_ENTRY_MSTI ]) { +NL_SET_ERR_MSG_MOD (extack,"MSTI not specified" ); +return -EINVAL ; + } + +if (!tb[IFLA_BRIDGE_MST_ENTRY_STATE ]) { +NL_SET_ERR_MSG_MOD (extack,"State not specified" ); +return -EINVAL ; + }
net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 200
Quoted 10 lines
net/bridge/br_mst.c +10
-0+ + msti =nla_get_u16 (tb[IFLA_BRIDGE_MST_ENTRY_MSTI ]); + state =nla_get_u8 (tb[IFLA_BRIDGE_MST_ENTRY_STATE ]); + +br_mst_set_state (p, msti, state); +return 0 ; +} + +int br_mst_parse (struct net_bridge_port *p,struct nlattr *mst_attr, +struct netlink_ext_ack *extack)
This doesn't just parse though, it also sets the state. Please rename it to something more appropriate.
const mst_attr
Quoted 46 lines
net/bridge/br_mst.c +31
-0+{ +struct nlattr *attr; +int err, msts =0 ; +int rem; + +if (!br_opt_get (p->br,BROPT_MST_ENABLED )) { +NL_SET_ERR_MSG_MOD (extack,"Can't modify MST state when MST is disabled" ); +return -EBUSY ; + } + +nla_for_each_nested (attr, mst_attr, rem) { +switch (nla_type (attr)) { +case IFLA_BRIDGE_MST_ENTRY : + err =br_mst_parse_one (p, attr, extack); +break ; +default : +continue ; + } + + msts++; +if (err) +break ; + } + +if (!msts) { +NL_SET_ERR_MSG_MOD (extack,"Found no MST entries to process" ); + err = -EINVAL ; + } + +return err; +}net/bridge/br_netlink.c +2
-1@@ -485,7 +485,8 @@ static int br_fill_ifinfo(struct sk_buff *skb, RTEXT_FILTER_BRVLAN_COMPRESSED | RTEXT_FILTER_MRP | RTEXT_FILTER_CFM_CONFIG | - RTEXT_FILTER_CFM_STATUS)) { + RTEXT_FILTER_CFM_STATUS | + RTEXT_FILTER_MST)) { af =nla_nest_start_noflag (skb,IFLA_AF_SPEC );if (!af) goto nla_put_failure;
net/bridge/br_netlink.c static int br_fill_ifinfo(struct sk_buff *skb, · line 570
Quoted 6 lines
net/bridge/br_netlink.c +3
-0@@ -564,7 +565,28 @@ static int br_fill_ifinfo(struct sk_buff *skb,nla_nest_end (skb, cfm_nest); } +if ((filter_mask &RTEXT_FILTER_MST ) && +br_opt_get (br,BROPT_MST_ENABLED ) && port) { +struct net_bridge_vlan_group *vg =nbp_vlan_group (port);
const vg
Quoted 7 lines
net/bridge/br_netlink.c +7
-0+struct nlattr *mst_nest; +int err; + +if (!vg || !vg->num_vlans) + goto done; + + mst_nest =nla_nest_start (skb,IFLA_BRIDGE_MST );
net/bridge/br_netlink.c static int br_fill_ifinfo(struct sk_buff *skb, · line 587
Quoted 10 lines
net/bridge/br_netlink.c +10
-0+if (!mst_nest) + goto nla_put_failure; + + err =br_mst_fill_info (skb, vg); +if (err) + goto nla_put_failure; + +nla_nest_end (skb, mst_nest); + } +
I think you should also update br_get_link_af_size_filtered() to account for the new dump attributes based on the filter. I'd adjust vinfo_sz based on the filter flag.
net/bridge/br_netlink.c static int br_afspec(struct net_bridge *br, · line 830
Quoted 12 lines
net/bridge/br_netlink.c +4
-0done: +if (af)nla_nest_end (skb, af);nlmsg_end (skb, nlh);@@ -803,6 +825,14 @@ static int br_afspec(struct net_bridge *br,if (err)return err;break ; +case IFLA_BRIDGE_MST : +if (cmd !=RTM_SETLINK || !p) +return -EINVAL ;
These are two different errors, please set extack appropriately for each error.
Quoted 41 lines
net/bridge/br_netlink.c +5
-0+ + err =br_mst_parse (p, attr, extack); +if (err) +return err; +break ; } }net/bridge/br_private.h +15
-0@@ -1783,6 +1783,9 @@ int br_mst_vlan_set_msti(struct net_bridge_vlan *v, u16 msti);void br_mst_vlan_init_state (struct net_bridge_vlan *v);int br_mst_set_enabled (struct net_bridge *br,bool on,struct netlink_ext_ack *extack); +int br_mst_fill_info (struct sk_buff *skb,struct net_bridge_vlan_group *vg); +int br_mst_parse (struct net_bridge_port *p,struct nlattr *mst_attr, +struct netlink_ext_ack *extack);#else static inline bool br_mst_is_enabled (struct net_bridge *br) {@@ -1791,6 +1794,18 @@ static inline bool br_mst_is_enabled(struct net_bridge *br)static inline void br_mst_set_state (struct net_bridge_port *p,u16 msti,u8 state) {} +static inline int br_mst_fill_info (struct sk_buff *skb, +struct net_bridge_vlan_group *vg) +{ +return -EOPNOTSUPP ; +} + +static inline int br_mst_parse (struct net_bridge_port *p, +struct nlattr *mst_attr, +struct netlink_ext_ack *extack) +{ +return -EOPNOTSUPP ; +}#endif struct nf_br_ops {
Re: [PATCH v3 net-next 03/14] net: bridge: mst: Support setting and reporting MST port states
Quoted 93 lines · Nikolay Aleksandrov
Quoted 46 lines · Tobias Waldekranz
Make it possible to change the port state in a given MSTI by extending the bridge port netlink interface (
RTM_SETLINKon PF_BRIDGE).The proposed iproute2 interface would be:bridge mst set dev <PORT> msti <MSTI> state <STATE>
Current states in all applicable MSTIs can also be dumped via a corresponding
RTM_GETLINK. The proposed iproute interface looks like this:$ bridge mst port msti vb1 0 state forwarding 100 state disabled vb2 0 state forwarding 100 state forwardingThe preexisting per-VLAN states are still valid in the MST mode (although they are read-only), and can be queried as usual if one is interested in knowing a particular VLAN's state without having to care about the VID to MSTI mapping (in this example VLAN 20 and 30 are bound to MSTI 100):
$ bridge -d vlan port vlan-id vb1 10 state forwarding mcast_router 1 20 state disabled mcast_router 1 30 state disabled mcast_router 1 40 state forwarding mcast_router 1 vb2 10 state forwarding mcast_router 1 20 state forwarding mcast_router 1 30 state forwarding mcast_router 1 40 state forwarding mcast_router 1Quoted 2 lines
Signed-off-by Tobias Waldekranz <[email protected]>---
Hi Tobias,
A few comments below..Quoted 40 lines
include/uapi/linux/if_bridge.h | 17 ++++++ include/uapi/linux/rtnetlink.h | 1 + net/bridge/br_mst.c | 105 +++++++++++++++++++++++++++++++++ net/bridge/br_netlink.c | 32 +++++++++- net/bridge/br_private.h | 15 +++++ 5 files changed, 169 insertions(+), 1 deletion(-)include/uapi/linux/if_bridge.h +16
-0@@ -122,6 +122,7 @@ enum {IFLA_BRIDGE_VLAN_TUNNEL_INFO ,IFLA_BRIDGE_MRP ,IFLA_BRIDGE_CFM , +IFLA_BRIDGE_MST , __IFLA_BRIDGE_MAX, };#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)@@ -453,6 +454,21 @@ enum {#define IFLA_BRIDGE_CFM_CC_PEER_STATUS_MAX (__IFLA_BRIDGE_CFM_CC_PEER_STATUS_MAX - 1) +enum { +IFLA_BRIDGE_MST_UNSPEC , +IFLA_BRIDGE_MST_ENTRY , + __IFLA_BRIDGE_MST_MAX, +}; +#define IFLA_BRIDGE_MST_MAX (__IFLA_BRIDGE_MST_MAX - 1) + +enum { +IFLA_BRIDGE_MST_ENTRY_UNSPEC , +IFLA_BRIDGE_MST_ENTRY_MSTI , +IFLA_BRIDGE_MST_ENTRY_STATE , + __IFLA_BRIDGE_MST_ENTRY_MAX, +}; +#define IFLA_BRIDGE_MST_ENTRY_MAX (__IFLA_BRIDGE_MST_ENTRY_MAX - 1) +struct bridge_stp_xstats {__u64 transition_blk;
Quoted 8 lines
include/uapi/linux/if_bridge.h enum { · line 805
Quoted 6 lines
include/uapi/linux/if_bridge.h +1
-0__u64 transition_fwd;@@ -786,4 +802,5 @@ enum { __BRIDGE_QUERIER_MAX };#define BRIDGE_QUERIER_MAX (__BRIDGE_QUERIER_MAX - 1) +stray new line
Well that's embarrassing :)
Quoted 191 lines
Quoted 18 lines
include/uapi/linux/if_bridge.h +0
-0#endif /* _UAPI_LINUX_IF_BRIDGE_H */ include/uapi/linux/rtnetlink.h +1
-0@@ -817,6 +817,7 @@ enum {#define RTEXT_FILTER_MRP (1 << 4)#define RTEXT_FILTER_CFM_CONFIG (1 << 5)#define RTEXT_FILTER_CFM_STATUS (1 << 6) +#define RTEXT_FILTER_MST (1 << 7)/* End of information exported to user level */ net/bridge/br_mst.c +0
-0net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 128
Quoted 5 lines
net/bridge/br_mst.c +2
-0@@ -124,3 +124,108 @@ int br_mst_set_enabled(struct net_bridge *br, bool on,br_opt_toggle (br,BROPT_MST_ENABLED , on);return 0 ; } + +int br_mst_fill_info (struct sk_buff *skb,struct net_bridge_vlan_group *vg)const vg
net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 130
Quoted 2 lines
net/bridge/br_mst.c +2
-0+{ +struct net_bridge_vlan *v;const v
Quoted 12 lines
net/bridge/br_mst.c +12
-0+struct nlattr *nest; +unsigned long *seen; +int err =0 ; + + seen =bitmap_zalloc (VLAN_N_VID ,0 ); +if (!seen) +return -ENOMEM ; + +list_for_each_entry (v, &vg->vlan_list, vlist) { +if (test_bit (v->brvlan->msti, seen)) +continue ; +net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 152
Quoted 10 lines
net/bridge/br_mst.c +10
-0+ nest =nla_nest_start_noflag (skb,IFLA_BRIDGE_MST_ENTRY ); +if (!nest || +nla_put_u16 (skb,IFLA_BRIDGE_MST_ENTRY_MSTI , v->brvlan->msti) || +nla_put_u8 (skb,IFLA_BRIDGE_MST_ENTRY_STATE , v->state)) { + err = -EMSGSIZE ; +break ; + } +nla_nest_end (skb, nest); + +set_bit (v->brvlan->msti, seen);
__set_bit()Quoted 9 lines
net/bridge/br_mst.c +9
-0+ } + +kfree (seen); +return err; +} + +static const struct nla_policy br_mst_nl_policy[IFLA_BRIDGE_MST_ENTRY_MAX +1 ] = { + [IFLA_BRIDGE_MST_ENTRY_MSTI] = NLA_POLICY_RANGE(NLA_U16, + 1, /* 0 reserved for CST */net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 171
Quoted 10 lines
net/bridge/br_mst.c +10
-0+ VLAN_N_VID - 1), + [IFLA_BRIDGE_MST_ENTRY_STATE ] =NLA_POLICY_RANGE (NLA_U8 , +BR_STATE_DISABLED , + BR_STATE_BLOCKING), +}; + +static int br_mst_parse_one (struct net_bridge_port *p, +const struct nlattr *attr, +struct netlink_ext_ack *extack) +{I'd either set the state after parsing, so this function just does what it says (parse) or I'd rename it.
Quoted 19 lines
net/bridge/br_mst.c +19
-0+struct nlattr *tb[IFLA_BRIDGE_MST_ENTRY_MAX +1 ]; +u16 msti; +u8 state; +int err; + + err =nla_parse_nested (tb,IFLA_BRIDGE_MST_ENTRY_MAX , attr, + br_mst_nl_policy, extack); +if (err) +return err; + +if (!tb[IFLA_BRIDGE_MST_ENTRY_MSTI ]) { +NL_SET_ERR_MSG_MOD (extack,"MSTI not specified" ); +return -EINVAL ; + } + +if (!tb[IFLA_BRIDGE_MST_ENTRY_STATE ]) { +NL_SET_ERR_MSG_MOD (extack,"State not specified" ); +return -EINVAL ; + }net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 200
Quoted 10 lines
net/bridge/br_mst.c +10
-0+ + msti =nla_get_u16 (tb[IFLA_BRIDGE_MST_ENTRY_MSTI ]); + state =nla_get_u8 (tb[IFLA_BRIDGE_MST_ENTRY_STATE ]); + +br_mst_set_state (p, msti, state); +return 0 ; +} + +int br_mst_parse (struct net_bridge_port *p,struct nlattr *mst_attr, +struct netlink_ext_ack *extack)This doesn't just parse though, it also sets the state. Please rename it to something more appropriate.
const
mst_attrQuoted 46 lines
net/bridge/br_mst.c +31
-0+{ +struct nlattr *attr; +int err, msts =0 ; +int rem; + +if (!br_opt_get (p->br,BROPT_MST_ENABLED )) { +NL_SET_ERR_MSG_MOD (extack,"Can't modify MST state when MST is disabled" ); +return -EBUSY ; + } + +nla_for_each_nested (attr, mst_attr, rem) { +switch (nla_type (attr)) { +case IFLA_BRIDGE_MST_ENTRY : + err =br_mst_parse_one (p, attr, extack); +break ; +default : +continue ; + } + + msts++; +if (err) +break ; + } + +if (!msts) { +NL_SET_ERR_MSG_MOD (extack,"Found no MST entries to process" ); + err = -EINVAL ; + } + +return err; +}net/bridge/br_netlink.c +2
-1@@ -485,7 +485,8 @@ static int br_fill_ifinfo(struct sk_buff *skb, RTEXT_FILTER_BRVLAN_COMPRESSED | RTEXT_FILTER_MRP | RTEXT_FILTER_CFM_CONFIG | - RTEXT_FILTER_CFM_STATUS)) { + RTEXT_FILTER_CFM_STATUS | + RTEXT_FILTER_MST)) { af =nla_nest_start_noflag (skb,IFLA_AF_SPEC );if (!af) goto nla_put_failure;net/bridge/br_netlink.c static int br_fill_ifinfo(struct sk_buff *skb, · line 570
Quoted 6 lines
net/bridge/br_netlink.c +3
-0@@ -564,7 +565,28 @@ static int br_fill_ifinfo(struct sk_buff *skb,nla_nest_end (skb, cfm_nest); } +if ((filter_mask &RTEXT_FILTER_MST ) && +br_opt_get (br,BROPT_MST_ENABLED ) && port) { +struct net_bridge_vlan_group *vg =nbp_vlan_group (port);const vg
Quoted 7 lines
net/bridge/br_netlink.c +7
-0+struct nlattr *mst_nest; +int err; + +if (!vg || !vg->num_vlans) + goto done; + + mst_nest =nla_nest_start (skb,IFLA_BRIDGE_MST );net/bridge/br_netlink.c static int br_fill_ifinfo(struct sk_buff *skb, · line 587
Quoted 10 lines
net/bridge/br_netlink.c +10
-0+if (!mst_nest) + goto nla_put_failure; + + err =br_mst_fill_info (skb, vg); +if (err) + goto nla_put_failure; + +nla_nest_end (skb, mst_nest); + } +I think you should also update
br_get_link_af_size_filtered()to account for the new dump attributes based on the filter. I'd adjustvinfo_szbased on the filter flag.
Quoted 15 lines
net/bridge/br_netlink.c static int br_afspec(struct net_bridge *br, · line 830
Quoted 12 lines
net/bridge/br_netlink.c +4
-0done: +if (af)nla_nest_end (skb, af);nlmsg_end (skb, nlh);@@ -803,6 +825,14 @@ static int br_afspec(struct net_bridge *br,if (err)return err;break ; +case IFLA_BRIDGE_MST : +if (cmd !=RTM_SETLINK || !p) +return -EINVAL ;These are two different errors, please set extack appropriately for each error.
Thanks for the review, all of the above will be fixed in v4.
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 03/14] net: bridge: mst: Support setting and reporting MST port states
In reply to Tobias Waldekranznet/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 135
Quoted 8 lines · Tobias Waldekranz
net/bridge/br_mst.c +8
-0+int br_mst_fill_info (struct sk_buff *skb,struct net_bridge_vlan_group *vg) +{ +struct net_bridge_vlan *v; +struct nlattr *nest; +unsigned long *seen; +int err =0 ; + + seen =bitmap_zalloc (VLAN_N_VID ,0 );
I see there is precedent in the bridge driver for using dynamic allocation as opposed to on-stack declaration using DECLARE_BITMAP(). I imagine this isn't just to be "heapsters", but why?
I don't have a very good sense of how much on-stack memory is too much (a lot probably depends on the expected depth of the call stack too, and here it doesn't appear to be too deep), but I see that mlxsw_sp_bridge_vxlan_vlan_is_valid() has a DECLARE_BITMAP(vlans, VLAN_N_VID) too.
The comment applies for callers of br_mst_get_info() too.
Quoted 22 lines
net/bridge/br_mst.c +22
-0+if (!seen) +return -ENOMEM ; + +list_for_each_entry (v, &vg->vlan_list, vlist) { +if (test_bit (v->brvlan->msti, seen)) +continue ; + + nest =nla_nest_start_noflag (skb,IFLA_BRIDGE_MST_ENTRY ); +if (!nest || +nla_put_u16 (skb,IFLA_BRIDGE_MST_ENTRY_MSTI , v->brvlan->msti) || +nla_put_u8 (skb,IFLA_BRIDGE_MST_ENTRY_STATE , v->state)) { + err = -EMSGSIZE ; +break ; + } +nla_nest_end (skb, nest); + +set_bit (v->brvlan->msti, seen); + } + +kfree (seen); +return err; +}
Re: [PATCH v3 net-next 03/14] net: bridge: mst: Support setting and reporting MST port states
Quoted 14 lines · Vladimir Oltean
net/bridge/br_mst.c int br_mst_set_enabled(struct net_bridge *br, bool on, · line 135
Quoted 8 lines · Tobias Waldekranz
net/bridge/br_mst.c +8
-0+int br_mst_fill_info (struct sk_buff *skb,struct net_bridge_vlan_group *vg) +{ +struct net_bridge_vlan *v; +struct nlattr *nest; +unsigned long *seen; +int err =0 ; + + seen =bitmap_zalloc (VLAN_N_VID ,0 );I see there is precedent in the bridge driver for using dynamic allocation as opposed to on-stack declaration using
DECLARE_BITMAP(). I imagine this isn't just to be "heapsters", but why?
Quoted 6 lines
I don't have a very good sense of how much on-stack memory is too much (a lot probably depends on the expected depth of the call stack too, and here it doesn't appear to be too deep), but I see that
mlxsw_sp_bridge_vxlan_vlan_is_valid()has aDECLARE_BITMAP(vlans, VLAN_N_VID)too.The comment applies for callers of
br_mst_get_info()too.
In v4, things become even worse, as I need to allocate the bitmap in a context where I can't return an error. So if it's ok to keep it on the stack, then that would be great.
Here's the code in question:
size_t br_mst_info_size(const struct net_bridge_vlan_group *vg)
{
const struct net_bridge_vlan *v;
unsigned long *seen;
size_t sz;
seen = bitmap_zalloc(VLAN_N_VID, 0);
if (WARN_ON(!seen))
return 0;
/* IFLA_BRIDGE_MST */
sz = nla_total_size(0);
list_for_each_entry(v, &vg->vlan_list, vlist) {
if (test_bit(v->brvlan->msti, seen))
continue;
/* IFLA_BRIDGE_MST_ENTRY */
sz += nla_total_size(0) +
/* IFLA_BRIDGE_MST_ENTRY_MSTI */
nla_total_size(sizeof(u16)) +
/* IFLA_BRIDGE_MST_ENTRY_STATE */
nla_total_size(sizeof(u8));
__set_bit(v->brvlan->msti, seen);
}
kfree(seen);
return sz;
}PATCH v3 4/14 net: bridge: mst: Notify switchdev drivers of MST mode changes
In reply to Tobias WaldekranzTrigger a switchdev event whenever the bridge's MST mode is enabled/disabled. This allows constituent ports to either perform any required hardware config, or refuse the change if it not supported.
--- include/net/switchdev.h | 2 ++ net/bridge/br_mst.c | 10 ++++++++++ 2 files changed, 12 insertions(+)
include/net/switchdev.h +2 -0
@@ -27,6 +27,7 @@ enum switchdev_attr_id {SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL ,SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED ,SWITCHDEV_ATTR_ID_BRIDGE_MROUTER , +SWITCHDEV_ATTR_ID_BRIDGE_MST , SWITCHDEV_ATTR_ID_MRP_PORT_ROLE, };
@@ -48,6 +49,7 @@ struct switchdev_attr {clock_t ageing_time;/* BRIDGE_AGEING_TIME */ bool vlan_filtering;/* BRIDGE_VLAN_FILTERING */ u16 vlan_protocol;/* BRIDGE_VLAN_PROTOCOL */ +bool mst;/* BRIDGE_MST */ bool mc_disabled;/* MC_DISABLED */ u8 mrp_port_role;/* MRP_PORT_ROLE */ } u;
net/bridge/br_mst.c +10 -0
@@ -99,8 +99,14 @@ void br_mst_vlan_init_state(struct net_bridge_vlan *v)int br_mst_set_enabled (struct net_bridge *br,bool on,struct netlink_ext_ack *extack) { +struct switchdev_attr attr = { + .id =SWITCHDEV_ATTR_ID_BRIDGE_MST , + .orig_dev = br->dev, + .u.mst = on, + };struct net_bridge_vlan_group *vg;struct net_bridge_port *p; +int err;list_for_each_entry (p, &br->port_list, list) { vg =nbp_vlan_group (p);
@@ -116,6 +122,10 @@ int br_mst_set_enabled(struct net_bridge *br, bool on,if (br_opt_get (br,BROPT_MST_ENABLED ) == on)return 0 ; + err =switchdev_port_attr_set (br->dev, &attr, extack); +if (err && err != -EOPNOTSUPP ) +return err; +if (on)static_branch_enable (&br_mst_used);else
Signature · 1 line
2.25.1
PATCH v3 5/14 net: bridge: mst: Notify switchdev drivers of VLAN MSTI migrations
In reply to Tobias WaldekranzWhenever a VLAN moves to a new MSTI, send a switchdev notification so that switchdevs can track a bridge's VID to MSTI mappings.
--- include/net/switchdev.h | 7 ++++++ net/bridge/br_mst.c | 14 ++++++++++++ net/bridge/br_switchdev.c | 46 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+)
include/net/switchdev.h +7 -0
@@ -29,6 +29,7 @@ enum switchdev_attr_id {SWITCHDEV_ATTR_ID_BRIDGE_MROUTER ,SWITCHDEV_ATTR_ID_BRIDGE_MST ,SWITCHDEV_ATTR_ID_MRP_PORT_ROLE , + SWITCHDEV_ATTR_ID_VLAN_MSTI, }; struct switchdev_brport_flags {
@@ -36,6 +37,11 @@ struct switchdev_brport_flags {unsigned long mask; }; +struct switchdev_vlan_msti { +u16 vid; +u16 msti; +}; +struct switchdev_attr {struct net_device *orig_dev;enum switchdev_attr_id id;
@@ -52,6 +58,7 @@ struct switchdev_attr {bool mst;/* BRIDGE_MST */ bool mc_disabled;/* MC_DISABLED */ u8 mrp_port_role;/* MRP_PORT_ROLE */ +struct switchdev_vlan_msti vlan_msti;/* VLAN_MSTI */ } u; };
net/bridge/br_mst.c +14 -0
@@ -7,6 +7,7 @@*/ #include <linux/kernel.h> +#include <net/switchdev.h> #include "br_private.h"
@@ -65,13 +66,26 @@ static void br_mst_vlan_sync_state(struct net_bridge_vlan *pv, u16 msti)int br_mst_vlan_set_msti (struct net_bridge_vlan *mv,u16 msti) { +struct switchdev_attr attr = { + .id =SWITCHDEV_ATTR_ID_VLAN_MSTI , + .orig_dev = mv->br->dev, + .u.vlan_msti = { + .vid = mv->vid, + .msti = msti, + }, + };struct net_bridge_vlan_group *vg;struct net_bridge_vlan *pv;struct net_bridge_port *p; +int err;if (mv->msti == msti)return 0 ; + err =switchdev_port_attr_set (mv->br->dev, &attr,NULL ); +if (err && err != -EOPNOTSUPP ) +return err; + mv->msti = msti;list_for_each_entry (p, &mv->br->port_list, list) {
net/bridge/br_switchdev.c +46 -0
58 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 6/14 net: bridge: mst: Notify switchdev drivers of MST state changes
In reply to Tobias WaldekranzGenerate a switchdev notification whenever an MST state changes. This notification is keyed by the VLANs MSTI rather than the VID, since multiple VLANs may share the same MST instance.
--- include/net/switchdev.h | 7 +++++++ net/bridge/br_mst.c | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+)
include/net/switchdev.h +7 -0
@@ -19,6 +19,7 @@enum switchdev_attr_id {SWITCHDEV_ATTR_ID_UNDEFINED ,SWITCHDEV_ATTR_ID_PORT_STP_STATE , +SWITCHDEV_ATTR_ID_PORT_MST_STATE ,SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS ,SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS ,SWITCHDEV_ATTR_ID_PORT_MROUTER ,
@@ -32,6 +33,11 @@ enum switchdev_attr_id { SWITCHDEV_ATTR_ID_VLAN_MSTI, }; +struct switchdev_mst_state { +u16 msti; +u8 state; +}; +struct switchdev_brport_flags {unsigned long val;unsigned long mask;
@@ -50,6 +56,7 @@ struct switchdev_attr {void (*complete)(struct net_device *dev,int err,void *priv);union {u8 stp_state;/* PORT_STP_STATE */ +struct switchdev_mst_state mst_state;/* PORT_MST_STATE */ struct switchdev_brport_flags brport_flags;/* PORT_BRIDGE_FLAGS */ bool mrouter;/* PORT_MROUTER */ clock_t ageing_time;/* BRIDGE_AGEING_TIME */
net/bridge/br_mst.c +20 -0
@@ -29,8 +29,17 @@ static void br_mst_vlan_set_state(struct net_bridge_port *p, struct net_bridge_vvoid br_mst_set_state (struct net_bridge_port *p,u16 msti,u8 state) { +struct switchdev_attr attr = { + .id =SWITCHDEV_ATTR_ID_PORT_MST_STATE , + .orig_dev = p->dev, + .u.mst_state = { + .msti = msti, + .state = state, + }, + };struct net_bridge_vlan_group *vg;struct net_bridge_vlan *v; +int err; vg =nbp_vlan_group (p);if (!vg)
@@ -42,6 +51,17 @@ void br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state)br_mst_vlan_set_state (p, v, state); } + +if (!msti) +/* MSTI 0 (CST) state changes are notified via the +* regular SWITCHDEV_ATTR_ID_PORT_STP_STATE. +*/ +return ; + + err =switchdev_port_attr_set (p->dev, &attr,NULL ); +if (err && err != -EOPNOTSUPP ) +br_warn (p->br,"unable to offload MST state on %s in MSTI %u" , +netdev_name (p->dev), msti); }static void br_mst_vlan_sync_state (struct net_bridge_vlan *pv,u16 msti)
Signature · 1 line
2.25.1
PATCH v3 7/14 net: bridge: mst: Add helper to map an MSTI to a VID set
In reply to Tobias Waldekranzbr_mst_get_info answers the question: "On this bridge, which VIDs are mapped to the given MSTI?"
This is useful in switchdev drivers, which might have to fan-out operations, relating to an MSTI, per VLAN.
An example: When a port's MST state changes from forwarding to blocking, a driver may choose to flush the dynamic FDB entries on that port to get faster reconvergence of the network, but this should only be done in the VLANs that are managed by the MSTI in question.
--- include/linux/if_bridge.h | 6 ++++++ net/bridge/br_mst.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
include/linux/if_bridge.h +6 -0
@@ -119,6 +119,7 @@ int br_vlan_get_info(const struct net_device *dev, u16 vid, struct bridge_vlan_info *p_vinfo);int br_vlan_get_info_rcu (const struct net_device *dev,u16 vid,struct bridge_vlan_info *p_vinfo); +int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids);#else static inline bool br_vlan_enabled (const struct net_device *dev) {
@@ -151,6 +152,11 @@ static inline int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid, {return -EINVAL ; } +static inline int br_mst_get_info (struct net_device *dev,u16 msti, +unsigned long *vids) +{ +return -EINVAL ; +}#endif #if IS_ENABLED (CONFIG_BRIDGE )
net/bridge/br_mst.c +26 -0
@@ -13,6 +13,32 @@DEFINE_STATIC_KEY_FALSE (br_mst_used); +int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids) +{ +struct net_bridge_vlan_group *vg; +struct net_bridge_vlan *v; +struct net_bridge *br; + +ASSERT_RTNL (); + +if (!netif_is_bridge_master (dev)) +return -EINVAL ; + + br =netdev_priv (dev); +if (!br_opt_get (br,BROPT_MST_ENABLED )) +return -EINVAL ; + + vg =br_vlan_group (br); + +list_for_each_entry (v, &vg->vlan_list, vlist) { +if (v->msti == msti) +set_bit (v->vid, vids); + } + +return 0 ; +} +EXPORT_SYMBOL (br_mst_get_info); +static void br_mst_vlan_set_state (struct net_bridge_port *p,struct net_bridge_vlan *v,u8 state) {
Signature · 1 line
2.25.1
Nikolay Aleksandrov
maintainerRe: [PATCH v3 net-next 07/14] net: bridge: mst: Add helper to map an MSTI to a VID set
Quoted 46 lines · Tobias Waldekranz
br_mst_get_infoanswers the question: "On this bridge, which VIDs are mapped to the given MSTI?"This is useful in switchdev drivers, which might have to fan-out operations, relating to an MSTI, per VLAN.
An example: When a port's MST state changes from forwarding to blocking, a driver may choose to flush the dynamic FDB entries on that port to get faster reconvergence of the network, but this should only be done in the VLANs that are managed by the MSTI in question.
Signed-off-by Tobias Waldekranz <[email protected]>--- include/linux/if_bridge.h | 6 ++++++ net/bridge/br_mst.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)include/linux/if_bridge.h +6
-0@@ -119,6 +119,7 @@ int br_vlan_get_info(const struct net_device *dev, u16 vid, struct bridge_vlan_info *p_vinfo);int br_vlan_get_info_rcu (const struct net_device *dev,u16 vid,struct bridge_vlan_info *p_vinfo); +int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids);#else static inline bool br_vlan_enabled (const struct net_device *dev) {@@ -151,6 +152,11 @@ static inline int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid, {return -EINVAL ; } +static inline int br_mst_get_info (struct net_device *dev,u16 msti, +unsigned long *vids) +{ +return -EINVAL ; +}#endif #if IS_ENABLED (CONFIG_BRIDGE )net/bridge/br_mst.c +0
-0
net/bridge/br_mst.c line 20
Quoted 8 lines
net/bridge/br_mst.c +5
-0@@ -13,6 +13,32 @@DEFINE_STATIC_KEY_FALSE (br_mst_used); +int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids) +{ +struct net_bridge_vlan_group *vg; +struct net_bridge_vlan *v; +struct net_bridge *br;
const dev, vg, v, br
Quoted 5 lines
net/bridge/br_mst.c +5
-0+ +ASSERT_RTNL (); + +if (!netif_is_bridge_master (dev)) +return -EINVAL ;
net/bridge/br_mst.c line 35
Quoted 10 lines
net/bridge/br_mst.c +10
-0+ + br =netdev_priv (dev); +if (!br_opt_get (br,BROPT_MST_ENABLED )) +return -EINVAL ; + + vg =br_vlan_group (br); + +list_for_each_entry (v, &vg->vlan_list, vlist) { +if (v->msti == msti) +set_bit (v->vid, vids);
__set_bit()
net/bridge/br_mst.c line 40
Quoted 5 lines
net/bridge/br_mst.c +5
-0+ } + +return 0 ; +} +EXPORT_SYMBOL (br_mst_get_info);
EXPORT_SYMBOL_GPL
Quoted 4 lines
net/bridge/br_mst.c +1
-0+static void br_mst_vlan_set_state (struct net_bridge_port *p,struct net_bridge_vlan *v,u8 state) {
PATCH v3 8/14 net: bridge: mst: Add helper to check if MST is enabled
In reply to Tobias WaldekranzThis is useful for switchdev drivers that might want to refuse to join a bridge where MST is enabled, if the hardware can't support it.
--- include/linux/if_bridge.h | 5 +++++ net/bridge/br_mst.c | 9 +++++++++ 2 files changed, 14 insertions(+)
include/linux/if_bridge.h +5 -0
@@ -119,6 +119,7 @@ int br_vlan_get_info(const struct net_device *dev, u16 vid, struct bridge_vlan_info *p_vinfo);int br_vlan_get_info_rcu (const struct net_device *dev,u16 vid,struct bridge_vlan_info *p_vinfo); +bool br_mst_enabled (struct net_device *dev);int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids);#else static inline bool br_vlan_enabled (const struct net_device *dev)
@@ -152,6 +153,10 @@ static inline int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid, {return -EINVAL ; } +static inline bool br_mst_enabled (struct net_device *dev) +{ +return false; +}static inline int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids) {
net/bridge/br_mst.c +9 -0
@@ -13,6 +13,15 @@DEFINE_STATIC_KEY_FALSE (br_mst_used); +bool br_mst_enabled (struct net_device *dev) +{ +if (!netif_is_bridge_master (dev)) +return false; + +return br_opt_get (netdev_priv (dev),BROPT_MST_ENABLED ); +} +EXPORT_SYMBOL (br_mst_enabled); +int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids) {struct net_bridge_vlan_group *vg;
Signature · 1 line
2.25.1
Nikolay Aleksandrov
maintainerRe: [PATCH v3 net-next 08/14] net: bridge: mst: Add helper to check if MST is enabled
Quoted 37 lines · Tobias Waldekranz
This is useful for switchdev drivers that might want to refuse to join a bridge where MST is enabled, if the hardware can't support it.
Signed-off-by Tobias Waldekranz <[email protected]>--- include/linux/if_bridge.h | 5 +++++ net/bridge/br_mst.c | 9 +++++++++ 2 files changed, 14 insertions(+)include/linux/if_bridge.h +5
-0@@ -119,6 +119,7 @@ int br_vlan_get_info(const struct net_device *dev, u16 vid, struct bridge_vlan_info *p_vinfo);int br_vlan_get_info_rcu (const struct net_device *dev,u16 vid,struct bridge_vlan_info *p_vinfo); +bool br_mst_enabled (struct net_device *dev);int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids);#else static inline bool br_vlan_enabled (const struct net_device *dev)@@ -152,6 +153,10 @@ static inline int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid, {return -EINVAL ; } +static inline bool br_mst_enabled (struct net_device *dev) +{ +return false; +}static inline int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids) {net/bridge/br_mst.c +0
-0
net/bridge/br_mst.c line 16
Quoted 4 lines
net/bridge/br_mst.c +1
-0@@ -13,6 +13,15 @@DEFINE_STATIC_KEY_FALSE (br_mst_used); +bool br_mst_enabled (struct net_device *dev)
const dev
net/bridge/br_mst.c line 23
Quoted 7 lines
net/bridge/br_mst.c +7
-0+{ +if (!netif_is_bridge_master (dev)) +return false; + +return br_opt_get (netdev_priv (dev),BROPT_MST_ENABLED ); +} +EXPORT_SYMBOL (br_mst_enabled);
EXPORT_SYMBOL_GPL
Quoted 4 lines
net/bridge/br_mst.c +1
-0+int br_mst_get_info (struct net_device *dev,u16 msti,unsigned long *vids) {struct net_bridge_vlan_group *vg;
PATCH v3 9/14 net: dsa: Validate hardware support for MST
In reply to Tobias WaldekranzWhen joining a bridge where MST is enabled, we validate that the proper offloading support is in place, otherwise we fallback to software bridging.
When then mode is changed on a bridge in which we are members, we refuse the change if offloading is not supported.
At the moment we only check for configurable learning, but this will be further restricted as we support more MST related switchdev events.
--- net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 20 ++++++++++++++++++++ net/dsa/slave.c | 6 ++++++ 3 files changed, 28 insertions(+)
net/dsa/dsa_priv.h +2 -0
@@ -234,6 +234,8 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, struct netlink_ext_ack *extack);bool dsa_port_skip_vlan_configuration (struct dsa_port *dp);int dsa_port_ageing_time (struct dsa_port *dp,clock_t ageing_clock); +int dsa_port_mst_enable (struct dsa_port *dp,bool on, +struct netlink_ext_ack *extack);int dsa_port_mtu_change (struct dsa_port *dp,int new_mtu,bool targeted_match); int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
net/dsa/port.c +20 -0
@@ -240,6 +240,10 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,if (err && err != -EOPNOTSUPP )return err; + err =dsa_port_mst_enable (dp,br_mst_enabled (br), extack); +if (err && err != -EOPNOTSUPP ) +return err; +return 0 ; }
@@ -735,6 +739,22 @@ int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock)return 0 ; } +int dsa_port_mst_enable (struct dsa_port *dp,bool on, +struct netlink_ext_ack *extack) +{ +struct dsa_switch *ds = dp->ds; + +if (!on) +return 0 ; + +if (!dsa_port_can_configure_learning (dp)) { +NL_SET_ERR_MSG_MOD (extack,"Hardware does not support MST" ); +return -EINVAL ; + } + +return 0 ; +} +int dsa_port_pre_bridge_flags (const struct dsa_port *dp,struct switchdev_brport_flags flags,struct netlink_ext_ack *extack)
net/dsa/slave.c +6 -0
@@ -463,6 +463,12 @@ static int dsa_slave_port_attr_set(struct net_device *dev, const void *ctx, ret =dsa_port_ageing_time (dp, attr->u.ageing_time);break ; +case SWITCHDEV_ATTR_ID_BRIDGE_MST : +if (!dsa_port_offloads_bridge_dev (dp, attr->orig_dev)) +return -EOPNOTSUPP ; + + ret =dsa_port_mst_enable (dp, attr->u.mst, extack); +break ;case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS :if (!dsa_port_offloads_bridge_port (dp, attr->orig_dev))return -EOPNOTSUPP ;
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 09/14] net: dsa: Validate hardware support for MST
Quoted 35 lines · Tobias Waldekranz
When joining a bridge where MST is enabled, we validate that the proper offloading support is in place, otherwise we fallback to software bridging.
When then mode is changed on a bridge in which we are members, we refuse the change if offloading is not supported.
At the moment we only check for configurable learning, but this will be further restricted as we support more MST related switchdev events.
Signed-off-by Tobias Waldekranz <[email protected]>--- net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 20 ++++++++++++++++++++ net/dsa/slave.c | 6 ++++++ 3 files changed, 28 insertions(+)net/dsa/dsa_priv.h +2
-0@@ -234,6 +234,8 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, struct netlink_ext_ack *extack);bool dsa_port_skip_vlan_configuration (struct dsa_port *dp);int dsa_port_ageing_time (struct dsa_port *dp,clock_t ageing_clock); +int dsa_port_mst_enable (struct dsa_port *dp,bool on, +struct netlink_ext_ack *extack);int dsa_port_mtu_change (struct dsa_port *dp,int new_mtu,bool targeted_match); int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,net/dsa/port.c +0
-0
net/dsa/port.c static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp, · line 245
Quoted 6 lines
net/dsa/port.c +3
-0@@ -240,6 +240,10 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,if (err && err != -EOPNOTSUPP )return err; + err =dsa_port_mst_enable (dp,br_mst_enabled (br), extack); +if (err && err != -EOPNOTSUPP ) +return err;
Sadly this will break down because we don't have unwinding on error in place (sorry). We'd end up with an unoffloaded bridge port with partially synced bridge port attributes. Could you please add a patch previous to this one that handles this, and unoffloads those on error?
Quoted 47 lines
net/dsa/port.c +17
-0+return 0 ; }@@ -735,6 +739,22 @@ int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock)return 0 ; } +int dsa_port_mst_enable (struct dsa_port *dp,bool on, +struct netlink_ext_ack *extack) +{ +struct dsa_switch *ds = dp->ds; + +if (!on) +return 0 ; + +if (!dsa_port_can_configure_learning (dp)) { +NL_SET_ERR_MSG_MOD (extack,"Hardware does not support MST" ); +return -EINVAL ; + } + +return 0 ; +} +int dsa_port_pre_bridge_flags (const struct dsa_port *dp,struct switchdev_brport_flags flags,struct netlink_ext_ack *extack)net/dsa/slave.c +6
-0@@ -463,6 +463,12 @@ static int dsa_slave_port_attr_set(struct net_device *dev, const void *ctx, ret =dsa_port_ageing_time (dp, attr->u.ageing_time);break ; +case SWITCHDEV_ATTR_ID_BRIDGE_MST : +if (!dsa_port_offloads_bridge_dev (dp, attr->orig_dev)) +return -EOPNOTSUPP ; + + ret =dsa_port_mst_enable (dp, attr->u.mst, extack); +break ;case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS :if (!dsa_port_offloads_bridge_port (dp, attr->orig_dev))return -EOPNOTSUPP ;Signature · 1 line
2.25.1
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 09/14] net: dsa: Validate hardware support for MST
Quoted 8 lines · Vladimir Oltean
Quoted 8 lines
net/dsa/port.c +0
-0@@ -240,6 +240,10 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,if (err && err != -EOPNOTSUPP )return err;
Quoted 8 lines
net/dsa/port.c static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp, · line 245
Quoted 3 lines
net/dsa/port.c +3
-0+ err =dsa_port_mst_enable (dp,br_mst_enabled (br), extack); +if (err && err != -EOPNOTSUPP ) +return err;Sadly this will break down because we don't have unwinding on error in place (sorry). We'd end up with an unoffloaded bridge port with partially synced bridge port attributes. Could you please add a patch previous to this one that handles this, and unoffloads those on error?
Actually I would rather rename the entire dsa_port_mst_enable() function to dsa_port_mst_validate() and move it to the beginning of dsa_port_bridge_join(). This simplifies the unwinding that needs to take place quite a bit.
Re: [PATCH v3 net-next 09/14] net: dsa: Validate hardware support for MST
Quoted 18 lines · Vladimir Oltean
Quoted 8 lines · Vladimir Oltean
Quoted 8 lines
net/dsa/port.c +0
-0@@ -240,6 +240,10 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,if (err && err != -EOPNOTSUPP )return err;Quoted 8 lines
net/dsa/port.c static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp, · line 245
Quoted 3 lines
net/dsa/port.c +3
-0+ err =dsa_port_mst_enable (dp,br_mst_enabled (br), extack); +if (err && err != -EOPNOTSUPP ) +return err;Sadly this will break down because we don't have unwinding on error in place (sorry). We'd end up with an unoffloaded bridge port with partially synced bridge port attributes. Could you please add a patch previous to this one that handles this, and unoffloads those on error?
Quoted 3 lines
Actually I would rather rename the entire
dsa_port_mst_enable()function todsa_port_mst_validate()and move it to the beginning ofdsa_port_bridge_join(). This simplifies the unwinding that needs to take place quite a bit.
Well you still need to unwind vlan filtering if setting the ageing time fails, which is the most complicated one, right? Still, I agree that _validate is a better name, and then _bridge_join seems like a more reasonable placement. Should the unwinding patch still be part of this series then?
While we're here, I actually made this a hard error in both scenarios (but forgot to update the log - will do that in v4, depending on what we decide here). There's a dilemma:
- When reacting to the attribute event, i.e. changing the mode on a member we're apart of, we _can't_ return -EOPNOTSUPP as it will be ignored, which is why dsa_port_mst_validate (nee _enable) returns -EINVAL.
- When joining a bridge, we _must_ return -EOPNOTSUPP to trigger the software fallback.
Having something like this in dsa_port_bridge_join...
err = dsa_port_mst_validate(dp);
if (err == -EINVAL)
return -EOPNOTSUPP; else if (err) return err;
...works I suppose, but feels somewhat awkwark. Any better ideas?
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 09/14] net: dsa: Validate hardware support for MST
Quoted 19 lines · Tobias Waldekranz
Quoted 18 lines · Vladimir Oltean
Quoted 16 lines · Vladimir Oltean
net/dsa/port.c static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp, · line 245
Quoted 11 lines
net/dsa/port.c +3
-0@@ -240,6 +240,10 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,if (err && err != -EOPNOTSUPP )return err; + err =dsa_port_mst_enable (dp,br_mst_enabled (br), extack); +if (err && err != -EOPNOTSUPP ) +return err;Sadly this will break down because we don't have unwinding on error in place (sorry). We'd end up with an unoffloaded bridge port with partially synced bridge port attributes. Could you please add a patch previous to this one that handles this, and unoffloads those on error?
Quoted 6 lines
Quoted 3 lines
Actually I would rather rename the entire
dsa_port_mst_enable()function todsa_port_mst_validate()and move it to the beginning ofdsa_port_bridge_join(). This simplifies the unwinding that needs to take place quite a bit.Well you still need to unwind vlan filtering if setting the ageing time fails, which is the most complicated one, right?
Yes, but we can leave that for another day :)
...ergo
Quoted 1 line
Should the unwinding patch still be part of this series then?
no.
Quoted 17 lines
Still, I agree that
_validateis a better name, and then_bridge_joinseems like a more reasonable placement.While we're here, I actually made this a hard error in both scenarios (but forgot to update the log - will do that in v4, depending on what we decide here). There's a dilemma:
- When reacting to the attribute event, i.e. changing the mode on a member we're apart of, we _can't_ return
-EOPNOTSUPPas it will be ignored, which is whydsa_port_mst_validate(nee_enable) returns-EINVAL.- When joining a bridge, we _must_ return
-EOPNOTSUPPto trigger the software fallback.Having something like this in
dsa_port_bridge_join...
Quoted 7 lines
err =
dsa_port_mst_validate(dp);
if (err ==-EINVAL)return -EOPNOTSUPP; else if (err) return err;...works I suppose, but feels somewhat awkwark. Any better ideas?
What you can do is follow the model of dsa_switch_supports_uc_filtering(), and create a dsa_switch_supports_mst() which is called inside an "if br_mst_enabled(br)" check, and returns bool. When false, you could return -EINVAL or -EOPNOTSUPP, as appropriate.
This is mostly fine, except for the pesky dsa_port_can_configure_learning(dp) check :) So while you could name it dsa_port_supports_mst() and pass it a dsa_port, the problem is that you can't put the implementation of this new dsa_port_supports_mst() next to dsa_switch_supports_uc_filtering() where it would be nice to sit for symmetry, because the latter is static inline and we're missing the definition of dsa_port_can_configure_learning(). So.. the second best thing is to keep dsa_port_supports_mst() in the same place where dsa_port_mst_enable() currently is.
What do you think?
Re: [PATCH v3 net-next 09/14] net: dsa: Validate hardware support for MST
Quoted 27 lines · Vladimir Oltean
Quoted 19 lines · Tobias Waldekranz
Quoted 18 lines · Vladimir Oltean
Quoted 16 lines · Vladimir Oltean
net/dsa/port.c static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp, · line 245
Quoted 11 lines
net/dsa/port.c +3
-0@@ -240,6 +240,10 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,if (err && err != -EOPNOTSUPP )return err; + err =dsa_port_mst_enable (dp,br_mst_enabled (br), extack); +if (err && err != -EOPNOTSUPP ) +return err;Sadly this will break down because we don't have unwinding on error in place (sorry). We'd end up with an unoffloaded bridge port with partially synced bridge port attributes. Could you please add a patch previous to this one that handles this, and unoffloads those on error?
Quoted 6 lines
Quoted 3 lines
Actually I would rather rename the entire
dsa_port_mst_enable()function todsa_port_mst_validate()and move it to the beginning ofdsa_port_bridge_join(). This simplifies the unwinding that needs to take place quite a bit.Well you still need to unwind vlan filtering if setting the ageing time fails, which is the most complicated one, right?
Quoted 7 lines
Yes, but we can leave that for another day :)
...ergo
Quoted 1 line
Should the unwinding patch still be part of this series then?
no.
Agreed
Quoted 39 lines
Quoted 17 lines
Still, I agree that
_validateis a better name, and then_bridge_joinseems like a more reasonable placement.While we're here, I actually made this a hard error in both scenarios (but forgot to update the log - will do that in v4, depending on what we decide here). There's a dilemma:
- When reacting to the attribute event, i.e. changing the mode on a member we're apart of, we _can't_ return
-EOPNOTSUPPas it will be ignored, which is whydsa_port_mst_validate(nee_enable) returns-EINVAL.- When joining a bridge, we _must_ return
-EOPNOTSUPPto trigger the software fallback.Having something like this in
dsa_port_bridge_join...Quoted 7 lines
err =
dsa_port_mst_validate(dp);
if (err ==-EINVAL)return -EOPNOTSUPP; else if (err) return err;...works I suppose, but feels somewhat awkwark. Any better ideas?
What you can do is follow the model of
dsa_switch_supports_uc_filtering(), and create adsa_switch_supports_mst()which is called inside an "ifbr_mst_enabled(br)" check, and returns bool. When false, you could return-EINVALor-EOPNOTSUPP, as appropriate.This is mostly fine, except for the pesky
dsa_port_can_configure_learning(dp)check :) So while you could name itdsa_port_supports_mst()and pass it adsa_port, the problem is that you can't put the implementation of this newdsa_port_supports_mst()next todsa_switch_supports_uc_filtering()where it would be nice to sit for symmetry, because the latter is static inline and we're missing the definition ofdsa_port_can_configure_learning(). So.. the second best thing is to keepdsa_port_supports_mst()in the same place wheredsa_port_mst_enable()currently is.
Quoted 1 line
What do you think?
I think that would mostly work. It would have to be positioned higher up in the file though, so that it can be called from _bridge_join. Unless we add a forward for it of course, but that seems to break with existing conventions.
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 09/14] net: dsa: Validate hardware support for MST
In reply to Tobias WaldekranzQuoted 35 lines · Tobias Waldekranz
When joining a bridge where MST is enabled, we validate that the proper offloading support is in place, otherwise we fallback to software bridging.
When then mode is changed on a bridge in which we are members, we refuse the change if offloading is not supported.
At the moment we only check for configurable learning, but this will be further restricted as we support more MST related switchdev events.
Signed-off-by Tobias Waldekranz <[email protected]>--- net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 20 ++++++++++++++++++++ net/dsa/slave.c | 6 ++++++ 3 files changed, 28 insertions(+)net/dsa/dsa_priv.h +2
-0@@ -234,6 +234,8 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, struct netlink_ext_ack *extack);bool dsa_port_skip_vlan_configuration (struct dsa_port *dp);int dsa_port_ageing_time (struct dsa_port *dp,clock_t ageing_clock); +int dsa_port_mst_enable (struct dsa_port *dp,bool on, +struct netlink_ext_ack *extack);int dsa_port_mtu_change (struct dsa_port *dp,int new_mtu,bool targeted_match); int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,net/dsa/port.c +0
-0
net/dsa/port.c static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp, · line 245
Quoted 6 lines
net/dsa/port.c +3
-0@@ -240,6 +240,10 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,if (err && err != -EOPNOTSUPP )return err; + err =dsa_port_mst_enable (dp,br_mst_enabled (br), extack); +if (err && err != -EOPNOTSUPP ) +return err;
The "err && err != -EOPNOTSUPP" scheme is in place for compatibility with drivers that don't all support the bridge port attributes, but used to work prior to dsa_port_switchdev_sync_attrs()'s existence.
I don't think this scheme is necessary for dsa_port_mst_enable(), you can just return -EOPNOTSUPP and remove the special handling for this code.
Quoted 47 lines
net/dsa/port.c +17
-0+return 0 ; }@@ -735,6 +739,22 @@ int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock)return 0 ; } +int dsa_port_mst_enable (struct dsa_port *dp,bool on, +struct netlink_ext_ack *extack) +{ +struct dsa_switch *ds = dp->ds; + +if (!on) +return 0 ; + +if (!dsa_port_can_configure_learning (dp)) { +NL_SET_ERR_MSG_MOD (extack,"Hardware does not support MST" ); +return -EINVAL ; + } + +return 0 ; +} +int dsa_port_pre_bridge_flags (const struct dsa_port *dp,struct switchdev_brport_flags flags,struct netlink_ext_ack *extack)net/dsa/slave.c +6
-0@@ -463,6 +463,12 @@ static int dsa_slave_port_attr_set(struct net_device *dev, const void *ctx, ret =dsa_port_ageing_time (dp, attr->u.ageing_time);break ; +case SWITCHDEV_ATTR_ID_BRIDGE_MST : +if (!dsa_port_offloads_bridge_dev (dp, attr->orig_dev)) +return -EOPNOTSUPP ; + + ret =dsa_port_mst_enable (dp, attr->u.mst, extack); +break ;case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS :if (!dsa_port_offloads_bridge_port (dp, attr->orig_dev))return -EOPNOTSUPP ;Signature · 1 line
2.25.1
PATCH v3 10/14 net: dsa: Pass VLAN MSTI migration notifications to driver
In reply to Tobias WaldekranzAdd the usual trampoline functionality from the generic DSA layer down to the drivers for VLAN MSTI migrations.
--- include/net/dsa.h | 3 +++ net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 14 +++++++++++++- net/dsa/slave.c | 6 ++++++ 4 files changed, 24 insertions(+), 1 deletion(-)
include/net/dsa.h +3 -0
@@ -964,6 +964,9 @@ struct dsa_switch_ops { struct netlink_ext_ack *extack);int (*port_vlan_del)(struct dsa_switch *ds,int port,const struct switchdev_obj_port_vlan *vlan); +int (*vlan_msti_set)(struct dsa_switch *ds,struct dsa_bridge bridge, +const struct switchdev_vlan_msti *msti); +/* * Forwarding database */
net/dsa/dsa_priv.h +2 -0
@@ -236,6 +236,8 @@ bool dsa_port_skip_vlan_configuration(struct dsa_port *dp);int dsa_port_ageing_time (struct dsa_port *dp,clock_t ageing_clock);int dsa_port_mst_enable (struct dsa_port *dp,bool on,struct netlink_ext_ack *extack); +int dsa_port_vlan_msti (struct dsa_port *dp, +const struct switchdev_vlan_msti *msti);int dsa_port_mtu_change (struct dsa_port *dp,int new_mtu,bool targeted_match); int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
net/dsa/port.c +13 -1
@@ -747,7 +747,8 @@ int dsa_port_mst_enable(struct dsa_port *dp, bool on,if (!on)return 0 ; -if (!dsa_port_can_configure_learning (dp)) { +if (!(ds->ops->vlan_msti_set && +dsa_port_can_configure_learning (dp))) {NL_SET_ERR_MSG_MOD (extack,"Hardware does not support MST" );return -EINVAL ; }
@@ -798,6 +799,17 @@ int dsa_port_bridge_flags(struct dsa_port *dp,return 0 ; } +int dsa_port_vlan_msti (struct dsa_port *dp, +const struct switchdev_vlan_msti *msti) +{ +struct dsa_switch *ds = dp->ds; + +if (!ds->ops->vlan_msti_set) +return -EOPNOTSUPP ; + +return ds->ops->vlan_msti_set (ds, *dp->bridge, msti); +} +int dsa_port_mtu_change (struct dsa_port *dp,int new_mtu,bool targeted_match) {
net/dsa/slave.c +6 -0
@@ -482,6 +482,12 @@ static int dsa_slave_port_attr_set(struct net_device *dev, const void *ctx, ret =dsa_port_bridge_flags (dp, attr->u.brport_flags, extack);break ; +case SWITCHDEV_ATTR_ID_VLAN_MSTI : +if (!dsa_port_offloads_bridge_dev (dp, attr->orig_dev)) +return -EOPNOTSUPP ; + + ret =dsa_port_vlan_msti (dp, &attr->u.vlan_msti); +break ;default : ret = -EOPNOTSUPP ;break ;
Signature · 1 line
2.25.1
Re: [PATCH v3 net-next 10/14] net: dsa: Pass VLAN MSTI migration notifications to driver
Quoted 5 lines · Tobias Waldekranz
Add the usual trampoline functionality from the generic DSA layer down to the drivers for VLAN MSTI migrations.
Signed-off-by Tobias Waldekranz <[email protected]>---
PATCH v3 11/14 net: dsa: Handle MST state changes
In reply to Tobias WaldekranzAdd the usual trampoline functionality from the generic DSA layer down to the drivers for MST state changes.
When a state changes to disabled/blocking/listening, make sure to fast age any dynamic entries in the affected VLANs (those controlled by the MSTI in question).
--- include/net/dsa.h | 3 +++ net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 67 +++++++++++++++++++++++++++++++++++++++++++--- net/dsa/slave.c | 6 +++++ 4 files changed, 74 insertions(+), 4 deletions(-)
include/net/dsa.h +3 -0
@@ -945,7 +945,10 @@ struct dsa_switch_ops { struct dsa_bridge bridge);void (*port_stp_state_set)(struct dsa_switch *ds,int port,u8 state); +int (*port_mst_state_set)(struct dsa_switch *ds,int port, +const struct switchdev_mst_state *state);void (*port_fast_age)(struct dsa_switch *ds,int port); +void (*port_vlan_fast_age)(struct dsa_switch *ds,int port,u16 vid);int (*port_pre_bridge_flags)(struct dsa_switch *ds,int port,struct switchdev_brport_flags flags,struct netlink_ext_ack *extack);
net/dsa/dsa_priv.h +2 -0
@@ -215,6 +215,8 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,void dsa_port_set_tag_protocol (struct dsa_port *cpu_dp,const struct dsa_device_ops *tag_ops);int dsa_port_set_state (struct dsa_port *dp,u8 state,bool do_fast_age); +int dsa_port_set_mst_state (struct dsa_port *dp, +const struct switchdev_mst_state *state);int dsa_port_enable_rt (struct dsa_port *dp,struct phy_device *phy);int dsa_port_enable (struct dsa_port *dp,struct phy_device *phy);void dsa_port_disable_rt (struct dsa_port *dp);
net/dsa/port.c +63 -4
94 lines not on this page · raw message
net/dsa/slave.c +6 -0
@@ -450,6 +450,12 @@ static int dsa_slave_port_attr_set(struct net_device *dev, const void *ctx, ret =dsa_port_set_state (dp, attr->u.stp_state, true);break ; +case SWITCHDEV_ATTR_ID_PORT_MST_STATE : +if (!dsa_port_offloads_bridge_port (dp, attr->orig_dev)) +return -EOPNOTSUPP ; + + ret =dsa_port_set_mst_state (dp, &attr->u.mst_state); +break ;case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING :if (!dsa_port_offloads_bridge_dev (dp, attr->orig_dev))return -EOPNOTSUPP ;
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 11/14] net: dsa: Handle MST state changes
Quoted 63 lines · Tobias Waldekranz
Add the usual trampoline functionality from the generic DSA layer down to the drivers for MST state changes.
When a state changes to disabled/blocking/listening, make sure to fast age any dynamic entries in the affected VLANs (those controlled by the MSTI in question).
Signed-off-by Tobias Waldekranz <[email protected]>--- include/net/dsa.h | 3 +++ net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 67 +++++++++++++++++++++++++++++++++++++++++++--- net/dsa/slave.c | 6 +++++ 4 files changed, 74 insertions(+), 4 deletions(-)include/net/dsa.h +3
-0@@ -945,7 +945,10 @@ struct dsa_switch_ops { struct dsa_bridge bridge);void (*port_stp_state_set)(struct dsa_switch *ds,int port,u8 state); +int (*port_mst_state_set)(struct dsa_switch *ds,int port, +const struct switchdev_mst_state *state);void (*port_fast_age)(struct dsa_switch *ds,int port); +void (*port_vlan_fast_age)(struct dsa_switch *ds,int port,u16 vid);int (*port_pre_bridge_flags)(struct dsa_switch *ds,int port,struct switchdev_brport_flags flags,struct netlink_ext_ack *extack);net/dsa/dsa_priv.h +2
-0@@ -215,6 +215,8 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,void dsa_port_set_tag_protocol (struct dsa_port *cpu_dp,const struct dsa_device_ops *tag_ops);int dsa_port_set_state (struct dsa_port *dp,u8 state,bool do_fast_age); +int dsa_port_set_mst_state (struct dsa_port *dp, +const struct switchdev_mst_state *state);int dsa_port_enable_rt (struct dsa_port *dp,struct phy_device *phy);int dsa_port_enable (struct dsa_port *dp,struct phy_device *phy);void dsa_port_disable_rt (struct dsa_port *dp);net/dsa/port.c +2
-3@@ -30,12 +30,11 @@ static int dsa_port_notify(const struct dsa_port *dp, unsigned long e, void *v)return dsa_tree_notify (dp->ds->dst, e, v); } -static void dsa_port_notify_bridge_fdb_flush (const struct dsa_port *dp) +static void dsa_port_notify_bridge_fdb_flush (const struct dsa_port *dp,u16 vid) {struct net_device *brport_dev =dsa_port_to_bridge_port (dp);struct switchdev_notifier_fdb_info info = { -/* flush all VLANs */ - .vid =0 , + .vid = vid, };/* When the port becomes standalone it has already left the bridge.
net/dsa/port.c static void dsa_port_fast_age(const struct dsa_port *dp) · line 60
Quoted 4 lines
net/dsa/port.c +0
-1@@ -57,7 +56,39 @@ static void dsa_port_fast_age(const struct dsa_port *dp) ds->ops->port_fast_age (ds, dp->index); -dsa_port_notify_bridge_fdb_flush (dp);
Could you please migrate the "flush all VLANs" comment here?
Quoted 13 lines
net/dsa/port.c +13
-0+dsa_port_notify_bridge_fdb_flush (dp,0 ); +} + +static void dsa_port_vlan_fast_age (const struct dsa_port *dp,u16 vid) +{ +struct dsa_switch *ds = dp->ds; + +if (!ds->ops->port_vlan_fast_age) +return ; + + ds->ops->port_vlan_fast_age (ds, dp->index, vid); + +dsa_port_notify_bridge_fdb_flush (dp, vid);
net/dsa/port.c static void dsa_port_fast_age(const struct dsa_port *dp) · line 81
Quoted 10 lines
net/dsa/port.c +10
-0+} + +static void dsa_port_msti_fast_age (const struct dsa_port *dp,u16 msti) +{ +unsigned long *vids; +int vid; + + vids =bitmap_zalloc (VLAN_N_VID ,0 ); +if (!vids) +return ;
As discussed, I think you can/should use DECLARE_BITMAP().
net/dsa/port.c static void dsa_port_fast_age(const struct dsa_port *dp) · line 87
Quoted 6 lines
net/dsa/port.c +6
-0+ +if (br_mst_get_info (dsa_port_bridge_dev_get (dp), msti, vids)) + goto out_free; + +for_each_set_bit (vid, vids,VLAN_N_VID ) { +dsa_port_vlan_fast_age (dp, vid);
This has an error propagation path to user space, since just user space sets it via IFLA_BRIDGE_MST_ENTRY_STATE, does it not?
So could we actually propagate an error all the way from ds->ops->port_vlan_fast_age to the mstpd daemon?
Quoted 69 lines
net/dsa/port.c +32
-0+ } + +out_free: +kfree (vids); }static bool dsa_port_can_configure_learning (struct dsa_port *dp)@@ -118,6 +149,32 @@ static void dsa_port_set_state_now(struct dsa_port *dp, u8 state,pr_err ("DSA: failed to set STP state %u (%d)\n" , state, err); } +int dsa_port_set_mst_state (struct dsa_port *dp, +const struct switchdev_mst_state *state) +{ +struct dsa_switch *ds = dp->ds; +int err; + +if (!ds->ops->port_mst_state_set) +return -EOPNOTSUPP ; + + err = ds->ops->port_mst_state_set (ds, dp->index, state); +if (err) +return err; + +if (dp->learning) { +switch (state->state) { +case BR_STATE_DISABLED : +case BR_STATE_BLOCKING : +case BR_STATE_LISTENING : +dsa_port_msti_fast_age (dp, state->msti); +break ; + } + } + +return 0 ; +} +int dsa_port_enable_rt (struct dsa_port *dp,struct phy_device *phy) {struct dsa_switch *ds = dp->ds;@@ -748,6 +805,8 @@ int dsa_port_mst_enable(struct dsa_port *dp, bool on,return 0 ;if (!(ds->ops->vlan_msti_set && + ds->ops->port_mst_state_set && + ds->ops->port_vlan_fast_age &&dsa_port_can_configure_learning (dp))) {NL_SET_ERR_MSG_MOD (extack,"Hardware does not support MST" );return -EINVAL ;net/dsa/slave.c +6
-0@@ -450,6 +450,12 @@ static int dsa_slave_port_attr_set(struct net_device *dev, const void *ctx, ret =dsa_port_set_state (dp, attr->u.stp_state, true);break ; +case SWITCHDEV_ATTR_ID_PORT_MST_STATE : +if (!dsa_port_offloads_bridge_port (dp, attr->orig_dev)) +return -EOPNOTSUPP ; + + ret =dsa_port_set_mst_state (dp, &attr->u.mst_state); +break ;case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING :if (!dsa_port_offloads_bridge_dev (dp, attr->orig_dev))return -EOPNOTSUPP ;Signature · 1 line
2.25.1
PATCH v3 12/14 net: dsa: mv88e6xxx: Disentangle STU from VTU
In reply to Tobias WaldekranzIn early LinkStreet silicon (e.g. 6095/6185), the per-VLAN STP states were kept in the VTU - there was no concept of a SID. Later, the information was split into two tables, where the VTU only tracked memberships and deferred the STP state tracking to the STU via a pointer (SID). This meant that a group of VLANs could share the same STU entry. Most likely, this was done to align with MSTP (802.1Q-2018, Clause 13), which is built on this principle.
While the VTU is still 4k lines on most devices, the STU is capped at 64 entries. This means that the current stategy, updating STU info whenever a VTU entry is updated, can not easily support MSTP because:
- The maximum number of VIDs would also be capped at 64, as we would have to allocate one SID for every VTU entry - even if many VLANs would effectively share the same MST.
- MSTP updates would be unnecessarily slow as you would have to iterate over all VLANs that share the same MST.
In order to support MSTP offloading in the future, manage the STU as a separate entity from the VTU.
Only add support for newer hardware with separate VTU and STU. VTU-only devices can also be supported, but essentially this requires a software implementation of an STU (fanning out state changed to all VLANs tied to the same MST).
--- drivers/net/dsa/mv88e6xxx/chip.c | 54 ++++ drivers/net/dsa/mv88e6xxx/chip.h | 24 ++ drivers/net/dsa/mv88e6xxx/global1.h | 10 + drivers/net/dsa/mv88e6xxx/global1_vtu.c | 311 ++++++++++++++---------- 4 files changed, 264 insertions(+), 135 deletions(-)
drivers/net/dsa/mv88e6xxx/chip.c +54 -0
@@ -1791,6 +1791,33 @@ static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)return mv88e6xxx_g1_atu_flush (chip, *fid, true); } +static int mv88e6xxx_stu_loadpurge (struct mv88e6xxx_chip *chip, +struct mv88e6xxx_stu_entry *entry) +{ +if (!chip->info->ops->stu_loadpurge) +return -EOPNOTSUPP ; + +return chip->info->ops->stu_loadpurge (chip, entry); +} + +static int mv88e6xxx_stu_setup (struct mv88e6xxx_chip *chip) +{ +struct mv88e6xxx_stu_entry stu = { + .valid = true, + .sid =0 + }; + +if (!mv88e6xxx_has_stu (chip)) +return 0 ; + +/* Make sure that SID 0 is always valid. This is used by VTU +* entries that do not make use of the STU, e.g. when creating +* a VLAN upper on a port that is also part of a VLAN +* filtering bridge. +*/ +return mv88e6xxx_stu_loadpurge (chip, &stu); +} +static int mv88e6xxx_port_check_hw_vlan (struct dsa_switch *ds,int port,u16 vid) {
@@ -3427,6 +3454,13 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)if (err) goto unlock; +/* Must be called after mv88e6xxx_vtu_setup (which flushes the +* VTU, thereby also flushing the STU). +*/ + err =mv88e6xxx_stu_setup (chip); +if (err) + goto unlock; +/* Setup Switch Port Registers */ for (i =0 ; i <mv88e6xxx_num_ports (chip); i++) {if (dsa_is_unused_port (ds, i))
@@ -3882,6 +3916,8 @@ static const struct mv88e6xxx_ops mv88e6097_ops = { .vtu_getnext = mv88e6352_g1_vtu_getnext, .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, .phylink_get_caps = mv88e6095_phylink_get_caps, + .stu_getnext = mv88e6352_g1_stu_getnext, + .stu_loadpurge = mv88e6352_g1_stu_loadpurge, .set_max_frame_size = mv88e6185_g1_set_max_frame_size, };
@@ -4968,6 +5004,8 @@ static const struct mv88e6xxx_ops mv88e6352_ops = { .atu_set_hash = mv88e6165_g1_atu_set_hash, .vtu_getnext = mv88e6352_g1_vtu_getnext, .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, + .stu_getnext = mv88e6352_g1_stu_getnext, + .stu_loadpurge = mv88e6352_g1_stu_loadpurge, .serdes_get_lane = mv88e6352_serdes_get_lane, .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state, .serdes_pcs_config = mv88e6352_serdes_pcs_config,
@@ -5033,6 +5071,8 @@ static const struct mv88e6xxx_ops mv88e6390_ops = { .atu_set_hash = mv88e6165_g1_atu_set_hash, .vtu_getnext = mv88e6390_g1_vtu_getnext, .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, + .stu_getnext = mv88e6390_g1_stu_getnext, + .stu_loadpurge = mv88e6390_g1_stu_loadpurge, .serdes_power = mv88e6390_serdes_power, .serdes_get_lane = mv88e6390_serdes_get_lane,/* Check status register pause & lpa register */
@@ -5098,6 +5138,8 @@ static const struct mv88e6xxx_ops mv88e6390x_ops = { .atu_set_hash = mv88e6165_g1_atu_set_hash, .vtu_getnext = mv88e6390_g1_vtu_getnext, .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, + .stu_getnext = mv88e6390_g1_stu_getnext, + .stu_loadpurge = mv88e6390_g1_stu_loadpurge, .serdes_power = mv88e6390_serdes_power, .serdes_get_lane = mv88e6390x_serdes_get_lane, .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
@@ -5166,6 +5208,8 @@ static const struct mv88e6xxx_ops mv88e6393x_ops = { .atu_set_hash = mv88e6165_g1_atu_set_hash, .vtu_getnext = mv88e6390_g1_vtu_getnext, .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, + .stu_getnext = mv88e6390_g1_stu_getnext, + .stu_loadpurge = mv88e6390_g1_stu_loadpurge, .serdes_power = mv88e6393x_serdes_power, .serdes_get_lane = mv88e6393x_serdes_get_lane, .serdes_pcs_get_state = mv88e6393x_serdes_pcs_get_state,
@@ -5234,6 +5278,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_ports = 11, .num_internal_phys = 8, .max_vid = 4095, + .max_sid = 63, .port_base_addr = 0x10, .phy_base_addr = 0x0, .global1_addr = 0x1b,
@@ -5487,6 +5532,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_internal_phys = 9, .num_gpio = 16, .max_vid = 8191, + .max_sid = 63, .port_base_addr = 0x0, .phy_base_addr = 0x0, .global1_addr = 0x1b,
@@ -5510,6 +5556,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_internal_phys = 9, .num_gpio = 16, .max_vid = 8191, + .max_sid = 63, .port_base_addr = 0x0, .phy_base_addr = 0x0, .global1_addr = 0x1b,
@@ -5532,6 +5579,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_ports = 11, /* 10 + Z80 */ .num_internal_phys = 9, .max_vid = 8191, + .max_sid = 63, .port_base_addr = 0x0, .phy_base_addr = 0x0, .global1_addr = 0x1b,
@@ -5554,6 +5602,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_ports = 11, /* 10 + Z80 */ .num_internal_phys = 9, .max_vid = 8191, + .max_sid = 63, .port_base_addr = 0x0, .phy_base_addr = 0x0, .global1_addr = 0x1b,
@@ -5576,6 +5625,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_ports = 11, /* 10 + Z80 */ .num_internal_phys = 9, .max_vid = 8191, + .max_sid = 63, .port_base_addr = 0x0, .phy_base_addr = 0x0, .global1_addr = 0x1b,
@@ -5815,6 +5865,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_internal_phys = 5, .num_gpio = 15, .max_vid = 4095, + .max_sid = 63, .port_base_addr = 0x10, .phy_base_addr = 0x0, .global1_addr = 0x1b,
@@ -5839,6 +5890,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_internal_phys = 9, .num_gpio = 16, .max_vid = 8191, + .max_sid = 63, .port_base_addr = 0x0, .phy_base_addr = 0x0, .global1_addr = 0x1b,
@@ -5863,6 +5915,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_internal_phys = 9, .num_gpio = 16, .max_vid = 8191, + .max_sid = 63, .port_base_addr = 0x0, .phy_base_addr = 0x0, .global1_addr = 0x1b,
@@ -5886,6 +5939,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .num_ports = 11, /* 10 + Z80 */ .num_internal_phys = 9, .max_vid = 8191, + .max_sid = 63, .port_base_addr = 0x0, .phy_base_addr = 0x0, .global1_addr = 0x1b,
drivers/net/dsa/mv88e6xxx/chip.h +24 -0
@@ -20,6 +20,7 @@#define EDSA_HLEN 8#define MV88E6XXX_N_FID 4096 +#define MV88E6XXX_N_SID 64#define MV88E6XXX_FID_STANDALONE 0#define MV88E6XXX_FID_BRIDGED 1
@@ -130,6 +131,7 @@ struct mv88e6xxx_info {unsigned int num_internal_phys;unsigned int num_gpio;unsigned int max_vid; +unsigned int max_sid;unsigned int port_base_addr;unsigned int phy_base_addr;unsigned int global1_addr;
@@ -181,6 +183,12 @@ struct mv88e6xxx_vtu_entry {bool valid;bool policy;u8 member[DSA_MAX_PORTS ]; +u8 state[DSA_MAX_PORTS ];/* Older silicon has no STU */ +}; + +struct mv88e6xxx_stu_entry { +u8 sid; +bool valid;u8 state[DSA_MAX_PORTS ]; };
@@ -602,6 +610,12 @@ struct mv88e6xxx_ops {int (*vtu_loadpurge)(struct mv88e6xxx_chip *chip,struct mv88e6xxx_vtu_entry *entry); +/* Spanning Tree Unit operations */ +int (*stu_getnext)(struct mv88e6xxx_chip *chip, +struct mv88e6xxx_stu_entry *entry); +int (*stu_loadpurge)(struct mv88e6xxx_chip *chip, +struct mv88e6xxx_stu_entry *entry); +/* GPIO operations */ const struct mv88e6xxx_gpio_ops *gpio_ops;
@@ -700,6 +714,11 @@ struct mv88e6xxx_hw_stat {int type; }; +static inline bool mv88e6xxx_has_stu (struct mv88e6xxx_chip *chip) +{ +return chip->info->max_sid >0 ; +} +static inline bool mv88e6xxx_has_pvt (struct mv88e6xxx_chip *chip) {return chip->info->pvt;
@@ -730,6 +749,11 @@ static inline unsigned int mv88e6xxx_max_vid(struct mv88e6xxx_chip *chip)return chip->info->max_vid; } +static inline unsigned int mv88e6xxx_max_sid (struct mv88e6xxx_chip *chip) +{ +return chip->info->max_sid; +} +static inline u16 mv88e6xxx_port_mask (struct mv88e6xxx_chip *chip) {return GENMASK ((s32 )mv88e6xxx_num_ports (chip) -1 ,0 );
drivers/net/dsa/mv88e6xxx/global1.h +10 -0
@@ -348,6 +348,16 @@ int mv88e6390_g1_vtu_getnext(struct mv88e6xxx_chip *chip,int mv88e6390_g1_vtu_loadpurge (struct mv88e6xxx_chip *chip,struct mv88e6xxx_vtu_entry *entry);int mv88e6xxx_g1_vtu_flush (struct mv88e6xxx_chip *chip); +int mv88e6xxx_g1_stu_getnext (struct mv88e6xxx_chip *chip, +struct mv88e6xxx_stu_entry *entry); +int mv88e6352_g1_stu_getnext (struct mv88e6xxx_chip *chip, +struct mv88e6xxx_stu_entry *entry); +int mv88e6352_g1_stu_loadpurge (struct mv88e6xxx_chip *chip, +struct mv88e6xxx_stu_entry *entry); +int mv88e6390_g1_stu_getnext (struct mv88e6xxx_chip *chip, +struct mv88e6xxx_stu_entry *entry); +int mv88e6390_g1_stu_loadpurge (struct mv88e6xxx_chip *chip, +struct mv88e6xxx_stu_entry *entry);int mv88e6xxx_g1_vtu_prob_irq_setup (struct mv88e6xxx_chip *chip);void mv88e6xxx_g1_vtu_prob_irq_free (struct mv88e6xxx_chip *chip);int mv88e6xxx_g1_atu_get_next (struct mv88e6xxx_chip *chip,u16 fid);
drivers/net/dsa/mv88e6xxx/global1_vtu.c +176 -135
506 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 13/14 net: dsa: mv88e6xxx: Export STU as devlink region
In reply to Tobias WaldekranzExport the raw STU data in a devlink region so that it can be inspected from userspace and compared to the current bridge configuration.
--- drivers/net/dsa/mv88e6xxx/chip.h | 1 + drivers/net/dsa/mv88e6xxx/devlink.c | 94 +++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+)
drivers/net/dsa/mv88e6xxx/chip.h +1 -0
@@ -287,6 +287,7 @@ enum mv88e6xxx_region_id {MV88E6XXX_REGION_GLOBAL2 ,MV88E6XXX_REGION_ATU ,MV88E6XXX_REGION_VTU , +MV88E6XXX_REGION_STU ,MV88E6XXX_REGION_PVT , _MV88E6XXX_REGION_MAX,
drivers/net/dsa/mv88e6xxx/devlink.c +94 -0
118 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 14/14 net: dsa: mv88e6xxx: MST Offloading
In reply to Tobias WaldekranzAllocate a SID in the STU for each MSTID in use by a bridge and handle the mapping of MSTIDs to VLANs using the SID field of each VTU entry.
--- drivers/net/dsa/mv88e6xxx/chip.c | 251 ++++++++++++++++++++++++++++++- drivers/net/dsa/mv88e6xxx/chip.h | 13 ++ 2 files changed, 257 insertions(+), 7 deletions(-)
drivers/net/dsa/mv88e6xxx/chip.c +244 -7
@@ -1667,24 +1667,32 @@ static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)return 0 ; } -static void mv88e6xxx_port_fast_age (struct dsa_switch *ds,int port) +static void mv88e6xxx_port_fast_age_fid (struct mv88e6xxx_chip *chip,int port, +u16 fid) { -struct mv88e6xxx_chip *chip = ds->priv;int err; -if (dsa_to_port (ds, port)->lag) +if (dsa_to_port (chip->ds, port)->lag)/* Hardware is incapable of fast-aging a LAG through a * regular ATU move operation. Until we have something * more fancy in place this is a no-op. */ return ; -mv88e6xxx_reg_lock (chip); - err =mv88e6xxx_g1_atu_remove (chip,0 , port, false); -mv88e6xxx_reg_unlock (chip); + err =mv88e6xxx_g1_atu_remove (chip, fid, port, false);if (err) -dev_err (ds->dev,"p%d: failed to flush ATU\n" , port); +dev_err (chip->ds->dev,"p%d: failed to flush ATU (FID %u)\n" , + port, fid); +} + +static void mv88e6xxx_port_fast_age (struct dsa_switch *ds,int port) +{ +struct mv88e6xxx_chip *chip = ds->priv; + +mv88e6xxx_reg_lock (chip); +mv88e6xxx_port_fast_age_fid (chip, port,0 ); +mv88e6xxx_reg_unlock (chip); }static int mv88e6xxx_vtu_setup (struct mv88e6xxx_chip *chip)
@@ -1818,6 +1826,159 @@ static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip)return mv88e6xxx_stu_loadpurge (chip, &stu); } +static int mv88e6xxx_sid_get (struct mv88e6xxx_chip *chip,u8 *sid) +{ + DECLARE_BITMAP(busy, MV88E6XXX_N_SID) = { 0 }; +struct mv88e6xxx_mst *mst; + +set_bit (0 , busy); + +list_for_each_entry (mst, &chip->msts, node) { +set_bit (mst->stu.sid, busy); + } + + *sid =find_first_zero_bit (busy,MV88E6XXX_N_SID ); + +return (*sid >=mv88e6xxx_max_sid (chip)) ? -ENOSPC :0 ; +} + +static int mv88e6xxx_mst_put (struct mv88e6xxx_chip *chip,u8 sid) +{ +struct mv88e6xxx_mst *mst, *tmp; +int err; + +if (!sid) +return 0 ; + +list_for_each_entry_safe (mst, tmp, &chip->msts, node) { +if (mst->stu.sid != sid) +continue ; + +if (!refcount_dec_and_test (&mst->refcnt)) +return 0 ; + + mst->stu.valid = false; + err =mv88e6xxx_stu_loadpurge (chip, &mst->stu); +if (err) +return err; + +list_del (&mst->node); +kfree (mst); +return 0 ; + } + +return -ENOENT ; +} + +static int mv88e6xxx_mst_get (struct mv88e6xxx_chip *chip,struct net_device *br, +u16 msti,u8 *sid) +{ +struct mv88e6xxx_mst *mst; +int err, i; + +if (!mv88e6xxx_has_stu (chip)) { + err = -EOPNOTSUPP ; + goto err; + } + +if (!msti) { + *sid =0 ; +return 0 ; + } + +list_for_each_entry (mst, &chip->msts, node) { +if (mst->br == br && mst->msti == msti) { +refcount_inc (&mst->refcnt); + *sid = mst->stu.sid; +return 0 ; + } + } + + err =mv88e6xxx_sid_get (chip, sid); +if (err) + goto err; + + mst =kzalloc (sizeof (*mst),GFP_KERNEL ); +if (!mst) { + err = -ENOMEM ; + goto err; + } + +INIT_LIST_HEAD (&mst->node); +refcount_set (&mst->refcnt,1 ); + mst->br = br; + mst->msti = msti; + mst->stu.valid = true; + mst->stu.sid = *sid; + +/* The bridge starts out all ports in the disabled state. But +* a STU state of disabled means to go by the port-global +* state. So we set all user port's initial state to blocking, +* to match the bridge's behavior. +*/ +for (i =0 ; i <mv88e6xxx_num_ports (chip); i++) + mst->stu.state[i] =dsa_is_user_port (chip->ds, i) ? +MV88E6XXX_PORT_CTL0_STATE_BLOCKING : +MV88E6XXX_PORT_CTL0_STATE_DISABLED ; + + err =mv88e6xxx_stu_loadpurge (chip, &mst->stu); +if (err) + goto err_free; + +list_add_tail (&mst->node, &chip->msts); +return 0 ; + +err_free: +kfree (mst); +err: +return err; +} + +static int mv88e6xxx_port_mst_state_set (struct dsa_switch *ds,int port, +const struct switchdev_mst_state *st) +{ +struct dsa_port *dp =dsa_to_port (ds, port); +struct mv88e6xxx_chip *chip = ds->priv; +struct mv88e6xxx_mst *mst; +u8 state; +int err; + +if (!mv88e6xxx_has_stu (chip)) +return -EOPNOTSUPP ; + +switch (st->state) { +case BR_STATE_DISABLED : +case BR_STATE_BLOCKING : +case BR_STATE_LISTENING : + state =MV88E6XXX_PORT_CTL0_STATE_BLOCKING ; +break ; +case BR_STATE_LEARNING : + state =MV88E6XXX_PORT_CTL0_STATE_LEARNING ; +break ; +case BR_STATE_FORWARDING : + state =MV88E6XXX_PORT_CTL0_STATE_FORWARDING ; +break ; +default : +return -EINVAL ; + } + +list_for_each_entry (mst, &chip->msts, node) { +if (mst->br ==dsa_port_bridge_dev_get (dp) && + mst->msti == st->msti) { +if (mst->stu.state[port] == state) +return 0 ; + + mst->stu.state[port] = state; +mv88e6xxx_reg_lock (chip); + err =mv88e6xxx_stu_loadpurge (chip, &mst->stu); +mv88e6xxx_reg_unlock (chip); +return err; + } + } + +return -ENOENT ; +} +static int mv88e6xxx_port_check_hw_vlan (struct dsa_switch *ds,int port,u16 vid) {
@@ -2437,6 +2598,12 @@ static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,if (err)return err; +if (!vlan.valid && vlan.sid) { + err =mv88e6xxx_mst_put (chip, vlan.sid); +if (err) +return err; + } +return mv88e6xxx_g1_atu_remove (chip, vlan.fid, port, false); }
@@ -2482,6 +2649,72 @@ static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,return err; } +static void mv88e6xxx_port_vlan_fast_age (struct dsa_switch *ds,int port,u16 vid) +{ +struct mv88e6xxx_chip *chip = ds->priv; +struct mv88e6xxx_vtu_entry vlan; +int err; + +mv88e6xxx_reg_lock (chip); + + err =mv88e6xxx_vtu_get (chip, vid, &vlan); +if (err) + goto unlock; + +mv88e6xxx_port_fast_age_fid (chip, port, vlan.fid); + +unlock: +mv88e6xxx_reg_unlock (chip); + +if (err) +dev_err (ds->dev,"p%d: failed to flush ATU in VID %u\n" , + port, vid); +} + +static int mv88e6xxx_vlan_msti_set (struct dsa_switch *ds, +struct dsa_bridge bridge, +const struct switchdev_vlan_msti *msti) +{ +struct mv88e6xxx_chip *chip = ds->priv; +struct mv88e6xxx_vtu_entry vlan; +u8 old_sid, new_sid; +int err; + +mv88e6xxx_reg_lock (chip); + + err =mv88e6xxx_vtu_get (chip, msti->vid, &vlan); +if (err) + goto unlock; + +if (!vlan.valid) { + err = -EINVAL ; + goto unlock; + } + + old_sid = vlan.sid; + + err =mv88e6xxx_mst_get (chip, bridge.dev, msti->msti, &new_sid); +if (err) + goto unlock; + +if (new_sid != old_sid) { + vlan.sid = new_sid; + + err =mv88e6xxx_vtu_loadpurge (chip, &vlan); +if (err) { +mv88e6xxx_mst_put (chip, new_sid); + goto unlock; + } + } + +if (old_sid) + err =mv88e6xxx_mst_put (chip, old_sid); + +unlock: +mv88e6xxx_reg_unlock (chip); +return err; +} +static int mv88e6xxx_port_fdb_add (struct dsa_switch *ds,int port,const unsigned char *addr,u16 vid,struct dsa_db db)
@@ -6008,6 +6241,7 @@ static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)mutex_init (&chip->reg_lock);INIT_LIST_HEAD (&chip->mdios);idr_init (&chip->policies); +INIT_LIST_HEAD (&chip->msts);return chip; }
@@ -6540,10 +6774,13 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags, .port_bridge_flags = mv88e6xxx_port_bridge_flags, .port_stp_state_set = mv88e6xxx_port_stp_state_set, + .port_mst_state_set = mv88e6xxx_port_mst_state_set, .port_fast_age = mv88e6xxx_port_fast_age, + .port_vlan_fast_age = mv88e6xxx_port_vlan_fast_age, .port_vlan_filtering = mv88e6xxx_port_vlan_filtering, .port_vlan_add = mv88e6xxx_port_vlan_add, .port_vlan_del = mv88e6xxx_port_vlan_del, + .vlan_msti_set = mv88e6xxx_vlan_msti_set, .port_fdb_add = mv88e6xxx_port_fdb_add, .port_fdb_del = mv88e6xxx_port_fdb_del, .port_fdb_dump = mv88e6xxx_port_fdb_dump,
drivers/net/dsa/mv88e6xxx/chip.h +13 -0
@@ -297,6 +297,16 @@ struct mv88e6xxx_region_priv {enum mv88e6xxx_region_id id; }; +struct mv88e6xxx_mst { +struct list_head node; + +refcount_t refcnt; +struct net_device *br; +u16 msti; + +struct mv88e6xxx_stu_entry stu; +}; +struct mv88e6xxx_chip {const struct mv88e6xxx_info *info;
@@ -397,6 +407,9 @@ struct mv88e6xxx_chip {/* devlink regions */ struct devlink_region *regions[_MV88E6XXX_REGION_MAX]; + +/* Bridge MST to SID mappings */ +struct list_head msts; };struct mv88e6xxx_bus_ops {
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 14/14] net: dsa: mv88e6xxx: MST Offloading
Quoted 54 lines · Tobias Waldekranz
Allocate a SID in the STU for each MSTID in use by a bridge and handle the mapping of MSTIDs to VLANs using the SID field of each VTU entry.
Signed-off-by Tobias Waldekranz <[email protected]>--- drivers/net/dsa/mv88e6xxx/chip.c | 251 ++++++++++++++++++++++++++++++- drivers/net/dsa/mv88e6xxx/chip.h | 13 ++ 2 files changed, 257 insertions(+), 7 deletions(-)drivers/net/dsa/mv88e6xxx/chip.c +15
-7@@ -1667,24 +1667,32 @@ static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)return 0 ; } -static void mv88e6xxx_port_fast_age (struct dsa_switch *ds,int port) +static void mv88e6xxx_port_fast_age_fid (struct mv88e6xxx_chip *chip,int port, +u16 fid) { -struct mv88e6xxx_chip *chip = ds->priv;int err; -if (dsa_to_port (ds, port)->lag) +if (dsa_to_port (chip->ds, port)->lag)/* Hardware is incapable of fast-aging a LAG through a * regular ATU move operation. Until we have something * more fancy in place this is a no-op. */ return ; -mv88e6xxx_reg_lock (chip); - err =mv88e6xxx_g1_atu_remove (chip,0 , port, false); -mv88e6xxx_reg_unlock (chip); + err =mv88e6xxx_g1_atu_remove (chip, fid, port, false);if (err) -dev_err (ds->dev,"p%d: failed to flush ATU\n" , port); +dev_err (chip->ds->dev,"p%d: failed to flush ATU (FID %u)\n" , + port, fid); +} + +static void mv88e6xxx_port_fast_age (struct dsa_switch *ds,int port) +{ +struct mv88e6xxx_chip *chip = ds->priv; + +mv88e6xxx_reg_lock (chip); +mv88e6xxx_port_fast_age_fid (chip, port,0 ); +mv88e6xxx_reg_unlock (chip); }static int mv88e6xxx_vtu_setup (struct mv88e6xxx_chip *chip)
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip) · line 1834
Quoted 9 lines
drivers/net/dsa/mv88e6xxx/chip.c +6
-0@@ -1818,6 +1826,159 @@ static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip)return mv88e6xxx_stu_loadpurge (chip, &stu); } +static int mv88e6xxx_sid_get (struct mv88e6xxx_chip *chip,u8 *sid) +{ + DECLARE_BITMAP(busy, MV88E6XXX_N_SID) = { 0 }; +struct mv88e6xxx_mst *mst; + +set_bit (0 , busy);
__set_bit
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip) · line 1838
Quoted 4 lines
drivers/net/dsa/mv88e6xxx/chip.c +4
-0+ +list_for_each_entry (mst, &chip->msts, node) { +set_bit (mst->stu.sid, busy); + }
Up to you, but parentheses are generally not used for single-line blocks.
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip) · line 1851
Quoted 13 lines
drivers/net/dsa/mv88e6xxx/chip.c +13
-0+ + *sid =find_first_zero_bit (busy,MV88E6XXX_N_SID ); + +return (*sid >=mv88e6xxx_max_sid (chip)) ? -ENOSPC :0 ; +} + +static int mv88e6xxx_mst_put (struct mv88e6xxx_chip *chip,u8 sid) +{ +struct mv88e6xxx_mst *mst, *tmp; +int err; + +if (!sid) +return 0 ;
Very minor nitpick: since mv88e6xxx_mst_put already checks this, could you drop the "!sid" check from callers?
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip) · line 1862
Quoted 11 lines
drivers/net/dsa/mv88e6xxx/chip.c +11
-0+ +list_for_each_entry_safe (mst, tmp, &chip->msts, node) { +if (mst->stu.sid != sid) +continue ; + +if (!refcount_dec_and_test (&mst->refcnt)) +return 0 ; + + mst->stu.valid = false; + err =mv88e6xxx_stu_loadpurge (chip, &mst->stu); +if (err)
Should we bother with a refcount_set(&mst->refcount, 1) on error?
Quoted 149 lines
drivers/net/dsa/mv88e6xxx/chip.c +135
-0+return err; + +list_del (&mst->node); +kfree (mst); +return 0 ; + } + +return -ENOENT ; +} + +static int mv88e6xxx_mst_get (struct mv88e6xxx_chip *chip,struct net_device *br, +u16 msti,u8 *sid) +{ +struct mv88e6xxx_mst *mst; +int err, i; + +if (!mv88e6xxx_has_stu (chip)) { + err = -EOPNOTSUPP ; + goto err; + } + +if (!msti) { + *sid =0 ; +return 0 ; + } + +list_for_each_entry (mst, &chip->msts, node) { +if (mst->br == br && mst->msti == msti) { +refcount_inc (&mst->refcnt); + *sid = mst->stu.sid; +return 0 ; + } + } + + err =mv88e6xxx_sid_get (chip, sid); +if (err) + goto err; + + mst =kzalloc (sizeof (*mst),GFP_KERNEL ); +if (!mst) { + err = -ENOMEM ; + goto err; + } + +INIT_LIST_HEAD (&mst->node); +refcount_set (&mst->refcnt,1 ); + mst->br = br; + mst->msti = msti; + mst->stu.valid = true; + mst->stu.sid = *sid; + +/* The bridge starts out all ports in the disabled state. But +* a STU state of disabled means to go by the port-global +* state. So we set all user port's initial state to blocking, +* to match the bridge's behavior. +*/ +for (i =0 ; i <mv88e6xxx_num_ports (chip); i++) + mst->stu.state[i] =dsa_is_user_port (chip->ds, i) ? +MV88E6XXX_PORT_CTL0_STATE_BLOCKING : +MV88E6XXX_PORT_CTL0_STATE_DISABLED ; + + err =mv88e6xxx_stu_loadpurge (chip, &mst->stu); +if (err) + goto err_free; + +list_add_tail (&mst->node, &chip->msts); +return 0 ; + +err_free: +kfree (mst); +err: +return err; +} + +static int mv88e6xxx_port_mst_state_set (struct dsa_switch *ds,int port, +const struct switchdev_mst_state *st) +{ +struct dsa_port *dp =dsa_to_port (ds, port); +struct mv88e6xxx_chip *chip = ds->priv; +struct mv88e6xxx_mst *mst; +u8 state; +int err; + +if (!mv88e6xxx_has_stu (chip)) +return -EOPNOTSUPP ; + +switch (st->state) { +case BR_STATE_DISABLED : +case BR_STATE_BLOCKING : +case BR_STATE_LISTENING : + state =MV88E6XXX_PORT_CTL0_STATE_BLOCKING ; +break ; +case BR_STATE_LEARNING : + state =MV88E6XXX_PORT_CTL0_STATE_LEARNING ; +break ; +case BR_STATE_FORWARDING : + state =MV88E6XXX_PORT_CTL0_STATE_FORWARDING ; +break ; +default : +return -EINVAL ; + } + +list_for_each_entry (mst, &chip->msts, node) { +if (mst->br ==dsa_port_bridge_dev_get (dp) && + mst->msti == st->msti) { +if (mst->stu.state[port] == state) +return 0 ; + + mst->stu.state[port] = state; +mv88e6xxx_reg_lock (chip); + err =mv88e6xxx_stu_loadpurge (chip, &mst->stu); +mv88e6xxx_reg_unlock (chip); +return err; + } + } + +return -ENOENT ; +} +static int mv88e6xxx_port_check_hw_vlan (struct dsa_switch *ds,int port,u16 vid) {@@ -2437,6 +2598,12 @@ static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,if (err)return err; +if (!vlan.valid && vlan.sid) { + err =mv88e6xxx_mst_put (chip, vlan.sid); +if (err) +return err; + } +return mv88e6xxx_g1_atu_remove (chip, vlan.fid, port, false); }@@ -2482,6 +2649,72 @@ static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,return err; } +static void mv88e6xxx_port_vlan_fast_age (struct dsa_switch *ds,int port,u16 vid) +{ +struct mv88e6xxx_chip *chip = ds->priv; +struct mv88e6xxx_vtu_entry vlan; +int err; + +mv88e6xxx_reg_lock (chip); + + err =mv88e6xxx_vtu_get (chip, vid, &vlan); +if (err)
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, · line 2671
Quoted 10 lines
drivers/net/dsa/mv88e6xxx/chip.c +10
-0+ goto unlock; + +mv88e6xxx_port_fast_age_fid (chip, port, vlan.fid); + +unlock: +mv88e6xxx_reg_unlock (chip); + +if (err) +dev_err (ds->dev,"p%d: failed to flush ATU in VID %u\n" , + port, vid);
This error message actually corresponds to an mv88e6xxx_vtu_get() error, so the message is kind of incorrect. mv88e6xxx_port_fast_age_fid(), whose error code isn't propagated here, has its own "failed to flush ATU" error message.
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, · line 2672
Quoted 1 line
drivers/net/dsa/mv88e6xxx/chip.c +1
-0+}
Otherwise this looks pretty good.
Re: [PATCH v3 net-next 14/14] net: dsa: mv88e6xxx: MST Offloading
Quoted 58 lines · Vladimir Oltean
Quoted 57 lines · Tobias Waldekranz
Allocate a SID in the STU for each MSTID in use by a bridge and handle the mapping of MSTIDs to VLANs using the SID field of each VTU entry.
Signed-off-by Tobias Waldekranz <[email protected]>--- drivers/net/dsa/mv88e6xxx/chip.c | 251 ++++++++++++++++++++++++++++++- drivers/net/dsa/mv88e6xxx/chip.h | 13 ++ 2 files changed, 257 insertions(+), 7 deletions(-)drivers/net/dsa/mv88e6xxx/chip.c +15
-7@@ -1667,24 +1667,32 @@ static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)return 0 ; } -static void mv88e6xxx_port_fast_age (struct dsa_switch *ds,int port) +static void mv88e6xxx_port_fast_age_fid (struct mv88e6xxx_chip *chip,int port, +u16 fid) { -struct mv88e6xxx_chip *chip = ds->priv;int err; -if (dsa_to_port (ds, port)->lag) +if (dsa_to_port (chip->ds, port)->lag)/* Hardware is incapable of fast-aging a LAG through a * regular ATU move operation. Until we have something * more fancy in place this is a no-op. */ return ; -mv88e6xxx_reg_lock (chip); - err =mv88e6xxx_g1_atu_remove (chip,0 , port, false); -mv88e6xxx_reg_unlock (chip); + err =mv88e6xxx_g1_atu_remove (chip, fid, port, false);if (err) -dev_err (ds->dev,"p%d: failed to flush ATU\n" , port); +dev_err (chip->ds->dev,"p%d: failed to flush ATU (FID %u)\n" , + port, fid); +} + +static void mv88e6xxx_port_fast_age (struct dsa_switch *ds,int port) +{ +struct mv88e6xxx_chip *chip = ds->priv; + +mv88e6xxx_reg_lock (chip); +mv88e6xxx_port_fast_age_fid (chip, port,0 ); +mv88e6xxx_reg_unlock (chip); }static int mv88e6xxx_vtu_setup (struct mv88e6xxx_chip *chip)@@ -1818,6 +1826,159 @@ static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip)return mv88e6xxx_stu_loadpurge (chip, &stu); }
Quoted 9 lines
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip) · line 1834
Quoted 6 lines
drivers/net/dsa/mv88e6xxx/chip.c +6
-0+static int mv88e6xxx_sid_get (struct mv88e6xxx_chip *chip,u8 *sid) +{ + DECLARE_BITMAP(busy, MV88E6XXX_N_SID) = { 0 }; +struct mv88e6xxx_mst *mst; + +set_bit (0 , busy);
__set_bit
Ack
Quoted 7 lines
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip) · line 1838
Quoted 4 lines
drivers/net/dsa/mv88e6xxx/chip.c +4
-0+ +list_for_each_entry (mst, &chip->msts, node) { +set_bit (mst->stu.sid, busy); + }Up to you, but parentheses are generally not used for single-line blocks.
Ack
Quoted 8 lines
Quoted 8 lines
drivers/net/dsa/mv88e6xxx/chip.c +8
-0+ + *sid =find_first_zero_bit (busy,MV88E6XXX_N_SID ); + +return (*sid >=mv88e6xxx_max_sid (chip)) ? -ENOSPC :0 ; +} + +static int mv88e6xxx_mst_put (struct mv88e6xxx_chip *chip,u8 sid) +{
Quoted 8 lines
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip) · line 1851
Quoted 5 lines
drivers/net/dsa/mv88e6xxx/chip.c +5
-0+struct mv88e6xxx_mst *mst, *tmp; +int err; + +if (!sid) +return 0 ;Very minor nitpick: since
mv88e6xxx_mst_putalready checks this, could you drop the "!sid" check from callers?
Dropping
Quoted 5 lines
Quoted 5 lines
drivers/net/dsa/mv88e6xxx/chip.c +5
-0+ +list_for_each_entry_safe (mst, tmp, &chip->msts, node) { +if (mst->stu.sid != sid) +continue ; +
Quoted 8 lines
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip) · line 1862
Quoted 6 lines
drivers/net/dsa/mv88e6xxx/chip.c +6
-0+if (!refcount_dec_and_test (&mst->refcnt)) +return 0 ; + + mst->stu.valid = false; + err =mv88e6xxx_stu_loadpurge (chip, &mst->stu); +if (err)Should we bother with a
refcount_set(&mst->refcount, 1)on error?
We might as well. Thanks.
Quoted 156 lines
Quoted 156 lines
drivers/net/dsa/mv88e6xxx/chip.c +142
-0+return err; + +list_del (&mst->node); +kfree (mst); +return 0 ; + } + +return -ENOENT ; +} + +static int mv88e6xxx_mst_get (struct mv88e6xxx_chip *chip,struct net_device *br, +u16 msti,u8 *sid) +{ +struct mv88e6xxx_mst *mst; +int err, i; + +if (!mv88e6xxx_has_stu (chip)) { + err = -EOPNOTSUPP ; + goto err; + } + +if (!msti) { + *sid =0 ; +return 0 ; + } + +list_for_each_entry (mst, &chip->msts, node) { +if (mst->br == br && mst->msti == msti) { +refcount_inc (&mst->refcnt); + *sid = mst->stu.sid; +return 0 ; + } + } + + err =mv88e6xxx_sid_get (chip, sid); +if (err) + goto err; + + mst =kzalloc (sizeof (*mst),GFP_KERNEL ); +if (!mst) { + err = -ENOMEM ; + goto err; + } + +INIT_LIST_HEAD (&mst->node); +refcount_set (&mst->refcnt,1 ); + mst->br = br; + mst->msti = msti; + mst->stu.valid = true; + mst->stu.sid = *sid; + +/* The bridge starts out all ports in the disabled state. But +* a STU state of disabled means to go by the port-global +* state. So we set all user port's initial state to blocking, +* to match the bridge's behavior. +*/ +for (i =0 ; i <mv88e6xxx_num_ports (chip); i++) + mst->stu.state[i] =dsa_is_user_port (chip->ds, i) ? +MV88E6XXX_PORT_CTL0_STATE_BLOCKING : +MV88E6XXX_PORT_CTL0_STATE_DISABLED ; + + err =mv88e6xxx_stu_loadpurge (chip, &mst->stu); +if (err) + goto err_free; + +list_add_tail (&mst->node, &chip->msts); +return 0 ; + +err_free: +kfree (mst); +err: +return err; +} + +static int mv88e6xxx_port_mst_state_set (struct dsa_switch *ds,int port, +const struct switchdev_mst_state *st) +{ +struct dsa_port *dp =dsa_to_port (ds, port); +struct mv88e6xxx_chip *chip = ds->priv; +struct mv88e6xxx_mst *mst; +u8 state; +int err; + +if (!mv88e6xxx_has_stu (chip)) +return -EOPNOTSUPP ; + +switch (st->state) { +case BR_STATE_DISABLED : +case BR_STATE_BLOCKING : +case BR_STATE_LISTENING : + state =MV88E6XXX_PORT_CTL0_STATE_BLOCKING ; +break ; +case BR_STATE_LEARNING : + state =MV88E6XXX_PORT_CTL0_STATE_LEARNING ; +break ; +case BR_STATE_FORWARDING : + state =MV88E6XXX_PORT_CTL0_STATE_FORWARDING ; +break ; +default : +return -EINVAL ; + } + +list_for_each_entry (mst, &chip->msts, node) { +if (mst->br ==dsa_port_bridge_dev_get (dp) && + mst->msti == st->msti) { +if (mst->stu.state[port] == state) +return 0 ; + + mst->stu.state[port] = state; +mv88e6xxx_reg_lock (chip); + err =mv88e6xxx_stu_loadpurge (chip, &mst->stu); +mv88e6xxx_reg_unlock (chip); +return err; + } + } + +return -ENOENT ; +} +static int mv88e6xxx_port_check_hw_vlan (struct dsa_switch *ds,int port,u16 vid) {@@ -2437,6 +2598,12 @@ static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,if (err)return err; +if (!vlan.valid && vlan.sid) { + err =mv88e6xxx_mst_put (chip, vlan.sid); +if (err) +return err; + } +return mv88e6xxx_g1_atu_remove (chip, vlan.fid, port, false); }@@ -2482,6 +2649,72 @@ static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,return err; } +static void mv88e6xxx_port_vlan_fast_age (struct dsa_switch *ds,int port,u16 vid) +{ +struct mv88e6xxx_chip *chip = ds->priv; +struct mv88e6xxx_vtu_entry vlan; +int err; + +mv88e6xxx_reg_lock (chip); + + err =mv88e6xxx_vtu_get (chip, vid, &vlan); +if (err) + goto unlock; + +mv88e6xxx_port_fast_age_fid (chip, port, vlan.fid); + +unlock: +mv88e6xxx_reg_unlock (chip); +
Quoted 8 lines
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, · line 2671
Quoted 3 lines
drivers/net/dsa/mv88e6xxx/chip.c +3
-0+if (err) +dev_err (ds->dev,"p%d: failed to flush ATU in VID %u\n" , + port, vid);This error message actually corresponds to an
mv88e6xxx_vtu_get()error, so the message is kind of incorrect.mv88e6xxx_port_fast_age_fid(), whose error code isn't propagated here, has its own "failed to flush ATU" error message.
Not sure I agree. If this fails, the symptom will be lingering dynamic entries in the affected VLAN. In that case I think the current message, or something similar, will make it as easy as possible to establish a correlation.
Yes, it failed because the VTU get op failed, but that is more of an internal affair in the driver.
Anyway, it's a moot point, because I think we should just allow the error to bubble up to userspace instead - as you suggested in 11/14.
Quoted 3 lines
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, · line 2672
Quoted 1 line
drivers/net/dsa/mv88e6xxx/chip.c +1
-0+}Otherwise this looks pretty good.
Careful now, don't spoil me :)