tag_8021q for Ocelot switches
Subsystems (4)
Vladimir Oltean
maintainerv5 cover tag_8021q for Ocelot switches
From: Vladimir Oltean <[email protected]>
Changes in v5:
- Split patch series in half, removing PTP bits.
- Split previous monolithic patch "net: dsa: felix: add new VLAN-based tagger" into 3 smaller patches.
- Updated the sysfs documentation
- Made the tagger_lock per DSA switch tree instead of per DSA switch
- Using dsa_tree_notify instead of dsa_broadcast.
Changes in v4:
- Support simultaneous compilation of tag_ocelot.c and tag_ocelot_8021q.c.
- Support runtime switchover between the two taggers, by using echo ocelot-8021q > /sys/class/net/eno2/dsa/tagging
- We are now actually performing cleanup instead of just probe-time setup, which is required for supporting tagger switchover.
- Now draining the CPU queues by continuously reading QS_XTR_READ, same as Ocelot, instead of one-time asserting QS_XTR_FLUSH, which actually needed a sleep to be effective.
Changes in v3:
Use a per-port bool is_dsa_8021q_cpu instead of a single dsa_8021q_cpu variable, to be compatible with future work where there may be potentially multiple tag_8021q CPU ports in a LAG.
Changes in v2:
Posted the entire rework necessary for PTP support using tag_8021q.c. Added a larger audience to the series.
The Felix switch inside LS1028A has an issue. It has a 2.5G CPU port, and the external ports, in the majority of use cases, run at 1G. This means that, when the CPU injects traffic into the switch, it is very easy to run into congestion. This is not to say that it is impossible to enter congestion even with all ports running at the same speed, just that the default configuration is already very prone to that by design.
Normally, the way to deal with that is using Ethernet flow control (PAUSE frames).
However, this functionality is not working today with the ENETC - Felix switch pair. The hardware issue is undergoing documentation right now as an erratum within NXP, but several customers have been requesting a reasonable workaround for it.
In truth, the LS1028A has 2 internal port pairs. The lack of flow control is an issue only when NPI mode (Node Processor Interface, aka the mode where the "CPU port module", which carries DSA-style tagged packets, is connected to a regular Ethernet port) is used, and NPI mode is supported by Felix on a single port.
In past BSPs, we have had setups where both internal port pairs were enabled. We were advertising the following setup:
"data port" "control port"
(2.5G) (1G)
eno2 eno3
^ ^
| |
| regular | DSA-tagged
| frames | frames
| |
v vswp4 swp5
This works but is highly unpractical, due to NXP shifting the task of designing a functional system (choosing which port to use, depending on type of traffic required) up to the end user. The swpN interfaces would have to be bridged with swp4, in order for the eno2 "data port" to have access to the outside network. And the swpN interfaces would still be capable of IP networking. So running a DHCP client would give us two IP interfaces from the same subnet, one assigned to eno2, and the other to swpN (0, 1, 2, 3).
Also, the dual port design doesn't scale. When attaching another DSA switch to a Felix port, the end result is that the "data port" cannot carry any meaningful data to the external world, since it lacks the DSA tags required to traverse the sja1105 switches below. All that traffic needs to go through the "control port".
So in newer BSPs there was a desire to simplify that setup, and only have one internal port pair:
eno2 eno3
^
|
| DSA-tagged x disabled
| frames
|
vswp4 swp5
However, this setup only exacerbates the issue of not having flow control on the NPI port, since that is the only port now. Also, there are use cases that still require the "data port", such as IEEE 802.1CB (TSN stream identification doesn't work over an NPI port), source MAC address learning over NPI, etc.
Again, there is a desire to keep the simplicity of the single internal port setup, while regaining the benefits of having a dedicated data port as well. And this series attempts to deliver just that.
So the NPI functionality is disabled conditionally. Its purpose was:
- To ensure individually addressable ports on TX. This can be replaced by using some designated VLAN tags which are pushed by the DSA tagger code, then removed by the switch (so they are invisible to the outside world and to the user).
- To ensure source port identification on RX. Again, this can be replaced by using some designated VLAN tags to encapsulate all RX traffic (each VLAN uniquely identifies a source port). The DSA tagger determines which port it was based on the VLAN number, then removes that header.
- To deliver PTP timestamps. This cannot be obtained through VLAN headers, so we need to take a step back and see how else we can do that. The Microchip Ocelot-1 (VSC7514 MIPS) driver performs manual injection/extraction from the CPU port module using register-based MMIO, and not over Ethernet. We will need to do the same from DSA, which makes this tagger a sort of hybrid between DSA and pure switchdev.
Vladimir Oltean (10):
net: dsa: tag_8021q: add helpers to deduce whether a VLAN ID is RX or
TX VLAN
net: mscc: ocelot: export VCAP structures to include/soc/mscc
net: mscc: ocelot: store a namespaced VCAP filter ID
net: mscc: ocelot: reapply bridge forwarding mask on bonding
join/leave
net: mscc: ocelot: don't use NPI tag prefix for the CPU port module
net: dsa: document the existing switch tree notifiers and add a new
one
net: dsa: allow changing the tag protocol via the "tagging" device
attribute
net: dsa: felix: convert to the new .{set,del}_tag_protocol DSA API
net: dsa: add a second tagger for Ocelot switches based on tag_8021q
net: dsa: felix: perform switch setup for tag_8021q
Documentation/ABI/testing/sysfs-class-net-dsa | 11 +- MAINTAINERS | 1 + drivers/net/dsa/ocelot/Kconfig | 2 + drivers/net/dsa/ocelot/felix.c | 486 ++++++++++++++++-- drivers/net/dsa/ocelot/felix.h | 2 + drivers/net/dsa/ocelot/felix_vsc9959.c | 1 + drivers/net/dsa/ocelot/seville_vsc9953.c | 1 + drivers/net/ethernet/mscc/ocelot.c | 93 ++-- drivers/net/ethernet/mscc/ocelot_flower.c | 7 +- drivers/net/ethernet/mscc/ocelot_net.c | 1 + drivers/net/ethernet/mscc/ocelot_vcap.c | 19 +- drivers/net/ethernet/mscc/ocelot_vcap.h | 295 +---------- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 2 - include/linux/dsa/8021q.h | 14 + include/net/dsa.h | 23 + include/soc/mscc/ocelot.h | 6 +- include/soc/mscc/ocelot_vcap.h | 297 +++++++++++ net/dsa/Kconfig | 21 +- net/dsa/Makefile | 1 + net/dsa/dsa.c | 20 + net/dsa/dsa2.c | 129 ++++- net/dsa/dsa_priv.h | 19 + net/dsa/master.c | 26 +- net/dsa/port.c | 44 +- net/dsa/slave.c | 35 +- net/dsa/switch.c | 88 ++++ net/dsa/tag_8021q.c | 15 +- net/dsa/tag_ocelot_8021q.c | 68 +++ 28 files changed, 1306 insertions(+), 421 deletions(-) create mode 100644 net/dsa/tag_ocelot_8021q.c
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v5 1/10 net: dsa: tag_8021q: add helpers to deduce whether a VLAN ID is RX or TX VLAN
From: Vladimir Oltean <[email protected]>
The sja1105 implementation can be blind about this, but the felix driver doesn't do exactly what it's being told, so it needs to know whether it is a TX or an RX VLAN, so it can install the appropriate type of TCAM rule.
---
Changes in v5:
None.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
None.
include/linux/dsa/8021q.h | 14 ++++++++++++++ net/dsa/tag_8021q.c | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-)
include/linux/dsa/8021q.h +14 -0
@@ -64,6 +64,10 @@ int dsa_8021q_rx_source_port(u16 vid);u16 dsa_8021q_rx_subvlan (u16 vid); +bool vid_is_dsa_8021q_rxvlan (u16 vid); + +bool vid_is_dsa_8021q_txvlan (u16 vid); +bool vid_is_dsa_8021q (u16 vid);#else
@@ -123,6 +127,16 @@ u16 dsa_8021q_rx_subvlan(u16 vid)return 0 ; } +bool vid_is_dsa_8021q_rxvlan (u16 vid) +{ +return false; +} + +bool vid_is_dsa_8021q_txvlan (u16 vid) +{ +return false; +} +bool vid_is_dsa_8021q (u16 vid) {return false;
net/dsa/tag_8021q.c +13 -2
@@ -133,10 +133,21 @@ u16 dsa_8021q_rx_subvlan(u16 vid) }EXPORT_SYMBOL_GPL (dsa_8021q_rx_subvlan); +bool vid_is_dsa_8021q_rxvlan (u16 vid) +{ +return (vid &DSA_8021Q_DIR_MASK ) ==DSA_8021Q_DIR_RX ; +} +EXPORT_SYMBOL_GPL (vid_is_dsa_8021q_rxvlan); + +bool vid_is_dsa_8021q_txvlan (u16 vid) +{ +return (vid &DSA_8021Q_DIR_MASK ) ==DSA_8021Q_DIR_TX ; +} +EXPORT_SYMBOL_GPL (vid_is_dsa_8021q_txvlan); +bool vid_is_dsa_8021q (u16 vid) { -return ((vid &DSA_8021Q_DIR_MASK ) ==DSA_8021Q_DIR_RX || - (vid &DSA_8021Q_DIR_MASK ) ==DSA_8021Q_DIR_TX ); +return vid_is_dsa_8021q_rxvlan (vid) ||vid_is_dsa_8021q_txvlan (vid); }EXPORT_SYMBOL_GPL (vid_is_dsa_8021q);
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v5 2/10 net: mscc: ocelot: export VCAP structures to include/soc/mscc
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The Felix driver will need to preinstall some VCAP filters for its tag_8021q implementation (outside of the tc-flower offload logic), so these need to be exported to the common includes.
---
Changes in v5:
None.
Changes in v3:
None.
Changes in v2:
Patch is new.
Changes in v4:
Use EXPORT_SYMBOL for ocelot_vcap_filter_add and ocelot_vcap_filter_del so that building as module does not fail.
Changes in v3:
None.
Changes in v2:
Patch is new.
drivers/net/ethernet/mscc/ocelot_net.c | 1 + drivers/net/ethernet/mscc/ocelot_vcap.c | 2 + drivers/net/ethernet/mscc/ocelot_vcap.h | 293 +----------------------- include/soc/mscc/ocelot_vcap.h | 289 +++++++++++++++++++++++ 4 files changed, 294 insertions(+), 291 deletions(-)
drivers/net/ethernet/mscc/ocelot_net.c +1 -0
@@ -9,6 +9,7 @@*/ #include <linux/if_bridge.h> +#include <net/pkt_cls.h> #include "ocelot.h" #include "ocelot_vcap.h"
drivers/net/ethernet/mscc/ocelot_vcap.c +2 -0
@@ -1150,6 +1150,7 @@ int ocelot_vcap_filter_add(struct ocelot *ocelot,vcap_entry_set (ocelot, index, filter);return 0 ; } +EXPORT_SYMBOL (ocelot_vcap_filter_add); static void ocelot_vcap_block_remove_filter(struct ocelot *ocelot, struct ocelot_vcap_block *block,
@@ -1204,6 +1205,7 @@ int ocelot_vcap_filter_del(struct ocelot *ocelot,return 0 ; } +EXPORT_SYMBOL (ocelot_vcap_filter_del);int ocelot_vcap_filter_stats_update (struct ocelot *ocelot,struct ocelot_vcap_filter *filter)
drivers/net/ethernet/mscc/ocelot_vcap.h +2 -291
302 lines not on this page · raw message
include/soc/mscc/ocelot_vcap.h +289 -0
293 lines not on this page · raw message
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v5 3/10 net: mscc: ocelot: store a namespaced VCAP filter ID
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
We will be adding some private VCAP filters that should not interfere in any way with the filters added using tc-flower. So we need to allocate some IDs which will not be used by tc.
Currently ocelot uses an u32 id derived from the flow cookie, which in itself is an unsigned long. This is a problem in itself, since on 64 bit systems, sizeof(unsigned long)=8, so the driver is already truncating these.
Create a struct ocelot_vcap_id which contains the full unsigned long cookie from tc, as well as a boolean that is supposed to namespace the filters added by tc with the ones that aren't.
---
Changes in v5:
None.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
Patch is new.
drivers/net/ethernet/mscc/ocelot_flower.c | 7 ++++--- drivers/net/ethernet/mscc/ocelot_vcap.c | 16 ++++++++++++---- drivers/net/ethernet/mscc/ocelot_vcap.h | 3 ++- include/soc/mscc/ocelot_vcap.h | 7 ++++++- 4 files changed, 24 insertions(+), 9 deletions(-)
drivers/net/ethernet/mscc/ocelot_flower.c +4 -3
@@ -622,7 +622,8 @@ static int ocelot_flower_parse(struct ocelot *ocelot, int port, bool ingress,int ret; filter->prio = f->common.prio; - filter->id = f->cookie; + filter->id.cookie = f->cookie; + filter->id.tc_offload = true; ret =ocelot_flower_parse_action (ocelot, port, ingress, f, filter);if (ret)
@@ -717,7 +718,7 @@ int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port, block = &ocelot->block[block_id]; - filter =ocelot_vcap_block_find_filter_by_id (block, f->cookie); + filter =ocelot_vcap_block_find_filter_by_id (block, f->cookie, true);if (!filter)return 0 ;
@@ -741,7 +742,7 @@ int ocelot_cls_flower_stats(struct ocelot *ocelot, int port, block = &ocelot->block[block_id]; - filter =ocelot_vcap_block_find_filter_by_id (block, f->cookie); + filter =ocelot_vcap_block_find_filter_by_id (block, f->cookie, true);if (!filter || filter->type ==OCELOT_VCAP_FILTER_DUMMY )return 0 ;
drivers/net/ethernet/mscc/ocelot_vcap.c +12 -4
@@ -959,6 +959,12 @@ static void ocelot_vcap_filter_add_to_block(struct ocelot *ocelot,list_add (&filter->list, pos->prev); } +static bool ocelot_vcap_filter_equal (const struct ocelot_vcap_filter *a, +const struct ocelot_vcap_filter *b) +{ +return !memcmp (&a->id, &b->id,sizeof (struct ocelot_vcap_id )); +} +static int ocelot_vcap_block_get_filter_index (struct ocelot_vcap_block *block,struct ocelot_vcap_filter *filter) {
@@ -966,7 +972,7 @@ static int ocelot_vcap_block_get_filter_index(struct ocelot_vcap_block *block,int index =0 ;list_for_each_entry (tmp, &block->rules, list) { -if (filter->id == tmp->id) +if (ocelot_vcap_filter_equal (filter, tmp))return index; index++; }
@@ -991,12 +997,14 @@ ocelot_vcap_block_find_filter_by_index(struct ocelot_vcap_block *block, }struct ocelot_vcap_filter * -ocelot_vcap_block_find_filter_by_id (struct ocelot_vcap_block *block,int id) +ocelot_vcap_block_find_filter_by_id (struct ocelot_vcap_block *block,int cookie, +bool tc_offload) {struct ocelot_vcap_filter *filter;list_for_each_entry (filter, &block->rules, list) -if (filter->id == id) +if (filter->id.tc_offload == tc_offload && + filter->id.cookie == cookie)return filter;return NULL ;
@@ -1161,7 +1169,7 @@ static void ocelot_vcap_block_remove_filter(struct ocelot *ocelot,list_for_each_safe (pos, q, &block->rules) { tmp = list_entry(pos, struct ocelot_vcap_filter, list); -if (tmp->id == filter->id) { +if (ocelot_vcap_filter_equal (filter, tmp)) {if (tmp->block_id ==VCAP_IS2 && tmp->action.police_ena) ocelot_vcap_policer_del(ocelot, block,
drivers/net/ethernet/mscc/ocelot_vcap.h +2 -1
@@ -15,7 +15,8 @@int ocelot_vcap_filter_stats_update (struct ocelot *ocelot,struct ocelot_vcap_filter *rule);struct ocelot_vcap_filter * -ocelot_vcap_block_find_filter_by_id (struct ocelot_vcap_block *block,int id); +ocelot_vcap_block_find_filter_by_id (struct ocelot_vcap_block *block,int id, +bool tc_offload);void ocelot_detect_vcap_constants (struct ocelot *ocelot);int ocelot_vcap_init (struct ocelot *ocelot);
include/soc/mscc/ocelot_vcap.h +6 -1
@@ -648,6 +648,11 @@ enum ocelot_vcap_filter_type { OCELOT_VCAP_FILTER_OFFLOAD, }; +struct ocelot_vcap_id { +unsigned long cookie; +bool tc_offload; +}; +struct ocelot_vcap_filter {struct list_head list;
@@ -657,7 +662,7 @@ struct ocelot_vcap_filter {int lookup;u8 pag;u16 prio; -u32 id; +struct ocelot_vcap_id id;struct ocelot_vcap_action action;struct ocelot_vcap_stats stats;
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v5 4/10 net: mscc: ocelot: reapply bridge forwarding mask on bonding join/leave
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Applying the bridge forwarding mask currently is done only on the STP state changes for any port. But it depends on both STP state changes, and bonding interface state changes. Export the bit that recalculates the forwarding mask so that it could be reused, and call it when a port starts and stops offloading a bonding interface.
Now that the logic is split into a separate function, we can rename "p" into "port", since the "port" variable was already taken in ocelot_bridge_stp_state_set. Also, we can rename "i" into "lag", to make it more clear what is it that we're iterating through.
---
Changes in v5:
None.
Changes in v4:
Patch is carried over from the "LAG offload for Ocelot DSA switches" series:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
I need it here because it refactors ocelot_apply_bridge_fwd_mask into a separate function which I also need to call from felix now.
drivers/net/ethernet/mscc/ocelot.c | 63 +++++++++++++++++------------- 1 file changed, 36 insertions(+), 27 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +36 -27
@@ -876,10 +876,42 @@ int ocelot_get_ts_info(struct ocelot *ocelot, int port, }EXPORT_SYMBOL (ocelot_get_ts_info); +static void ocelot_apply_bridge_fwd_mask (struct ocelot *ocelot) +{ +int port; + +/* Apply FWD mask. The loop is needed to add/remove the current port as +* a source for the other ports. +*/ +for (port =0 ; port < ocelot->num_phys_ports; port++) { +if (ocelot->bridge_fwd_mask &BIT (port)) { +unsigned long mask = ocelot->bridge_fwd_mask & ~BIT (port); +int lag; + +for (lag =0 ; lag < ocelot->num_phys_ports; lag++) { +unsigned long bond_mask = ocelot->lags[lag]; + +if (!bond_mask) +continue ; + +if (bond_mask &BIT (port)) { + mask &= ~bond_mask; +break ; + } + } + +ocelot_write_rix (ocelot, mask, +ANA_PGID_PGID ,PGID_SRC + port); + }else { +ocelot_write_rix (ocelot,0 , +ANA_PGID_PGID ,PGID_SRC + port); + } + } +} +void ocelot_bridge_stp_state_set (struct ocelot *ocelot,int port,u8 state) {u32 port_cfg; -int p, i;if (!(BIT (port) & ocelot->bridge_mask))return ;
@@ -902,32 +934,7 @@ void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state)ocelot_write_gix (ocelot, port_cfg,ANA_PORT_PORT_CFG , port); -/* Apply FWD mask. The loop is needed to add/remove the current port as -* a source for the other ports. -*/ -for (p =0 ; p < ocelot->num_phys_ports; p++) { -if (ocelot->bridge_fwd_mask &BIT (p)) { -unsigned long mask = ocelot->bridge_fwd_mask & ~BIT (p); - -for (i =0 ; i < ocelot->num_phys_ports; i++) { -unsigned long bond_mask = ocelot->lags[i]; - -if (!bond_mask) -continue ; - -if (bond_mask &BIT (p)) { - mask &= ~bond_mask; -break ; - } - } - -ocelot_write_rix (ocelot, mask, -ANA_PGID_PGID ,PGID_SRC + p); - }else { -ocelot_write_rix (ocelot,0 , -ANA_PGID_PGID ,PGID_SRC + p); - } - } +ocelot_apply_bridge_fwd_mask (ocelot); }EXPORT_SYMBOL (ocelot_bridge_stp_state_set);
@@ -1284,6 +1291,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, }ocelot_setup_lag (ocelot, lag); +ocelot_apply_bridge_fwd_mask (ocelot);ocelot_set_aggr_pgids (ocelot);return 0 ;
@@ -1317,6 +1325,7 @@ void ocelot_port_lag_leave(struct ocelot *ocelot, int port,ocelot_write_gix (ocelot, port_cfg |ANA_PORT_PORT_CFG_PORTID_VAL (port),ANA_PORT_PORT_CFG , port); +ocelot_apply_bridge_fwd_mask (ocelot);ocelot_set_aggr_pgids (ocelot); }EXPORT_SYMBOL (ocelot_port_lag_leave);
Signature · 1 line
2.25.1
Re: [PATCH v5 net-next 04/10] net: mscc: ocelot: reapply bridge forwarding mask on bonding join/leave
Quoted 8 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Applying the bridge forwarding mask currently is done only on the STP state changes for any port. But it depends on both STP state changes, and bonding interface state changes. Export the bit that recalculates the forwarding mask so that it could be reused, and call it when a port starts and stops offloading a bonding interface.
Quoted 7 lines
Now that the logic is split into a separate function, we can rename "p" into "port", since the "port" variable was already taken in
ocelot_bridge_stp_state_set. Also, we can rename "i" into "lag", to make it more clear what is it that we're iterating through.Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Alexandre Belloni <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v5 5/10 net: mscc: ocelot: don't use NPI tag prefix for the CPU port module
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Context: Ocelot switches put the injection/extraction frame header in front of the Ethernet header. When used in NPI mode, a DSA master would see junk instead of the destination MAC address, and it would most likely drop the packets. So the Ocelot frame header can have an optional prefix, which is just "ff:ff:ff:ff:ff:fe > ff:ff:ff:ff:ff:ff" padding put before the actual tag (still before the real Ethernet header) such that the DSA master thinks it's looking at a broadcast frame with a strange EtherType.
Unfortunately, a lesson learned in commit 69df578c5f4b ("net: mscc:
ocelot: eliminate confusion between CPU and NPI port") seems to have been forgotten in the meanwhile.
The CPU port module and the NPI port have independent settings for the length of the tag prefix. However, the driver is using the same variable to program both of them.
There is no reason really to use any tag prefix with the CPU port module, since that is not connected to any Ethernet port. So this patch makes the inj_prefix and xtr_prefix variables apply only to the NPI port (which the switchdev ocelot_vsc7514 driver does not use).
---
Changes in v5:
Patch is new.
Changes in v4:
Patch is new.
drivers/net/dsa/ocelot/felix.c | 8 ++++---- drivers/net/ethernet/mscc/ocelot.c | 12 ++++++------ drivers/net/ethernet/mscc/ocelot_vsc7514.c | 2 -- include/soc/mscc/ocelot.h | 4 ++-- 4 files changed, 12 insertions(+), 14 deletions(-)
drivers/net/dsa/ocelot/felix.c +4 -4
@@ -425,8 +425,8 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports) ocelot->num_mact_rows = felix->info->num_mact_rows; ocelot->vcap = felix->info->vcap; ocelot->ops = felix->info->ops; - ocelot->inj_prefix =OCELOT_TAG_PREFIX_SHORT ; - ocelot->xtr_prefix =OCELOT_TAG_PREFIX_SHORT ; + ocelot->npi_inj_prefix =OCELOT_TAG_PREFIX_SHORT ; + ocelot->npi_xtr_prefix =OCELOT_TAG_PREFIX_SHORT ; ocelot->devlink = felix->ds->devlink; port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t),
@@ -541,9 +541,9 @@ static void felix_npi_port_init(struct ocelot *ocelot, int port)/* NPI port Injection/Extraction configuration */ ocelot_fields_write (ocelot, port,SYS_PORT_MODE_INCL_XTR_HDR , - ocelot->xtr_prefix); + ocelot->npi_xtr_prefix);ocelot_fields_write (ocelot, port,SYS_PORT_MODE_INCL_INJ_HDR , - ocelot->inj_prefix); + ocelot->npi_inj_prefix);/* Disable transmission of pause frames */ ocelot_fields_write (ocelot, port,SYS_PAUSE_CFG_PAUSE_ENA ,0 );
drivers/net/ethernet/mscc/ocelot.c +6 -6
@@ -1346,9 +1346,9 @@ void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu)if (port == ocelot->npi) { maxlen +=OCELOT_TAG_LEN ; -if (ocelot->inj_prefix ==OCELOT_TAG_PREFIX_SHORT ) +if (ocelot->npi_inj_prefix ==OCELOT_TAG_PREFIX_SHORT ) maxlen +=OCELOT_SHORT_PREFIX_LEN ; -else if (ocelot->inj_prefix ==OCELOT_TAG_PREFIX_LONG ) +else if (ocelot->npi_inj_prefix ==OCELOT_TAG_PREFIX_LONG ) maxlen +=OCELOT_LONG_PREFIX_LEN ; }
@@ -1378,9 +1378,9 @@ int ocelot_get_max_mtu(struct ocelot *ocelot, int port)if (port == ocelot->npi) { max_mtu -=OCELOT_TAG_LEN ; -if (ocelot->inj_prefix ==OCELOT_TAG_PREFIX_SHORT ) +if (ocelot->npi_inj_prefix ==OCELOT_TAG_PREFIX_SHORT ) max_mtu -=OCELOT_SHORT_PREFIX_LEN ; -else if (ocelot->inj_prefix ==OCELOT_TAG_PREFIX_LONG ) +else if (ocelot->npi_inj_prefix ==OCELOT_TAG_PREFIX_LONG ) max_mtu -=OCELOT_LONG_PREFIX_LEN ; }
@@ -1465,9 +1465,9 @@ static void ocelot_cpu_port_init(struct ocelot *ocelot)ocelot_fields_write (ocelot, cpu,QSYS_SWITCH_PORT_MODE_PORT_ENA ,1 );/* CPU port Injection/Extraction configuration */ ocelot_fields_write (ocelot, cpu,SYS_PORT_MODE_INCL_XTR_HDR , - ocelot->xtr_prefix); +OCELOT_TAG_PREFIX_NONE );ocelot_fields_write (ocelot, cpu,SYS_PORT_MODE_INCL_INJ_HDR , - ocelot->inj_prefix); +OCELOT_TAG_PREFIX_NONE );/* Configure the CPU port to be VLAN aware */ ocelot_write_gix(ocelot, ANA_PORT_VLAN_CFG_VLAN_VID(0) |
drivers/net/ethernet/mscc/ocelot_vsc7514.c +0 -2
@@ -1347,8 +1347,6 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->num_flooding_pgids =1 ; ocelot->vcap = vsc7514_vcap_props; - ocelot->inj_prefix =OCELOT_TAG_PREFIX_NONE ; - ocelot->xtr_prefix =OCELOT_TAG_PREFIX_NONE ; ocelot->npi =-1 ; err =ocelot_init (ocelot);
include/soc/mscc/ocelot.h +2 -2
@@ -651,8 +651,8 @@ struct ocelot {int npi; -enum ocelot_tag_prefix inj_prefix; -enum ocelot_tag_prefix xtr_prefix; +enum ocelot_tag_prefix npi_inj_prefix; +enum ocelot_tag_prefix npi_xtr_prefix;u32 *lags;
Signature · 1 line
2.25.1
Re: [PATCH v5 net-next 05/10] net: mscc: ocelot: don't use NPI tag prefix for the CPU port module
Quoted 19 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Context: Ocelot switches put the injection/extraction frame header in front of the Ethernet header. When used in NPI mode, a DSA master would see junk instead of the destination MAC address, and it would most likely drop the packets. So the Ocelot frame header can have an optional prefix, which is just "ff:ff:ff:ff:ff:fe > ff:ff:ff:ff:ff:ff" padding put before the actual tag (still before the real Ethernet header) such that the DSA master thinks it's looking at a broadcast frame with a strange EtherType.
Unfortunately, a lesson learned in commit
69df578c5f4b("net: mscc:
ocelot: eliminate confusion between CPU and NPI port") seems to have been forgotten in the meanwhile.The CPU port module and the NPI port have independent settings for the length of the tag prefix. However, the driver is using the same variable to program both of them.
Quoted 6 lines
There is no reason really to use any tag prefix with the CPU port module, since that is not connected to any Ethernet port. So this patch makes the
inj_prefixandxtr_prefixvariables apply only to the NPI port (which the switchdevocelot_vsc7514driver does not use).Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v5 6/10 net: dsa: document the existing switch tree notifiers and add a new one
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The existence of dsa_broadcast has generated some confusion in the past:
https://www.mail-archive.com/[email protected]/msg365042.html
So let's document the existing dsa_port_notify and dsa_broadcast functions and explain when each of them should be used.
Also, in fact, the in-between function has always been there but was lacking a name, and is the main reason for this patch: dsa_tree_notify. Refactor dsa_broadcast to use it.
This patch also moves dsa_broadcast (a top-level function) to dsa2.c, where it really belonged in the first place, but had no companion so it stood with dsa_port_notify.
---
Changes in v5:
Patch is new.
net/dsa/dsa2.c | 43 +++++++++++++++++++++++++++++++++++++++++++ net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 36 +++++++++++++----------------------- 3 files changed, 58 insertions(+), 23 deletions(-)
net/dsa/dsa2.c +43 -0
@@ -21,6 +21,49 @@static DEFINE_MUTEX (dsa2_mutex);LIST_HEAD (dsa_tree_list); +/** +* dsa_tree_notify - Execute code for all switches in a DSA switch tree. +* @dst: collection of struct dsa_switch devices to notify. +* @e: event, must be of type DSA_NOTIFIER_* +* @v: event-specific value. +* +* Given a struct dsa_switch_tree, this can be used to run a function once for +* each member DSA switch. The other alternative of traversing the tree is only +* through its ports list, which does not uniquely list the switches. +*/ +int dsa_tree_notify (struct dsa_switch_tree *dst,unsigned long e,void *v) +{ +struct raw_notifier_head *nh = &dst->nh; +int err; + + err =raw_notifier_call_chain (nh, e, v); + +return notifier_to_errno (err); +} + +/** +* dsa_broadcast - Notify all DSA trees in the system. +* @e: event, must be of type DSA_NOTIFIER_* +* @v: event-specific value. +* +* Can be used to notify the switching fabric of events such as cross-chip +* bridging between disjoint trees (such as islands of tagger-compatible +* switches bridged by an incompatible middle switch). +*/ +int dsa_broadcast (unsigned long e,void *v) +{ +struct dsa_switch_tree *dst; +int err =0 ; + +list_for_each_entry (dst, &dsa_tree_list, list) { + err =dsa_tree_notify (dst, e, v); +if (err) +break ; + } + +return err; +} +/** * dsa_lag_map() - Map LAG netdev to a linear LAG ID * @dst: Tree in which to record the mapping.
net/dsa/dsa_priv.h +2 -0
@@ -283,6 +283,8 @@ void dsa_switch_unregister_notifier(struct dsa_switch *ds);/* dsa2.c */ void dsa_lag_map (struct dsa_switch_tree *dst,struct net_device *lag);void dsa_lag_unmap (struct dsa_switch_tree *dst,struct net_device *lag); +int dsa_tree_notify (struct dsa_switch_tree *dst,unsigned long e,void *v); +int dsa_broadcast (unsigned long e,void *v);extern struct list_head dsa_tree_list;
net/dsa/port.c +13 -23
@@ -13,31 +13,21 @@#include "dsa_priv.h" -static int dsa_broadcast (unsigned long e,void *v) -{ -struct dsa_switch_tree *dst; -int err =0 ; - -list_for_each_entry (dst, &dsa_tree_list, list) { -struct raw_notifier_head *nh = &dst->nh; - - err =raw_notifier_call_chain (nh, e, v); - err =notifier_to_errno (err); -if (err) -break ; - } - -return err; -} - +/** +* dsa_port_notify - Notify the switching fabric of changes to a port +* @dp: port on which change occurred +* @e: event, must be of type DSA_NOTIFIER_* +* @v: event-specific value. +* +* Notify all switches in the DSA tree that this port's switch belongs to, +* including this switch itself, of an event. Allows the other switches to +* reconfigure themselves for cross-chip operations. Can also be used to +* reconfigure ports without net_devices (CPU ports, DSA links) whenever +* a user port's state changes. +*/ static int dsa_port_notify (const struct dsa_port *dp,unsigned long e,void *v) { -struct raw_notifier_head *nh = &dp->ds->dst->nh; -int err; - - err =raw_notifier_call_chain (nh, e, v); - -return notifier_to_errno (err); +return dsa_tree_notify (dp->ds->dst, e, v); }int dsa_port_set_state (struct dsa_port *dp,u8 state)
Signature · 1 line
2.25.1
Re: [PATCH v5 net-next 06/10] net: dsa: document the existing switch tree notifiers and add a new one
Quoted 12 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
The existence of
dsa_broadcasthas generated some confusion in the past:
https://www.mail-archive.com/[email protected]/msg365042.htmlSo let's document the existing
dsa_port_notifyanddsa_broadcastfunctions and explain when each of them should be used.Also, in fact, the in-between function has always been there but was lacking a name, and is the main reason for this patch:
dsa_tree_notify. Refactordsa_broadcastto use it.
Quoted 5 lines
This patch also moves
dsa_broadcast(a top-level function) todsa2.c, where it really belonged in the first place, but had no companion so it stood withdsa_port_notify.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v5 7/10 net: dsa: allow changing the tag protocol via the "tagging" device attribute
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Currently DSA exposes the following sysfs:
$ cat /sys/class/net/eno2/dsa/tagging ocelot
which is a read-only device attribute, introduced in the kernel as commit 98cdb4807123 ("net: dsa: Expose tagging protocol to user-space"), and used by libpcap since its commit 993db3800d7d ("Add support for DSA link-layer types").
It would be nice if we could extend this device attribute by making it writable:
$ echo ocelot-8021q > /sys/class/net/eno2/dsa/tagging
This is useful with DSA switches that can make use of more than one tagging protocol. It may be useful in dsa_loop in the future too, to perform offline testing of various taggers, or for changing between dsa and edsa on Marvell switches, if that is desirable.
In terms of implementation, drivers can now move their tagging protocol configuration outside of .setup/.teardown, and into .set_tag_protocol and .del_tag_protocol. The calling order is:
.setup -> [.set_tag_protocol -> .del_tag_protocol]+ -> .teardown
There was one more contract between the DSA framework and drivers, which is that if a CPU port needs to account for the tagger overhead in its MTU configuration, it must do that privately. Which means it needs the information about what tagger it uses before we call its MTU configuration function. That promise is still held.
Writing to the tagging sysfs will first tear down the tagging protocol for all switches in the tree attached to that DSA master, then will attempt setup with the new tagger.
Writing will fail quickly with -EOPNOTSUPP for drivers that don't support .set_tag_protocol, since that is checked during the deletion phase. It is assumed that all switches within the same DSA tree use the same driver, and therefore either all have .set_tag_protocol implemented, or none do.
---
Changes in v5:
- Update the sysfs documentation
- Make the tagger_lock per DSA switch tree instead of per DSA switch, and hold it across the entire delete -> set procedure.
- Use dsa_tree_notify instead of dsa_broadcast.
Changes in v4:
Patch is new.
Documentation/ABI/testing/sysfs-class-net-dsa | 11 ++- include/net/dsa.h | 21 +++++ net/dsa/dsa.c | 20 +++++ net/dsa/dsa2.c | 86 +++++++++++++++++- net/dsa/dsa_priv.h | 17 ++++ net/dsa/master.c | 26 +++++- net/dsa/port.c | 8 ++ net/dsa/slave.c | 35 +++++--- net/dsa/switch.c | 88 +++++++++++++++++++ 9 files changed, 294 insertions(+), 18 deletions(-)
Documentation/ABI/testing/sysfs-class-net-dsa +9 -2
@@ -3,5 +3,12 @@ Date: August 2018 KernelVersion: 4.20 Contact: [email protected] Description: - String indicating the type of tagging protocol used by the - DSA slave network device. + On read, this file returns a string indicating the type of + tagging protocol used by the DSA network devices that are + attached to this master interface. + On write, this file changes the tagging protocol of the + attached DSA switches, if this operation is supported by the + driver. Changing the tagging protocol must be done with the DSA + interfaces and the master interface all administratively down. + See the "name" field of each registered struct dsa_device_ops + for a list of valid values.
include/net/dsa.h +21 -0
@@ -140,6 +140,12 @@ struct dsa_switch_tree {/* Has this tree been applied to the hardware? */ bool setup; +/* +* Used to serialize concurrent attempts to change the tagging +* protocol via the "tagging" device attribute. +*/ +struct mutex tagger_lock; +/* * Configuration data for the platform device that owns * this dsa switch tree instance.
@@ -480,9 +486,24 @@ static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)typedef int dsa_fdb_dump_cb_t (const unsigned char *addr,u16 vid,bool is_static,void *data);struct dsa_switch_ops { +/* +* Tagging protocol helpers. +* Switches that support a single tagging protocol should implement +* only @get_tag_protocol and hardcode the protocol that they support. +* Switches which can operate using multiple tagging protocols should +* report in @get_tag_protocol the tagger in current use. They can +* optionally set up the tagging protocol in @set_tag_protocol and +* perform teardown (memory deallocation, etc) in @del_tag_protocol. +* The framework guarantees paired calls to the last two functions. +* For all of these helpers, @port is the CPU port that gets set up. +*/ enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,int port,enum dsa_tag_protocol mprot); +int (*set_tag_protocol)(struct dsa_switch *ds,int port, +enum dsa_tag_protocol proto); +void (*del_tag_protocol)(struct dsa_switch *ds,int port, +enum dsa_tag_protocol proto);int (*setup)(struct dsa_switch *ds);void (*teardown)(struct dsa_switch *ds);
net/dsa/dsa.c +20 -0
@@ -84,6 +84,26 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)return ops->name; }; +const struct dsa_device_ops *dsa_find_tagger_by_name (const char *buf) +{ +const struct dsa_device_ops *ops =NULL ; +struct dsa_tag_driver *dsa_tag_driver; + +mutex_lock (&dsa_tag_drivers_lock); +list_for_each_entry (dsa_tag_driver, &dsa_tag_drivers_list, list) { +const struct dsa_device_ops *tmp = dsa_tag_driver->ops; + +if (!sysfs_streq (buf, tmp->name)) +continue ; + + ops = tmp; +break ; + } +mutex_unlock (&dsa_tag_drivers_lock); + +return ops; +} +const struct dsa_device_ops *dsa_tag_driver_get (int tag_protocol) {struct dsa_tag_driver *dsa_tag_driver;
net/dsa/dsa2.c +83 -3
123 lines not on this page · raw message
net/dsa/dsa_priv.h +17 -0
@@ -28,6 +28,8 @@ enum {DSA_NOTIFIER_VLAN_ADD ,DSA_NOTIFIER_VLAN_DEL ,DSA_NOTIFIER_MTU , +DSA_NOTIFIER_TAG_PROTO_SET , + DSA_NOTIFIER_TAG_PROTO_DEL, };/* DSA_NOTIFIER_AGEING_TIME */
@@ -82,6 +84,12 @@ struct dsa_notifier_mtu_info {int mtu; }; +/* DSA_NOTIFIER_TAG_PROTO_* */ +struct dsa_notifier_tag_proto_info { +int tree_index; +const struct dsa_device_ops *tag_ops; +}; +struct dsa_switchdev_event_work {struct dsa_switch *ds;int port;
@@ -115,6 +123,7 @@ struct dsa_slave_priv {/* dsa.c */ const struct dsa_device_ops *dsa_tag_driver_get (int tag_protocol);void dsa_tag_driver_put (const struct dsa_device_ops *ops); +const struct dsa_device_ops *dsa_find_tagger_by_name (const char *buf);bool dsa_schedule_work (struct work_struct *work);const char *dsa_tag_protocol_to_str (const struct dsa_device_ops *ops);
@@ -139,6 +148,8 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev, }/* port.c */ +void dsa_port_set_tag_protocol (struct dsa_port *cpu_dp, +const struct dsa_device_ops *tag_ops);int dsa_port_set_state (struct dsa_port *dp,u8 state);int dsa_port_enable_rt (struct dsa_port *dp,struct phy_device *phy);int dsa_port_enable (struct dsa_port *dp,struct phy_device *phy);
@@ -201,6 +212,8 @@ int dsa_slave_suspend(struct net_device *slave_dev);int dsa_slave_resume (struct net_device *slave_dev);int dsa_slave_register_notifier (void );void dsa_slave_unregister_notifier (void ); +void dsa_slave_setup_tagger (struct net_device *slave); +int dsa_slave_change_mtu (struct net_device *dev,int new_mtu);static inline struct dsa_port *dsa_slave_to_port (const struct net_device *dev) {
@@ -285,6 +298,10 @@ void dsa_lag_map(struct dsa_switch_tree *dst, struct net_device *lag);void dsa_lag_unmap (struct dsa_switch_tree *dst,struct net_device *lag);int dsa_tree_notify (struct dsa_switch_tree *dst,unsigned long e,void *v);int dsa_broadcast (unsigned long e,void *v); +int dsa_tree_change_tag_proto (struct dsa_switch_tree *dst, +struct net_device *master, +const struct dsa_device_ops *tag_ops, +const struct dsa_device_ops *old_tag_ops);extern struct list_head dsa_tree_list;
net/dsa/master.c +25 -1
@@ -280,7 +280,31 @@ static ssize_t tagging_show(struct device *d, struct device_attribute *attr,return sprintf (buf,"%s\n" ,dsa_tag_protocol_to_str (cpu_dp->tag_ops)); } -static DEVICE_ATTR_RO (tagging); + +static ssize_t tagging_store (struct device *d,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct net_device *dev =to_net_dev (d); +struct dsa_port *cpu_dp = dev->dsa_ptr; +const struct dsa_device_ops *ops; +int err; + + ops =dsa_find_tagger_by_name (buf); +/* Bad tagger name, or module is not loaded? */ +if (!ops) +return -ENOENT ; + +if (ops == cpu_dp->tag_ops) + goto out; + + err =dsa_tree_change_tag_proto (cpu_dp->ds->dst, dev, ops, + cpu_dp->tag_ops); +if (err) +return err; +out: +return count; +} +static DEVICE_ATTR_RW (tagging);static struct attribute *dsa_slave_attrs[] = { &dev_attr_tagging.attr,
net/dsa/port.c +8 -0
@@ -526,6 +526,14 @@ int dsa_port_vlan_del(struct dsa_port *dp,return dsa_port_notify (dp,DSA_NOTIFIER_VLAN_DEL , &info); } +void dsa_port_set_tag_protocol (struct dsa_port *cpu_dp, +const struct dsa_device_ops *tag_ops) +{ + cpu_dp->filter = tag_ops->filter; + cpu_dp->rcv = tag_ops->rcv; + cpu_dp->tag_ops = tag_ops; +} +static struct phy_device *dsa_port_get_phy_device (struct dsa_port *dp) {struct device_node *phy_dn;
net/dsa/slave.c +23 -12
@@ -1430,7 +1430,7 @@ static void dsa_bridge_mtu_normalization(struct dsa_port *dp)dsa_hw_port_list_free (&hw_port_list); } -static int dsa_slave_change_mtu (struct net_device *dev,int new_mtu) +int dsa_slave_change_mtu (struct net_device *dev,int new_mtu) {struct net_device *master =dsa_slave_to_master (dev);struct dsa_port *dp =dsa_slave_to_port (dev);
@@ -1708,6 +1708,27 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)return ret; } +void dsa_slave_setup_tagger (struct net_device *slave) +{ +struct dsa_port *dp =dsa_slave_to_port (slave); +struct dsa_slave_priv *p =netdev_priv (slave); +const struct dsa_port *cpu_dp = dp->cpu_dp; +struct net_device *master = cpu_dp->master; + +if (cpu_dp->tag_ops->tail_tag) + slave->needed_tailroom = cpu_dp->tag_ops->overhead; +else + slave->needed_headroom = cpu_dp->tag_ops->overhead; +/* Try to save one extra realloc later in the TX path (in the master) +* by also inheriting the master's needed headroom and tailroom. +* The 8021q driver also does this. +*/ + slave->needed_headroom += master->needed_headroom; + slave->needed_tailroom += master->needed_tailroom; + + p->xmit = cpu_dp->tag_ops->xmit; +} +static struct lock_class_key dsa_slave_netdev_xmit_lock_key; static void dsa_slave_set_lockdep_class_one(struct net_device *dev, struct netdev_queue *txq,
@@ -1782,16 +1803,6 @@ int dsa_slave_create(struct dsa_port *port) slave_dev->netdev_ops = &dsa_slave_netdev_ops;if (ds->ops->port_max_mtu) slave_dev->max_mtu = ds->ops->port_max_mtu (ds, port->index); -if (cpu_dp->tag_ops->tail_tag) - slave_dev->needed_tailroom = cpu_dp->tag_ops->overhead; -else - slave_dev->needed_headroom = cpu_dp->tag_ops->overhead; -/* Try to save one extra realloc later in the TX path (in the master) -* by also inheriting the master's needed headroom and tailroom. -* The 8021q driver also does this. -*/ - slave_dev->needed_headroom += master->needed_headroom; - slave_dev->needed_tailroom += master->needed_tailroom;SET_NETDEV_DEVTYPE (slave_dev, &dsa_type); netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one,
@@ -1814,8 +1825,8 @@ int dsa_slave_create(struct dsa_port *port) p->dp = port;INIT_LIST_HEAD (&p->mall_tc_list); - p->xmit = cpu_dp->tag_ops->xmit; port->slave = slave_dev; +dsa_slave_setup_tagger (slave_dev);rtnl_lock (); ret =dsa_slave_change_mtu (slave_dev,ETH_DATA_LEN );
net/dsa/switch.c +88 -0
100 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v5 net-next 07/10] net: dsa: allow changing the tag protocol via the "tagging" device attribute
Quoted 36 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Currently DSA exposes the following sysfs:
$ cat /sys/class/net/eno2/dsa/tagging ocelotwhich is a read-only device attribute, introduced in the kernel as commit
98cdb4807123("net: dsa: Expose tagging protocol to user-space"), and used by libpcap since its commit993db3800d7d("Add support for DSA link-layer types").It would be nice if we could extend this device attribute by making it writable:
$ echo ocelot-8021q > /sys/class/net/eno2/dsa/taggingThis is useful with DSA switches that can make use of more than one tagging protocol. It may be useful in
dsa_loopin the future too, to perform offline testing of various taggers, or for changing between dsa and edsa on Marvell switches, if that is desirable.In terms of implementation, drivers can now move their tagging protocol configuration outside of .setup/.teardown, and into .set_tag_protocol and .del_tag_protocol. The calling order is:
.setup -> [.set_tag_protocol -> .del_tag_protocol]+ -> .teardown
There was one more contract between the DSA framework and drivers, which is that if a CPU port needs to account for the tagger overhead in its MTU configuration, it must do that privately. Which means it needs the information about what tagger it uses before we call its MTU configuration function. That promise is still held.
Writing to the tagging sysfs will first tear down the tagging protocol for all switches in the tree attached to that DSA master, then will attempt setup with the new tagger.
Quoted 8 lines
Writing will fail quickly with
-EOPNOTSUPPfor drivers that don't support .set_tag_protocol, since that is checked during the deletion phase. It is assumed that all switches within the same DSA tree use the same driver, and therefore either all have .set_tag_protocol implemented, or none do.Signed-off-by Vladimir Oltean <[email protected]>---
We talked about it over IRC and I like the approach you have taken, few comments below:
[snip]
Quoted 6 lines
net/dsa/switch.c +6
-0+static int dsa_switch_tag_proto_del (struct dsa_switch *ds, +struct dsa_notifier_tag_proto_info *info) +{ +int err =0 , port; + +for (port =0 ; port < ds->num_ports; port++) {
net/dsa/switch.c static int dsa_switch_vlan_del(struct dsa_switch *ds, · line 324
Quoted 10 lines
net/dsa/switch.c +10
-0+if (!dsa_switch_tag_proto_match (ds, port, info)) +continue ; + +/* Check early if we can replace it, so we don't delete it +* for nothing and leave the switch dangling. +*/ +if (!ds->ops->set_tag_protocol) { + err = -EOPNOTSUPP ; +break ; + }
This can be moved out of the loop.
Quoted 18 lines
net/dsa/switch.c +18
-0+ +/* The delete method is optional, just the setter +* is mandatory +*/ +if (ds->ops->del_tag_protocol) + ds->ops->del_tag_protocol (ds, port, + info->tag_ops->proto); + } + +return err; +} + +static int dsa_switch_tag_proto_set (struct dsa_switch *ds, +struct dsa_notifier_tag_proto_info *info) +{ +bool proto_changed = false; +int port, err; +
net/dsa/switch.c static int dsa_switch_vlan_del(struct dsa_switch *ds, · line 352
Quoted 10 lines
net/dsa/switch.c +10
-0+for (port =0 ; port < ds->num_ports; port++) { +struct dsa_port *cpu_dp =dsa_to_port (ds, port); + +if (!dsa_switch_tag_proto_match (ds, port, info)) +continue ; + + err = ds->ops->set_tag_protocol (ds, cpu_dp->index, + info->tag_ops->proto); +if (err) +return err;
Don't you need to test for ds->ops->set_tag_protocol to be implemented before calling it? Similar comment to earlier, can we do an early check for the operation being supported outside of the loop?
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 07/10] net: dsa: allow changing the tag protocol via the "tagging" device attribute
Hi Florian,
Quoted 10 lines · Florian Fainelli
Quoted 10 lines
net/dsa/switch.c +10
-0+static int dsa_switch_tag_proto_del (struct dsa_switch *ds, +struct dsa_notifier_tag_proto_info *info) +{ +int err =0 , port; + +for (port =0 ; port < ds->num_ports; port++) { +if (!dsa_switch_tag_proto_match (ds, port, info)) +continue ; + +/* Check early if we can replace it, so we don't delete it
Quoted 8 lines
net/dsa/switch.c static int dsa_switch_vlan_del(struct dsa_switch *ds, · line 324
Quoted 6 lines
net/dsa/switch.c +6
-0+* for nothing and leave the switch dangling. +*/ +if (!ds->ops->set_tag_protocol) { + err = -EOPNOTSUPP ; +break ; + }This can be moved out of the loop.
Thanks a lot for reviewing.
Yes, you are right, this can be moved out. It is a left-over from using dsa_broadcast in the previous version. It is not the only left-over: the info->tree_index is now redundant because we are notifying within a single DSA switch tree.
Quoted 24 lines
Quoted 24 lines
net/dsa/switch.c +24
-0+ +/* The delete method is optional, just the setter +* is mandatory +*/ +if (ds->ops->del_tag_protocol) + ds->ops->del_tag_protocol (ds, port, + info->tag_ops->proto); + } + +return err; +} + +static int dsa_switch_tag_proto_set (struct dsa_switch *ds, +struct dsa_notifier_tag_proto_info *info) +{ +bool proto_changed = false; +int port, err; + +for (port =0 ; port < ds->num_ports; port++) { +struct dsa_port *cpu_dp =dsa_to_port (ds, port); + +if (!dsa_switch_tag_proto_match (ds, port, info)) +continue ; +
Quoted 8 lines
net/dsa/switch.c static int dsa_switch_vlan_del(struct dsa_switch *ds, · line 352
Quoted 4 lines
net/dsa/switch.c +4
-0+ err = ds->ops->set_tag_protocol (ds, cpu_dp->index, + info->tag_ops->proto); +if (err) +return err;Don't you need to test for
ds->ops->set_tag_protocolto be implemented before calling it? Similar comment to earlier, can we do an early check for the operation being supported outside of the loop?
My assumption was that I had already added the check in tag_proto_del. There are no code paths that call one but not the other. I can add the check here too.
There's one more thing I would change: the dsa_switch_tag_proto_match. Right now I am matching only on the CPU port, but if I take a look at the mv88e6xxx driver:
static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
{
if (dsa_is_dsa_port(chip->ds, port))
return mv88e6xxx_set_port_mode_dsa(chip, port);
if (dsa_is_user_port(chip->ds, port))
return mv88e6xxx_set_port_mode_normal(chip, port);
/* Setup CPU port mode depending on its supported tag format */
if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
return mv88e6xxx_set_port_mode_dsa(chip, port);
if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
return mv88e6xxx_set_port_mode_edsa(chip, port);
return -EINVAL;
}DSA links call the same function as CPU ports configured for DSA_TAG_PROTO_DSA. So to cater to Marvell switches too, and to ease a potential conversion to this API, I could add dsa_is_dsa_port to the matching function too.
Vladimir Oltean
maintainerPATCH v5 8/10 net: dsa: felix: convert to the new .{set,del}_tag_protocol DSA API
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
In expectation of the new tag_ocelot_8021q tagger implementation, we need to be able to do runtime switchover between one tagger and another. So we must implement the .set_tag_protocol() and .del_tag_protocol() for the current NPI-based tagger.
We move the felix_npi_port_init function in expectation of the future driver configuration necessary for tag_ocelot_8021q: we would like to not have the NPI-related bits interspersed with the tag_8021q bits.
Note that the NPI port is no longer configured when the .setup() method concludes - aka when ocelot_init() and ocelot_init_port() are called. So we need to set the replicator groups - the PGIDs - again, when the NPI port is configured - in .set_tag_protocol(). So we export and call ocelot_apply_bridge_fwd_mask().
The conversion from this:
ocelot_write_rix(ocelot, ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)), ANA_PGID_PGID, PGID_UC);
to this:
cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)); ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_UC);
is perhaps non-trivial, but is nonetheless non-functional. The PGID_UC (replicator for unknown unicast) is already configured out of hardware reset to flood to all ports except ocelot->num_phys_ports (the CPU port module). All we change is that we use a read-modify-write to only add the CPU port module to the unknown unicast replicator, as opposed to doing a full write to the register.
---
Changes in v5:
Path is split from previous monolithic patch "net: dsa: felix: add new VLAN-based tagger".
drivers/net/dsa/ocelot/felix.c | 150 +++++++++++++++++------ drivers/net/dsa/ocelot/felix.h | 1 + drivers/net/dsa/ocelot/felix_vsc9959.c | 1 + drivers/net/dsa/ocelot/seville_vsc9953.c | 1 + drivers/net/ethernet/mscc/ocelot.c | 3 +- include/soc/mscc/ocelot.h | 1 + 6 files changed, 120 insertions(+), 37 deletions(-)
drivers/net/dsa/ocelot/felix.c +114 -36
@@ -1,5 +1,5 @@// SPDX-License-Identifier: GPL-2.0 -/* Copyright 2019 NXP Semiconductors +/* Copyright 2019-2021 NXP Semiconductors * * This is an umbrella module for all network switches that are * register-compatible with Ocelot and that perform I/O to their host CPU
@@ -24,11 +24,118 @@#include <net/dsa.h> #include "felix.h" +/* The CPU port module is connected to the Node Processor Interface (NPI). This +* is the mode through which frames can be injected from and extracted to an +* external CPU, over Ethernet. In NXP SoCs, the "external CPU" is the ARM CPU +* running Linux, and this forms a DSA setup together with the enetc or fman +* DSA master. +*/ +static void felix_npi_port_init (struct ocelot *ocelot,int port) +{ + ocelot->npi = port; + +ocelot_write (ocelot,QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M | +QSYS_EXT_CPU_CFG_EXT_CPU_PORT (port), +QSYS_EXT_CPU_CFG ); + +/* NPI port Injection/Extraction configuration */ +ocelot_fields_write (ocelot, port,SYS_PORT_MODE_INCL_XTR_HDR , + ocelot->npi_xtr_prefix); +ocelot_fields_write (ocelot, port,SYS_PORT_MODE_INCL_INJ_HDR , + ocelot->npi_inj_prefix); + +/* Disable transmission of pause frames */ +ocelot_fields_write (ocelot, port,SYS_PAUSE_CFG_PAUSE_ENA ,0 ); +} + +static void felix_npi_port_deinit (struct ocelot *ocelot,int port) +{ +/* Restore hardware defaults */ +int unused_port = ocelot->num_phys_ports +2 ; + + ocelot->npi =-1 ; + +ocelot_write (ocelot,QSYS_EXT_CPU_CFG_EXT_CPU_PORT (unused_port), +QSYS_EXT_CPU_CFG ); + +ocelot_fields_write (ocelot, port,SYS_PORT_MODE_INCL_XTR_HDR , +OCELOT_TAG_PREFIX_DISABLED ); +ocelot_fields_write (ocelot, port,SYS_PORT_MODE_INCL_INJ_HDR , +OCELOT_TAG_PREFIX_DISABLED ); + +/* Enable transmission of pause frames */ +ocelot_fields_write (ocelot, port,SYS_PAUSE_CFG_PAUSE_ENA ,1 ); +} + +static int felix_setup_tag_npi (struct dsa_switch *ds,int cpu) +{ +struct ocelot *ocelot = ds->priv; +unsigned long cpu_flood; + +felix_npi_port_init (ocelot, cpu); + +/* Include the CPU port module (and indirectly, the NPI port) +* 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. +* We do this because DSA does not yet perform RX filtering, +* and the NPI port does not perform source address learning, +* so traffic sent to Linux is effectively unknown from the +* switch's perspective. +*/ + cpu_flood =ANA_PGID_PGID_PGID (BIT (ocelot->num_phys_ports)); +ocelot_rmw_rix (ocelot, cpu_flood, cpu_flood,ANA_PGID_PGID ,PGID_UC ); + +ocelot_apply_bridge_fwd_mask (ocelot); + +return 0 ; +} + +static void felix_teardown_tag_npi (struct dsa_switch *ds,int cpu) +{ +struct ocelot *ocelot = ds->priv; + +felix_npi_port_deinit (ocelot, cpu); +} +static enum dsa_tag_protocol felix_get_tag_protocol (struct dsa_switch *ds,int port,enum dsa_tag_protocol mp) { -return DSA_TAG_PROTO_OCELOT ; +struct ocelot *ocelot = ds->priv; +struct felix *felix =ocelot_to_felix (ocelot); + +return felix->tag_proto; +} + +static int felix_set_tag_protocol (struct dsa_switch *ds,int cpu, +enum dsa_tag_protocol proto) +{ +int err; + +switch (proto) { +case DSA_TAG_PROTO_OCELOT : + err =felix_setup_tag_npi (ds, cpu); +break ; +default : + err = -EOPNOTSUPP ; + } + +return err; +} + +static void felix_del_tag_protocol (struct dsa_switch *ds,int cpu, +enum dsa_tag_protocol proto) +{ +switch (proto) { +case DSA_TAG_PROTO_OCELOT : +felix_teardown_tag_npi (ds, cpu); +break ; +default : +break ; + } } static int felix_set_ageing_time(struct dsa_switch *ds,
@@ -527,28 +634,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)return 0 ; } -/* The CPU port module is connected to the Node Processor Interface (NPI). This -* is the mode through which frames can be injected from and extracted to an -* external CPU, over Ethernet. -*/ -static void felix_npi_port_init (struct ocelot *ocelot,int port) -{ - ocelot->npi = port; - -ocelot_write (ocelot,QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M | -QSYS_EXT_CPU_CFG_EXT_CPU_PORT (port), -QSYS_EXT_CPU_CFG ); - -/* NPI port Injection/Extraction configuration */ -ocelot_fields_write (ocelot, port,SYS_PORT_MODE_INCL_XTR_HDR , - ocelot->npi_xtr_prefix); -ocelot_fields_write (ocelot, port,SYS_PORT_MODE_INCL_INJ_HDR , - ocelot->npi_inj_prefix); - -/* Disable transmission of pause frames */ -ocelot_fields_write (ocelot, port,SYS_PAUSE_CFG_PAUSE_ENA ,0 ); -} -/* Hardware initialization done here so that we can allocate structures with * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing * us to allocate structures twice (leak memory) and map PCI memory twice
@@ -578,10 +663,10 @@ static int felix_setup(struct dsa_switch *ds) }for (port =0 ; port < ds->num_ports; port++) { -ocelot_init_port (ocelot, port); +if (dsa_is_unused_port (ds, port)) +continue ; -if (dsa_is_cpu_port (ds, port)) -felix_npi_port_init (ocelot, port); +ocelot_init_port (ocelot, port);/* Set the default QoS Classification based on PCP and DEI * bits of vlan tag.
@@ -593,15 +678,6 @@ static int felix_setup(struct dsa_switch *ds)if (err)return err; -/* 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 ); - ds->mtu_enforcement_ingress = true; ds->assisted_learning_on_cpu_port = true;
@@ -860,6 +936,8 @@ static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port,const struct dsa_switch_ops felix_switch_ops = { .get_tag_protocol = felix_get_tag_protocol, + .set_tag_protocol = felix_set_tag_protocol, + .del_tag_protocol = felix_del_tag_protocol, .setup = felix_setup, .teardown = felix_teardown, .set_ageing_time = felix_set_ageing_time,
drivers/net/dsa/ocelot/felix.h +1 -0
@@ -48,6 +48,7 @@ struct felix {struct lynx_pcs **pcs;resource_size_t switch_base;resource_size_t imdio_base; +enum dsa_tag_protocol tag_proto; };struct net_device *felix_port_to_netdev (struct ocelot *ocelot,int port);
drivers/net/dsa/ocelot/felix_vsc9959.c +1 -0
@@ -1467,6 +1467,7 @@ static int felix_pci_probe(struct pci_dev *pdev, ds->ops = &felix_switch_ops; ds->priv = ocelot; felix->ds = ds; + felix->tag_proto =DSA_TAG_PROTO_OCELOT ; err =dsa_register_switch (ds);if (err) {
drivers/net/dsa/ocelot/seville_vsc9953.c +1 -0
@@ -1246,6 +1246,7 @@ static int seville_probe(struct platform_device *pdev) ds->ops = &felix_switch_ops; ds->priv = ocelot; felix->ds = ds; + felix->tag_proto =DSA_TAG_PROTO_OCELOT ; err =dsa_register_switch (ds);if (err) {
drivers/net/ethernet/mscc/ocelot.c +2 -1
@@ -876,7 +876,7 @@ int ocelot_get_ts_info(struct ocelot *ocelot, int port, }EXPORT_SYMBOL (ocelot_get_ts_info); -static void ocelot_apply_bridge_fwd_mask (struct ocelot *ocelot) +void ocelot_apply_bridge_fwd_mask (struct ocelot *ocelot) {int port;
@@ -908,6 +908,7 @@ static void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot) } } } +EXPORT_SYMBOL (ocelot_apply_bridge_fwd_mask);void ocelot_bridge_stp_state_set (struct ocelot *ocelot,int port,u8 state) {
include/soc/mscc/ocelot.h +1 -0
@@ -760,6 +760,7 @@ void ocelot_adjust_link(struct ocelot *ocelot, int port, struct phy_device *phydev);int ocelot_port_vlan_filtering (struct ocelot *ocelot,int port,bool enabled);void ocelot_bridge_stp_state_set (struct ocelot *ocelot,int port,u8 state); +void ocelot_apply_bridge_fwd_mask (struct ocelot *ocelot);int ocelot_port_bridge_join (struct ocelot *ocelot,int port,struct net_device *bridge); int ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
Signature · 1 line
2.25.1
Re: [PATCH v5 net-next 08/10] net: dsa: felix: convert to the new .{set,del}_tag_protocol DSA API
Quoted 28 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
In expectation of the new
tag_ocelot_8021qtagger implementation, we need to be able to do runtime switchover between one tagger and another. So we must implement the .set_tag_protocol() and .del_tag_protocol() for the current NPI-based tagger.We move the
felix_npi_port_initfunction in expectation of the future driver configuration necessary fortag_ocelot_8021q: we would like to not have the NPI-related bits interspersed with thetag_8021qbits.Note that the NPI port is no longer configured when the .setup() method concludes - aka when
ocelot_init()andocelot_init_port()are called. So we need to set the replicator groups - the PGIDs - again, when the NPI port is configured - in .set_tag_protocol(). So we export and callocelot_apply_bridge_fwd_mask().The conversion from this:
ocelot_write_rix(ocelot, ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)), ANA_PGID_PGID, PGID_UC);to this:
cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)); ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_UC);
Quoted 8 lines
is perhaps non-trivial, but is nonetheless non-functional. The
PGID_UC(replicator for unknown unicast) is already configured out of hardware reset to flood to all ports exceptocelot->num_phys_ports(the CPU port module). All we change is that we use a read-modify-write to only add the CPU port module to the unknown unicast replicator, as opposed to doing a full write to the register.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v5 9/10 net: dsa: add a second tagger for Ocelot switches based on tag_8021q
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
There are use cases for which the existing tagger, based on the NPI (Node Processor Interface) functionality, is insufficient.
Namely:
- Frames injected through the NPI port bypass the frame analyzer, so no source address learning is performed, no TSN stream classification, etc.
- Flow control is not functional over an NPI port (PAUSE frames are encapsulated in the same Extraction Frame Header as all other frames)
- There can be at most one NPI port configured for an Ocelot switch. But in NXP LS1028A and T1040 there are two Ethernet CPU ports. The non-NPI port is currently either disabled, or operated as a plain user port (albeit an internally-facing one). Having the ability to configure the two CPU ports symmetrically could pave the way for e.g. creating a LAG between them, to increase bandwidth seamlessly for the system.
So there is a desire to have an alternative to the NPI mode. This change keeps the default tagger for the Seville and Felix switches as "ocelot", but it can be changed via the following device attribute:
echo ocelot-8021q > /sys/class/<dsa-master>/dsa/tagging
---
Changes in v5:
Path is split from previous monolithic patch "net: dsa: felix: add new VLAN-based tagger".
MAINTAINERS | 1 + drivers/net/dsa/ocelot/Kconfig | 2 + include/net/dsa.h | 2 + net/dsa/Kconfig | 21 +++++++++-- net/dsa/Makefile | 1 + net/dsa/tag_ocelot_8021q.c | 68 ++++++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 net/dsa/tag_ocelot_8021q.c
MAINTAINERS +1 -0
@@ -12842,6 +12842,7 @@ F: drivers/net/dsa/ocelot/* F: drivers/net/ethernet/mscc/ F: include/soc/mscc/ocelot* F: net/dsa/tag_ocelot.c +F: net/dsa/tag_ocelot_8021q.c F: tools/testing/selftests/drivers/net/ocelot/* OCXL (Open Coherent Accelerator Processor Interface OpenCAPI) DRIVER
drivers/net/dsa/ocelot/Kconfig +2 -0
@@ -6,6 +6,7 @@ config NET_DSA_MSCC_FELIX depends on NET_VENDOR_FREESCALE depends on HAS_IOMEM select MSCC_OCELOT_SWITCH_LIB + select NET_DSA_TAG_OCELOT_8021Q select NET_DSA_TAG_OCELOT select FSL_ENETC_MDIO select PCS_LYNX
@@ -19,6 +20,7 @@ config NET_DSA_MSCC_SEVILLE depends on NET_VENDOR_MICROSEMI depends on HAS_IOMEM select MSCC_OCELOT_SWITCH_LIB + select NET_DSA_TAG_OCELOT_8021Q select NET_DSA_TAG_OCELOT select PCS_LYNX help
include/net/dsa.h +2 -0
@@ -47,6 +47,7 @@ struct phylink_link_state;#define DSA_TAG_PROTO_RTL4_A_VALUE 17#define DSA_TAG_PROTO_HELLCREEK_VALUE 18#define DSA_TAG_PROTO_XRS700X_VALUE 19 +#define DSA_TAG_PROTO_OCELOT_8021Q_VALUE 20enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -69,6 +70,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_RTL4_A =DSA_TAG_PROTO_RTL4_A_VALUE ,DSA_TAG_PROTO_HELLCREEK =DSA_TAG_PROTO_HELLCREEK_VALUE ,DSA_TAG_PROTO_XRS700X =DSA_TAG_PROTO_XRS700X_VALUE , + DSA_TAG_PROTO_OCELOT_8021Q = DSA_TAG_PROTO_OCELOT_8021Q_VALUE, };struct packet_type ;
net/dsa/Kconfig +18 -3
@@ -105,11 +105,26 @@ config NET_DSA_TAG_RTL4_A the Realtek RTL8366RB. config NET_DSA_TAG_OCELOT - tristate "Tag driver for Ocelot family of switches" + tristate "Tag driver for Ocelot family of switches, using NPI port" select PACKING help - Say Y or M if you want to enable support for tagging frames for the - Ocelot switches (VSC7511, VSC7512, VSC7513, VSC7514, VSC9959). + Say Y or M if you want to enable NPI tagging for the Ocelot switches + (VSC7511, VSC7512, VSC7513, VSC7514, VSC9953, VSC9959). In this mode, + the frames over the Ethernet CPU port are prepended with a + hardware-defined injection/extraction frame header. Flow control + (PAUSE frames) over the CPU port is not supported when operating in + this mode. + +config NET_DSA_TAG_OCELOT_8021Q + tristate "Tag driver for Ocelot family of switches, using VLAN" + select NET_DSA_TAG_8021Q + help + Say Y or M if you want to enable support for tagging frames with a + custom VLAN-based header. Frames that require timestamping, such as + PTP, are not delivered over Ethernet but over register-based MMIO. + Flow control over the CPU port is functional in this mode. When using + this mode, less TCAM resources (VCAP IS1, IS2, ES0) are available for + use with tc-flower. config NET_DSA_TAG_QCA tristate "Tag driver for Qualcomm Atheros QCA8K switches"
net/dsa/Makefile +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_NET_DSA_TAG_RTL4_A) += tag_rtl4_a.o obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o obj-$(CONFIG_NET_DSA_TAG_OCELOT) += tag_ocelot.o +obj-$(CONFIG_NET_DSA_TAG_OCELOT_8021Q) += tag_ocelot_8021q.o obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
net/dsa/tag_ocelot_8021q.c new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v5 net-next 09/10] net: dsa: add a second tagger for Ocelot switches based on tag_8021q
Quoted 18 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
There are use cases for which the existing tagger, based on the NPI (Node Processor Interface) functionality, is insufficient.
Namely:
- Frames injected through the NPI port bypass the frame analyzer, so no source address learning is performed, no TSN stream classification, etc.
- Flow control is not functional over an NPI port (PAUSE frames are encapsulated in the same Extraction Frame Header as all other frames)
- There can be at most one NPI port configured for an Ocelot switch. But in NXP LS1028A and T1040 there are two Ethernet CPU ports. The non-NPI port is currently either disabled, or operated as a plain user port (albeit an internally-facing one). Having the ability to configure the two CPU ports symmetrically could pave the way for e.g. creating a LAG between them, to increase bandwidth seamlessly for the system.
Quoted 7 lines
So there is a desire to have an alternative to the NPI mode. This change keeps the default tagger for the Seville and Felix switches as "ocelot", but it can be changed via the following device attribute:
echo ocelot-8021q > /sys/class/<dsa-master>/dsa/tagging
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v5 10/10 net: dsa: felix: perform switch setup for tag_8021q
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Unlike sja1105, the only other user of the software-defined tag_8021q.c tagger format, the implementation we choose for the Felix DSA switch driver preserves full functionality under a vlan_filtering bridge (i.e. IP termination works through the DSA user ports under all circumstances).
The tag_8021q protocol just wants:
- Identifying the ingress switch port based on the RX VLAN ID, as seen by the CPU. We achieve this by using the TCAM engines (which are also used for tc-flower offload) to push the RX VLAN as a second, outer tag, on egress towards the CPU port.
- Steering traffic injected into the switch from the network stack towards the correct front port based on the TX VLAN, and consuming (popping) that header on the switch's egress.
A tc-flower pseudocode of the static configuration done by the driver would look like this:
$ tc qdisc add dev <cpu-port> clsact
$ for eth in swp0 swp1 swp2 swp3; do \
tc filter add dev <cpu-port> egress flower indev ${eth} \
action vlan push id <rxvlan> protocol 802.1ad; \
tc filter add dev <cpu-port> ingress protocol 802.1Q flower
vlan_id <txvlan> action vlan pop \
action mirred egress redirect dev ${eth}; \
donebut of course since DSA does not register network interfaces for the CPU port, this configuration would be impossible for the user to do. Also, due to the same reason, it is impossible for the user to inadvertently delete these rules using tc. These rules do not collide in any way with tc-flower, they just consume some TCAM space, which is something we can live with.
---
Changes in v5:
Path is split from previous monolithic patch "net: dsa: felix: add new VLAN-based tagger".
Changes in v4:
- Support simultaneous compilation of tag_ocelot.c and tag_ocelot_8021q.c.
- Support runtime switchover between these two taggers.
- We are now actually performing cleanup instead of just probe-time setup, which is required for supporting tagger switchover.
Changes in v3:
- Use a per-port bool is_dsa_8021q_cpu instead of a single dsa_8021q_cpu variable, to be compatible with future work where there may be potentially multiple tag_8021q CPU ports in a LAG.
- Initialize ocelot->npi = -1 in felix_8021q_cpu_port_init to ensure we don't mistakenly trigger NPI-specific code in ocelot.
Changes in v2:
Clean up the hardcoding of random VCAP filter IDs and the inclusion of a private ocelot header.
drivers/net/dsa/ocelot/felix.c | 332 ++++++++++++++++++++++++ drivers/net/dsa/ocelot/felix.h | 1 + drivers/net/ethernet/mscc/ocelot.c | 33 ++- drivers/net/ethernet/mscc/ocelot_vcap.c | 1 + drivers/net/ethernet/mscc/ocelot_vcap.h | 3 - include/soc/mscc/ocelot.h | 1 + include/soc/mscc/ocelot_vcap.h | 3 + 7 files changed, 363 insertions(+), 11 deletions(-)
drivers/net/dsa/ocelot/felix.c +332 -0
@@ -13,6 +13,7 @@#include <soc/mscc/ocelot_ana.h> #include <soc/mscc/ocelot_ptp.h> #include <soc/mscc/ocelot.h> +#include <linux/dsa/8021q.h> #include <linux/platform_device.h> #include <linux/packing.h> #include <linux/module.h>
@@ -24,6 +25,331 @@#include <net/dsa.h> #include "felix.h" +static int felix_tag_8021q_rxvlan_add (struct felix *felix,int port,u16 vid, +bool pvid,bool untagged) +{ +struct ocelot_vcap_filter *outer_tagging_rule; +struct ocelot *ocelot = &felix->ocelot; +struct dsa_switch *ds = felix->ds; +int key_length, upstream, err; + +/* We don't need to install the rxvlan into the other ports' filtering +* tables, because we're just pushing the rxvlan when sending towards +* the CPU +*/ +if (!pvid) +return 0 ; + + key_length = ocelot->vcap[VCAP_ES0 ].keys[VCAP_ES0_IGR_PORT ].length; + upstream =dsa_upstream_port (ds, port); + + outer_tagging_rule =kzalloc (sizeof (struct ocelot_vcap_filter ), +GFP_KERNEL ); +if (!outer_tagging_rule) +return -ENOMEM ; + + outer_tagging_rule->key_type =OCELOT_VCAP_KEY_ANY ; + outer_tagging_rule->prio =1 ; + outer_tagging_rule->id.cookie = port; + outer_tagging_rule->id.tc_offload = false; + outer_tagging_rule->block_id =VCAP_ES0 ; + outer_tagging_rule->type =OCELOT_VCAP_FILTER_OFFLOAD ; + outer_tagging_rule->lookup =0 ; + outer_tagging_rule->ingress_port.value = port; + outer_tagging_rule->ingress_port.mask =GENMASK (key_length -1 ,0 ); + outer_tagging_rule->egress_port.value = upstream; + outer_tagging_rule->egress_port.mask =GENMASK (key_length -1 ,0 ); + outer_tagging_rule->action.push_outer_tag =OCELOT_ES0_TAG ; + outer_tagging_rule->action.tag_a_tpid_sel =OCELOT_TAG_TPID_SEL_8021AD ; + outer_tagging_rule->action.tag_a_vid_sel =1 ; + outer_tagging_rule->action.vid_a_val = vid; + + err =ocelot_vcap_filter_add (ocelot, outer_tagging_rule,NULL ); +if (err) +kfree (outer_tagging_rule); + +return err; +} + +static int felix_tag_8021q_txvlan_add (struct felix *felix,int port,u16 vid, +bool pvid,bool untagged) +{ +struct ocelot_vcap_filter *untagging_rule, *redirect_rule; +struct ocelot *ocelot = &felix->ocelot; +struct dsa_switch *ds = felix->ds; +int upstream, err; + +/* tag_8021q.c assumes we are implementing this via port VLAN +* membership, which we aren't. So we don't need to add any VCAP filter +* for the CPU port. +*/ +if (ocelot->ports[port]->is_dsa_8021q_cpu) +return 0 ; + + untagging_rule =kzalloc (sizeof (struct ocelot_vcap_filter ),GFP_KERNEL ); +if (!untagging_rule) +return -ENOMEM ; + + redirect_rule =kzalloc (sizeof (struct ocelot_vcap_filter ),GFP_KERNEL ); +if (!redirect_rule) { +kfree (untagging_rule); +return -ENOMEM ; + } + + upstream =dsa_upstream_port (ds, port); + + untagging_rule->key_type =OCELOT_VCAP_KEY_ANY ; + untagging_rule->ingress_port_mask =BIT (upstream); + untagging_rule->vlan.vid.value = vid; + untagging_rule->vlan.vid.mask =VLAN_VID_MASK ; + untagging_rule->prio =1 ; + untagging_rule->id.cookie = port; + untagging_rule->id.tc_offload = false; + untagging_rule->block_id =VCAP_IS1 ; + untagging_rule->type =OCELOT_VCAP_FILTER_OFFLOAD ; + untagging_rule->lookup =0 ; + untagging_rule->action.vlan_pop_cnt_ena = true; + untagging_rule->action.vlan_pop_cnt =1 ; + untagging_rule->action.pag_override_mask =0xff ; + untagging_rule->action.pag_val = port; + + err =ocelot_vcap_filter_add (ocelot, untagging_rule,NULL ); +if (err) { +kfree (untagging_rule); +kfree (redirect_rule); +return err; + } + + redirect_rule->key_type =OCELOT_VCAP_KEY_ANY ; + redirect_rule->ingress_port_mask =BIT (upstream); + redirect_rule->pag = port; + redirect_rule->prio =1 ; + redirect_rule->id.cookie = port; + redirect_rule->id.tc_offload = false; + redirect_rule->block_id =VCAP_IS2 ; + redirect_rule->type =OCELOT_VCAP_FILTER_OFFLOAD ; + redirect_rule->lookup =0 ; + redirect_rule->action.mask_mode =OCELOT_MASK_MODE_REDIRECT ; + redirect_rule->action.port_mask =BIT (port); + + err =ocelot_vcap_filter_add (ocelot, redirect_rule,NULL ); +if (err) { +ocelot_vcap_filter_del (ocelot, untagging_rule); +kfree (redirect_rule); +return err; + } + +return 0 ; +} + +static int felix_tag_8021q_vlan_add (struct dsa_switch *ds,int port,u16 vid, +u16 flags) +{ +bool untagged = flags &BRIDGE_VLAN_INFO_UNTAGGED ; +bool pvid = flags &BRIDGE_VLAN_INFO_PVID ; +struct ocelot *ocelot = ds->priv; + +if (vid_is_dsa_8021q_rxvlan (vid)) +return felix_tag_8021q_rxvlan_add (ocelot_to_felix (ocelot), + port, vid, pvid, untagged); + +if (vid_is_dsa_8021q_txvlan (vid)) +return felix_tag_8021q_txvlan_add (ocelot_to_felix (ocelot), + port, vid, pvid, untagged); + +return 0 ; +} + +static int felix_tag_8021q_rxvlan_del (struct felix *felix,int port,u16 vid) +{ +struct ocelot_vcap_filter *outer_tagging_rule; +struct ocelot_vcap_block *block_vcap_es0; +struct ocelot *ocelot = &felix->ocelot; + + block_vcap_es0 = &ocelot->block[VCAP_ES0 ]; + + outer_tagging_rule =ocelot_vcap_block_find_filter_by_id (block_vcap_es0, + port, false); +/* In rxvlan_add, we had the "if (!pvid) return 0" logic to avoid +* installing outer tagging ES0 rules where they weren't needed. +* But in rxvlan_del, the API doesn't give us the "flags" anymore, +* so that forces us to be slightly sloppy here, and just assume that +* if we didn't find an outer_tagging_rule it means that there was +* none in the first place, i.e. rxvlan_del is called on a non-pvid +* port. This is most probably true though. +*/ +if (!outer_tagging_rule) +return 0 ; + +return ocelot_vcap_filter_del (ocelot, outer_tagging_rule); +} + +static int felix_tag_8021q_txvlan_del (struct felix *felix,int port,u16 vid) +{ +struct ocelot_vcap_filter *untagging_rule, *redirect_rule; +struct ocelot_vcap_block *block_vcap_is1; +struct ocelot_vcap_block *block_vcap_is2; +struct ocelot *ocelot = &felix->ocelot; +int err; + +if (ocelot->ports[port]->is_dsa_8021q_cpu) +return 0 ; + + block_vcap_is1 = &ocelot->block[VCAP_IS1 ]; + block_vcap_is2 = &ocelot->block[VCAP_IS2 ]; + + untagging_rule =ocelot_vcap_block_find_filter_by_id (block_vcap_is1, + port, false); +if (!untagging_rule) +return 0 ; + + err =ocelot_vcap_filter_del (ocelot, untagging_rule); +if (err) +return err; + + redirect_rule =ocelot_vcap_block_find_filter_by_id (block_vcap_is2, + port, false); +if (!redirect_rule) +return 0 ; + +return ocelot_vcap_filter_del (ocelot, redirect_rule); +} + +static int felix_tag_8021q_vlan_del (struct dsa_switch *ds,int port,u16 vid) +{ +struct ocelot *ocelot = ds->priv; + +if (vid_is_dsa_8021q_rxvlan (vid)) +return felix_tag_8021q_rxvlan_del (ocelot_to_felix (ocelot), + port, vid); + +if (vid_is_dsa_8021q_txvlan (vid)) +return felix_tag_8021q_txvlan_del (ocelot_to_felix (ocelot), + port, vid); + +return 0 ; +} + +static const struct dsa_8021q_ops felix_tag_8021q_ops = { + .vlan_add = felix_tag_8021q_vlan_add, + .vlan_del = felix_tag_8021q_vlan_del, +}; + +/* Alternatively to using the NPI functionality, that same hardware MAC +* connected internally to the enetc or fman DSA master can be configured to +* use the software-defined tag_8021q frame format. As far as the hardware is +* concerned, it thinks it is a "dumb switch" - the queues of the CPU port +* module are now disconnected from it, but can still be accessed through +* register-based MMIO. +*/ +static void felix_8021q_cpu_port_init (struct ocelot *ocelot,int port) +{ + ocelot->ports[port]->is_dsa_8021q_cpu = true; + ocelot->npi =-1 ; + +/* Overwrite PGID_CPU with the non-tagging port */ +ocelot_write_rix (ocelot,BIT (port),ANA_PGID_PGID ,PGID_CPU ); +} + +static void felix_8021q_cpu_port_deinit (struct ocelot *ocelot,int port) +{ + ocelot->ports[port]->is_dsa_8021q_cpu = false; + +/* Restore PGID_CPU */ +ocelot_write_rix (ocelot,BIT (ocelot->num_phys_ports),ANA_PGID_PGID , +PGID_CPU ); +} + +static int felix_setup_tag_8021q (struct dsa_switch *ds,int cpu) +{ +struct ocelot *ocelot = ds->priv; +struct felix *felix =ocelot_to_felix (ocelot); +unsigned long cpu_flood; +int port, err; + +felix_8021q_cpu_port_init (ocelot, cpu); + +for (port =0 ; port < ds->num_ports; port++) { +if (dsa_is_unused_port (ds, port)) +continue ; + +/* This overwrites ocelot_init(): +* Do not forward BPDU frames to the CPU port module, +* for 2 reasons: +* - When these packets are injected from the tag_8021q +* CPU port, we want them to go out, not loop back +* into the system. +* - STP traffic ingressing on a user port should go to +* the tag_8021q CPU port, not to the hardware CPU +* port module. +*/ +ocelot_write_gix (ocelot, +ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA (0 ), +ANA_PORT_CPU_FWD_BPDU_CFG , port); + } + +/* In tag_8021q mode, the CPU port module is unused. So we +* want to disable flooding of any kind to the CPU port module, +* since packets going there will end in a black hole. +*/ + cpu_flood =ANA_PGID_PGID_PGID (BIT (ocelot->num_phys_ports)); +ocelot_rmw_rix (ocelot,0 , cpu_flood,ANA_PGID_PGID ,PGID_UC ); +ocelot_rmw_rix (ocelot,0 , cpu_flood,ANA_PGID_PGID ,PGID_MC ); + +ocelot_apply_bridge_fwd_mask (ocelot); + + felix->dsa_8021q_ctx =kzalloc (sizeof (*felix->dsa_8021q_ctx), +GFP_KERNEL ); +if (!felix->dsa_8021q_ctx) +return -ENOMEM ; + + felix->dsa_8021q_ctx->ops = &felix_tag_8021q_ops; + felix->dsa_8021q_ctx->proto =htons (ETH_P_8021AD ); + felix->dsa_8021q_ctx->ds = ds; + +rtnl_lock (); + err =dsa_8021q_setup (felix->dsa_8021q_ctx, true); +rtnl_unlock (); +if (err) + goto out_free_dsa_8021_ctx; + +return 0 ; + +out_free_dsa_8021_ctx: +kfree (felix->dsa_8021q_ctx); +return err; +} + +static void felix_teardown_tag_8021q (struct dsa_switch *ds,int cpu) +{ +struct ocelot *ocelot = ds->priv; +struct felix *felix =ocelot_to_felix (ocelot); +int err, port; + +rtnl_lock (); + err =dsa_8021q_setup (felix->dsa_8021q_ctx, false); +rtnl_unlock (); +if (err) +dev_err (ds->dev,"dsa_8021q_setup returned %d" , err); + +kfree (felix->dsa_8021q_ctx); + +for (port =0 ; port < ds->num_ports; port++) { +if (dsa_is_unused_port (ds, port)) +continue ; + +/* Restore the logic from ocelot_init: +* do not forward BPDU frames to the front ports. +*/ +ocelot_write_gix (ocelot, +ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA (0xffff ), +ANA_PORT_CPU_FWD_BPDU_CFG , + port); + } + +felix_8021q_cpu_port_deinit (ocelot, cpu); +} +/* The CPU port module is connected to the Node Processor Interface (NPI). This * is the mode through which frames can be injected from and extracted to an * external CPU, over Ethernet. In NXP SoCs, the "external CPU" is the ARM CPU
@@ -119,6 +445,9 @@ static int felix_set_tag_protocol(struct dsa_switch *ds, int cpu,case DSA_TAG_PROTO_OCELOT : err =felix_setup_tag_npi (ds, cpu);break ; +case DSA_TAG_PROTO_OCELOT_8021Q : + err =felix_setup_tag_8021q (ds, cpu); +break ;default : err = -EOPNOTSUPP ; }
@@ -133,6 +462,9 @@ static void felix_del_tag_protocol(struct dsa_switch *ds, int cpu,case DSA_TAG_PROTO_OCELOT :felix_teardown_tag_npi (ds, cpu);break ; +case DSA_TAG_PROTO_OCELOT_8021Q : +felix_teardown_tag_8021q (ds, cpu); +break ;default :break ; }
drivers/net/dsa/ocelot/felix.h +1 -0
@@ -48,6 +48,7 @@ struct felix {struct lynx_pcs **pcs;resource_size_t switch_base;resource_size_t imdio_base; +struct dsa_8021q_context *dsa_8021q_ctx;enum dsa_tag_protocol tag_proto; };
drivers/net/ethernet/mscc/ocelot.c +25 -8
@@ -878,16 +878,37 @@ EXPORT_SYMBOL(ocelot_get_ts_info);void ocelot_apply_bridge_fwd_mask (struct ocelot *ocelot) { +unsigned long cpu_fwd_mask =0 ;int port; +/* If a DSA tag_8021q CPU exists, it needs to be unconditionally +* (i.e. regardless of whether the port is bridged or standalone) +* included in the regular forwarding path, as opposed to the +* hardware-based CPU port module which can be a destination for +* packets even if it isn't part of PGID_SRC. +*/ +for (port =0 ; port < ocelot->num_phys_ports; port++) +if (ocelot->ports[port]->is_dsa_8021q_cpu) + cpu_fwd_mask |=BIT (port); +/* Apply FWD mask. The loop is needed to add/remove the current port as * a source for the other ports. */ for (port =0 ; port < ocelot->num_phys_ports; port++) { -if (ocelot->bridge_fwd_mask &BIT (port)) { -unsigned long mask = ocelot->bridge_fwd_mask & ~BIT (port); +/* Standalone ports forward only to DSA tag_8021q CPU ports */ +unsigned long mask = cpu_fwd_mask; + +/* The DSA tag_8021q CPU ports need to be able to forward +* packets to all other ports except for themselves +*/ +if (ocelot->ports[port]->is_dsa_8021q_cpu) { + mask =GENMASK (ocelot->num_phys_ports -1 ,0 ); + mask &= ~cpu_fwd_mask; + }else if (ocelot->bridge_fwd_mask &BIT (port)) {int lag; + mask |= ocelot->bridge_fwd_mask & ~BIT (port); +for (lag =0 ; lag < ocelot->num_phys_ports; lag++) {unsigned long bond_mask = ocelot->lags[lag];
@@ -899,13 +920,9 @@ void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot)break ; } } - -ocelot_write_rix (ocelot, mask, -ANA_PGID_PGID ,PGID_SRC + port); - }else { -ocelot_write_rix (ocelot,0 , -ANA_PGID_PGID ,PGID_SRC + port); } + +ocelot_write_rix (ocelot, mask,ANA_PGID_PGID ,PGID_SRC + port); } }EXPORT_SYMBOL (ocelot_apply_bridge_fwd_mask);
drivers/net/ethernet/mscc/ocelot_vcap.c +1 -0
@@ -1009,6 +1009,7 @@ ocelot_vcap_block_find_filter_by_id(struct ocelot_vcap_block *block, int cookie,return NULL ; } +EXPORT_SYMBOL (ocelot_vcap_block_find_filter_by_id);/* If @on=false, then SNAP, ARP, IP and OAM frames will not match on keys based * on destination and source MAC addresses, but only on higher-level protocol
drivers/net/ethernet/mscc/ocelot_vcap.h +0 -3
@@ -14,9 +14,6 @@int ocelot_vcap_filter_stats_update (struct ocelot *ocelot,struct ocelot_vcap_filter *rule); -struct ocelot_vcap_filter * -ocelot_vcap_block_find_filter_by_id (struct ocelot_vcap_block *block,int id, -bool tc_offload);void ocelot_detect_vcap_constants (struct ocelot *ocelot);int ocelot_vcap_init (struct ocelot *ocelot);
include/soc/mscc/ocelot.h +1 -0
@@ -610,6 +610,7 @@ struct ocelot_port {phy_interface_t phy_mode;u8 *xmit_template; +bool is_dsa_8021q_cpu; };struct ocelot {
include/soc/mscc/ocelot_vcap.h +3 -0
@@ -693,5 +693,8 @@ int ocelot_vcap_filter_add(struct ocelot *ocelot, struct netlink_ext_ack *extack);int ocelot_vcap_filter_del (struct ocelot *ocelot,struct ocelot_vcap_filter *rule); +struct ocelot_vcap_filter * +ocelot_vcap_block_find_filter_by_id (struct ocelot_vcap_block *block,int id, +bool tc_offload);#endif /* _OCELOT_VCAP_H_ */
Signature · 1 line
2.25.1
Re: [PATCH v5 net-next 10/10] net: dsa: felix: perform switch setup for tag_8021q
Quoted 29 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Unlike sja1105, the only other user of the software-defined
tag_8021q.ctagger format, the implementation we choose for the Felix DSA switch driver preserves full functionality under avlan_filteringbridge (i.e. IP termination works through the DSA user ports under all circumstances).The
tag_8021qprotocol just wants:
- Identifying the ingress switch port based on the RX VLAN ID, as seen by the CPU. We achieve this by using the TCAM engines (which are also used for tc-flower offload) to push the RX VLAN as a second, outer tag, on egress towards the CPU port.
- Steering traffic injected into the switch from the network stack towards the correct front port based on the TX VLAN, and consuming (popping) that header on the switch's egress.A tc-flower pseudocode of the static configuration done by the driver would look like this:
$ tc qdisc add dev <cpu-port> clsact $ for eth in swp0 swp1 swp2 swp3; do \ tc filter add dev <cpu-port> egress flower indev ${eth} \ action vlan push id <rxvlan> protocol 802.1ad; \ tc filter add dev <cpu-port> ingress protocol 802.1Q flower vlan_id <txvlan> action vlan pop \ action mirred egress redirect dev ${eth}; \ done
Quoted 8 lines
but of course since DSA does not register network interfaces for the CPU port, this configuration would be impossible for the user to do. Also, due to the same reason, it is impossible for the user to inadvertently delete these rules using tc. These rules do not collide in any way with tc-flower, they just consume some TCAM space, which is something we can live with.
Signed-off-by Vladimir Oltean <[email protected]>
Quite an interesting read.
Signature · 1 line
Florian