4.4. ENET¶
4.4.1. Introduction¶
Enet LLD is an unified Ethernet driver that support Ethernet peripherals found in TI SoCs, such as CPSW and ICSSG. Enet LLD supports CPSW_2G and CPSW_5G in J7200 devices.
The diagram below shows the overall software architecture of the Enet low-level driver. A top-level driver layer provides the interface that the applications can use to configure the switch and to send/receive Ethernet frames.
For instance, the CPSW support in the Enet driver consists of several software submodules that mirror those of the CPSW hardware, like DMA, ALE, MAC port, host port, MDIO, etc. Additionally, the Enet driver also includes PHY driver support as well as a resource manager to administrate the CPSW resources.
Enet LLD relies on other PDK drivers like UDMA for data transfer to/from the Ethernet peripheral’s host port to the other processing cores inside the TI SoC devices. For the lower level access to the hardware registers, Enet LLD relies on the Chip Support Library (CSL).
4.4.2. User Interface¶
For details about individual fields of this library structure, see the PDK doxygen documentation
4.4.2.1. APIs¶
The Enet LLD APIs can be broadly divided into two categories: control and data path. The control APIs can be used to configure all Ethernet hardware submodules like FDB, MAC port, host port, MDIO, statistics, as well as PHY drivers and resource management. The data path APIs are exclusive for the DMA-based data transfers between the TI SoC processing cores and the Ethernet peripheral.
API reference for application:
#include <ti/drv/enet/enet.h>
The main APIs of the Enet LLD are the following:
- Enet_open()
- Enet_close()
- Enet_ioctl()
- Enet_poll()
- Enet_periodicTick()
4.4.2.1.1. Data Path APIs¶
The main Enet LLD functions used to send and receive packets are:
- EnetDma_openRxCh()
- EnetDma_closeRxCh()
- EnetDma_openTxCh()
- EnetDma_closeTxCh()
- EnetDma_retrieveRxPktQ()
- EnetDma_submitRxPktQ()
- EnetDma_retrieveTxPktQ()
- EnetDma_submitTxPktQ()
It’s worth noting that the control path APIs are mainly IOCTL-based, and the data path APIs are direct functions in order to avoid any additional overhead associated with IOCTL calls as DMA data operations occur highly frequently.
4.4.2.1.2. IOCTL Interface¶
IOCTLs are system calls that take an argument specifying the command code and
can take none or additional parameters via Enet_IoctlPrms
argument.
IOCTL are used by all Enet submodules except for DMA.
The Enet_IoctlPrms
parameter structure consists of input and output
argument pointers and their corresponding size. The following helper macros are
provided to help construct the IOCTL params:
ENET_IOCTL_SET_NO_ARGS(prms)
. Used for IOCTL commands that take no parameters.ENET_IOCTL_SET_IN_ARGS(prms, in)
. Used for IOCTL commands that take input parameters but don’t output any parameter.ENET_IOCTL_SET_OUT_ARGS(prms, out)
. Used for IOCTL commands that don’t take input parameters but return output parameters.ENET_IOCTL_SET_INOUT_ARGS(prms, in, out)
. Used for IOCTL commands that take input parameters and also return output parameters.
where prms
in a pointer to Enet_IoctlPrms
variable, in
is the pointer
to IOCTL input argument and out
is the pointer to IOCTL output argument.
It’s recommended that the application doesn’t set the Enet_IoctlPrms
members individually, but only through the helper macros listed above.
Please refer to the individual IOCTL command to find out if it requires input and/or output parameters.
4.4.3. lwIP Integration¶
See lwIP User’s Guide for further information about lwIP integration into PDK using Enet LLD, and NDK-to-lwIP migration guide.
4.4.4. Application¶
4.4.4.1. Examples¶
Enet LLD comes with a set of examples demonstrating the usage of driver APIs. The examples are:
- enet_loopback: Internal (MAC port) or external loopback test.
- enet_lwip_example: TCP/IP stack integration using lwIP.
Name | Description | Expected Results | Cores Supported | Peripherals |
---|---|---|---|---|
Loopback | Enet Loopback example demonstrates basic packet send and receive on an Ethernet peripheral configured in MAC loopback or PHY loopback. | All packets sent from the example application shall be received back after being looped in MAC or PHY. | mcu1_0 | CPSW_2G |
mcu2_0 | CPSW_5G | |||
mcu2_1 | CPSW_2G | |||
mpu1_0 | CPSW_2G | |||
lwIP | Enet lwIP example demonstrates Enet driver integration with open source lwIP TCP/IP stack. The example enables DHCP client, it can get an IP address when connected to a network. | lwIP example application shall be able to get an IP address when connected to a network. User can test ‘ping’, ‘echo’ and ‘iperf’. | mcu1_0 | CPSW_2G |
mcu2_0 | CPSW_5G | |||
mcu2_1 | CPSW_2G | |||
mpu1_0 | CPSW_2G |
4.4.4.1.1. Enet loopback¶
This example exercises the MAC loopback functionality of the hardware. The example is developed and tested on both bare metal and TI RTOS code base. The Ethernet peripheral is opened with default initialization parameters and the MAC loopback is enabled.
A Tx channel and a Rx flow are opened to enable data transfers. Packets are transmitted from the Switch R5F (Main R5F0_0) to the host port using the Tx channel. These packets are routed back to the host port by the switch hardware as the internal loopback feature is enabled. These packets are then transmitted to the Switch R5F by the Rx flow and the application is notified.
The Tx and Rx functions in the example are set to transmit and receive 10000 packets. After reaching the count of 10000, the application closes the Tx channel, Rx flow, peripheral (i.e. CPSW) and restarts the application for a configurable number of times. Restarting the loopback test application ensures that there aren’t any memory leaks, and the hardware is closed properly and can be reopened any time.
4.4.4.1.2. Enet LWIP¶
Building LWIP example
Enabling specific features in the test
To configure what gets built in the example, navigate to the example directory
pdk/packages/ti/drv/enet/examples/enet_lwip_example
and find thelwipcfg.h
file. Inside, change the macros corresponding to the program that you wish to build to 1.For example, if udpecho is required, set:
#define LWIP_UDPECHO_APP 1
Note
The heap memory may need to be increased in the
FreeRTOSConfig.h
file to accomodate multiple apps.
To build the lwip example, issue the following command:
make -s enet_lwip_example_freertos
Running LWIP example
Load and run the enet_lwip_example image from the corresponding binaries folder.
The setup requires a LAN cable to be connected between the device and a multiport-router for the link status to be UP and aquire an IP address.
Connect the LAN cable between the same router and Laptop/PC from where the ping/echo tests are run.
Wait until the local interface IP is assigned and printed on the console like below.
Starting lwIP, local interface IP is dhcp-enabled CPSW_2G Test on MCU NAVSS EnetPhy_bindDriver: PHY 0: OUI:080028 Model:23 Ver:01 <-> 'dp83867' : OK PHY 0 is alive Host MAC address: 70:ff:76:01:02:03 [LWIPIF_LWIP] CPSW has been started successfully [LWIPIF_LWIP] NETIF INIT SUCCESS status_callback==UP, local interface IP is 0.0.0.0 Cpsw_handleLinkUp: Port 1: Link up: 100-Mbps Full-Duplex MAC Port 1: link up link_callback==UP status_callback==UP, local interface IP is 192.168.0.9 Initializing apps UDP server listening on port 5001
Testing LWIP example
Prerequisites: LAN cable setup and device link is UP and Local interface IP is successfully aquired.
Ping test
ping -t <ip_addr> ping -t 192.168.0.9
UDP/ TCP echo test
Download echotool from this website and execute the commands to see the response.
UDP echo command:
echotool.exe <ip_addr> /p udp /r 7 /n 0 echotool.exe 192.168.0.9 /p udp /r 7 /n 0
TCP echo command:
echotool.exe <ip_addr> /p tcp /r 7 /n 0 echotool.exe 192.168.0.9 /p tcp /r 7 /n 0
iperf test
Download iperf2 from iperf website and execute the commands to see the response.
iperf TCP test command:
iperf.exe -c <ip_addr> -r iperf.exe -c 192.168.0.9 -r
iperf UDP test command:
iperf.exe -c <ip_addr> -r -u iperf.exe -c 192.168.0.9 -r -u
Static IP
The Enet lwIP example uses DHCP by default. If static IP needs to be tested, the following
two config options need to be disabled in examples/enet_lwip_example/lwipcfg.h
.
#define USE_DHCP 0 #define USE_AUTOIP 0
The IP address, gateway and netmask can be set in the same lwipcfg.h file.
#define LWIP_PORT_INIT_IPADDR(addr) IP4_ADDR((addr), 192,168,1,200) #define LWIP_PORT_INIT_GW(addr) IP4_ADDR((addr), 192,168,1,1) #define LWIP_PORT_INIT_NETMASK(addr) IP4_ADDR((addr), 255,255,255,0)
4.4.4.1.3. Enet Multiport¶
Not supported for this SoC.
4.4.4.1.4. Enet TAS¶
Not supported for this SoC.