SSD_Ethernet Reference


1. ETHERNET Usage Reference


1.1. Ethernet Architecture

From the hardware aspect, the Ethernet interface circuit is mainly composed of MAC (Media Access Control) controller and physical layer interface PHY (Physical Layer). The Sigmastar platform has a built-in MAC controller and a built-in PHY; it also supports the RMII bus protocol, which can be connected to an external switch or PHY chip. The diagram is as follows:


1.2. RMII interface introduction

The RMII interface includes a data interface, and a management interface between the MAC and the PHY. The MDIO management interface includes two signal lines (MDC and MDIO). Through this interface , the MAC can read the PHY or Switch chip registers to achieve transmission information and status control.


1.3. Using RMII under uboot

SSD2XX platform example

1.3.1. Enable RMII support under uboot

Enable emac in menuconfig, close the built-in phy and open the rmii interface, as follows:


1.3.2. Initialize PHY or Switch with MDIO

The mdio read and write operation functions are provided under uboot , see the file: boot/drivers/mstar/emac/pioneer3/mhal_emac.c

MDIO read:

void MHal_EMAC_read_phy(unsigned char phy_addr, unsigned char address, u32
*value)

MDIO write:

void MHal_EMAC_write_phy (unsigned char phy_addr, unsigned char address, u32
value)

Refer to the ip101a_g_config_init function in the boot/drivers/mstar/emac/mdrv_emac.c file and use mdio read/write access register initializes the external PHY or Switch chip.

It should be noted that during the read operation, the MDC clock on the master side will become the falling edge sampling after the TA signal; the write operation will always keep the rising edge sampling. To determine whether the MDIO is read and written correctly, a logic analyzer can be used to capture the MDIO and MDC signal waveforms.


1.3.3. Test MDIO under Uboot

The mdio read and write commands are also provided under Uboot. You need to enter estart to enable the network card. The specific usage is as follows:

mdio reads register 1 such as:

SigmaStar # phy_r 1

phy read address[1] value is 78ed

mdio writes register 0 such as:

SigmaStar # phy_w 0 1234

phy write address[0] value is 1234

1.4. Using RMII under the kernel

SSD2XX example

1.4.1. Enable network support in kernel

Open the following options in menuconfig:


1.4.2. Configure RMII pin PINMUX

Open the kernel/arch/arm/boot/dts/pioneer3-ssc020a-s01a-demo-camera-padmux.dtsi file and add the following content to the padmux field:

{
    soc {
        padmux {
        compatible = "sstar-padmux";
        schematic =

        //for eth0 rmii
        <PAD_GPIO0      PINMUX_FOR_ETH0_MODE_11       MDRV_PUSE_ETH_MDIO>,
        <PAD_GPIO1      PINMUX_FOR_ETH0_MODE_11       MDRV_PUSE_ETH_MDC>,
        <PAD_GPIO2      PINMUX_FOR_ETH0_MODE_11       MDRV_PUSE_ETH_COL>,
        <PAD_GPIO3      PINMUX_FOR_ETH0_MODE_11       MDRV_PUSE_ETH_RXD0>,
        <PAD_GPIO4      PINMUX_FOR_ETH0_MODE_11       MDRV_PUSE_ETH_RXD1>,
        <PAD_GPIO5      PINMUX_FOR_ETH0_MODE_11       MDRV_PUSE_ETH_TX_CLK>,
        <PAD_GPIO6      PINMUX_FOR_ETH0_MODE_11       MDRV_PUSE_ETH_TXD0>,
        <PAD_GPIO7      PINMUX_FOR_ETH0_MODE_11       MDRV_PUSE_ETH_TXD1>,
        <PAD_GPIO8      PINMUX_FOR_ETH0_MODE_11       MDRV_PUSE_ETH_TX_EN>,

        status = "ok";
        };
    };
};

1.4.3. Modify device tree to enable RMII

Open the kernel/arch/arm/boot/dts/pioneer3-ssc020a-s01a-demo-camera.dts file, modify the following content, and configure the phy-mode as the rmii interface:

#if 0
emac0: emac0 {
    compatible = "sstar-emac";
    reg = <0x1F2A2000 0x800>, <0x1F343C00 0x600>, <0x1F006200 0x600>;
    pad = <0x1F2079B8 0x000F 0x0000>;  //for internal phy
    status = "ok";
    phy-handle = <&phy0>;
    mdio-bus {
        phy0: ethernet-phy@0 {
            phy-mode = "mii";
        };
    };
};
#endif

#if 1
//for emac0 rmii
emac0: emac0 {
    compatible = "sstar-emac";
    reg = <0x1F2A2000 0x800>, <0x1F343C00 0x600>, <0x00000000 0x600>;
    pad = <0x1F2079B8 0x000F 0x000B>;  //for external phy
    status = "ok";
    phy-handle = <&phy0>;
    mdio-bus {
        phy0: ethernet-phy@0 {
            phy-mode = "rmii";
        };
    };
};
#endif

1.4.4. Initialize PHY or Switch through MDIO interface

Kernel also supports mdio read and write operations, as follows:

MDIO read function: MDev_EMAC_mii_read

MDIO write function: MDev_EMAC_mii_write

MII/RMII initialization function: MDev_EMAC_mii_init

See the kernel/drivers/sstar/emac/mdrv_emac.c file for the specific code. The function for user to initialize the PHY or Switch chip can be added after the MDev_EMAC_mii_init function.

static int MDev_EMAC_mii_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val)
{
    struct emac_handle *hemac = (struct emac_handle *) bus->priv;
    int ret;

    ret = MHal_EMAC_write_phy(hemac->hal, phy_addr, phy_reg, (u32)val);
    return ret;
}

static int MDev_EMAC_mii_read(struct mii_bus *bus, int phy_addr, int phy_reg)
{
    u32 val;
    struct emac_handle *hemac = (struct emac_handle *) bus->priv;
    int ret;

    ret = MHal_EMAC_read_phy(hemac->hal, phy_addr, phy_reg, &val);
    return (int)val;
}

static int MDev_EMAC_mii_init(struct net_device* emac_dev)
{
    struct emac_handle *hemac = (struct emac_handle *) netdev_priv(emac_dev);
    struct device_node *mii_np = NULL;
    int ret = 0;

    ...

    hemac->mii_bus->name = "mdio";
    hemac->mii_bus->read = MDev_EMAC_mii_read;
    hemac->mii_bus->write = MDev_EMAC_mii_write;
    hemac->mii_bus->priv = hemac;
    hemac->mii_bus->parent = hemac->dev;

    ...

    return ret;
}

1.4.5. Test MDIO under Kernel

After the Kernel is up, the file is operated by the echo command, and the mdio read and write registers are implemented in the underlying driver. The commands are as follows:

MDIO read:

echo phy_r phyAddress > phyStatusWR

MDIO write:

echo phy_w phyAddress phyValue > phyStatusWR

For example, read the value of register 1; write 0x1234 to register 0, as follows:

# echo phy_r 1 > /sys/devices/virtual/mstar/emac0/phyStatusWR
# echo phy_w 0 1234 > /sys/devices/virtual/mstar/emac0/phyStatusWR

2. ETHERNET common configuration instructions


2.1. Configure IP address under uboot and kernel

Use the following commands to set the IP of the board and the IP of the computer under uboot, and use the ping command to test whether the network is connected:

SigmaStar # setenv ipaddr 192.168.50.123

SigmaStar # setenv serverip 192.168.50.249

SigmaStar # ping 192.168.50.249

Using sstar_emac device

host 192.168.50.249 is alive

Use the ifconfig command to configure IP-related properties under the kernel :

# ifconfig eth0 up
# ifconfig eth0 hw ether 00:70:27:00:00:03
# ifconfig eth0 192.168.50.123 netmask 255.255.255.0
# route add default gw 192.168.50.1

2.2. Obtaining IP automatically using DHCP

The script file is located in the project directory project/image/etc/init.d/udhcpc.script , and it will be copied to the board when the image is packaged. After the kernel is up, the board will run the udhcpc command to automatically obtain the ip. The example is as follows:

# udhcpc -i eth0 -s /etc/init.d/udhcpc.script
udhcpc (v1.20.2) started
Setting IP address 0.0.0.0 on eth0
Sending discover...
Sending discover...
Sending select for 192.168.50.243...
Lease of 192.168.50.243 obtained, lease time 86400
Setting IP address 192.168.50.243 on eth0
Deleting routers
route: SIOCDELRT: No such process
Adding router 192.168.50.1
Recreating /appconfigs/resolv.conf
Adding DNS server 192.168.50.1

2.3. DNS service usage

2.3.1. Prepare DNS dependencies

To open the DNS service, you need to depend on the relevant library files, which can be copied from the toolchain to the board, and the dynamic library can be exported using the export command.

# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib/libdns

For example, if you are using the 9.1.0 toolchain, the relevant library files are in the following directory:

/tools/toolchain/gcc-sigmastar-9.1.0-2020.07-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/

libnsl-2.30.so
libnsl.so.1
libnss_compat-2.30.so
libnss_compat.so.2
libnss_db-2.30.so
libnss_db.so.2
libnss_dns-2.30.so
libnss_dns.so.2
libnss_files-2.30.so
libnss_files.so.2
libnss_hesiod-2.30.so
libnss_hesiod.so.2
libresolv-2.30.so
libresolv.so.2

2.3.2. Configure DNS server

Create the /etc/resolv.conf configuration file on the board and write the corresponding dns server ip, such as:

# echo "nameserver 8.8.8.8" >> /etc/resolv.conf

2.3.3. Test DNS

Use the ping command to test the DNS resolution domain name, such as:

# ping www.baidu.com
PING www.baidu.com (163.177.151.109): 56 data bytes
64 bytes from 163.177.151.109: seq=0 ttl=55 time=7.640 ms
64 bytes from 163.177.151.109: seq=1 ttl=55 time=8.002 ms
64 bytes from 163.177.151.109: seq=2 ttl=55 time=7.443 ms
--- www.baidu.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 7.443/7.695/8.002 ms

3. ETHERNET Bandwidth Test Instructions


3.1. Use iperf to test network performance

3.1.1. Download iperf source code

Linux side download address:

https://iperf.fr/download/source/iperf-2.0.9-source.tar.gz

PC download address:

https://iperf.fr/iperf-download.php#windows

== Note: The version of iperf on the linux side is the same as that on the PC side==

3.1.2. Compiling iperf

Configure the cross compiler:

./configure --help
./configure --prefix=$(pwd)/host --host=arm-linux-gnueabihf CXX=arm-linux-gnueabihf-g++ CC=arm-linux-gnueabihf-gcc

Compile and install. After completion, the executable file iperf will be generated in the current directory host/bin and copied to the board:

make clean
make -j4
make install

3.1.3. Test network

Help command:

# ./iperf –h

-f [k|m|K|M] means to display the report in Kbits, Mbits, KBytes, MBytes respectively, the default is in Mbits
-i sec Display report interval in seconds, eg: iperf -c 222.35.11.23 -i 2
-l buffer size, the default is 8KB, eg: iperf -c 222.35.11.23 -l 16 -m Display the maximum mtu value of tcp
-o output reports and error messages to a file, eg: iperf -c 222.35.11.23 -o /mnt/iperflog.txt
-p specifies the port used by the server or the port the client is connected to
-u use udp protocol
-w specifies the TCP window size, the default is 8KB
-M Set the maximum mtu value of TCP packets
Client-side dedicated parameters
-d Simultaneous bidirectional transmission test
-n specifies the number of bytes to transfer, eg: iperf -c 222.35.11.23 -n 100000
-r Test for bidirectional transmission alone
-t test time, the default is 10 seconds, eg: iperf -c 222.35.11.23 -t 5
-F specifies the file to transfer
-T specifies the ttl value

3.1.4. TCP throughput test

The PC side is used as the server, and the board side is used as the client. Open the cmd command line in Windows and enter iperf -s to run iperf in server mode, as shown in the following figure:

On the Linux board, run iperf in client mode and test for 10 seconds, as follows:

# ./iperf -c 192.168.50.249 -i 1 -t 10
-------------------------------------------------- ------------
Client connecting to 192.168.50.249, TCP port 5001
TCP window size: 128 KByte (default)
-------------------------------------------------- ------------
[ 3] local 192.168.50.243 port 49902 connected with 192.168.50.249 port 5001
[ID] Interval Transfer Bandwidth
[ 3] 0.0- 1.0 sec 11.1 MBytes 93.3 Mbits/sec
[ 3] 1.0- 2.0 sec 11.2 MBytes 94.4 Mbits/sec
[ 3] 2.0- 3.0 sec 11.0 MBytes 92.3 Mbits/sec
[ 3] 3.0- 4.0 sec 11.2 MBytes 94.4 Mbits/sec
[ 3] 4.0- 5.0 sec 11.2 MBytes 94.4 Mbits/sec

3.1.5. UDP packet loss test

The PC side is used as the server, and the board side is used as the client. Open the cmd command line in Windows and enter iperf -s -u to run iperf in server mode, as shown in the following figure:

On the Linux board, run iperf in client mode and test for 10 seconds, as follows:

# ./iperf -c 192.168.50.249 -i 1 -t 10 -u
------------------------------------------------------------
Client connecting to 192.168.50.249, UDP port 5001
Sending 1470 byte datagrams, IPG target: 11215.21 us (kalman adjust)
UDP buffer size:  512 KByte (default)
------------------------------------------------------------
[  3] local 192.168.50.243 port 57894 connected with 192.168.50.249 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec   131 KBytes  1.07 Mbits/sec
[  3]  1.0- 2.0 sec   128 KBytes  1.05 Mbits/sec
[  3]  2.0- 3.0 sec   128 KBytes  1.05 Mbits/sec
[  3]  3.0- 4.0 sec   128 KBytes  1.05 Mbits/sec
[  3]  4.0- 5.0 sec   128 KBytes  1.05 Mbits/sec
[  3]  5.0- 6.0 sec   128 KBytes  1.05 Mbits/sec
[  3]  6.0- 7.0 sec   129 KBytes  1.06 Mbits/sec
[  3]  7.0- 8.0 sec   128 KBytes  1.05 Mbits/sec
[  3]  8.0- 9.0 sec   128 KBytes  1.05 Mbits/sec
[  3]  9.0-10.0 sec   128 KBytes  1.05 Mbits/sec
[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec
[  3] Sent 893 datagrams
[  3] Server Report:
[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec   0.417 ms    0/  893 (0%)

4. Typical FAQ Example


Q1: How to add ephy's network port driver capability?

For [SSD20X][SSD212][SSD22X]

riu_r 0x31 0x2E

riu_w 0x31 0x2E 0x7001 //Set bit0 to 1

echo swing_100 2 > /sys/devices/virtual/mstar/emac0/turndrv //Enhance network port driver capability

riu_r 0x33 0x42 //View the current network drive amplitude

Q2: What if there are some scenes with extra long network cables (>200m)?

For [SSD20X][SSD212][SSD22X]

The transmission distance of more than 100m is out of specification, and reliability cannot be guaranteed, but you can try to limit the speed to 10M.

riu_w 0x31 0x04 0x61

riu_w 0x31 0x00 0x1200

echo max > /sys /class/mstar/emac0/turndrv