net: dsa: add driver for NXP SJA1105 L2 switch
authorVladimir Oltean <vladimir.oltean@nxp.com>
Wed, 29 Sep 2021 15:04:41 +0000 (18:04 +0300)
committerRamon Fried <rfried.dev@gmail.com>
Tue, 23 Nov 2021 07:57:56 +0000 (09:57 +0200)
commitf24b666b22048d30347666066ce08bad5720c6a6
treeed3027f3774f83fec4a22f707038ce4db348428d
parente3789a726269ce6c6e78277930cd1c2633e959a5
net: dsa: add driver for NXP SJA1105 L2 switch

The SJA1105 driver is largely reused from Linux. Its programming model
is that it is blank out of reset, and it waits for a static
configuration stream over SPI, which contains all runtime parameters (it
has no notion of "default values").

Keeping a binary array for the configuration stream would have meant
that aspects such as the CPU port and the MAC speeds could have not been
configured easily, and would have been static and board-dependent.
Live-patching the binary array means recalculating the static config
table CRCs, which is not a fun process.

So we create an abstraction over the static config tables, using the
packing API, same as in Linux. The tables are kept as C structures, and
the binary configuration stream is constructed on-the-go, with CRC and
all.

All static config tables instantiated in this driver are mandatory.
The hardware reference manual can be found at:
https://www.nxp.com/docs/en/user-guide/UM10944.pdf

For tagging, a simplified version of tag_8021q from Linux is used. The
VLAN EtherType is the same (0xdadb) but since we don't want switching in
U-Boot, there is no reason to have a TX VLAN and an RX VLAN for each
port. We just need the RX VLANs to act as the unique pvid of each
front-panel port, to decode the switch port number. The RX VLAN is used
for both RX and TX.

The device tree bindings are the same as in Linux.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
drivers/net/Kconfig
drivers/net/Makefile
drivers/net/sja1105.c [new file with mode: 0644]