In order to properly support VLAN filtering being enabled/disabled on a bridge, while having other ports being non bridge port members, we need to support the ndo_vlan_rx_{add,kill}_vid callbacks in order to make sure the non-bridge ports can continue receiving VLAN tags, even when the switch is globally configured to do ingress/egress VID checking.
We don't allow configuring VLAN devices on a bridge port member though, since the bridge with VLAN awareness should be taking care of that, if needed. Since we can call dsa_port_vlan_{add,del} with a bridge_dev pointer NULL, we now need to check that in these two functions. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- net/dsa/port.c | 12 +++++++++-- net/dsa/slave.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/net/dsa/port.c b/net/dsa/port.c index 2d7e01b23572..185e85a4f5f0 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -252,7 +252,11 @@ int dsa_port_vlan_add(struct dsa_port *dp, .vlan = vlan, }; - if (br_vlan_enabled(dp->bridge_dev)) + /* Can be called from dsa_slave_port_obj_add() or + * dsa_slave_vlan_rx_add_vid() + */ + if ((dp->bridge_dev && br_vlan_enabled(dp->bridge_dev)) || + !dp->bridge_dev) return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, &info); return 0; @@ -270,7 +274,11 @@ int dsa_port_vlan_del(struct dsa_port *dp, if (netif_is_bridge_master(vlan->obj.orig_dev)) return -EOPNOTSUPP; - if (br_vlan_enabled(dp->bridge_dev)) + /* Can be called from dsa_slave_port_obj_del() or + * dsa_slave_vlan_rx_kill_vid() + */ + if ((dp->bridge_dev && br_vlan_enabled(dp->bridge_dev)) || + !dp->bridge_dev) return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, &info); return 0; diff --git a/net/dsa/slave.c b/net/dsa/slave.c index a6a803262929..306fd1b45f0c 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1027,6 +1027,54 @@ static int dsa_slave_get_ts_info(struct net_device *dev, return ds->ops->get_ts_info(ds, p->dp->index, ts); } +static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto, + u16 vid) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct switchdev_obj_port_vlan vlan = { }; + int ret = 0; + + /* If the port is bridged and the bridge is VLAN aware, let the bridge + * manage VLANs + */ + if (dp->bridge_dev && br_vlan_enabled(dp->bridge_dev)) + return -EINVAL; + + /* This API only allows programming tagged, non-PVID VIDs */ + vlan.vid_begin = vid; + vlan.vid_end = vid; + + ret = dsa_port_vlan_add(dp, &vlan, NULL); + if (ret == -EOPNOTSUPP) + ret = 0; + + return ret; +} + +static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, + u16 vid) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct switchdev_obj_port_vlan vlan = { }; + int ret = 0; + + /* If the port is bridged and the bridge is VLAN aware, let the bridge + * manage VLANs + */ + if (dp->bridge_dev && br_vlan_enabled(dp->bridge_dev)) + return -EINVAL; + + /* This API only allows programming tagged, non-PVID VIDs */ + vlan.vid_begin = vid; + vlan.vid_end = vid; + + ret = dsa_port_vlan_del(dp, &vlan); + if (ret == -EOPNOTSUPP) + ret = 0; + + return ret; +} + static const struct ethtool_ops dsa_slave_ethtool_ops = { .get_drvinfo = dsa_slave_get_drvinfo, .get_regs_len = dsa_slave_get_regs_len, @@ -1091,6 +1139,8 @@ static const struct net_device_ops dsa_slave_netdev_ops = { .ndo_get_phys_port_name = dsa_slave_get_phys_port_name, .ndo_setup_tc = dsa_slave_setup_tc, .ndo_get_stats64 = dsa_slave_get_stats64, + .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid, + .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid, }; static const struct switchdev_ops dsa_slave_switchdev_ops = { @@ -1351,7 +1401,8 @@ int dsa_slave_create(struct dsa_port *port) if (slave_dev == NULL) return -ENOMEM; - slave_dev->features = master->vlan_features | NETIF_F_HW_TC; + slave_dev->features = master->vlan_features | NETIF_F_HW_TC | + NETIF_F_HW_VLAN_CTAG_FILTER; slave_dev->hw_features |= NETIF_F_HW_TC; slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; eth_hw_addr_inherit(slave_dev, master); -- 2.17.1