From: Vladimir Oltean <vladimir.oltean@nxp.com> Date: 2021-08-04 13:16:46
Changes in v2:
Send as non-RFC, drop the patches for discarding DSA-tagged packets on
user ports and DSA-untagged packets on DSA and CPU ports for now.
NXP builds boards like the Bluebox 3 where there are multiple SJA1110
switches connected to an LX2160A, but they are also connected to each
other. I call this topology an "H" tree because of the lateral
connection between switches. A piece extracted from a non-upstream
device tree looks like this:
&spi_bridge {
/* SW1 */
ethernet-switch@0 {
compatible = "nxp,sja1110a";
reg = <0>;
dsa,member = <0 0>;
ethernet-ports {
#address-cells = <1>;
#size-cells = <0>;
/* SW1_P1 */
port@1 {
reg = <1>;
label = "con_2x20";
phy-mode = "sgmii";
fixed-link {
speed = <1000>;
full-duplex;
};
};
port@2 {
reg = <2>;
ethernet = <&dpmac17>;
phy-mode = "rgmii-id";
fixed-link {
speed = <1000>;
full-duplex;
};
};
port@3 {
reg = <3>;
label = "1ge_p1";
phy-mode = "rgmii-id";
phy-handle = <&sw1_mii3_phy>;
};
sw1p4: port@4 {
reg = <4>;
link = <&sw2p1>;
phy-mode = "sgmii";
fixed-link {
speed = <1000>;
full-duplex;
};
};
port@5 {
reg = <5>;
label = "trx1";
phy-mode = "internal";
phy-handle = <&sw1_port5_base_t1_phy>;
};
port@6 {
reg = <6>;
label = "trx2";
phy-mode = "internal";
phy-handle = <&sw1_port6_base_t1_phy>;
};
port@7 {
reg = <7>;
label = "trx3";
phy-mode = "internal";
phy-handle = <&sw1_port7_base_t1_phy>;
};
port@8 {
reg = <8>;
label = "trx4";
phy-mode = "internal";
phy-handle = <&sw1_port8_base_t1_phy>;
};
port@9 {
reg = <9>;
label = "trx5";
phy-mode = "internal";
phy-handle = <&sw1_port9_base_t1_phy>;
};
port@a {
reg = <10>;
label = "trx6";
phy-mode = "internal";
phy-handle = <&sw1_port10_base_t1_phy>;
};
};
};
/* SW2 */
ethernet-switch@2 {
compatible = "nxp,sja1110a";
reg = <2>;
dsa,member = <0 1>;
ethernet-ports {
#address-cells = <1>;
#size-cells = <0>;
sw2p1: port@1 {
reg = <1>;
link = <&sw1p4>;
phy-mode = "sgmii";
fixed-link {
speed = <1000>;
full-duplex;
};
};
port@2 {
reg = <2>;
ethernet = <&dpmac18>;
phy-mode = "rgmii-id";
fixed-link {
speed = <1000>;
full-duplex;
};
};
port@3 {
reg = <3>;
label = "1ge_p2";
phy-mode = "rgmii-id";
phy-handle = <&sw2_mii3_phy>;
};
port@4 {
reg = <4>;
label = "to_sw3";
phy-mode = "2500base-x";
fixed-link {
speed = <2500>;
full-duplex;
};
};
port@5 {
reg = <5>;
label = "trx7";
phy-mode = "internal";
phy-handle = <&sw2_port5_base_t1_phy>;
};
port@6 {
reg = <6>;
label = "trx8";
phy-mode = "internal";
phy-handle = <&sw2_port6_base_t1_phy>;
};
port@7 {
reg = <7>;
label = "trx9";
phy-mode = "internal";
phy-handle = <&sw2_port7_base_t1_phy>;
};
port@8 {
reg = <8>;
label = "trx10";
phy-mode = "internal";
phy-handle = <&sw2_port8_base_t1_phy>;
};
port@9 {
reg = <9>;
label = "trx11";
phy-mode = "internal";
phy-handle = <&sw2_port9_base_t1_phy>;
};
port@a {
reg = <10>;
label = "trx12";
phy-mode = "internal";
phy-handle = <&sw2_port10_base_t1_phy>;
};
};
};
};
Basically it is a single DSA tree with 2 "ethernet" properties, i.e. a
multi-CPU-port system. There is also a DSA link between the switches,
but it is not a daisy chain topology, i.e. there is no "upstream" and
"downstream" switch, the DSA link is only to be used for the bridge data
plane (autonomous forwarding between switches, between the RJ-45 ports
and the automotive Ethernet ports), otherwise all traffic that should
reach the host should do so through the dedicated CPU port of the switch.
Of course, plain forwarding in this topology is bound to create packet
loops. I have thought long and hard about strategies to cut forwarding
in such a way as to prevent loops but also not impede normal operation
of the network on such a system, and I believe I have found a solution
that does work as expected. This relies heavily on DSA's recent ability
to perform RX filtering towards the host by installing MAC addresses as
static FDB entries. Since we have 2 distinct DSA masters, we have 2
distinct MAC addresses, and if the bridge is configured to have its own
MAC address that makes it 3 distinct MAC addresses. The bridge core,
plus the switchdev_handle_fdb_add_to_device() extension, handle each MAC
address by replicating it to each port of the DSA switch tree. So the
end result is that both switch 1 and switch 2 will have static FDB
entries towards their respective CPU ports for the 3 MAC addresses
corresponding to the DSA masters and to the bridge net device (and of
course, towards any station learned on a foreign interface).
So I think the basic design works, and it is basically just as fragile
as any other multi-CPU-port system is bound to be in terms of reliance
on static FDB entries towards the host (if hardware address learning on
the CPU port is to be used, MAC addresses would randomly bounce between
one CPU port and the other otherwise). In fact, I think it is even
better to start DSA's support of multi-CPU-port systems with something
small like the NXP Bluebox 3, because we allow some time for the code
paths like dsa_switch_host_address_match(), which were specifically
designed for it, to break in, and this board needs no user space
configuration of CPU ports, like static assignments between user and CPU
ports, or bonding between the CPU ports/DSA masters.
Vladimir Oltean (8):
net: dsa: rename teardown_default_cpu to teardown_cpu_ports
net: dsa: give preference to local CPU ports
net: dsa: sja1105: configure the cascade ports based on topology
net: dsa: sja1105: manage the forwarding domain towards DSA ports
net: dsa: sja1105: manage VLANs on cascade ports
net: dsa: sja1105: increase MTU to account for VLAN header on DSA
ports
net: dsa: sja1105: suppress TX packets from looping back in "H"
topologies
net: dsa: sja1105: enable address learning on cascade ports
drivers/net/dsa/sja1105/sja1105_main.c | 229 ++++++++++++++++++-------
net/dsa/dsa2.c | 47 ++++-
2 files changed, 210 insertions(+), 66 deletions(-)
--
2.25.1
From: Vladimir Oltean <vladimir.oltean@nxp.com> Date: 2021-08-04 13:16:48
There is nothing specific to having a default CPU port to what
dsa_tree_teardown_default_cpu() does. Even with multiple CPU ports,
it would do the same thing: iterate through the ports of this switch
tree and reset the ->cpu_dp pointer to NULL. So rename it accordingly.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
net/dsa/dsa2.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
From: Vladimir Oltean <vladimir.oltean@nxp.com> Date: 2021-08-04 13:16:52
Be there an "H" switch topology, where there are 2 switches connected as
follows:
eth0 eth1
| |
CPU port CPU port
| DSA link |
sw0p0 sw0p1 sw0p2 sw0p3 sw0p4 -------- sw1p4 sw1p3 sw1p2 sw1p1 sw1p0
| | | | | |
user user user user user user
port port port port port port
basically one where each switch has its own CPU port for termination,
but there is also a DSA link in case packets need to be forwarded in
hardware between one switch and another.
DSA insists to see this as a daisy chain topology, basically registering
all network interfaces as sw0p0@eth0, ... sw1p0@eth0 and disregarding
eth1 as a valid DSA master.
This is only half the story, since when asked using dsa_port_is_cpu(),
DSA will respond that sw1p1 is a CPU port, however one which has no
dp->cpu_dp pointing to it. So sw1p1 is enabled, but not used.
Furthermore, be there a driver for switches which support only one
upstream port. This driver iterates through its ports and checks using
dsa_is_upstream_port() whether the current port is an upstream one.
For switch 1, two ports pass the "is upstream port" checks:
- sw1p4 is an upstream port because it is a routing port towards the
dedicated CPU port assigned using dsa_tree_setup_default_cpu()
- sw1p1 is also an upstream port because it is a CPU port, albeit one
that is disabled. This is because dsa_upstream_port() returns:
if (!cpu_dp)
return port;
which means that if @dp does not have a ->cpu_dp pointer (which is a
characteristic of CPU ports themselves as well as unused ports), then
@dp is its own upstream port.
So the driver for switch 1 rightfully says: I have two upstream ports,
but I don't support multiple upstream ports! So let me error out, I
don't know which one to choose and what to do with the other one.
Generally I am against enforcing any default policy in the kernel in
terms of user to CPU port assignment (like round robin or such) but this
case is different. To solve the conundrum, one would have to:
- Disable sw1p1 in the device tree or mark it as "not a CPU port" in
order to comply with DSA's view of this topology as a daisy chain,
where the termination traffic from switch 1 must pass through switch 0.
This is counter-productive because it wastes 1Gbps of termination
throughput in switch 1.
- Disable the DSA link between sw0p4 and sw1p4 and do software
forwarding between switch 0 and 1, and basically treat the switches as
part of disjoint switch trees. This is counter-productive because it
wastes 1Gbps of autonomous forwarding throughput between switch 0 and 1.
- Treat sw0p4 and sw1p4 as user ports instead of DSA links. This could
work, but it makes cross-chip bridging impossible. In this setup we
would need to have 2 separate bridges, br0 spanning the ports of
switch 0, and br1 spanning the ports of switch 1, and the "DSA links
treated as user ports" sw0p4 (part of br0) and sw1p4 (part of br1) are
the gateway ports between one bridge and another. This is hard to
manage from a user's perspective, who wants to have a unified view of
the switching fabric and the ability to transparently add ports to the
same bridge. VLANs would also need to be explicitly managed by the
user on these gateway ports.
So it seems that the only reasonable thing to do is to make DSA prefer
CPU ports that are local to the switch. Meaning that by default, the
user and DSA ports of switch 0 will get assigned to the CPU port from
switch 0 (sw0p1) and the user and DSA ports of switch 1 will get
assigned to the CPU port from switch 1.
The way this solves the problem is that sw1p4 is no longer an upstream
port as far as switch 1 is concerned (it no longer views sw0p1 as its
dedicated CPU port).
So here we are, the first multi-CPU port that DSA supports is also
perhaps the most uneventful one: the individual switches don't support
multiple CPUs, however the DSA switch tree as a whole does have multiple
CPU ports. No user space assignment of user ports to CPU ports is
desirable, necessary, or possible.
Ports that do not have a local CPU port (say there was an extra switch
hanging off of sw0p0) default to the standard implementation of getting
assigned to the first CPU port of the DSA switch tree. Is that good
enough? Probably not (if the downstream switch was hanging off of switch
1, we would most certainly prefer its CPU port to be sw1p1), but in
order to support that use case too, we would need to traverse the
dst->rtable in search of an optimum dedicated CPU port, one that has the
smallest number of hops between dp->ds and dp->cpu_dp->ds. At the
moment, the DSA routing table structure does not keep the number of hops
between dl->dp and dl->link_dp, and while it is probably deducible,
there is zero justification to write that code now. Let's hope DSA will
never have to support that use case.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
net/dsa/dsa2.c | 37 ++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
@@ -311,6 +311,9 @@ static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst)returnNULL;}+/* Assign the default CPU port (the first one in the tree) to all ports of the+*fabricwhichdon'talreadyhaveoneaspartoftheirownswitch.+*/staticintdsa_tree_setup_default_cpu(structdsa_switch_tree*dst){structdsa_port*cpu_dp,*dp;
@@ -321,14 +324,42 @@ static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst)return-EINVAL;}-/* Assign the default CPU port to all ports of the fabric */-list_for_each_entry(dp,&dst->ports,list)+list_for_each_entry(dp,&dst->ports,list){+if(dp->cpu_dp)+continue;+if(dsa_port_is_user(dp)||dsa_port_is_dsa(dp))dp->cpu_dp=cpu_dp;+}return0;}+/* Perform initial assignment of CPU ports to user ports and DSA links in the+*fabric,givingpreferencetoCPUportslocaltoeachswitch.Defaultto+*usingthefirstCPUportintheswitchtreeiftheportdoesnothaveaCPU+*portlocaltothisswitch.+*/+staticintdsa_tree_setup_cpu_ports(structdsa_switch_tree*dst)+{+structdsa_port*cpu_dp,*dp;++list_for_each_entry(cpu_dp,&dst->ports,list){+if(!dsa_port_is_cpu(cpu_dp))+continue;++list_for_each_entry(dp,&dst->ports,list){+if(dp->ds!=cpu_dp->ds)+continue;++if(dsa_port_is_user(dp)||dsa_port_is_dsa(dp))+dp->cpu_dp=cpu_dp;+}+}++returndsa_tree_setup_default_cpu(dst);+}+staticvoiddsa_tree_teardown_cpu_ports(structdsa_switch_tree*dst){structdsa_port*dp;
@@ -921,7 +952,7 @@ static int dsa_tree_setup(struct dsa_switch_tree *dst)if(!complete)return0;-err=dsa_tree_setup_default_cpu(dst);+err=dsa_tree_setup_cpu_ports(dst);if(err)returnerr;
From: Vladimir Oltean <vladimir.oltean@nxp.com> Date: 2021-08-04 13:16:58
The sja1105 switch family has a feature called "cascade ports" which can
be used in topologies where multiple SJA1105/SJA1110 switches are daisy
chained. Upstream switches set this bit for the DSA link towards the
downstream switches. This is used when the upstream switch receives a
control packet (PTP, STP) from a downstream switch, because if the
source port for a control packet is marked as a cascade port, then the
source port, switch ID and RX timestamp will not be taken again on the
upstream switch, it is assumed that this has already been done by the
downstream switch (the leaf port in the tree) and that the CPU has
everything it needs to decode the information from this packet.
We need to distinguish between an upstream-facing DSA link and a
downstream-facing DSA link, because the upstream-facing DSA links are
"host ports" for the SJA1105/SJA1110 switches, and the downstream-facing
DSA links are "cascade ports".
Note that SJA1105 supports a single cascade port, so only daisy chain
topologies work. With SJA1110, there can be more complex topologies such
as:
eth0
|
host port
|
sw0p0 sw0p1 sw0p2 sw0p3 sw0p4
| | | |
cascade cascade user user
port port port port
| |
| |
| |
| host
| port
| |
| sw1p0 sw1p1 sw1p2 sw1p3 sw1p4
| | | | |
| user user user user
host port port port port
port
|
sw2p0 sw2p1 sw2p2 sw2p3 sw2p4
| | | |
user user user user
port port port port
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/sja1105/sja1105_main.c | 97 +++++++++++++++++++-------
1 file changed, 70 insertions(+), 27 deletions(-)
@@ -688,6 +688,72 @@ static void sja1110_select_tdmaconfigidx(struct sja1105_private *priv)general_params->tdmaconfigidx=tdmaconfigidx;}+staticintsja1105_init_topology(structsja1105_private*priv,+structsja1105_general_params_entry*general_params)+{+structdsa_switch*ds=priv->ds;+intport;++/* The host port is the destination for traffic matching mac_fltres1+*andmac_fltres0onallportsexceptitself.Defaulttoaninvalid+*value.+*/+general_params->host_port=ds->num_ports;++/* Link-local traffic received on casc_port will be forwarded+*tohost_portwithoutembeddingthesourceportanddeviceID+*infointhedestinationMACaddress,andnoRXtimestampswillbe+*takeneither(presumablybecauseitisacascadedportanda+*downstreamSJAswitchalreadydidthat).+*Todisablethefeature,weneedtododifferentthingsdependingon+*switchgeneration.OnSJA1105weneedtosetaninvalidport,while+*onSJA1110whichsupportmultiplecascadedports,thisfieldisa+*bitmasksoitmustbeleftzero.+*/+if(!priv->info->multiple_cascade_ports)+general_params->casc_port=ds->num_ports;++for(port=0;port<ds->num_ports;port++){+boolis_upstream=dsa_is_upstream_port(ds,port);+boolis_dsa_link=dsa_is_dsa_port(ds,port);++/* Upstream ports can be dedicated CPU ports or+*upstream-facingDSAlinks+*/+if(is_upstream){+if(general_params->host_port==ds->num_ports){+general_params->host_port=port;+}else{+dev_err(ds->dev,+"Port %llu is already a host port, configuring %d as one too is not supported\n",+general_params->host_port,port);+return-EINVAL;+}+}++/* Cascade ports are downstream-facing DSA links */+if(is_dsa_link&&!is_upstream){+if(priv->info->multiple_cascade_ports){+general_params->casc_port|=BIT(port);+}elseif(general_params->casc_port==ds->num_ports){+general_params->casc_port=port;+}else{+dev_err(ds->dev,+"Port %llu is already a cascade port, configuring %d as one too is not supported\n",+general_params->casc_port,port);+return-EINVAL;+}+}+}++if(general_params->host_port==ds->num_ports){+dev_err(ds->dev,"No host port configured\n");+return-EINVAL;+}++return0;+}+staticintsja1105_init_general_params(structsja1105_private*priv){structsja1105_general_params_entrydefault_general_params={
@@ -706,12 +772,6 @@ static int sja1105_init_general_params(struct sja1105_private *priv).mac_flt0=SJA1105_LINKLOCAL_FILTER_B_MASK,.incl_srcpt0=false,.send_meta0=false,-/* The destination for traffic matching mac_fltres1 and-*mac_fltres0onallportsexcepthost_port.Suchtraffic-*receievedonhost_portitselfwouldbedropped,except-*byinstallingatemporary'managementroute'-*/-.host_port=priv->ds->num_ports,/* Default to an invalid value */.mirr_port=priv->ds->num_ports,/* No TTEthernet */
@@ -731,16 +791,12 @@ static int sja1105_init_general_params(struct sja1105_private *priv).header_type=ETH_P_SJA1110,};structsja1105_general_params_entry*general_params;-structdsa_switch*ds=priv->ds;structsja1105_table*table;-intport;+intrc;-for(port=0;port<ds->num_ports;port++){-if(dsa_is_cpu_port(ds,port)){-default_general_params.host_port=port;-break;-}-}+rc=sja1105_init_topology(priv,&default_general_params);+if(rc)+returnrc;table=&priv->static_config.tables[BLK_IDX_GENERAL_PARAMS];
@@ -763,19 +819,6 @@ static int sja1105_init_general_params(struct sja1105_private *priv)sja1110_select_tdmaconfigidx(priv);-/* Link-local traffic received on casc_port will be forwarded-*tohost_portwithoutembeddingthesourceportanddeviceID-*infointhedestinationMACaddress,andnoRXtimestampswillbe-*takeneither(presumablybecauseitisacascadedportanda-*downstreamSJAswitchalreadydidthat).-*Todisablethefeature,weneedtododifferentthingsdependingon-*switchgeneration.OnSJA1105weneedtosetaninvalidport,while-*onSJA1110whichsupportmultiplecascadedports,thisfieldisa-*bitmasksoitmustbeleftzero.-*/-if(!priv->info->multiple_cascade_ports)-general_params->casc_port=ds->num_ports;-return0;}
From: Vladimir Oltean <vladimir.oltean@nxp.com> Date: 2021-08-04 13:17:08
Manage DSA links towards other switches, be they host ports or cascade
ports, the same as the CPU port, i.e. allow forwarding and flooding
unconditionally from all user ports.
We send packets as always VLAN-tagged on a DSA port, and we rely on the
cross-chip notifiers from tag_8021q to install the RX VLAN of a switch
port only on the proper remote ports of another switch (the ports that
are in the same bridging domain). So if there is no cross-chip bridging
in the system, the flooded packets will be sent on the DSA ports too,
but they will be dropped by the remote switches due to either
(a) a lack of the RX VLAN in the VLAN table of the ingress DSA port, or
(b) a lack of valid destinations for those packets, due to a lack of the
RX VLAN on the user ports of the switch
Note that switches which only transport packets in a cross-chip bridge,
but have no user ports of their own as part of that bridge, such as
switch 1 in this case:
DSA link DSA link
sw0p0 sw0p1 sw0p2 -------- sw1p0 sw1p2 sw1p3 -------- sw2p0 sw2p2 sw2p3
ip link set sw0p0 master br0
ip link set sw2p3 master br0
will still work, because the tag_8021q cross-chip notifiers keep the RX
VLANs installed on all DSA ports.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/sja1105/sja1105_main.c | 84 ++++++++++++++++++--------
1 file changed, 60 insertions(+), 24 deletions(-)
@@ -475,7 +475,8 @@ static int sja1105_init_l2_forwarding(struct sja1105_private *priv)structsja1105_l2_forwarding_entry*l2fwd;structdsa_switch*ds=priv->ds;structsja1105_table*table;-inti,j;+intport,tc;+intfrom,to;table=&priv->static_config.tables[BLK_IDX_L2_FORWARDING];
@@ -493,47 +494,82 @@ static int sja1105_init_l2_forwarding(struct sja1105_private *priv)l2fwd=table->entries;-/* First 5 entries define the forwarding rules */-for(i=0;i<ds->num_ports;i++){-unsignedintupstream=dsa_upstream_port(priv->ds,i);+/* First 5 entries in the L2 Forwarding Table define the forwarding+*rulesandtheVLANPCPtoingressqueuemapping.+*Setuptheingressqueuemappingfirst.+*/+for(port=0;port<ds->num_ports;port++){+if(dsa_is_unused_port(ds,port))+continue;-if(dsa_is_unused_port(ds,i))+for(tc=0;tc<SJA1105_NUM_TC;tc++)+l2fwd[port].vlan_pmap[tc]=tc;+}++/* Then manage the forwarding domain for user ports. These can forward+*onlytothealways-ondomain(CPUportandDSAlinks)+*/+for(from=0;from<ds->num_ports;from++){+if(!dsa_is_user_port(ds,from))continue;-for(j=0;j<SJA1105_NUM_TC;j++)-l2fwd[i].vlan_pmap[j]=j;+for(to=0;to<ds->num_ports;to++){+if(!dsa_is_cpu_port(ds,to)&&+!dsa_is_dsa_port(ds,to))+continue;-/* All ports start up with egress flooding enabled,-*includingtheCPUport.-*/-priv->ucast_egress_floods|=BIT(i);-priv->bcast_egress_floods|=BIT(i);+l2fwd[from].bc_domain|=BIT(to);+l2fwd[from].fl_domain|=BIT(to);++sja1105_port_allow_traffic(l2fwd,from,to,true);+}+}-if(i==upstream)+/* Then manage the forwarding domain for DSA links and CPU ports (the+*always-ondomain).Thesecansendpacketstoanyenabledportexcept+*themselves.+*/+for(from=0;from<ds->num_ports;from++){+if(!dsa_is_cpu_port(ds,from)&&!dsa_is_dsa_port(ds,from))continue;-sja1105_port_allow_traffic(l2fwd,i,upstream,true);-sja1105_port_allow_traffic(l2fwd,upstream,i,true);+for(to=0;to<ds->num_ports;to++){+if(dsa_is_unused_port(ds,to))+continue;++if(from==to)+continue;-l2fwd[i].bc_domain=BIT(upstream);-l2fwd[i].fl_domain=BIT(upstream);+l2fwd[from].bc_domain|=BIT(to);+l2fwd[from].fl_domain|=BIT(to);-l2fwd[upstream].bc_domain|=BIT(i);-l2fwd[upstream].fl_domain|=BIT(i);+sja1105_port_allow_traffic(l2fwd,from,to,true);+}+}++/* Finally, manage the egress flooding domain. All ports start up with+*floodingenabled,includingtheCPUportandDSAlinks.+*/+for(port=0;port<ds->num_ports;port++){+if(dsa_is_unused_port(ds,port))+continue;++priv->ucast_egress_floods|=BIT(port);+priv->bcast_egress_floods|=BIT(port);}/* Next 8 entries define VLAN PCP mapping from ingress to egress.*Createaone-to-onemapping.*/-for(i=0;i<SJA1105_NUM_TC;i++){-for(j=0;j<ds->num_ports;j++){-if(dsa_is_unused_port(ds,j))+for(tc=0;tc<SJA1105_NUM_TC;tc++){+for(port=0;port<ds->num_ports;port++){+if(dsa_is_unused_port(ds,port))continue;-l2fwd[ds->num_ports+i].vlan_pmap[j]=i;+l2fwd[ds->num_ports+tc].vlan_pmap[port]=tc;}-l2fwd[ds->num_ports+i].type_egrpcp2outputq=true;+l2fwd[ds->num_ports+tc].type_egrpcp2outputq=true;}return0;
From: Vladimir Oltean <vladimir.oltean@nxp.com> Date: 2021-08-04 13:17:14
Since commit ed040abca4c1 ("net: dsa: sja1105: use 4095 as the private
VLAN for untagged traffic"), this driver uses a reserved value as pvid
for the host port (DSA CPU port). Control packets which are sent as
untagged get classified to this VLAN, and all ports are members of it
(this is to be expected for control packets).
Manage all cascade ports in the same way and allow control packets to
egress everywhere.
Also, all VLANs need to be sent as egress-tagged on all cascade ports.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/sja1105/sja1105_main.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -460,7 +460,7 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)pvid.vlan_bc|=BIT(port);pvid.tag_port&=~BIT(port);-if(dsa_is_cpu_port(ds,port)){+if(dsa_is_cpu_port(ds,port)||dsa_is_dsa_port(ds,port)){priv->tag_8021q_pvid[port]=SJA1105_DEFAULT_VLAN;priv->bridge_pvid[port]=SJA1105_DEFAULT_VLAN;}
@@ -2310,8 +2310,8 @@ static int sja1105_bridge_vlan_add(struct dsa_switch *ds, int port,return-EBUSY;}-/* Always install bridge VLANs as egress-tagged on the CPU port. */-if(dsa_is_cpu_port(ds,port))+/* Always install bridge VLANs as egress-tagged on CPU and DSA ports */+if(dsa_is_cpu_port(ds,port)||dsa_is_dsa_port(ds,port))flags=0;rc=sja1105_vlan_add(priv,port,vlan->vid,flags);
From: Vladimir Oltean <vladimir.oltean@nxp.com> Date: 2021-08-04 13:17:33
Since all packets are transmitted as VLAN-tagged over a DSA link (this
VLAN tag represents the tag_8021q header), we need to increase the MTU
of these interfaces to account for the possibility that we are already
transporting a user-visible VLAN header.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/sja1105/sja1105_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -982,7 +982,7 @@ static int sja1105_init_l2_policing(struct sja1105_private *priv)for(port=0;port<ds->num_ports;port++){intmtu=VLAN_ETH_FRAME_LEN+ETH_FCS_LEN;-if(dsa_is_cpu_port(priv->ds,port))+if(dsa_is_cpu_port(ds,port)||dsa_is_dsa_port(ds,port))mtu+=VLAN_HLEN;policing[port].smax=65535;/* Burst size in bytes */
@@ -2664,7 +2664,7 @@ static int sja1105_change_mtu(struct dsa_switch *ds, int port, int new_mtu)new_mtu+=VLAN_ETH_HLEN+ETH_FCS_LEN;-if(dsa_is_cpu_port(ds,port))+if(dsa_is_cpu_port(ds,port)||dsa_is_dsa_port(ds,port))new_mtu+=VLAN_HLEN;policing=priv->static_config.tables[BLK_IDX_L2_POLICING].entries;
From: Vladimir Oltean <vladimir.oltean@nxp.com> Date: 2021-08-04 13:17:37
H topologies like this one have a problem:
eth0 eth1
| |
CPU port CPU port
| DSA link |
sw0p0 sw0p1 sw0p2 sw0p3 sw0p4 -------- sw1p4 sw1p3 sw1p2 sw1p1 sw1p0
| | | | | |
user user user user user user
port port port port port port
Basically any packet sent by the eth0 DSA master can be flooded on the
interconnecting DSA link sw0p4 <-> sw1p4 and it will be received by the
eth1 DSA master too. Basically we are talking to ourselves.
In VLAN-unaware mode, these packets are encoded using a tag_8021q TX
VLAN, which dsa_8021q_rcv() rightfully cannot decode and complains.
Whereas in VLAN-aware mode, the packets are encoded with a bridge VLAN
which _can_ be decoded by the tagger running on eth1, so it will attempt
to reinject that packet into the network stack (the bridge, if there is
any port under eth1 that is under a bridge). In the case where the ports
under eth1 are under the same cross-chip bridge as the ports under eth0,
the TX packets will even be learned as RX packets. The only thing that
will prevent loops with the software bridging path, and therefore
disaster, is that the source port and the destination port are in the
same hardware domain, and the bridge will receive packets from the
driver with skb->offload_fwd_mark = true and will not forward between
the two.
The proper solution to this problem is to detect H topologies and
enforce that all packets are received through the local switch and we do
not attempt to receive packets on our CPU port from switches that have
their own. This is a viable solution which works thanks to the fact that
MAC addresses which should be filtered towards the host are installed by
DSA as static MAC addresses towards the CPU port of each switch.
TX from a CPU port towards the DSA port continues to be allowed, this is
because sja1105 supports bridge TX forwarding offload, and the skb->dev
used initially for xmit does not have any direct correlation with where
the station that will respond to that packet is connected. It may very
well happen that when we send a ping through a br0 interface that spans
all switch ports, the xmit packet will exit the system through a DSA
switch interface under eth1 (say sw1p2), but the destination station is
connected to a switch port under eth0, like sw0p0. So the switch under
eth1 needs to communicate on TX with the switch under eth0. The
response, however, will not follow the same path, but instead, this
patch enforces that the response is sent by the first switch directly to
its DSA master which is eth0.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/sja1105/sja1105_main.c | 29 ++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
@@ -474,7 +474,9 @@ static int sja1105_init_l2_forwarding(struct sja1105_private *priv){structsja1105_l2_forwarding_entry*l2fwd;structdsa_switch*ds=priv->ds;+structdsa_switch_tree*dst;structsja1105_table*table;+structdsa_link*dl;intport,tc;intfrom,to;
@@ -547,6 +549,33 @@ static int sja1105_init_l2_forwarding(struct sja1105_private *priv)}}+/* In odd topologies ("H" connections where there is a DSA link to+*anotherswitchwhichalsohasitsownCPUport),TXpacketscanloop+*backintothesystem(theyarefloodedfromCPUport1totheDSA+*link,andfromtheretoCPUport2).Preventthisfromhappeningby+*cuttingRXfromDSAlinkstowardsourCPUport,iftheremoteswitch+*hasitsownCPUportandthereforedoesn'tneedoursfornetwork+*stacktermination.+*/+dst=ds->dst;++list_for_each_entry(dl,&dst->rtable,list){+if(dl->dp->ds!=ds||dl->link_dp->cpu_dp==dl->dp->cpu_dp)+continue;++from=dl->dp->index;+to=dsa_upstream_port(ds,from);++dev_warn(ds->dev,+"H topology detected, cutting RX from DSA link %d to CPU port %d to prevent TX packet loops\n",+from,to);++sja1105_port_allow_traffic(l2fwd,from,to,false);++l2fwd[from].bc_domain&=~BIT(to);+l2fwd[from].fl_domain&=~BIT(to);+}+/* Finally, manage the egress flooding domain. All ports start up with*floodingenabled,includingtheCPUportandDSAlinks.*/
From: Vladimir Oltean <vladimir.oltean@nxp.com> Date: 2021-08-04 13:17:41
Right now, address learning is disabled on DSA ports, which means that a
packet received over a DSA port from a cross-chip switch will be flooded
to unrelated ports.
It is desirable to eliminate that, but for that we need a breakdown of
the possibilities for the sja1105 driver. A DSA port can be:
- a downstream-facing cascade port. This is simple because it will
always receive packets from a downstream switch, and there should be
no other route to reach that downstream switch in the first place,
which means it should be safe to learn that MAC address towards that
switch.
- an upstream-facing cascade port. This receives packets either:
* autonomously forwarded by an upstream switch (and therefore these
packets belong to the data plane of a bridge, so address learning
should be ok), or
* injected from the CPU. This deserves further discussion, as normally,
an upstream-facing cascade port is no different than the CPU port
itself. But with "H" topologies (a DSA link towards a switch that
has its own CPU port), these are more "laterally-facing" cascade
ports than they are "upstream-facing". Here, there is a risk that
the port might learn the host addresses on the wrong port (on the
DSA port instead of on its own CPU port), but this is solved by
DSA's RX filtering infrastructure, which installs the host addresses
as static FDB entries on the CPU port of all switches in a "H" tree.
So even if there will be an attempt from the switch to migrate the
FDB entry from the CPU port to the laterally-facing cascade port, it
will fail to do that, because the FDB entry that already exists is
static and cannot migrate. So address learning should be safe for
this configuration too.
Ok, so what about other MAC addresses coming from the host, not
necessarily the bridge local FDB entries? What about MAC addresses
dynamically learned on foreign interfaces, isn't there a risk that
cascade ports will learn these entries dynamically when they are
supposed to be delivered towards the CPU port? Well, that is correct,
and this is why we also need to enable the assisted learning feature, to
snoop for these addresses and write them to hardware as static FDB
entries towards the CPU, to make the switch's learning process on the
cascade ports ineffective for them. With assisted learning enabled, the
hardware learning on the CPU port must be disabled.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/sja1105/sja1105_main.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)