Allow unknown unicast traffic to CPU for Felix DSA
Subsystems (4)
Vladimir Oltean
maintainerv3 cover Allow unknown unicast traffic to CPU for Felix DSA
This is the continuation of the previous "[PATCH net-next] net: mscc:
ocelot: Workaround to allow traffic to CPU in standalone mode":
https://www.spinics.net/lists/netdev/msg631067.html
Following the feedback received from Allan Nielsen, the Ocelot and Felix drivers were made to use the CPU port module in the same way (patch 1), and Felix was made to additionally allow unknown unicast frames towards the CPU port module (patch 2).
Vladimir Oltean (2):
net: mscc: ocelot: eliminate confusion between CPU and NPI port
net: dsa: felix: Allow unknown unicast traffic towards the CPU port
module
drivers/net/dsa/ocelot/felix.c | 16 +++++- drivers/net/ethernet/mscc/ocelot.c | 62 +++++++++++--------- drivers/net/ethernet/mscc/ocelot.h | 10 ---- drivers/net/ethernet/mscc/ocelot_board.c | 7 +-- include/soc/mscc/ocelot.h | 72 ++++++++++++++++++++++-- net/dsa/tag_ocelot.c | 3 +- 6 files changed, 121 insertions(+), 49 deletions(-)
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v3 1/2 net: mscc: ocelot: eliminate confusion between CPU and NPI port
From: Vladimir Oltean <[email protected]>
Ocelot has the concept of a CPU port. The CPU port is represented in the forwarding and the queueing system, but it is not a physical device. The CPU port can either be accessed via register-based injection/extraction (which is the case of Ocelot), via Frame-DMA (similar to the first one), or "connected" to a physical Ethernet port (called NPI in the datasheet) which is the case of the Felix DSA switch.
In Ocelot the CPU port is at index 11.
In Felix the CPU port is at index 6.
The CPU bit is treated special in the forwarding, as it is never cleared from the forwarding port mask (once added to it). Other than that, it is treated the same as a normal front port.
Both Felix and Ocelot should use the CPU port in the same way. This means that Felix should not use the NPI port directly when forwarding to the CPU, but instead use the CPU port.
This patch is fixing this such that Felix will use port 6 as its CPU port, and just use the NPI port to carry the traffic.
Therefore, eliminate the "ocelot->cpu" variable which was holding the index of the NPI port for Felix, and the index of the CPU port module for Ocelot, so the variable was actually configuring different things for different drivers and causing at least part of the confusion.
Also remove the "ocelot->num_cpu_ports" variable, which is the result of another confusion. The 2 CPU ports mentioned in the datasheet are because there are two frame extraction channels (register based or DMA based). This is of no relevance to the driver at the moment, and invisible to the analyzer module.
---
Changes in v3:
Replaced commit message verbiage with text from Allan Nielsen.
drivers/net/dsa/ocelot/felix.c | 7 +-- drivers/net/ethernet/mscc/ocelot.c | 62 ++++++++++++++---------- drivers/net/ethernet/mscc/ocelot_board.c | 7 ++- include/soc/mscc/ocelot.h | 12 +++-- net/dsa/tag_ocelot.c | 3 +- 5 files changed, 52 insertions(+), 39 deletions(-)
drivers/net/dsa/ocelot/felix.c +4 -3
@@ -512,10 +512,11 @@ static int felix_setup(struct dsa_switch *ds)for (port =0 ; port < ds->num_ports; port++) {ocelot_init_port (ocelot, port); +/* Bring up the CPU port module and configure the NPI port */ if (dsa_is_cpu_port (ds, port)) -ocelot_set_cpu_port (ocelot, port, -OCELOT_TAG_PREFIX_NONE , -OCELOT_TAG_PREFIX_LONG ); +ocelot_configure_cpu (ocelot, port, +OCELOT_TAG_PREFIX_NONE , +OCELOT_TAG_PREFIX_LONG ); }/* It looks like the MAC/PCS interrupt register - PM0_IEVENT (0x8040)
drivers/net/ethernet/mscc/ocelot.c +36 -26
112 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_board.c +3 -4
@@ -349,8 +349,6 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->ptp =1 ; } - ocelot->num_cpu_ports =1 ;/* 1 port on the switch, two groups */ - ports =of_get_child_by_name (np,"ethernet-ports" );if (!ports) {dev_err (&pdev->dev,"no ethernet-ports child node found\n" );
@@ -363,8 +361,9 @@ static int mscc_ocelot_probe(struct platform_device *pdev) sizeof(struct ocelot_port *), GFP_KERNEL);ocelot_init (ocelot); -ocelot_set_cpu_port (ocelot, ocelot->num_phys_ports, -OCELOT_TAG_PREFIX_NONE ,OCELOT_TAG_PREFIX_NONE ); +/* No NPI port */ +ocelot_configure_cpu (ocelot,-1 ,OCELOT_TAG_PREFIX_NONE , +OCELOT_TAG_PREFIX_NONE );for_each_available_child_of_node (ports, portnp) {struct ocelot_port_private *priv;
include/soc/mscc/ocelot.h +7 -5
@@ -447,9 +447,11 @@ struct ocelot {/* Keep track of the vlan port masks */ u32 vlan_mask[VLAN_N_VID ]; +/* In tables like ANA:PORT and the ANA:PGID:PGID mask, +* the CPU is located after the physical ports (at the +* num_phys_ports index). +*/ u8 num_phys_ports; -u8 num_cpu_ports; -u8 cpu;u32 *lags;
@@ -500,9 +502,9 @@ void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask, u32 reg,int ocelot_regfields_init (struct ocelot *ocelot,const struct reg_field *const regfields);struct regmap *ocelot_regmap_init (struct ocelot *ocelot,struct resource *res); -void ocelot_set_cpu_port (struct ocelot *ocelot,int cpu, -enum ocelot_tag_prefix injection, -enum ocelot_tag_prefix extraction); +void ocelot_configure_cpu (struct ocelot *ocelot,int npi, +enum ocelot_tag_prefix injection, +enum ocelot_tag_prefix extraction);int ocelot_init (struct ocelot *ocelot);void ocelot_deinit (struct ocelot *ocelot);void ocelot_init_port (struct ocelot *ocelot,int port);
net/dsa/tag_ocelot.c +2 -1
@@ -153,7 +153,8 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb,memset (injection,0 ,OCELOT_TAG_LEN ); - src =dsa_upstream_port (ds, port); +/* Set the source port as the CPU port module and not the NPI port */ + src = ocelot->num_phys_ports; dest =BIT (port); bypass = true; qos_class = skb->priority;
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v3 2/2 net: dsa: felix: Allow unknown unicast traffic towards the CPU port module
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Compared to other DSA switches, in the Ocelot cores, the RX filtering is a much more important concern.
Firstly, the primary use case for Ocelot is non-DSA, so there isn't any secondary Ethernet MAC [the DSA master's one] to implicitly drop frames having a DMAC we are not interested in. So the switch driver itself needs to install FDB entries towards the CPU port module (PGID_CPU) for the MAC address of each switch port, in each VLAN installed on the port. Every address that is not whitelisted is implicitly dropped. This is in order to achieve a behavior similar to N standalone net devices.
Secondly, even in the secondary use case of DSA, such as illustrated by Felix with the NPI port mode, that secondary Ethernet MAC is present, but its RX filter is bypassed. This is because the DSA tags themselves are placed before Ethernet, so the DMAC that the switch ports see is not seen by the DSA master too (since it's shifter to the right).
So RX filtering is pretty important. A good RX filter won't bother the CPU in case the switch port receives a frame that it's not interested in, and there exists no other line of defense.
Ocelot is pretty strict when it comes to RX filtering: non-IP multicast and broadcast traffic is allowed to go to the CPU port module, but unknown unicast isn't. This means that traffic reception for any other MAC addresses than the ones configured on each switch port net device won't work. This includes use cases such as macvlan or bridging with a non-Ocelot (so-called "foreign") interface. But this seems to be fine for the scenarios that the Linux system embedded inside an Ocelot switch is intended for - it is simply not interested in unknown unicast traffic, as explained in Allan Nielsen's presentation [0].
On the other hand, the Felix DSA switch is integrated in more general-purpose Linux systems, so it can't afford to drop that sort of traffic in hardware, even if it will end up doing so later, in software.
Actually, unknown unicast means more for Felix than it does for Ocelot. Felix doesn't attempt to perform the whitelisting of switch port MAC addresses towards PGID_CPU at all, mainly because it is too complicated to be feasible: while the MAC addresses are unique in Ocelot, by default in DSA all ports are equal and inherited from the DSA master. This adds into account the question of reference counting MAC addresses (delayed ocelot_mact_forget), not to mention reference counting for the VLAN IDs that those MAC addresses are installed in. This reference counting should be done in the DSA core, and the fact that it wasn't needed so far is due to the fact that the other DSA switches don't have the DSA tag placed before Ethernet, so the DSA master is able to whitelist the MAC addresses in hardware.
So this means that even regular traffic termination on a Felix switch port happens through flooding (because neither Felix nor Ocelot learn source MAC addresses from CPU-injected frames).
So far we've explained that whitelisting towards PGID_CPU:
- helps to reduce the likelihood of spamming the CPU with frames it won't process very far anyway
- is implemented in the ocelot driver
- is sufficient for the ocelot use cases
- is not feasible in DSA
- breaks use cases in DSA, in the current status (whitelisting enabled but no MAC address whitelisted)
So the proposed patch allows unknown unicast frames to be sent to the CPU port module. This is done for the Felix DSA driver only, as Ocelot seems to be happy without it.
[0]: https://www.youtube.com/watch?v=B1HhxEcU7Jg
---
Changes in v3:
None.
drivers/net/dsa/ocelot/felix.c | 9 +++++ drivers/net/ethernet/mscc/ocelot.h | 10 ----- include/soc/mscc/ocelot.h | 60 ++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 10 deletions(-)
drivers/net/dsa/ocelot/felix.c +9 -0
@@ -519,6 +519,15 @@ static int felix_setup(struct dsa_switch *ds) OCELOT_TAG_PREFIX_LONG); } +/* Include the CPU port module in the forwarding mask for unknown +* unicast - the hardware default value for ANA_FLOODING_FLD_UNICAST +* excludes BIT(ocelot->num_phys_ports), and so does ocelot_init, since +* Ocelot relies on whitelisting MAC addresses towards PGID_CPU. +*/ +ocelot_write_rix (ocelot, +ANA_PGID_PGID_PGID (GENMASK (ocelot->num_phys_ports,0 )), +ANA_PGID_PGID ,PGID_UC ); +/* It looks like the MAC/PCS interrupt register - PM0_IEVENT (0x8040) * isn't instantiated for the Felix PF. * In-band AN may take a few ms to complete, so we need to poll.
drivers/net/ethernet/mscc/ocelot.h +0 -10
@@ -28,16 +28,6 @@#include "ocelot_tc.h" #include "ocelot_ptp.h" -#define PGID_AGGR 64 -#define PGID_SRC 80 - -/* Reserved PGIDs */ -#define PGID_CPU (PGID_AGGR - 5) -#define PGID_UC (PGID_AGGR - 4) -#define PGID_MC (PGID_AGGR - 3) -#define PGID_MCIPV4 (PGID_AGGR - 2) -#define PGID_MCIPV6 (PGID_AGGR - 1) -#define OCELOT_BUFFER_CELL_SZ 60#define OCELOT_STATS_CHECK_DELAY (2 * HZ)
include/soc/mscc/ocelot.h +60 -0
66 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 2/2] net: dsa: felix: Allow unknown unicast traffic towards the CPU port module
Quoted 68 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Compared to other DSA switches, in the Ocelot cores, the RX filtering is a much more important concern.
Firstly, the primary use case for Ocelot is non-DSA, so there isn't any secondary Ethernet MAC [the DSA master's one] to implicitly drop frames having a DMAC we are not interested in. So the switch driver itself needs to install FDB entries towards the CPU port module (
PGID_CPU) for the MAC address of each switch port, in each VLAN installed on the port. Every address that is not whitelisted is implicitly dropped. This is in order to achieve a behavior similar to N standalone net devices.Secondly, even in the secondary use case of DSA, such as illustrated by Felix with the NPI port mode, that secondary Ethernet MAC is present, but its RX filter is bypassed. This is because the DSA tags themselves are placed before Ethernet, so the DMAC that the switch ports see is not seen by the DSA master too (since it's shifter to the right).
So RX filtering is pretty important. A good RX filter won't bother the CPU in case the switch port receives a frame that it's not interested in, and there exists no other line of defense.
Ocelot is pretty strict when it comes to RX filtering: non-IP multicast and broadcast traffic is allowed to go to the CPU port module, but unknown unicast isn't. This means that traffic reception for any other MAC addresses than the ones configured on each switch port net device won't work. This includes use cases such as macvlan or bridging with a non-Ocelot (so-called "foreign") interface. But this seems to be fine for the scenarios that the Linux system embedded inside an Ocelot switch is intended for - it is simply not interested in unknown unicast traffic, as explained in Allan Nielsen's presentation [0].
On the other hand, the Felix DSA switch is integrated in more general-purpose Linux systems, so it can't afford to drop that sort of traffic in hardware, even if it will end up doing so later, in software.
Actually, unknown unicast means more for Felix than it does for Ocelot. Felix doesn't attempt to perform the whitelisting of switch port MAC addresses towards
PGID_CPUat all, mainly because it is too complicated to be feasible: while the MAC addresses are unique in Ocelot, by default in DSA all ports are equal and inherited from the DSA master. This adds into account the question of reference counting MAC addresses (delayedocelot_mact_forget), not to mention reference counting for the VLAN IDs that those MAC addresses are installed in. This reference counting should be done in the DSA core, and the fact that it wasn't needed so far is due to the fact that the other DSA switches don't have the DSA tag placed before Ethernet, so the DSA master is able to whitelist the MAC addresses in hardware.So this means that even regular traffic termination on a Felix switch port happens through flooding (because neither Felix nor Ocelot learn source MAC addresses from CPU-injected frames).
So far we've explained that whitelisting towards
PGID_CPU:
- helps to reduce the likelihood of spamming the CPU with frames it won't process very far anyway
- is implemented in the ocelot driver
- is sufficient for the ocelot use cases
- is not feasible in DSA
- breaks use cases in DSA, in the current status (whitelisting enabled but no MAC address whitelisted)So the proposed patch allows unknown unicast frames to be sent to the CPU port module. This is done for the Felix DSA driver only, as Ocelot seems to be happy without it.
Quoted 5 lines
[0]: https://www.youtube.com/watch?v=B1HhxEcU7Jg
Suggested-by Allan W. Nielsen <[email protected]>Signed-off-by Vladimir Oltean <[email protected]>---
I see this patch has "Needs Review / ACK" in patchwork.
There is in fact a tag:
which I had forgotten to copy over from v2:
https://www.spinics.net/lists/netdev/msg633098.html
Hope there are no particular issues with this approach from DSA perspective.
Thanks,
-Vladimir
Re: [PATCH v3 net-next 2/2] net: dsa: felix: Allow unknown unicast traffic towards the CPU port module
Quoted 77 lines · Vladimir Oltean
Quoted 68 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Compared to other DSA switches, in the Ocelot cores, the RX filtering is a much more important concern.
Firstly, the primary use case for Ocelot is non-DSA, so there isn't any secondary Ethernet MAC [the DSA master's one] to implicitly drop frames having a DMAC we are not interested in. So the switch driver itself needs to install FDB entries towards the CPU port module (
PGID_CPU) for the MAC address of each switch port, in each VLAN installed on the port. Every address that is not whitelisted is implicitly dropped. This is in order to achieve a behavior similar to N standalone net devices.Secondly, even in the secondary use case of DSA, such as illustrated by Felix with the NPI port mode, that secondary Ethernet MAC is present, but its RX filter is bypassed. This is because the DSA tags themselves are placed before Ethernet, so the DMAC that the switch ports see is not seen by the DSA master too (since it's shifter to the right).
So RX filtering is pretty important. A good RX filter won't bother the CPU in case the switch port receives a frame that it's not interested in, and there exists no other line of defense.
Ocelot is pretty strict when it comes to RX filtering: non-IP multicast and broadcast traffic is allowed to go to the CPU port module, but unknown unicast isn't. This means that traffic reception for any other MAC addresses than the ones configured on each switch port net device won't work. This includes use cases such as macvlan or bridging with a non-Ocelot (so-called "foreign") interface. But this seems to be fine for the scenarios that the Linux system embedded inside an Ocelot switch is intended for - it is simply not interested in unknown unicast traffic, as explained in Allan Nielsen's presentation [0].
On the other hand, the Felix DSA switch is integrated in more general-purpose Linux systems, so it can't afford to drop that sort of traffic in hardware, even if it will end up doing so later, in software.
Actually, unknown unicast means more for Felix than it does for Ocelot. Felix doesn't attempt to perform the whitelisting of switch port MAC addresses towards
PGID_CPUat all, mainly because it is too complicated to be feasible: while the MAC addresses are unique in Ocelot, by default in DSA all ports are equal and inherited from the DSA master. This adds into account the question of reference counting MAC addresses (delayedocelot_mact_forget), not to mention reference counting for the VLAN IDs that those MAC addresses are installed in. This reference counting should be done in the DSA core, and the fact that it wasn't needed so far is due to the fact that the other DSA switches don't have the DSA tag placed before Ethernet, so the DSA master is able to whitelist the MAC addresses in hardware.So this means that even regular traffic termination on a Felix switch port happens through flooding (because neither Felix nor Ocelot learn source MAC addresses from CPU-injected frames).
So far we've explained that whitelisting towards
PGID_CPU:
- helps to reduce the likelihood of spamming the CPU with frames it won't process very far anyway
- is implemented in the ocelot driver
- is sufficient for the ocelot use cases
- is not feasible in DSA
- breaks use cases in DSA, in the current status (whitelisting enabled but no MAC address whitelisted)So the proposed patch allows unknown unicast frames to be sent to the CPU port module. This is done for the Felix DSA driver only, as Ocelot seems to be happy without it.
Quoted 5 lines
[0]: https://www.youtube.com/watch?v=B1HhxEcU7Jg
Suggested-by Allan W. Nielsen <[email protected]>Signed-off-by Vladimir Oltean <[email protected]>---
I see this patch has "Needs Review / ACK" in patchwork.
Quoted 8 lines
There is in fact a tag:
Reviewed-by Allan W. Nielsen <[email protected]>which I had forgotten to copy over from v2:
https://www.spinics.net/lists/netdev/msg633098.htmlHope there are no particular issues with this approach from DSA perspective.
Not really, until/if we implement UC and MC filtering on standalone DSA ports, this will be revisited, but for now, this is what is expected.
Signature · 1 line
Florian
David Miller
maintainerFrom: Vladimir Oltean <[email protected]>
Date: Sat, 29 Feb 2020 16:50:01 +0200
Quoted 9 lines
This is the continuation of the previous "[PATCH net-next] net: mscc:
ocelot: Workaround to allow traffic to CPU in standalone mode":https://www.spinics.net/lists/netdev/msg631067.html
Following the feedback received from Allan Nielsen, the Ocelot and Felix drivers were made to use the CPU port module in the same way (patch 1), and Felix was made to additionally allow unknown unicast frames towards the CPU port module (patch 2).
Series applied, thanks.