How to setup operation modes of Ethernet of SP7021

Please follow the following steps to setup operation modes and enable Ethernet of SP7021.

1. Enable Sunplus Ethernet device

Run make kconfig in project top directory. When “Linux/arm Kernel Configuration” menu pops up, use arrow and Enter key to select <Device Drivers> → <Network device support> → <Ethernet driver support> and then enable <Sunplus Ethernet devices>. Refer to screenshot below:

<Sunplus Ethernet devices> is enabled.

2. Setup operating mode of Ethernet device

Modify node l2sw in device-tree source file to set up operating mode of Ethernet device. For example, if you are using SP7021 demo board V3 and you need dual network interfaces, please modify the device-tree source file, linux/kernel/arch/arm/boot/dts/sp7021-demov3.dts, as shown below:

&l2sw { pinctrl-names = "default"; pinctrl-0 = <&l2sw_demo_board_v3_pins>; mode = < 1 >; /* 0 = daisy-chain mode * 1 = dual NIC mode * 2 = daisy-chain mode (disable SA learning) */ };

where property mode is set to 1 to set up operating mode to “dual NIC”.

SP7021 supports two Ethernet ports, you can set the two Ethernet ports in “daisy-chain” mode, “dual NIC” mode, or “daisy-chain mode but disable source-address learning” mode.

If “dual NIC” mode is set, you will have two Ethernet interfaces, eth0 and eth1, in Linux. Otherwise, you will have one Ethernet interface, eth0, in Linux.

3. Build Linux image

Go to top folder. Run make all to build Linux image.

4. Boot Linux

Boot Linux with the built image.

5. Dynamic switch operating mode

Besides selecting mode in device-tree source file, Sunplus Ethernet driver also supports dynamic (run-time) mode-switching. To enable dynamic mode-switching, please enable “Support Dynamic Mode-switching by sysfs“ in “Linux/arm Kernel Configuration” menu. Refer to screenshot below:

After Linux boots up, you can use ‘sysfs’ to switch operation mode. Just simply write a ‘mode’ character to ‘sysfs’. ‘mode’ character is defined as:

0: “daisy-chain” mode

1: “dual NIC” mode

2: “daisy-chain but disable SA learning” mode

For example, to switch to “dual NIC” mode, just simply issue shell command as:

/ # echo 1 > /sys/devices/platform/soc@B/9c108000.l2sw/mode

Current operation mode of Ethernet driver can also be read out from ‘sysfs’. For example, issue the shell command as:

/ # cat /sys/devices/platform/soc@B/9c108000.l2sw/mode

6. Appendix

Sunplus Ethernet driver supports 3 operation modes:

a. “daisy-chain” mode

b. “dual NIC” mode

c. “daisy-chain but disable source address learning” mode

In “daisy-chain” mode, Ethernet driver creates one net-device interface (eg: eth0). The net-device interface is connected to two LAN ports (two RJ45 sockets) via L2 switch. In this mode, a packet from one LAN port will be either forwarded to net-device interface (eht0) if its destination address matches MAC address of net-device interface (eth0), or forwarded to other LAN port. A packet from net-device interface (eth0) will be forwarded to a LAN port if its destination address is learnt by L2 switch, or forwarded to both LAN ports if its destination has not been learnt yet. The following diagram illustrates the packets flow in this mode.

In “dual NIC” mode, Ethernet driver creates two net-device interfaces (eg: eth0 and eth1). Each has its dedicated LAN port. Packets will not be forwarded between two ports, unless you run some bridge utilities manually in Linux. Refer to diagram below, packets from eth0 will be always forwarded to LAN port 0 and packets from LAN port 0 will be always forwarded to eth0. The same theory is applied for eth1 and LAN port 1.

“daisy-chain but disable source address learning” mode is similar to “daisy-chain” mode. The difference is that a packet from net-device interface (eth0) will be always forwarded to both LAN ports. Learning function of L2 switch is turned off in this mode. This means L2 switch will never learn the source address of a packet. So, it always forward packets to both LAN ports. This mode works like you have 2-port Ethernet hub.