They have a 500 MHz MIPS 24KEc CPU and the usual DDR, UART, I2C and SPI controllers. But more interestingly, they also have an 8 or 10-port Gigabit Ethernet switch allowing to offload common network bridging operations to the hardware. As is usual for that kind of products, the vendor-provided SDK (called WebStaX) used to configure the switch is running in userspace and uses a custom in-kernel UIO driver to talk to the hardware.
However, this has now changed as we submitted support for the platform and the switch to the upstream Linux kernel:
- Most of the platform support has been merged in v4.17
- The initial support for the switch was merged in v4.18. It supported bridging, STP and IGMP snooping support but also a driver for the MDIO interface.
- Finally, VLAN filtering and link aggregation support will appear in the upcoming v4.19.
The whole driver based on the switchdev Linux kernel subsystem, is about 5700 lines long.
Thanks to this work, it is now possible to use standard Linux user-space tools to configure the switch. For example, the following will bridge the switch port and offload to the hardware:
ip link add name br0 type bridge ip link set dev sw0p0 master br0 ip link set dev sw0p1 master br0
To achieve hardware offloading, the driver needs to:
- configure port forwarding i.e. to what port the frames coming form a particular port should be forwarded;
- handle the MAC table: this table is the one used to know on which port which machine is connected. Also, the broadcast and multicast MAC have to be installed;
- handle STP port state: whether the port is allowed to forward frames or learn new MAC addresses;
VLANs are configured using
ip link set dev br0 type bridge vlan_filtering 1 bridge vlan add dev sw0p0 vid 1 pvid untagged bridge vlan add dev sw0p1 vid 1 bridge vlan add dev sw0p0 vid 30 bridge vlan add dev sw0p1 vid 30
Here, the driver configures the VIDs on each port and what to do about them (tag, untag, forward).
Configuring link aggregation is also done with
ip link add name aggr0 type bond ip link set dev eth_yellow master aggr0 ip link set dev eth_blue master aggr0
The driver has to configure the aggregated ports and the balancing mode. It also has to ensure the switch will forward the control frame (LACPDUs) to the CPU so Linux can know the state of the links.
IGMP snooping is a simple feature where the switch is able to push new multicast addresses to the CPU so Linux can install the MACs in the table and avoid having to forward the multicast frames on all the switch ports. In our case, it is simply enabled using a single register when multicasting is enabled on the bridge.
The switch supports more features to be worked on: PTP timestamping, QoS and packet filtering to name a few. We have already implemented PTP support, and we will be submitting upstream this additional feature in the near future.
To learn more about the inner workings of switchdev, you can refer to Alexandre Belloni’s ELC talk:
If you’re interested about upstream Linux kernel support for other Ethernet switches, do not hesitate to contact us!