net: dsa: explicit programmation of VLAN on CPU ports
Subsystems (3)
cover net: dsa: explicit programmation of VLAN on CPU ports
When a VLAN is programmed on a user port, every switch of the fabric also program the CPU ports and the DSA links as part of the VLAN. To do that, DSA makes use of bitmaps to prepare all members of a VLAN.
While this is expected for DSA links which are used as conduit between interconnected switches, only the dedicated CPU port of the slave must be programmed, not all CPU ports of the fabric. This may also cause problems in other corners of DSA such as the tag_8021q.c driver, which needs to program its ports manually, CPU port included.
We need the dsa_port_vlan_{add,del} functions and its dsa_port_vid_{add,del} variants to simply trigger the VLAN programmation without any logic in them, but they may currently skip the operation based on the bridge device state.
This patchset gets rid of the bitmap operations, and moves the bridge device check as well as the explicit programmation of CPU ports where they belong, in the slave code.
While at it, clear the VLAN flags before programming a CPU port, as it doesn't make sense to forward the PVID flag for example for such ports.
Vivien Didelot (6):
net: dsa: remove bitmap operations
net: dsa: do not skip -EOPNOTSUPP in dsa_port_vid_add
net: dsa: add slave VLAN helpers
net: dsa: check bridge VLAN in slave operations
net: dsa: program VLAN on CPU port from slave
net: dsa: clear VLAN flags for CPU port
include/net/dsa.h | 3 -- net/dsa/dsa2.c | 14 ----- net/dsa/port.c | 14 ++--- net/dsa/slave.c | 79 +++++++++++++++++++++++---- net/dsa/switch.c | 135 +++++++++++++++++++++------------------------- 5 files changed, 136 insertions(+), 109 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/6 net: dsa: remove bitmap operations
The bitmap operations were introduced to simplify the switch drivers in the future, since most of them could implement the common VLAN and MDB operations (add, del, dump) with simple functions taking all target ports at once, and thus limiting the number of hardware accesses.
Programming an MDB or VLAN this way in a single operation would clearly simplify the drivers a lot but would require a new get-set interface in DSA. The usage of such bitmap from the stack also raised concerned in the past, leading to the dynamic allocation of a new ds->_bitmap member in the dsa_switch structure. So let's get rid of them for now.
This commit nicely wraps the ds->ops->port_{mdb,vlan}_{prepare,add} switch operations into new dsa_switch_{mdb,vlan}_{prepare,add} variants not using any bitmap argument anymore.
New dsa_switch_{mdb,vlan}_match helpers have been introduced to make clear which local port of a switch must be programmed with the target object. While the targeted user port is an obvious candidate, the DSA links must also be programmed, as well as the CPU port for VLANs.
While at it, also remove local variables that are only used once.
--- include/net/dsa.h | 3 -- net/dsa/dsa2.c | 14 ----- net/dsa/switch.c | 132 +++++++++++++++++++++------------------------- 3 files changed, 59 insertions(+), 90 deletions(-)
include/net/dsa.h +0 -3
@@ -275,9 +275,6 @@ struct dsa_switch {*/ bool vlan_filtering; -unsigned long *bitmap; -unsigned long _bitmap; -/* Dynamically allocated ports, keep last */ size_t num_ports;struct dsa_port ports[];
net/dsa/dsa2.c +0 -14
@@ -834,20 +834,6 @@ struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n)if (!ds)return NULL ; -/* We avoid allocating memory outside dsa_switch -* if it is not needed. -*/ -if (n <=sizeof (ds->_bitmap) *8 ) { - ds->bitmap = &ds->_bitmap; - }else { - ds->bitmap =devm_kcalloc (dev, -BITS_TO_LONGS (n), -sizeof (unsigned long ), -GFP_KERNEL ); -if (unlikely (!ds->bitmap)) -return NULL ; - } - ds->dev = dev; ds->num_ports = n;
net/dsa/switch.c +59 -73
201 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 2/6 net: dsa: do not skip -EOPNOTSUPP in dsa_port_vid_add
In reply to Vivien DidelotCurrently dsa_port_vid_add returns 0 if the switch returns -EOPNOTSUPP.
This function is used in the tag_8021q.c code to offload the PVID of ports, which would simply not work if .port_vlan_add is not supported by the underlying switch.
Do not skip -EOPNOTSUPP in dsa_port_vid_add but only when necessary, that is to say in dsa_slave_vlan_rx_add_vid.
--- net/dsa/port.c | 4 ++-- net/dsa/slave.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-)
net/dsa/port.c +2 -2
@@ -382,8 +382,8 @@ int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags) trans.ph_prepare = true; err =dsa_port_vlan_add (dp, &vlan, &trans); -if (err == -EOPNOTSUPP ) -return 0 ; +if (err) +return err; trans.ph_prepare = false;return dsa_port_vlan_add (dp, &vlan, &trans);
net/dsa/slave.c +5 -2
@@ -1082,8 +1082,11 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,return -EBUSY ; } -/* This API only allows programming tagged, non-PVID VIDs */ -return dsa_port_vid_add (dp, vid,0 ); + ret =dsa_port_vid_add (dp, vid,0 ); +if (ret && ret != -EOPNOTSUPP ) +return ret; + +return 0 ; } static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
Signature · 1 line
2.23.0
Vladimir Oltean
maintainerRe: [PATCH net-next 2/6] net: dsa: do not skip -EOPNOTSUPP in dsa_port_vid_add
Hi Vivien,
Quoted 9 lines · Vivien Didelot
Currently
dsa_port_vid_addreturns 0 if the switch returns-EOPNOTSUPP.This function is used in the
tag_8021q.ccode to offload the PVID of ports, which would simply not work if .port_vlan_add is not supported by the underlying switch.Do not skip
-EOPNOTSUPPindsa_port_vid_addbut only when necessary, that is to say indsa_slave_vlan_rx_add_vid.
Do you know why Florian suppressed -EOPNOTSUPP in 061f6a505ac3 ("net: dsa: Add ndo_vlan_rx_{add, kill}_vid implementation")? I forced a return value of -EOPNOTSUPP here and when I create a VLAN sub-interface nothing breaks, it just says:
RTNETLINK answers: Operation not supported
which IMO is expected.
Quoted 30 lines
Signed-off-by Vivien Didelot <[email protected]>--- net/dsa/port.c | 4 ++-- net/dsa/slave.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-)net/dsa/port.c +2
-2@@ -382,8 +382,8 @@ int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags) trans.ph_prepare = true; err =dsa_port_vlan_add (dp, &vlan, &trans); -if (err == -EOPNOTSUPP ) -return 0 ; +if (err) +return err; trans.ph_prepare = false;return dsa_port_vlan_add (dp, &vlan, &trans);net/dsa/slave.c +0
-0@@ -1082,8 +1082,11 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,return -EBUSY ; }
net/dsa/slave.c static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto, · line 1092
Quoted 10 lines
net/dsa/slave.c +5
-2-/* This API only allows programming tagged, non-PVID VIDs */ -return dsa_port_vid_add (dp, vid,0 ); + ret =dsa_port_vid_add (dp, vid,0 ); +if (ret && ret != -EOPNOTSUPP ) +return ret; + +return 0 ; } static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
Regards,
-Vladimir
Re: [PATCH net-next 2/6] net: dsa: do not skip -EOPNOTSUPP in dsa_port_vid_add
Hi Vladimir,
Quoted 13 lines · Vladimir Oltean
Hi Vivien,
Quoted 9 lines · Vivien Didelot
Currently
dsa_port_vid_addreturns 0 if the switch returns-EOPNOTSUPP.This function is used in the
tag_8021q.ccode to offload the PVID of ports, which would simply not work if .port_vlan_add is not supported by the underlying switch.Do not skip
-EOPNOTSUPPindsa_port_vid_addbut only when necessary, that is to say indsa_slave_vlan_rx_add_vid.
Quoted 6 lines
Do you know why Florian suppressed
-EOPNOTSUPPin061f6a505ac3("net:
dsa: Add ndo_vlan_rx_{add, kill}_vid implementation")?
I forced a return value of-EOPNOTSUPPhere and when I create a VLAN sub-interface nothing breaks, it just says:
RTNETLINK answers: Operation not supported
which IMO is expected.
I do not know what you mean. This patch does not change the behavior of dsa_slave_vlan_rx_add_vid, which returns 0 if -EOPNOTSUPP is caught.
Thanks,
Vivien
Vladimir Oltean
maintainerRe: [PATCH net-next 2/6] net: dsa: do not skip -EOPNOTSUPP in dsa_port_vid_add
Quoted 24 lines · Vivien Didelot
Hi Vladimir,
Quoted 13 lines · Vladimir Oltean
Hi Vivien,
Quoted 9 lines · Vivien Didelot
Currently
dsa_port_vid_addreturns 0 if the switch returns-EOPNOTSUPP.This function is used in the
tag_8021q.ccode to offload the PVID of ports, which would simply not work if .port_vlan_add is not supported by the underlying switch.Do not skip
-EOPNOTSUPPindsa_port_vid_addbut only when necessary, that is to say indsa_slave_vlan_rx_add_vid.Quoted 6 lines
Do you know why Florian suppressed
-EOPNOTSUPPin061f6a505ac3("net:
dsa: Add ndo_vlan_rx_{add, kill}_vid implementation")?
I forced a return value of-EOPNOTSUPPhere and when I create a VLAN sub-interface nothing breaks, it just says:
RTNETLINK answers: Operation not supported
which IMO is expected.
Quoted 3 lines
I do not know what you mean. This patch does not change the behavior of
dsa_slave_vlan_rx_add_vid, which returns 0 if-EOPNOTSUPPis caught.
Yes, but what's wrong with just forwarding -EOPNOTSUPP?
Quoted 4 lines
Thanks,
Vivien
Re: [PATCH net-next 2/6] net: dsa: do not skip -EOPNOTSUPP in dsa_port_vid_add
Quoted 25 lines · Vladimir Oltean
Quoted 24 lines · Vivien Didelot
Hi Vladimir,
Quoted 19 lines · Vladimir Oltean
Hi Vivien,
Quoted 9 lines · Vivien Didelot
Currently
dsa_port_vid_addreturns 0 if the switch returns-EOPNOTSUPP.This function is used in the
tag_8021q.ccode to offload the PVID of ports, which would simply not work if .port_vlan_add is not supported by the underlying switch.Do not skip
-EOPNOTSUPPindsa_port_vid_addbut only when necessary, that is to say indsa_slave_vlan_rx_add_vid.Do you know why Florian suppressed
-EOPNOTSUPPin061f6a505ac3("net:
dsa: Add ndo_vlan_rx_{add, kill}_vid implementation")?
I forced a return value of-EOPNOTSUPPhere and when I create a VLAN sub-interface nothing breaks, it just says:
RTNETLINK answers: Operation not supported
which IMO is expected.
Quoted 5 lines
Quoted 3 lines
I do not know what you mean. This patch does not change the behavior of
dsa_slave_vlan_rx_add_vid, which returns 0 if-EOPNOTSUPPis caught.Yes, but what's wrong with just forwarding
-EOPNOTSUPP?
It makes us fail adding the VLAN to the slave network device, which sounds silly, if we can't offload it in HW, that's fine, we can still do a SW VLAN instead, see net/8021q/vlan_core.c::vlan_add_rx_filter_info().
Maybe a more correct solution is to set the NETIF_F_HW_VLAN_CTAG_FILTER feature bit only if we have the ability to offload, now that I think about it. Would you want me to cook a patch doing that?
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [PATCH net-next 2/6] net: dsa: do not skip -EOPNOTSUPP in dsa_port_vid_add
Hi Florian,
Quoted 33 lines · Florian Fainelli
Quoted 25 lines · Vladimir Oltean
Quoted 24 lines · Vivien Didelot
Hi Vladimir,
Quoted 19 lines · Vladimir Oltean
Hi Vivien,
Quoted 9 lines · Vivien Didelot
Currently
dsa_port_vid_addreturns 0 if the switch returns-EOPNOTSUPP.This function is used in the
tag_8021q.ccode to offload the PVID of ports, which would simply not work if .port_vlan_add is not supported by the underlying switch.Do not skip
-EOPNOTSUPPindsa_port_vid_addbut only when necessary, that is to say indsa_slave_vlan_rx_add_vid.Do you know why Florian suppressed
-EOPNOTSUPPin061f6a505ac3("net:
dsa: Add ndo_vlan_rx_{add, kill}_vid implementation")?
I forced a return value of-EOPNOTSUPPhere and when I create a VLAN sub-interface nothing breaks, it just says:
RTNETLINK answers: Operation not supported
which IMO is expected.Quoted 5 lines
Quoted 3 lines
I do not know what you mean. This patch does not change the behavior of
dsa_slave_vlan_rx_add_vid, which returns 0 if-EOPNOTSUPPis caught.Yes, but what's wrong with just forwarding
-EOPNOTSUPP?
Quoted 7 lines
It makes us fail adding the VLAN to the slave network device, which sounds silly, if we can't offload it in HW, that's fine, we can still do a SW VLAN instead, see net/8021q/vlan_core.c::vlan_add_rx_filter_info().
Maybe a more correct solution is to set the
NETIF_F_HW_VLAN_CTAG_FILTERfeature bit only if we have the ability to offload, now that I think about it. Would you want me to cook a patch doing that?
sja1105 doesn't support offloading NETIF_F_HW_VLAN_CTAG_FILTER even though it does support programming VLANs.
Adding an offloaded VLAN sub-interface on a standalone switch port (vlan_filtering=0, uses dsa_8021q) would make the driver insert a VLAN entry whilst the TPID is ETH_P_DSA_8021Q.
Maybe just let the driver set the netdev features, similar to how it does for the number of TX queues?
Quoted 2 lines
--
Florian
Regards,
-Vladimir
Re: [PATCH net-next 2/6] net: dsa: do not skip -EOPNOTSUPP in dsa_port_vid_add
Quoted 40 lines · Vladimir Oltean
Hi Florian,
Quoted 37 lines · Florian Fainelli
Quoted 25 lines · Vladimir Oltean
Quoted 24 lines · Vivien Didelot
Hi Vladimir,
Quoted 19 lines · Vladimir Oltean
Hi Vivien,
Quoted 9 lines · Vivien Didelot
Currently
dsa_port_vid_addreturns 0 if the switch returns-EOPNOTSUPP.This function is used in the
tag_8021q.ccode to offload the PVID of ports, which would simply not work if .port_vlan_add is not supported by the underlying switch.Do not skip
-EOPNOTSUPPindsa_port_vid_addbut only when necessary, that is to say indsa_slave_vlan_rx_add_vid.Do you know why Florian suppressed
-EOPNOTSUPPin061f6a505ac3("net:
dsa: Add ndo_vlan_rx_{add, kill}_vid implementation")?
I forced a return value of-EOPNOTSUPPhere and when I create a VLAN sub-interface nothing breaks, it just says:
RTNETLINK answers: Operation not supported
which IMO is expected.Quoted 5 lines
Quoted 3 lines
I do not know what you mean. This patch does not change the behavior of
dsa_slave_vlan_rx_add_vid, which returns 0 if-EOPNOTSUPPis caught.Yes, but what's wrong with just forwarding
-EOPNOTSUPP?It makes us fail adding the VLAN to the slave network device, which sounds silly, if we can't offload it in HW, that's fine, we can still do a SW VLAN instead, see net/8021q/vlan_core.c::vlan_add_rx_filter_info().
Quoted 6 lines
Quoted 3 lines
Maybe a more correct solution is to set the
NETIF_F_HW_VLAN_CTAG_FILTERfeature bit only if we have the ability to offload, now that I think about it. Would you want me to cook a patch doing that?sja1105 doesn't support offloading
NETIF_F_HW_VLAN_CTAG_FILTEReven though it does support programming VLANs.
The additional of the ndo_vlan_rx_{add,kill}_vid() is such that standalone DSA ports continue to work while there is a bridge with vlan_filtering=1 spanning other ports. In order for that ndo operation to be called, we need to advertise the NETIF_F_HW_VLAN_CTAG_FILTER feature.
Quoted 5 lines
Adding an offloaded VLAN sub-interface on a standalone switch port (vlan_filtering=0, uses
dsa_8021q) would make the driver insert a VLAN entry whilst the TPID isETH_P_DSA_8021Q.
Maybe just let the driver set the netdev features, similar to how it does for the number of TX queues?
Why should we bend the framework because sja1105 and dsa_8021q are special? Let me counter the argument: if the tagging is DSA_8021Q, why not clear the feature then?
Signature · 1 line
Florian
PATCH 3/6 net: dsa: add slave VLAN helpers
In reply to Vivien DidelotAdd dsa_slave_vlan_add and dsa_slave_vlan_del helpers to handle SWITCHDEV_OBJ_ID_PORT_VLAN switchdev objects. Also copy the switchdev_obj_port_vlan structure on add since we will modify it in future patches.
--- net/dsa/slave.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-)
net/dsa/slave.c +33 -7
@@ -312,6 +312,26 @@ static int dsa_slave_port_attr_set(struct net_device *dev,return ret; } +static int dsa_slave_vlan_add (struct net_device *dev, +const struct switchdev_obj *obj, +struct switchdev_trans *trans) +{ +struct dsa_port *dp =dsa_slave_to_port (dev); +struct switchdev_obj_port_vlan vlan; +int err; + +if (obj->orig_dev != dev) +return -EOPNOTSUPP ; + + vlan = *SWITCHDEV_OBJ_PORT_VLAN (obj); + + err =dsa_port_vlan_add (dp, &vlan, trans); +if (err) +return err; + +return 0 ; +} + static int dsa_slave_port_obj_add(struct net_device *dev, const struct switchdev_obj *obj, struct switchdev_trans *trans,
@@ -339,10 +359,7 @@ static int dsa_slave_port_obj_add(struct net_device *dev, trans);break ;case SWITCHDEV_OBJ_ID_PORT_VLAN : -if (obj->orig_dev != dev) -return -EOPNOTSUPP ; - err =dsa_port_vlan_add (dp,SWITCHDEV_OBJ_PORT_VLAN (obj), - trans); + err =dsa_slave_vlan_add (dev, obj, trans);break ;default : err = -EOPNOTSUPP ;
@@ -352,6 +369,17 @@ static int dsa_slave_port_obj_add(struct net_device *dev,return err; } +static int dsa_slave_vlan_del (struct net_device *dev, +const struct switchdev_obj *obj) +{ +struct dsa_port *dp =dsa_slave_to_port (dev); + +if (obj->orig_dev != dev) +return -EOPNOTSUPP ; + +return dsa_port_vlan_del (dp,SWITCHDEV_OBJ_PORT_VLAN (obj)); +} +static int dsa_slave_port_obj_del (struct net_device *dev,const struct switchdev_obj *obj) {
@@ -371,9 +399,7 @@ static int dsa_slave_port_obj_del(struct net_device *dev, err =dsa_port_mdb_del (dp->cpu_dp,SWITCHDEV_OBJ_PORT_MDB (obj));break ;case SWITCHDEV_OBJ_ID_PORT_VLAN : -if (obj->orig_dev != dev) -return -EOPNOTSUPP ; - err =dsa_port_vlan_del (dp,SWITCHDEV_OBJ_PORT_VLAN (obj)); + err =dsa_slave_vlan_del (dev, obj);break ;default : err = -EOPNOTSUPP ;
Signature · 1 line
2.23.0
PATCH 4/6 net: dsa: check bridge VLAN in slave operations
In reply to Vivien DidelotThe bridge VLANs are not offloaded by dsa_port_vlan_* if the port is not bridged or if its bridge is not VLAN aware.
This is a good thing but other corners of DSA, such as the tag_8021q driver, may need to program VLANs regardless the bridge state.
And also because bridge_dev is specific to user ports anyway, move these checks were it belongs, one layer up in the slave code.
--- net/dsa/port.c | 10 ++-------- net/dsa/slave.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-)
net/dsa/port.c +2 -8
@@ -348,10 +348,7 @@ int dsa_port_vlan_add(struct dsa_port *dp, .vlan = vlan, }; -if (!dp->bridge_dev ||br_vlan_enabled (dp->bridge_dev)) -return dsa_port_notify (dp,DSA_NOTIFIER_VLAN_ADD , &info); - -return 0 ; +return dsa_port_notify (dp,DSA_NOTIFIER_VLAN_ADD , &info); } int dsa_port_vlan_del(struct dsa_port *dp,
@@ -363,10 +360,7 @@ int dsa_port_vlan_del(struct dsa_port *dp, .vlan = vlan, }; -if (!dp->bridge_dev ||br_vlan_enabled (dp->bridge_dev)) -return dsa_port_notify (dp,DSA_NOTIFIER_VLAN_DEL , &info); - -return 0 ; +return dsa_port_notify (dp,DSA_NOTIFIER_VLAN_DEL , &info); }int dsa_port_vid_add (struct dsa_port *dp,u16 vid,u16 flags)
net/dsa/slave.c +12 -0
@@ -323,6 +323,9 @@ static int dsa_slave_vlan_add(struct net_device *dev,if (obj->orig_dev != dev)return -EOPNOTSUPP ; +if (dp->bridge_dev && !br_vlan_enabled (dp->bridge_dev)) +return 0 ; + vlan = *SWITCHDEV_OBJ_PORT_VLAN (obj); err =dsa_port_vlan_add (dp, &vlan, trans);
@@ -377,6 +380,9 @@ static int dsa_slave_vlan_del(struct net_device *dev,if (obj->orig_dev != dev)return -EOPNOTSUPP ; +if (dp->bridge_dev && !br_vlan_enabled (dp->bridge_dev)) +return 0 ; +return dsa_port_vlan_del (dp,SWITCHDEV_OBJ_PORT_VLAN (obj)); }
@@ -1099,6 +1105,9 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,* need to emulate the switchdev prepare + commit phase. */ if (dp->bridge_dev) { +if (!br_vlan_enabled (dp->bridge_dev)) +return 0 ; +/* br_vlan_get_info() returns -EINVAL or -ENOENT if the * device, respectively the VID is not found, returning * 0 means success, which is a failure for us here.
@@ -1126,6 +1135,9 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,* need to emulate the switchdev prepare + commit phase. */ if (dp->bridge_dev) { +if (!br_vlan_enabled (dp->bridge_dev)) +return 0 ; +/* br_vlan_get_info() returns -EINVAL or -ENOENT if the * device, respectively the VID is not found, returning * 0 means success, which is a failure for us here.
Signature · 1 line
2.23.0
PATCH 5/6 net: dsa: program VLAN on CPU port from slave
In reply to Vivien DidelotDSA currently programs a VLAN on the CPU port implicitly after the related notifier is received by a switch.
While we still need to do this transparent programmation of the DSA links in the fabric, programming the CPU port this way may cause problems in some corners such as the tag_8021q driver.
Because the dedicated CPU port is specific to a slave, make their programmation explicit a few layers up, in the slave code.
Note that technically, DSA links have a dedicated CPU port as well, but since they are only used as conduit between interconnected switches of a fabric, programming them transparently this way is fine.
--- net/dsa/slave.c | 14 ++++++++++++++ net/dsa/switch.c | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-)
net/dsa/slave.c +14 -0
@@ -332,6 +332,10 @@ static int dsa_slave_vlan_add(struct net_device *dev,if (err)return err; + err =dsa_port_vlan_add (dp->cpu_dp, &vlan, trans); +if (err) +return err; +return 0 ; }
@@ -383,6 +387,9 @@ static int dsa_slave_vlan_del(struct net_device *dev,if (dp->bridge_dev && !br_vlan_enabled (dp->bridge_dev))return 0 ; +/* Do not deprogram the CPU port as it may be shared with other user +* ports which can be members of this VLAN as well. +*/ return dsa_port_vlan_del (dp,SWITCHDEV_OBJ_PORT_VLAN (obj)); }
@@ -1121,6 +1128,10 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,if (ret && ret != -EOPNOTSUPP )return ret; + ret =dsa_port_vid_add (dp->cpu_dp, vid,0 ); +if (ret && ret != -EOPNOTSUPP ) +return ret; +return 0 ; }
@@ -1151,6 +1162,9 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,if (ret == -EOPNOTSUPP ) ret =0 ; +/* Do not deprogram the CPU port as it may be shared with other user +* ports which can be members of this VLAN as well. +*/ return ret; }
net/dsa/switch.c +4 -1
@@ -232,7 +232,7 @@ static bool dsa_switch_vlan_match(struct dsa_switch *ds, int port,if (ds->index == info->sw_index && port == info->port)return true; -if (dsa_is_cpu_port (ds, port) ||dsa_is_dsa_port (ds, port)) +if (dsa_is_dsa_port (ds, port))return true;return false;
@@ -288,6 +288,9 @@ static int dsa_switch_vlan_del(struct dsa_switch *ds,if (ds->index == info->sw_index)return ds->ops->port_vlan_del (ds, info->port, info->vlan); +/* Do not deprogram the DSA links as they may be used as conduit +* for other VLAN members in the fabric. +*/ return 0 ; }
Signature · 1 line
2.23.0
Vladimir Oltean
maintainerRe: [PATCH net-next 5/6] net: dsa: program VLAN on CPU port from slave
Quoted 37 lines · Vivien Didelot
DSA currently programs a VLAN on the CPU port implicitly after the related notifier is received by a switch.
While we still need to do this transparent programmation of the DSA links in the fabric, programming the CPU port this way may cause problems in some corners such as the
tag_8021qdriver.Because the dedicated CPU port is specific to a slave, make their programmation explicit a few layers up, in the slave code.
Note that technically, DSA links have a dedicated CPU port as well, but since they are only used as conduit between interconnected switches of a fabric, programming them transparently this way is fine.
Signed-off-by Vivien Didelot <[email protected]>--- net/dsa/slave.c | 14 ++++++++++++++ net/dsa/switch.c | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-)net/dsa/slave.c +4
-0@@ -332,6 +332,10 @@ static int dsa_slave_vlan_add(struct net_device *dev,if (err)return err; + err =dsa_port_vlan_add (dp->cpu_dp, &vlan, trans); +if (err) +return err; +return 0 ; }
net/dsa/slave.c static int dsa_slave_vlan_del(struct net_device *dev, · line 392
Quoted 6 lines
net/dsa/slave.c +3
-0@@ -383,6 +387,9 @@ static int dsa_slave_vlan_del(struct net_device *dev,if (dp->bridge_dev && !br_vlan_enabled (dp->bridge_dev))return 0 ; +/* Do not deprogram the CPU port as it may be shared with other user +* ports which can be members of this VLAN as well. +*/
+1 for the comments, the deletion of dp->cpu_dp is less likely to get patched into the code in the future now.
net/dsa/slave.c static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto, · line 1134
Quoted 11 lines
net/dsa/slave.c +4
-0return dsa_port_vlan_del (dp,SWITCHDEV_OBJ_PORT_VLAN (obj)); }@@ -1121,6 +1128,10 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,if (ret && ret != -EOPNOTSUPP )return ret; + ret =dsa_port_vid_add (dp->cpu_dp, vid,0 ); +if (ret && ret != -EOPNOTSUPP ) +return ret; +
I think it's worth understanding what the EOPNOTSUPP -> 0 is avoiding.
Quoted 18 lines
net/dsa/slave.c +3
-0return 0 ; }@@ -1151,6 +1162,9 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,if (ret == -EOPNOTSUPP ) ret =0 ; +/* Do not deprogram the CPU port as it may be shared with other user +* ports which can be members of this VLAN as well. +*/ return ret; }net/dsa/switch.c +0
-0
net/dsa/switch.c static bool dsa_switch_vlan_match(struct dsa_switch *ds, int port, · line 235
Quoted 5 lines
net/dsa/switch.c +1
-1@@ -232,7 +232,7 @@ static bool dsa_switch_vlan_match(struct dsa_switch *ds, int port,if (ds->index == info->sw_index && port == info->port)return true; -if (dsa_is_cpu_port (ds, port) ||dsa_is_dsa_port (ds, port)) +if (dsa_is_dsa_port (ds, port))
Much better, thank you.
Quoted 16 lines
net/dsa/switch.c +3
-1return true;return false;@@ -288,6 +288,9 @@ static int dsa_switch_vlan_del(struct dsa_switch *ds,if (ds->index == info->sw_index)return ds->ops->port_vlan_del (ds, info->port, info->vlan); +/* Do not deprogram the DSA links as they may be used as conduit +* for other VLAN members in the fabric. +*/ return 0 ; } --2.23.0
PATCH 6/6 net: dsa: clear VLAN flags for CPU port
In reply to Vivien DidelotWhen the bridge offloads a VLAN on a slave port, we also need to program its dedicated CPU port as a member of the VLAN.
Drivers may handle the CPU port's membership as they want. For example, Marvell as a special "Unmodified" mode to pass frames as is through such ports.
Even though DSA expects the drivers to handle the CPU port membership, they are unlikely to program such VLANs untagged, and certainly not as PVID. This patch clears the VLAN flags before programming the CPU port.
--- net/dsa/slave.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/dsa/slave.c +6 -0
@@ -332,6 +332,12 @@ static int dsa_slave_vlan_add(struct net_device *dev,if (err)return err; +/* We need the dedicated CPU port to be a member of the VLAN as well. +* Even though drivers often handle CPU membership in special ways, +* CPU ports are likely to be tagged, so clear the VLAN flags. +*/ + vlan.flags =0 ; + err =dsa_port_vlan_add (dp->cpu_dp, &vlan, trans);if (err)return err;
Signature · 1 line
2.23.0
Vladimir Oltean
maintainerRe: [PATCH net-next 6/6] net: dsa: clear VLAN flags for CPU port
Quoted 22 lines · Vivien Didelot
When the bridge offloads a VLAN on a slave port, we also need to program its dedicated CPU port as a member of the VLAN.
Drivers may handle the CPU port's membership as they want. For example, Marvell as a special "Unmodified" mode to pass frames as is through such ports.
Even though DSA expects the drivers to handle the CPU port membership, they are unlikely to program such VLANs untagged, and certainly not as PVID. This patch clears the VLAN flags before programming the CPU port.
Signed-off-by Vivien Didelot <[email protected]>Suggested-by Vladimir Oltean <[email protected]>--- net/dsa/slave.c | 6 ++++++ 1 file changed, 6 insertions(+)net/dsa/slave.c +0
-0
net/dsa/slave.c static int dsa_slave_vlan_add(struct net_device *dev, · line 340
Quoted 9 lines
net/dsa/slave.c +6
-0@@ -332,6 +332,12 @@ static int dsa_slave_vlan_add(struct net_device *dev,if (err)return err; +/* We need the dedicated CPU port to be a member of the VLAN as well. +* Even though drivers often handle CPU membership in special ways, +* CPU ports are likely to be tagged, so clear the VLAN flags. +*/ + vlan.flags =0 ; +
How does this work exactly?
If I run 'sudo bridge vlan add vid 1 dev swp4 pvid untagged', then the CPU port starts sending VLAN-tagged traffic. I see this in tcpdump on the DSA master port, but if I tcpdump on swp4, the VLAN tag is removed. Who is doing that?
Quoted 4 lines
net/dsa/slave.c +0
-0err =dsa_port_vlan_add (dp->cpu_dp, &vlan, trans);if (err)return err;
Re: [PATCH net-next 6/6] net: dsa: clear VLAN flags for CPU port
Quoted 31 lines · Vladimir Oltean
Quoted 30 lines · Vivien Didelot
When the bridge offloads a VLAN on a slave port, we also need to program its dedicated CPU port as a member of the VLAN.
Drivers may handle the CPU port's membership as they want. For example, Marvell as a special "Unmodified" mode to pass frames as is through such ports.
Even though DSA expects the drivers to handle the CPU port membership, they are unlikely to program such VLANs untagged, and certainly not as PVID. This patch clears the VLAN flags before programming the CPU port.
Signed-off-by Vivien Didelot <[email protected]>Suggested-by Vladimir Oltean <[email protected]>---
net/dsa/slave.c| 6 ++++++1 file changed, 6 insertions(+)net/dsa/slave.c +0
-0@@ -332,6 +332,12 @@ static int dsa_slave_vlan_add(struct net_device *dev, if (err) return err;+ /* We need the dedicated CPU port to be a member of the VLAN as well.
+ * Even though drivers often handle CPU membership in special ways, + * CPU ports are likely to be tagged, so clear the VLAN flags. + */
Quoted 8 lines
Quoted 2 lines
+ vlan.flags = 0;
+How does this work exactly?
If I run 'sudo bridge vlan add vid 1 dev swp4 pvid untagged', then the CPU port starts sending VLAN-tagged traffic. I see this in tcpdump on the DSA master port, but if I tcpdump on swp4, the VLAN tag is removed. Who is doing that?
If vlan.flags = 0, then it does not have either BRIDGE_VLAN_INFO_PVID or BRIDGE_VLAN_INFO_UNTAGGED which means the VLAN should be programmed tagged on the CPU.
Since swp4 is part of the same VLAN, but has it configured PVID untagged, the tag is removed, that sounds about what I would expect to see...
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [PATCH net-next 6/6] net: dsa: clear VLAN flags for CPU port
Hi Florian,
Quoted 46 lines · Florian Fainelli
Quoted 31 lines · Vladimir Oltean
Quoted 30 lines · Vivien Didelot
When the bridge offloads a VLAN on a slave port, we also need to program its dedicated CPU port as a member of the VLAN.
Drivers may handle the CPU port's membership as they want. For example, Marvell as a special "Unmodified" mode to pass frames as is through such ports.
Even though DSA expects the drivers to handle the CPU port membership, they are unlikely to program such VLANs untagged, and certainly not as PVID. This patch clears the VLAN flags before programming the CPU port.
Signed-off-by Vivien Didelot <[email protected]>Suggested-by Vladimir Oltean <[email protected]>--- net/dsa/slave.c | 6 ++++++ 1 file changed, 6 insertions(+)net/dsa/slave.c +0
-0@@ -332,6 +332,12 @@ static int dsa_slave_vlan_add(struct net_device *dev, if (err)return err; + /* We need the dedicated CPU port to be a member of the VLAN aswell.
net/dsa/slave.c +3
-0+* Even though drivers often handle CPU membership in special ways, +* CPU ports are likely to be tagged, so clear the VLAN flags. +*/ Quoted 8 lines
net/dsa/slave.c static int dsa_slave_vlan_add(struct net_device *dev, · line 340
Quoted 2 lines
net/dsa/slave.c +2
-0+ vlan.flags =0 ; +How does this work exactly?
If I run 'sudo bridge vlan add vid 1 dev swp4 pvid untagged', then the CPU port starts sending VLAN-tagged traffic. I see this in tcpdump on the DSA master port, but if I tcpdump on swp4, the VLAN tag is removed. Who is doing that?If vlan.flags = 0, then it does not have either
BRIDGE_VLAN_INFO_PVIDorBRIDGE_VLAN_INFO_UNTAGGEDwhich means the VLAN should be programmed tagged on the CPU.
Quoted 5 lines
Since swp4 is part of the same VLAN, but has it configured PVID untagged, the tag is removed, that sounds about what I would expect to see...
--
Florian
The VLAN is "egress untagged", and "ingress tagged" (at least so it becomes with this patch). Of course in tcpdump I was looking for ingress traffic.
This patch is relying now on __netif_receive_skb_core[1] to remove the VLAN header from frames as soon as they exit the DSA master and before they enter the DSA packet_type handler. My point is that even untagged traffic gets pvid-tagged on ingress, and the net core has to remove the tag when it previously didn't have to. I'm not sure of other implications.
Vivien, can't you just unset the PVID flag? Keeping the same tagged/untagged setting on ingress as on egress does make more sense.
Regards,
-Vladimir
[1]: https://elixir.bootlin.com/linux/latest/source/net/core/dev.c#L4898
Re: [PATCH net-next 6/6] net: dsa: clear VLAN flags for CPU port
Quoted 2 lines · Vladimir Oltean
Vivien, can't you just unset the PVID flag? Keeping the same tagged/untagged setting on ingress as on egress does make more sense.
Why not. I've sent a v2 with this single change.
Thanks,
Vivien