Horatiu Vultur
2019-Aug-26 08:11 UTC
[Bridge] [PATCH v2 0/3] Add NETIF_F_HW_BR_CAP feature
When a network port is added to a bridge then the port is added in promisc mode. Some HW that has bridge capabilities(can learn, forward, flood etc the frames) they are disabling promisc mode in the network driver when the port is added to the SW bridge. This patch adds the feature NETIF_F_HW_BR_CAP so that the network ports that have this feature will not be set in promisc mode when they are added to a SW bridge. In this way the HW that has bridge capabilities don't need to send all the traffic to the CPU and can also implement the promisc mode and toggle it using the command 'ip link set dev swp promisc on' v1 -> v2 - rename feature to NETIF_F_HW_BR_CAP - add better description in the commit message and in the code - remove the check that all network driver have same netdev_ops and just check for the feature NETIF_F_HW_BR_CAP when setting the network port in promisc mode. Horatiu Vultur (3): net: Add NETIF_HW_BR_CAP feature net: mscc: Use NETIF_F_HW_BR_CAP net: mscc: Implement promisc mode. drivers/net/ethernet/mscc/ocelot.c | 26 ++++++++++++++++++++++++-- include/linux/netdev_features.h | 6 ++++++ net/bridge/br_if.c | 11 ++++++++++- net/core/ethtool.c | 1 + 4 files changed, 41 insertions(+), 3 deletions(-) -- 2.7.4
Horatiu Vultur
2019-Aug-26 08:11 UTC
[Bridge] [PATCH v2 1/3] net: Add NETIF_HW_BR_CAP feature
This patch adds a netdev feature to allow the SW bridge not to set all the slave interfaces in promisc mode if the HW is capable of learning and flooading the frames. The current implementation adds all the bridge ports in promisc mode. Even if the HW has bridge capabilities(can learn and flood frames). Then all the frames will be copy to the CPU even if there are cases where there is no need for this. For example in the following scenario: +----------------------------------+ | SW BR | +----------------------------------+ | | | | | +------------------+ | | | HW BR | | | +------------------+ | | | | + + + + p1 p2 p3 p4 Case A: There is a SW bridge with the ports p1 and p2 Case B: There is a SW bridge with the ports p3 and p4. Case C: THere is a SW bridge with the ports p2, p3 and p4. For case A, the HW can't do learning and flooding of the frames. Therefore all the frames need to be copied to the CPU to allow the SW bridge to decide what do do with the frame(forward, flood, copy to the upper layers, etc..). For case B, there is HW support to learn and flood the frames. In this case there is no point to send all the frames to the CPU(except for frames that need to go to CPU and flooded frames if flooding is enabled). Because the HW will already forward the frame to the correct network port, then the SW bridge will not have anything to do. It would just use CPU cycles and then drop the frame. The reason for dropping the frame is that the network driver will set the flag fwd_offload_mark and then SW bridge will skip all the ports that have the same parent_id as the port that received the frame. Which is this case. For case C, there is HW support to learn and flood frames for ports p3 and p4 while p2 doesn't have HW support. In this case the port p2 needs to be in promisc mode to allow SW bridge to do the learning and flooding of the frames while ports p3 and p4 they don't need to be in promisc mode. The ports p3 and p4 need to make sure that the CPU is in flood mask and need to know which addresses can be access through SW bridge so it could send those frames to CPU port. So it would allow the SW bridge to send to the correct network port. A workaround for all these cases is not to set the network port in promisc mode if it is a bridge port, which is the case for mlxsw. Or not to implement it at all, which is the case for ocelot. But the disadvantage of this approach is that the network bridge ports can not be set in promisc mode if there is a need to monitor all the traffic on that port using the command 'ip link set dev swp promisc on'. This patch adds also support for this case. Signed-off-by: Horatiu Vultur <horatiu.vultur at microchip.com> --- include/linux/netdev_features.h | 6 ++++++ net/bridge/br_if.c | 11 ++++++++++- net/core/ethtool.c | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/linux/netdev_features.h b/include/linux/netdev_features.h index 4b19c54..b5a3463 100644 --- a/include/linux/netdev_features.h +++ b/include/linux/netdev_features.h @@ -78,6 +78,11 @@ enum { NETIF_F_HW_TLS_TX_BIT, /* Hardware TLS TX offload */ NETIF_F_HW_TLS_RX_BIT, /* Hardware TLS RX offload */ + NETIF_F_HW_BR_CAP_BIT, /* Hardware is capable to behave as a + * bridge to learn and switch frames + */ + + NETIF_F_GRO_HW_BIT, /* Hardware Generic receive offload */ NETIF_F_HW_TLS_RECORD_BIT, /* Offload TLS record */ @@ -150,6 +155,7 @@ enum { #define NETIF_F_GSO_UDP_L4 __NETIF_F(GSO_UDP_L4) #define NETIF_F_HW_TLS_TX __NETIF_F(HW_TLS_TX) #define NETIF_F_HW_TLS_RX __NETIF_F(HW_TLS_RX) +#define NETIF_F_HW_BR_CAP __NETIF_F(HW_BR_CAP) /* Finds the next feature with the highest number of the range of start till 0. */ diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index 4fe30b1..93bfc55 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -161,7 +161,16 @@ void br_manage_promisc(struct net_bridge *br) (br->auto_cnt == 1 && br_auto_port(p))) br_port_clear_promisc(p); else - br_port_set_promisc(p); + /* If the HW has bridge capabilities to learn + * and flood the frames then there is no need + * to copy all the frames to the SW to do the + * same. Because the HW already switched the + * frame and then there is nothing to do for + * the SW bridge. The SW will just use CPU + * and it would drop the frame. + */ + if (!(p->dev->features & NETIF_F_HW_BR_CAP)) + br_port_set_promisc(p); } } } diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 6288e69..10430fe 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -111,6 +111,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] [NETIF_F_HW_TLS_RECORD_BIT] = "tls-hw-record", [NETIF_F_HW_TLS_TX_BIT] = "tls-hw-tx-offload", [NETIF_F_HW_TLS_RX_BIT] = "tls-hw-rx-offload", + [NETIF_F_HW_BR_CAP_BIT] = "bridge-capabilities-offload", }; static const char -- 2.7.4
Horatiu Vultur
2019-Aug-26 08:11 UTC
[Bridge] [PATCH v2 2/3] net: mscc: Use NETIF_F_HW_BR_CAP
Enable NETIF_F_HW_BR_CAP feature for ocelot. Because the HW can learn and flood the frames, so there is no need for SW bridge to do this. Signed-off-by: Horatiu Vultur <horatiu.vultur at microchip.com> --- drivers/net/ethernet/mscc/ocelot.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 4d1bce4..7d7c94b 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -2017,8 +2017,10 @@ int ocelot_probe_port(struct ocelot *ocelot, u8 port, dev->ethtool_ops = &ocelot_ethtool_ops; dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXFCS | - NETIF_F_HW_TC; - dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_TC; + NETIF_F_HW_TC | NETIF_F_HW_BR_CAP; + dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_TC | + NETIF_F_HW_BR_CAP; + dev->priv_flags |= IFF_UNICAST_FLT; memcpy(dev->dev_addr, ocelot->base_mac, ETH_ALEN); dev->dev_addr[ETH_ALEN - 1] += port; -- 2.7.4
Horatiu Vultur
2019-Aug-26 08:11 UTC
[Bridge] [PATCH v2 3/3] net: mscc: Implement promisc mode.
Before when a port was added to a bridge then the port was added in promisc mode. But because of the patches: commit e6300374f3be6 ("net: Add NETIF_HW_BR_CAP feature") commit 764866d46cc81 ("net: mscc: Use NETIF_F_HW_BR_CAP")' The port is not needed to be in promisc mode to be part of the bridge. So it is possible to togle the promisc mode of the port even if it is or not part of the bridge. Signed-off-by: Horatiu Vultur <horatiu.vultur at microchip.com> --- drivers/net/ethernet/mscc/ocelot.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 7d7c94b..8a18eef 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -691,6 +691,25 @@ static void ocelot_set_rx_mode(struct net_device *dev) __dev_mc_sync(dev, ocelot_mc_sync, ocelot_mc_unsync); } +static void ocelot_change_rx_flags(struct net_device *dev, int flags) +{ + struct ocelot_port *port = netdev_priv(dev); + struct ocelot *ocelot = port->ocelot; + u32 val; + + if (!(flags & IFF_PROMISC)) + return; + + val = ocelot_read_gix(ocelot, ANA_PORT_CPU_FWD_CFG, + port->chip_port); + if (dev->flags & IFF_PROMISC) + val |= ANA_PORT_CPU_FWD_CFG_CPU_SRC_COPY_ENA; + else + val &= ~(ANA_PORT_CPU_FWD_CFG_CPU_SRC_COPY_ENA); + + ocelot_write_gix(ocelot, val, ANA_PORT_CPU_FWD_CFG, port->chip_port); +} + static int ocelot_port_get_phys_port_name(struct net_device *dev, char *buf, size_t len) { @@ -1070,6 +1089,7 @@ static const struct net_device_ops ocelot_port_netdev_ops = { .ndo_stop = ocelot_port_stop, .ndo_start_xmit = ocelot_port_xmit, .ndo_set_rx_mode = ocelot_set_rx_mode, + .ndo_change_rx_flags = ocelot_change_rx_flags, .ndo_get_phys_port_name = ocelot_port_get_phys_port_name, .ndo_set_mac_address = ocelot_port_set_mac_address, .ndo_get_stats64 = ocelot_get_stats64, -- 2.7.4
On Mon, Aug 26, 2019 at 10:11:12AM +0200, Horatiu Vultur wrote:> When a network port is added to a bridge then the port is added in > promisc mode. Some HW that has bridge capabilities(can learn, forward, > flood etc the frames) they are disabling promisc mode in the network > driver when the port is added to the SW bridge. > > This patch adds the feature NETIF_F_HW_BR_CAP so that the network ports > that have this feature will not be set in promisc mode when they are > added to a SW bridge. > > In this way the HW that has bridge capabilities don't need to send all the > traffic to the CPU and can also implement the promisc mode and toggle it > using the command 'ip link set dev swp promisc on'Hi Horatiu I'm still not convinced this is needed. The model is, the hardware is there to accelerate what Linux can do in software. Any peculiarities of the accelerator should be hidden in the driver. If the accelerator can do its job without needing promisc mode, do that in the driver. So you are trying to differentiate between promisc mode because the interface is a member of a bridge, and promisc mode because some application, like pcap, has asked for promisc mode. dev->promiscuity is a counter. So what you can do it look at its value, and how the interface is being used. If the interface is not a member of a bridge, and the count > 0, enable promisc mode in the accelerator. If the interface is a member of a bridge, and the count > 1, enable promisc mode in the accelerator. Andrew