162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci======================================= 462306a36Sopenharmony_ciDSA switch configuration from userspace 562306a36Sopenharmony_ci======================================= 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciThe DSA switch configuration is not integrated into the main userspace 862306a36Sopenharmony_cinetwork configuration suites by now and has to be performed manually. 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci.. _dsa-config-showcases: 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ciConfiguration showcases 1362306a36Sopenharmony_ci----------------------- 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciTo configure a DSA switch a couple of commands need to be executed. In this 1662306a36Sopenharmony_cidocumentation some common configuration scenarios are handled as showcases: 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci*single port* 1962306a36Sopenharmony_ci Every switch port acts as a different configurable Ethernet port 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci*bridge* 2262306a36Sopenharmony_ci Every switch port is part of one configurable Ethernet bridge 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci*gateway* 2562306a36Sopenharmony_ci Every switch port except one upstream port is part of a configurable 2662306a36Sopenharmony_ci Ethernet bridge. 2762306a36Sopenharmony_ci The upstream port acts as different configurable Ethernet port. 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciAll configurations are performed with tools from iproute2, which is available 3062306a36Sopenharmony_ciat https://www.kernel.org/pub/linux/utils/net/iproute2/ 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ciThrough DSA every port of a switch is handled like a normal linux Ethernet 3362306a36Sopenharmony_ciinterface. The CPU port is the switch port connected to an Ethernet MAC chip. 3462306a36Sopenharmony_ciThe corresponding linux Ethernet interface is called the master interface. 3562306a36Sopenharmony_ciAll other corresponding linux interfaces are called slave interfaces. 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ciThe slave interfaces depend on the master interface being up in order for them 3862306a36Sopenharmony_cito send or receive traffic. Prior to kernel v5.12, the state of the master 3962306a36Sopenharmony_ciinterface had to be managed explicitly by the user. Starting with kernel v5.12, 4062306a36Sopenharmony_cithe behavior is as follows: 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci- when a DSA slave interface is brought up, the master interface is 4362306a36Sopenharmony_ci automatically brought up. 4462306a36Sopenharmony_ci- when the master interface is brought down, all DSA slave interfaces are 4562306a36Sopenharmony_ci automatically brought down. 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciIn this documentation the following Ethernet interfaces are used: 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci*eth0* 5062306a36Sopenharmony_ci the master interface 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci*eth1* 5362306a36Sopenharmony_ci another master interface 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci*lan1* 5662306a36Sopenharmony_ci a slave interface 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci*lan2* 5962306a36Sopenharmony_ci another slave interface 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci*lan3* 6262306a36Sopenharmony_ci a third slave interface 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci*wan* 6562306a36Sopenharmony_ci A slave interface dedicated for upstream traffic 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ciFurther Ethernet interfaces can be configured similar. 6862306a36Sopenharmony_ciThe configured IPs and networks are: 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci*single port* 7162306a36Sopenharmony_ci * lan1: 192.0.2.1/30 (192.0.2.0 - 192.0.2.3) 7262306a36Sopenharmony_ci * lan2: 192.0.2.5/30 (192.0.2.4 - 192.0.2.7) 7362306a36Sopenharmony_ci * lan3: 192.0.2.9/30 (192.0.2.8 - 192.0.2.11) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci*bridge* 7662306a36Sopenharmony_ci * br0: 192.0.2.129/25 (192.0.2.128 - 192.0.2.255) 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci*gateway* 7962306a36Sopenharmony_ci * br0: 192.0.2.129/25 (192.0.2.128 - 192.0.2.255) 8062306a36Sopenharmony_ci * wan: 192.0.2.1/30 (192.0.2.0 - 192.0.2.3) 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci.. _dsa-tagged-configuration: 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ciConfiguration with tagging support 8562306a36Sopenharmony_ci---------------------------------- 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ciThe tagging based configuration is desired and supported by the majority of 8862306a36Sopenharmony_ciDSA switches. These switches are capable to tag incoming and outgoing traffic 8962306a36Sopenharmony_ciwithout using a VLAN based configuration. 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci*single port* 9262306a36Sopenharmony_ci .. code-block:: sh 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci # configure each interface 9562306a36Sopenharmony_ci ip addr add 192.0.2.1/30 dev lan1 9662306a36Sopenharmony_ci ip addr add 192.0.2.5/30 dev lan2 9762306a36Sopenharmony_ci ip addr add 192.0.2.9/30 dev lan3 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci # For kernels earlier than v5.12, the master interface needs to be 10062306a36Sopenharmony_ci # brought up manually before the slave ports. 10162306a36Sopenharmony_ci ip link set eth0 up 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci # bring up the slave interfaces 10462306a36Sopenharmony_ci ip link set lan1 up 10562306a36Sopenharmony_ci ip link set lan2 up 10662306a36Sopenharmony_ci ip link set lan3 up 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci*bridge* 10962306a36Sopenharmony_ci .. code-block:: sh 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci # For kernels earlier than v5.12, the master interface needs to be 11262306a36Sopenharmony_ci # brought up manually before the slave ports. 11362306a36Sopenharmony_ci ip link set eth0 up 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci # bring up the slave interfaces 11662306a36Sopenharmony_ci ip link set lan1 up 11762306a36Sopenharmony_ci ip link set lan2 up 11862306a36Sopenharmony_ci ip link set lan3 up 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci # create bridge 12162306a36Sopenharmony_ci ip link add name br0 type bridge 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci # add ports to bridge 12462306a36Sopenharmony_ci ip link set dev lan1 master br0 12562306a36Sopenharmony_ci ip link set dev lan2 master br0 12662306a36Sopenharmony_ci ip link set dev lan3 master br0 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci # configure the bridge 12962306a36Sopenharmony_ci ip addr add 192.0.2.129/25 dev br0 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci # bring up the bridge 13262306a36Sopenharmony_ci ip link set dev br0 up 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci*gateway* 13562306a36Sopenharmony_ci .. code-block:: sh 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci # For kernels earlier than v5.12, the master interface needs to be 13862306a36Sopenharmony_ci # brought up manually before the slave ports. 13962306a36Sopenharmony_ci ip link set eth0 up 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci # bring up the slave interfaces 14262306a36Sopenharmony_ci ip link set wan up 14362306a36Sopenharmony_ci ip link set lan1 up 14462306a36Sopenharmony_ci ip link set lan2 up 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci # configure the upstream port 14762306a36Sopenharmony_ci ip addr add 192.0.2.1/30 dev wan 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci # create bridge 15062306a36Sopenharmony_ci ip link add name br0 type bridge 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci # add ports to bridge 15362306a36Sopenharmony_ci ip link set dev lan1 master br0 15462306a36Sopenharmony_ci ip link set dev lan2 master br0 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci # configure the bridge 15762306a36Sopenharmony_ci ip addr add 192.0.2.129/25 dev br0 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci # bring up the bridge 16062306a36Sopenharmony_ci ip link set dev br0 up 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci.. _dsa-vlan-configuration: 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ciConfiguration without tagging support 16562306a36Sopenharmony_ci------------------------------------- 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ciA minority of switches are not capable to use a taging protocol 16862306a36Sopenharmony_ci(DSA_TAG_PROTO_NONE). These switches can be configured by a VLAN based 16962306a36Sopenharmony_ciconfiguration. 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci*single port* 17262306a36Sopenharmony_ci The configuration can only be set up via VLAN tagging and bridge setup. 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci .. code-block:: sh 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci # tag traffic on CPU port 17762306a36Sopenharmony_ci ip link add link eth0 name eth0.1 type vlan id 1 17862306a36Sopenharmony_ci ip link add link eth0 name eth0.2 type vlan id 2 17962306a36Sopenharmony_ci ip link add link eth0 name eth0.3 type vlan id 3 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci # For kernels earlier than v5.12, the master interface needs to be 18262306a36Sopenharmony_ci # brought up manually before the slave ports. 18362306a36Sopenharmony_ci ip link set eth0 up 18462306a36Sopenharmony_ci ip link set eth0.1 up 18562306a36Sopenharmony_ci ip link set eth0.2 up 18662306a36Sopenharmony_ci ip link set eth0.3 up 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci # bring up the slave interfaces 18962306a36Sopenharmony_ci ip link set lan1 up 19062306a36Sopenharmony_ci ip link set lan2 up 19162306a36Sopenharmony_ci ip link set lan3 up 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci # create bridge 19462306a36Sopenharmony_ci ip link add name br0 type bridge 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci # activate VLAN filtering 19762306a36Sopenharmony_ci ip link set dev br0 type bridge vlan_filtering 1 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci # add ports to bridges 20062306a36Sopenharmony_ci ip link set dev lan1 master br0 20162306a36Sopenharmony_ci ip link set dev lan2 master br0 20262306a36Sopenharmony_ci ip link set dev lan3 master br0 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci # tag traffic on ports 20562306a36Sopenharmony_ci bridge vlan add dev lan1 vid 1 pvid untagged 20662306a36Sopenharmony_ci bridge vlan add dev lan2 vid 2 pvid untagged 20762306a36Sopenharmony_ci bridge vlan add dev lan3 vid 3 pvid untagged 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci # configure the VLANs 21062306a36Sopenharmony_ci ip addr add 192.0.2.1/30 dev eth0.1 21162306a36Sopenharmony_ci ip addr add 192.0.2.5/30 dev eth0.2 21262306a36Sopenharmony_ci ip addr add 192.0.2.9/30 dev eth0.3 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci # bring up the bridge devices 21562306a36Sopenharmony_ci ip link set br0 up 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci*bridge* 21962306a36Sopenharmony_ci .. code-block:: sh 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci # tag traffic on CPU port 22262306a36Sopenharmony_ci ip link add link eth0 name eth0.1 type vlan id 1 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci # For kernels earlier than v5.12, the master interface needs to be 22562306a36Sopenharmony_ci # brought up manually before the slave ports. 22662306a36Sopenharmony_ci ip link set eth0 up 22762306a36Sopenharmony_ci ip link set eth0.1 up 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci # bring up the slave interfaces 23062306a36Sopenharmony_ci ip link set lan1 up 23162306a36Sopenharmony_ci ip link set lan2 up 23262306a36Sopenharmony_ci ip link set lan3 up 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci # create bridge 23562306a36Sopenharmony_ci ip link add name br0 type bridge 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci # activate VLAN filtering 23862306a36Sopenharmony_ci ip link set dev br0 type bridge vlan_filtering 1 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci # add ports to bridge 24162306a36Sopenharmony_ci ip link set dev lan1 master br0 24262306a36Sopenharmony_ci ip link set dev lan2 master br0 24362306a36Sopenharmony_ci ip link set dev lan3 master br0 24462306a36Sopenharmony_ci ip link set eth0.1 master br0 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci # tag traffic on ports 24762306a36Sopenharmony_ci bridge vlan add dev lan1 vid 1 pvid untagged 24862306a36Sopenharmony_ci bridge vlan add dev lan2 vid 1 pvid untagged 24962306a36Sopenharmony_ci bridge vlan add dev lan3 vid 1 pvid untagged 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ci # configure the bridge 25262306a36Sopenharmony_ci ip addr add 192.0.2.129/25 dev br0 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci # bring up the bridge 25562306a36Sopenharmony_ci ip link set dev br0 up 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ci*gateway* 25862306a36Sopenharmony_ci .. code-block:: sh 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci # tag traffic on CPU port 26162306a36Sopenharmony_ci ip link add link eth0 name eth0.1 type vlan id 1 26262306a36Sopenharmony_ci ip link add link eth0 name eth0.2 type vlan id 2 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ci # For kernels earlier than v5.12, the master interface needs to be 26562306a36Sopenharmony_ci # brought up manually before the slave ports. 26662306a36Sopenharmony_ci ip link set eth0 up 26762306a36Sopenharmony_ci ip link set eth0.1 up 26862306a36Sopenharmony_ci ip link set eth0.2 up 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ci # bring up the slave interfaces 27162306a36Sopenharmony_ci ip link set wan up 27262306a36Sopenharmony_ci ip link set lan1 up 27362306a36Sopenharmony_ci ip link set lan2 up 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci # create bridge 27662306a36Sopenharmony_ci ip link add name br0 type bridge 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci # activate VLAN filtering 27962306a36Sopenharmony_ci ip link set dev br0 type bridge vlan_filtering 1 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_ci # add ports to bridges 28262306a36Sopenharmony_ci ip link set dev wan master br0 28362306a36Sopenharmony_ci ip link set eth0.1 master br0 28462306a36Sopenharmony_ci ip link set dev lan1 master br0 28562306a36Sopenharmony_ci ip link set dev lan2 master br0 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_ci # tag traffic on ports 28862306a36Sopenharmony_ci bridge vlan add dev lan1 vid 1 pvid untagged 28962306a36Sopenharmony_ci bridge vlan add dev lan2 vid 1 pvid untagged 29062306a36Sopenharmony_ci bridge vlan add dev wan vid 2 pvid untagged 29162306a36Sopenharmony_ci 29262306a36Sopenharmony_ci # configure the VLANs 29362306a36Sopenharmony_ci ip addr add 192.0.2.1/30 dev eth0.2 29462306a36Sopenharmony_ci ip addr add 192.0.2.129/25 dev br0 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci # bring up the bridge devices 29762306a36Sopenharmony_ci ip link set br0 up 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ciForwarding database (FDB) management 30062306a36Sopenharmony_ci------------------------------------ 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ciThe existing DSA switches do not have the necessary hardware support to keep 30362306a36Sopenharmony_cithe software FDB of the bridge in sync with the hardware tables, so the two 30462306a36Sopenharmony_citables are managed separately (``bridge fdb show`` queries both, and depending 30562306a36Sopenharmony_cion whether the ``self`` or ``master`` flags are being used, a ``bridge fdb 30662306a36Sopenharmony_ciadd`` or ``bridge fdb del`` command acts upon entries from one or both tables). 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ciUp until kernel v4.14, DSA only supported user space management of bridge FDB 30962306a36Sopenharmony_cientries using the bridge bypass operations (which do not update the software 31062306a36Sopenharmony_ciFDB, just the hardware one) using the ``self`` flag (which is optional and can 31162306a36Sopenharmony_cibe omitted). 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci .. code-block:: sh 31462306a36Sopenharmony_ci 31562306a36Sopenharmony_ci bridge fdb add dev swp0 00:01:02:03:04:05 self static 31662306a36Sopenharmony_ci # or shorthand 31762306a36Sopenharmony_ci bridge fdb add dev swp0 00:01:02:03:04:05 static 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ciDue to a bug, the bridge bypass FDB implementation provided by DSA did not 32062306a36Sopenharmony_cidistinguish between ``static`` and ``local`` FDB entries (``static`` are meant 32162306a36Sopenharmony_cito be forwarded, while ``local`` are meant to be locally terminated, i.e. sent 32262306a36Sopenharmony_cito the host port). Instead, all FDB entries with the ``self`` flag (implicit or 32362306a36Sopenharmony_ciexplicit) are treated by DSA as ``static`` even if they are ``local``. 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci .. code-block:: sh 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ci # This command: 32862306a36Sopenharmony_ci bridge fdb add dev swp0 00:01:02:03:04:05 static 32962306a36Sopenharmony_ci # behaves the same for DSA as this command: 33062306a36Sopenharmony_ci bridge fdb add dev swp0 00:01:02:03:04:05 local 33162306a36Sopenharmony_ci # or shorthand, because the 'local' flag is implicit if 'static' is not 33262306a36Sopenharmony_ci # specified, it also behaves the same as: 33362306a36Sopenharmony_ci bridge fdb add dev swp0 00:01:02:03:04:05 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ciThe last command is an incorrect way of adding a static bridge FDB entry to a 33662306a36Sopenharmony_ciDSA switch using the bridge bypass operations, and works by mistake. Other 33762306a36Sopenharmony_cidrivers will treat an FDB entry added by the same command as ``local`` and as 33862306a36Sopenharmony_cisuch, will not forward it, as opposed to DSA. 33962306a36Sopenharmony_ci 34062306a36Sopenharmony_ciBetween kernel v4.14 and v5.14, DSA has supported in parallel two modes of 34162306a36Sopenharmony_ciadding a bridge FDB entry to the switch: the bridge bypass discussed above, as 34262306a36Sopenharmony_ciwell as a new mode using the ``master`` flag which installs FDB entries in the 34362306a36Sopenharmony_cisoftware bridge too. 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ci .. code-block:: sh 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ci bridge fdb add dev swp0 00:01:02:03:04:05 master static 34862306a36Sopenharmony_ci 34962306a36Sopenharmony_ciSince kernel v5.14, DSA has gained stronger integration with the bridge's 35062306a36Sopenharmony_cisoftware FDB, and the support for its bridge bypass FDB implementation (using 35162306a36Sopenharmony_cithe ``self`` flag) has been removed. This results in the following changes: 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ci .. code-block:: sh 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ci # This is the only valid way of adding an FDB entry that is supported, 35662306a36Sopenharmony_ci # compatible with v4.14 kernels and later: 35762306a36Sopenharmony_ci bridge fdb add dev swp0 00:01:02:03:04:05 master static 35862306a36Sopenharmony_ci # This command is no longer buggy and the entry is properly treated as 35962306a36Sopenharmony_ci # 'local' instead of being forwarded: 36062306a36Sopenharmony_ci bridge fdb add dev swp0 00:01:02:03:04:05 36162306a36Sopenharmony_ci # This command no longer installs a static FDB entry to hardware: 36262306a36Sopenharmony_ci bridge fdb add dev swp0 00:01:02:03:04:05 static 36362306a36Sopenharmony_ci 36462306a36Sopenharmony_ciScript writers are therefore encouraged to use the ``master static`` set of 36562306a36Sopenharmony_ciflags when working with bridge FDB entries on DSA switch interfaces. 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ciAffinity of user ports to CPU ports 36862306a36Sopenharmony_ci----------------------------------- 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ciTypically, DSA switches are attached to the host via a single Ethernet 37162306a36Sopenharmony_ciinterface, but in cases where the switch chip is discrete, the hardware design 37262306a36Sopenharmony_cimay permit the use of 2 or more ports connected to the host, for an increase in 37362306a36Sopenharmony_citermination throughput. 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_ciDSA can make use of multiple CPU ports in two ways. First, it is possible to 37662306a36Sopenharmony_cistatically assign the termination traffic associated with a certain user port 37762306a36Sopenharmony_cito be processed by a certain CPU port. This way, user space can implement 37862306a36Sopenharmony_cicustom policies of static load balancing between user ports, by spreading the 37962306a36Sopenharmony_ciaffinities according to the available CPU ports. 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ciSecondly, it is possible to perform load balancing between CPU ports on a per 38262306a36Sopenharmony_cipacket basis, rather than statically assigning user ports to CPU ports. 38362306a36Sopenharmony_ciThis can be achieved by placing the DSA masters under a LAG interface (bonding 38462306a36Sopenharmony_cior team). DSA monitors this operation and creates a mirror of this software LAG 38562306a36Sopenharmony_cion the CPU ports facing the physical DSA masters that constitute the LAG slave 38662306a36Sopenharmony_cidevices. 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_ciTo make use of multiple CPU ports, the firmware (device tree) description of 38962306a36Sopenharmony_cithe switch must mark all the links between CPU ports and their DSA masters 39062306a36Sopenharmony_ciusing the ``ethernet`` reference/phandle. At startup, only a single CPU port 39162306a36Sopenharmony_ciand DSA master will be used - the numerically first port from the firmware 39262306a36Sopenharmony_cidescription which has an ``ethernet`` property. It is up to the user to 39362306a36Sopenharmony_ciconfigure the system for the switch to use other masters. 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_ciDSA uses the ``rtnl_link_ops`` mechanism (with a "dsa" ``kind``) to allow 39662306a36Sopenharmony_cichanging the DSA master of a user port. The ``IFLA_DSA_MASTER`` u32 netlink 39762306a36Sopenharmony_ciattribute contains the ifindex of the master device that handles each slave 39862306a36Sopenharmony_cidevice. The DSA master must be a valid candidate based on firmware node 39962306a36Sopenharmony_ciinformation, or a LAG interface which contains only slaves which are valid 40062306a36Sopenharmony_cicandidates. 40162306a36Sopenharmony_ci 40262306a36Sopenharmony_ciUsing iproute2, the following manipulations are possible: 40362306a36Sopenharmony_ci 40462306a36Sopenharmony_ci .. code-block:: sh 40562306a36Sopenharmony_ci 40662306a36Sopenharmony_ci # See the DSA master in current use 40762306a36Sopenharmony_ci ip -d link show dev swp0 40862306a36Sopenharmony_ci (...) 40962306a36Sopenharmony_ci dsa master eth0 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci # Static CPU port distribution 41262306a36Sopenharmony_ci ip link set swp0 type dsa master eth1 41362306a36Sopenharmony_ci ip link set swp1 type dsa master eth0 41462306a36Sopenharmony_ci ip link set swp2 type dsa master eth1 41562306a36Sopenharmony_ci ip link set swp3 type dsa master eth0 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_ci # CPU ports in LAG, using explicit assignment of the DSA master 41862306a36Sopenharmony_ci ip link add bond0 type bond mode balance-xor && ip link set bond0 up 41962306a36Sopenharmony_ci ip link set eth1 down && ip link set eth1 master bond0 42062306a36Sopenharmony_ci ip link set swp0 type dsa master bond0 42162306a36Sopenharmony_ci ip link set swp1 type dsa master bond0 42262306a36Sopenharmony_ci ip link set swp2 type dsa master bond0 42362306a36Sopenharmony_ci ip link set swp3 type dsa master bond0 42462306a36Sopenharmony_ci ip link set eth0 down && ip link set eth0 master bond0 42562306a36Sopenharmony_ci ip -d link show dev swp0 42662306a36Sopenharmony_ci (...) 42762306a36Sopenharmony_ci dsa master bond0 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ci # CPU ports in LAG, relying on implicit migration of the DSA master 43062306a36Sopenharmony_ci ip link add bond0 type bond mode balance-xor && ip link set bond0 up 43162306a36Sopenharmony_ci ip link set eth0 down && ip link set eth0 master bond0 43262306a36Sopenharmony_ci ip link set eth1 down && ip link set eth1 master bond0 43362306a36Sopenharmony_ci ip -d link show dev swp0 43462306a36Sopenharmony_ci (...) 43562306a36Sopenharmony_ci dsa master bond0 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_ciNotice that in the case of CPU ports under a LAG, the use of the 43862306a36Sopenharmony_ci``IFLA_DSA_MASTER`` netlink attribute is not strictly needed, but rather, DSA 43962306a36Sopenharmony_cireacts to the ``IFLA_MASTER`` attribute change of its present master (``eth0``) 44062306a36Sopenharmony_ciand migrates all user ports to the new upper of ``eth0``, ``bond0``. Similarly, 44162306a36Sopenharmony_ciwhen ``bond0`` is destroyed using ``RTM_DELLINK``, DSA migrates the user ports 44262306a36Sopenharmony_cithat were assigned to this interface to the first physical DSA master which is 44362306a36Sopenharmony_cieligible, based on the firmware description (it effectively reverts to the 44462306a36Sopenharmony_cistartup configuration). 44562306a36Sopenharmony_ci 44662306a36Sopenharmony_ciIn a setup with more than 2 physical CPU ports, it is therefore possible to mix 44762306a36Sopenharmony_cistatic user to CPU port assignment with LAG between DSA masters. It is not 44862306a36Sopenharmony_cipossible to statically assign a user port towards a DSA master that has any 44962306a36Sopenharmony_ciupper interfaces (this includes LAG devices - the master must always be the LAG 45062306a36Sopenharmony_ciin this case). 45162306a36Sopenharmony_ci 45262306a36Sopenharmony_ciLive changing of the DSA master (and thus CPU port) affinity of a user port is 45362306a36Sopenharmony_cipermitted, in order to allow dynamic redistribution in response to traffic. 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ciPhysical DSA masters are allowed to join and leave at any time a LAG interface 45662306a36Sopenharmony_ciused as a DSA master; however, DSA will reject a LAG interface as a valid 45762306a36Sopenharmony_cicandidate for being a DSA master unless it has at least one physical DSA master 45862306a36Sopenharmony_cias a slave device. 459