This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] TDA4VM: How to do a MAC loopback test with CPSW in TDA4/DRA8 devices

Part Number: TDA4VM

There is some issue in my ethernet link. I wanted to do a sanity check using MAC loopback and see if the MAC is working well or not. Is there an easy way to do this?

  • Hi,

    From CCS (for Enet LLD applications and Ethfw)

    1. Launch the correct target configuration and connect to the core running the application. It will be mcu2_0(MAIN_Cortex_R5_0_0 in CCS Debug window) in case of Ethfw server. Halt/Suspend the Core.
    2. You can read/write to a register from Memory Browser window in CCS. To open a memory browser window, go to View → Memory Browser
    3. In Memory Browser Window, enter the address for CPSW_PN_MAC_CONTROL_REG. You can get this address from TRM.
      1. In general, the address is CPSW_BASE_ADDR+0x22330+(k*0x1000), where k is port number (0 indexed without host port)
        1. So for example, if you are using port 3, k would 2.
        2. Use address in hex with a "0x" prefix.
    4. Read the value of CPSW_PN_MAC_CONTROL_REG from Memory Browser window.
    5. Set the 1st bit (LSB is 0th) in the register and write the value back at the same address. To write back to a register, double click on the value and you can just type in the new value. Press "Enter" once you have written the correct value.
      1. So if you read 0x000000B9 from the register, setting bit 1 would make the value 0x000000BB.
    6. Your MAC is now configured in the loopback mode.
    7. To do a loopback test,
      1. Take a dump of the CPSW statistics before the test.
      2. Send test data frames from SoC through the port. Send atleast 5-10 packets. and again take a dump of CPSW statistics
      3. If you see increment in both Tx_Good_frames and Rx_good_frames for the port under test, the MAC is working properly.
    8. Write back the original value to CPSW_PN_MAC_CONTROL_REG to remove the loopback. Normal communication doesn't work with loopback on. Make sure to remove the loopback after test.

    From Linux (Native Linux Driver)

    1. The process is same from linux except the method to read and write register.
      1. To read a register, use : devmem2 $addr
      2. To write to a register, use : devmem2 $addr w $value
    2. Follow steps 3 to 7 from the above section to do a MAC loopback test
    3. This test can be automated in linux using a script. You can use the following script as a reference
      1. #!/bin/bash
        echo "======= $IF_NAME stats ======="
        ethtool -S $IF_NAME | grep good
        echo "**************************"
        echo "Setting CPSW in Loopback"
        echo "**************************"
        var=$(( 16#$(devmem2 $mac_addr | tail -n1 -c9) ))
        devmem2 $mac_addr w `expr $var + 2`
        devmem2 $mac_addr
        echo ""
        echo "Running Ping ..."
        ping -c 5 $server_ip_addr
        echo ""
        echo "======= $IF_NAME stats ======="
        ethtool -S $IF_NAME | grep good
        echo "**************************"
        echo "Removing CPSW Loopback"
        echo "**************************"
        devmem2 $mac_addr w $var

    If you see the MAC loopback test passing, then you should next do a phy loopback test.

    Please refer this FAQ for more details on how to read statistics for CPSW