From: Florian Fainelli Subject: [RFC net-next 08/14] net: dsa: Add ndo_vlan_rx_{add,kill}_vid implementation Date: Tue, 15 Jan 2019 11:41:24 -0800 Message-ID: <20190115194130.19896-9-f.fainelli@gmail.com> References: <20190115194130.19896-1-f.fainelli@gmail.com> Cc: Florian Fainelli , andrew@lunn.ch, vivien.didelot@gmail.com, davem@davemloft.net, idosch@mellanox.com, jiri@mellanox.com, ilias.apalodimas@linaro.org, ivan.khoronzhuk@linaro.org, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com To: netdev@vger.kernel.org Return-path: Received: from mail-pl1-f196.google.com ([209.85.214.196]:35807 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389444AbfAOTmq (ORCPT ); Tue, 15 Jan 2019 14:42:46 -0500 Received: by mail-pl1-f196.google.com with SMTP id p8so1775758plo.2 for ; Tue, 15 Jan 2019 11:42:45 -0800 (PST) In-Reply-To: <20190115194130.19896-1-f.fainelli@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 --- 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 33f6b88b6fd6..e266ef329583 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, @@ -1090,6 +1138,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 = { @@ -1350,7 +1400,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