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 Configure CPSW 5G/9G ALE

Part Number: TDA4VM

How to configure CPSW 5G/9G to add static entries ?

  • About

    ALE stands for Address Lookup Engine and it is a module inside CPSW 5G/9G module which is used to implement features specified in IEEE 802.1 Q protocol like VLAN tagging, Learning, Forwarding, Filtering, Rate control, Mirroring etc. (A full list is beyond the scope of this guide). It is how the switch knows which packets are to be forwarded to which ports. Details about the module are described in Section 12.2.2.4.6.1 of TRM.

    Programmers can use the features of ALE to setup complicated rules to:

    1. Filter packets based on VLAN, Ethernet Type, Source MAC, Destination MAC, IP address etc (For a full list please see TRM and API Guide)
    2. Set up forwarding rules between ports (re-direct traffic)
    3. Perform rate limitation
    4. Implement Automotive security features such as
      1. Disallow IP fragmentation
      2. Drop invalid SA
      3. Setup black lists based on SA or DA
    5. Combine various features to setup complicated rules for forwarding/policing

    This guide will first explain the basics of Forwarding without re-iterating what is already covered in TRM and User Guide and then explain key use-cases with examples.

    NOTE : There are a lot of ALE features and not everything will be covered here, readers are expected to use this as a foundation and go through the TRM and API Guide

    Ingress and Forwarding

    When a packet is received it goes through three stages, this is part of IEEE 802.3 Q protocol and not specific to the HW

    1. Ingress Filtering : Port State check for Unicast and Multicast frames
    2. VLAN Aware Lookup Process : Check whether the port is part of VLAN group, whether VLAN entry exists in table etc
    3. Egress Process : Egress Port states are checked

    If the 3 checks pass, then the packet is forwarded to the respective port (Host or Physical ports), else it gets dropped. See below:

    For the CPSW IP, Host port can mean any of the cores in the SoC, either the Main R5F 2_0 which is running the Ethernet Firmware or any of the remote cores (A72, MCU R5F) which are running virtual clients. The destination is decided based on the Flow ID (Unique DMA ID) and CoreID (Unique ID for each core).

    Without getting too much into concepts of Flow ID and Core ID it's enough to understand that they are required to tie any data flow to a particular core for the DMA and it is how packets are routed by CPSW within the SoC.

    For this reason, whenever a rule is created in CPSW ALE to forward packets to Host Port it must also be tied to the relevant Core and Flow ID. This part is handled by the API's provided by ENET-LLD as we will later see with examples.

    To know more about Flow ID's, please read the NAVSS Functional Description (Section 10.2.1.3) in TRM.

    NOTE : Currently a packet can only be sent to one core as driver does not handle duplication. This is an issue for Multicast/Broadcast frames as multiple cores can subscribe to these frames, there is currently no workaround for this. So for example both Main R5F and A72 cannot receive broadcast frames but either one of them can.

    This feature will be implemented in SDK 8.1 (Nov 2021)

    Parts of ALE

    Port State/Rules

    Each Port has the following states as per IEEE 802.1 Q

    1. Disabled
    2. Forwarding
    3. Learning
    4. Blocked

    They can be configured using the IOCTL 'CPSW_ALE_IOCTL_SET_PORT_STATE'  ,the corresponding HW register for this is 'CPSW_Iy_ALE_PORTCTL0_y'  and the corresponding field Iy_REG_Py_PORTSTATE

    In addition to port states, one can also set rules like Drop Untagged, Trunk Enable, MAC Only etc. See the TRM and API Guide for more details

    Tables

    The ALE has multiple tables

    1. VLAN Tables : Inner and Outer
    2. EtherType Table Entry
    3. IPv4 Table
    4. IPv6 Table

    Right now, we will just focus on VLAN tables

    There are two VLAN Tables, Inner VLAN Table and Outer VLAN Table. They are identical in all respects and the two of them are used to implement dual tagging (Q in Q) feature. For single VLAN tag, users must only use Inner VLAN Table. To create a VLAN based FDB rule, users must first create a corresponding VLAN entry in the Inner VLAN Table.

    The IOCTL to add a VLAN entry is 'CPSW_ALE_IOCTL_ADD_VLAN' and the IOCTL to delete is 'CPSW_ALE_IOCTL_REMOVE_VLAN'

    The entries for VLAN table are shown below:

    FDB Entries

    The FDB entries are of four types (classified by ENTRY_TYPE[0:1] field)

    1. Empty
    2. Address Based Entry : Unicast/Multicast
    3. VLAN Entry
    4. Unicast/Multicast with VLAN

    See below:

    Multicast/Unicast without VLAN

    VLAN/Unicast Entry

    Classifier and Policing

    Classifiers are used to create rules using Multicast/Unicast entries, VLAN and other Table entries. They are applied per port and can be configured to look for one or multiple conditions. For example a classifier can match for a particular VLAN or DA or both.

    Use-Case with Examples

    There is currently no support to add an entry dynamically to the ALE from the remote cores (A72, MCU R5F) so one must add the entry in Ethernet Firmware and compile it before hand. This is done by adding a callback function to the MAC callback handler CpswProxyServer_registerMacHandlerCb() which adds a static configuration.

    See flow-chart below:

    Adding a multicast entry for A72

    See this reference patch for Ethernet Firmware (On top of SDK 7.3) for adding a static Multicast entry for A72 core

    static_multicast_config_patch.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    From 4850b72c76d1bfc1ed88b8633b9266bd32275edc Mon Sep 17 00:00:00 2001
    From: Vineet Roy <vroy@ti.com>
    Date: Thu, 17 Jun 2021 23:32:12 +0530
    Subject: [PATCH 1/4] Static Multicast configuration for Linux
    ---
    .../mcu_2_0/main_tirtos.c | 172 ++++++++++++++++++
    ethfw/ethfw.h | 35 ++++
    ethfw/src/ethfw.c | 18 ++
    .../server/include/cpsw_proxy_server.h | 34 ++++
    ethremotecfg/server/src/cpsw_proxy_server.c | 46 +++++
    5 files changed, 305 insertions(+)
    diff --git a/apps/app_remoteswitchcfg_server/mcu_2_0/main_tirtos.c b/apps/app_remoteswitchcfg_server/mcu_2_0/main_tirtos.c
    index 74cc0df..304d560 100644
    --- a/apps/app_remoteswitchcfg_server/mcu_2_0/main_tirtos.c
    +++ b/apps/app_remoteswitchcfg_server/mcu_2_0/main_tirtos.c
    @@ -207,6 +207,14 @@ static void EthApp_startSwInterVlan(char *recvBuff,
    static void EthApp_startHwInterVlan(char *recvBuff,
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Main Functions :

    1. EthApp_addMpu10StaticCfg() : used to create a classifier entry for matching DA and a multicast MAC using the IOCTL CPSW_ALE_IOCTL_SET_POLICER and then add an entry in Multicast Table using the IOCTL CPSW_ALE_IOCTL_ADD_MCAST
    2. EthApp_delMpu10StaticCfg() : Remove the entries created by EthApp_addMpu10StaticCfg() using CPSW_ALE_IOCTL_DEL_POLICER
    3. EthApp_addRemoteCoreStaticCfg() andEthApp_delRemoteCoreStaticCfg() : This is used to check the CoreID and make sure thatEthApp_addMpu10StaticCfg() and EthApp_delMpu10StaticCfg() are invoked only for A72 Core

    The relevant structures to understand here are CpswAle_PolicerMatchParams and CpswAle_SetMcastEntryInArgs

    Note:

    1. As you can see from the Policer/Classifier entry,  we set the policerMatchEnMask field to CPSW_ALE_POLICER_MATCH_MACDST so that it matches the Destination MAC
    2. Since packets are going to A72, Host port must be added as a destination port and Mask for all port settings

    Adding a VLAN entry for A72 only for Port 1

    Refer to the patch below for adding a VLAN entry (VID  = 70) for Port 1 and Host Port. This patch binds the VID TEST_VID_A72 to Port 1 and enables strict VID check (inArgs.vidIngressCheck = true) so that if this packet is received by any other port then it is dropped.

    vlan_config_patch.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    diff --git a/apps/app_remoteswitchcfg_server/mcu_2_0/main_tirtos.c b/apps/app_remoteswitchcfg_server/mcu_2_0/main_tirtos.c
    index 74cc0df..6e5b2c0 100644
    --- a/apps/app_remoteswitchcfg_server/mcu_2_0/main_tirtos.c
    +++ b/apps/app_remoteswitchcfg_server/mcu_2_0/main_tirtos.c
    @@ -147,6 +147,8 @@
    /* Define A72_QNX_OS if A72 is running Qnx. Qnx doesn't load resource table. */
    /* #define A72_QNX_OS */
    +#define TEST_VID_A72 (70U)
    +
    /* ========================================================================== */
    /* Structure Declarations */
    /* ========================================================================== */
    @@ -207,6 +209,14 @@ static void EthApp_startSwInterVlan(char *recvBuff,
    static void EthApp_startHwInterVlan(char *recvBuff,
    char *sendBuff);
    +static int32_t EthApp_addRemoteCoreStaticCfg(Enet_Handle hEnet,
    + uint32_t coreId,
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Note:

    1. First VLAN configuration must be created using the IOCTL CPSW_ALE_IOCTL_ADD_VLAN
    2. Same VID (TEST_VID_A72) must be configured for both Policer and VLAN Table
    3. Only Inner VLAN is used
    4. For Policer, the match critiera mask checks for Inner VLAN entry (policerMatchEnMask = CPSW_ALE_POLICER_MATCH_IVLAN)

    Verifying ALE Entries

    Users can either run the GEL script cpsw_ale_print_table.gel on R5F (requires CCS and JTAG) or use the script below on A72 to print it. Both of these methods scan the entire ALE table and print all populated entries.

    cpsw_all_reg_print.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    #include <ctype.h>
    #include <error.h>
    #include <fcntl.h>
    #include <stdarg.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/mman.h>
    #include <unistd.h>
    #define MEMORY "/dev/mem"
    #define CPSW_9G_PORT_NUM 8
    #define CPSW_5G_PORT_NUM 4
    #define CPSW_2G_PORT_NUM 1
    #define ALE_TBLCTL_2G 0x4603E020
    #define ALE_TBLW2_2G 0x4603E034
    #define ALE_TBLW1_2G 0x4603E038
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    This file needs to be compiled on the device using GCC and executed. It has functions for various tasks, from print statistics to printing ALE entries.

    References

    1. DRA829 Technical Reference Manual
    2. Ethernet Firmware User Guide
    3. ENET ALE API Guide
    4. 802.1 Q - 2014

    Regards

    Vineet

  • Please find the updated VLAN patch for SDK 8.4 and it has fixed the following issues.

    1. Corrected policer structure member used for addition and deletion of VLAN policer entry.
    2. Corrected the sequence of ALE deletion and policer deletion (policer has to be deleted first, as policer dependence on ALE entry)

    Adding a VLAN entry for A72 only for Port 3

    6355.vlan_config_patch.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    From ab6202a076f88e0990e4e782ca8b9b53dfc5e423 Mon Sep 17 00:00:00 2001
    From: Sudheer Doredla <s-doredla@ti.com>
    Date: Wed, 4 Jan 2023 17:30:17 +0530
    Subject: [PATCH] Vlan Configuration
    Signed-off-by: Sudheer Doredla <s-doredla@ti.com>
    ---
    .../app_remoteswitchcfg_server/mcu_2_0/main.c | 180 ++++++++++++++++++
    ethfw/ethfw/ethfw.h | 37 ++++
    ethfw/ethfw/src/ethfw.c | 22 +++
    .../server/include/cpsw_proxy_server.h | 37 ++++
    .../server/src/cpsw_proxy_server.c | 33 ++++
    5 files changed, 309 insertions(+)
    diff --git a/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c b/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c
    index 67b866e7..3b792d67 100644
    --- a/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c
    +++ b/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c
    @@ -218,6 +218,8 @@
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


    Note:
    1. We have to create VLAN Interface on A72 with same VLAN ID being using in Ethfw.
    2. In case of Vision-apps applications, whatever the changes made in "ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c" file should be done in "vision_apps/utils/ethfw/src/app_ethfw_freertos.c" file.

    Regards,
    Sudheer

  • Adding a Unicast MAC Address entry for A72 only for Port-2.

    See this reference patch for Ethernet Firmware (On top of SDK 8.6) for adding a static Unicast MAC Address entry for A72 core.

    2352.0001-Adding-a-Unicast-Destination-MAC-Address-entry-for-A72.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    From f11ac5c9c5ee404c78f46f9273a190111f70fec9 Mon Sep 17 00:00:00 2001
    From: Doredla Sudheer Kumar <s-doredla@ti.com>
    Date: Tue, 18 Apr 2023 15:53:43 +0530
    Subject: [PATCH] Adding a Unicast Destination MAC Address entry for A72 on
    Port 2
    Signed-off-by: Doredla Sudheer Kumar <s-doredla@ti.com>
    ---
    .../app_remoteswitchcfg_server/mcu_2_0/main.c | 176 ++++++++++++++++++
    ethfw/ethfw/ethfw.h | 36 ++++
    ethfw/ethfw/src/ethfw.c | 19 ++
    .../server/include/cpsw_proxy_server.h | 35 ++++
    .../server/src/cpsw_proxy_server.c | 28 +++
    5 files changed, 294 insertions(+)
    diff --git a/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c b/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c
    index 75f18755..441b7011 100644
    --- a/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c
    +++ b/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


    Note:
    In case of Vision-apps applications, whatever the changes made in "ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c" file should be done in "vision_apps/utils/ethfw/src/app_ethfw_freertos.c" file.

  • Adding a Unicast MAC Address entry for A72.

    See this reference patch for Ethernet Firmware (On top of SDK 8.6) for adding a static Unicast MAC Address entry for A72 core.

    0447.0001-Adding-a-Unicast-Destination-MAC-Address-entry-for-A72.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    From 5840bd2378fb0eb7d875535b461df14fdbcff65c Mon Sep 17 00:00:00 2001
    From: Doredla Sudheer Kumar <s-doredla@ti.com>
    Date: Tue, 18 Apr 2023 15:53:43 +0530
    Subject: [PATCH] Adding a Unicast Destination MAC Address entry for A72 on
    Port 2
    Signed-off-by: Doredla Sudheer Kumar <s-doredla@ti.com>
    ---
    .../app_remoteswitchcfg_server/mcu_2_0/main.c | 166 ++++++++++++++++++
    ethfw/ethfw/ethfw.h | 36 ++++
    ethfw/ethfw/src/ethfw.c | 19 ++
    .../server/include/cpsw_proxy_server.h | 35 ++++
    .../server/src/cpsw_proxy_server.c | 28 +++
    5 files changed, 284 insertions(+)
    diff --git a/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c b/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c
    index 75f18755..ccd1c634 100644
    --- a/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c
    +++ b/ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


    Note:
    In case of Vision-apps applications, whatever the changes made in "ethfw/apps/app_remoteswitchcfg_server/mcu_2_0/main.c" file should be done in "vision_apps/utils/ethfw/src/app_ethfw_freertos.c" file.

    Best Regards,
    Sudheer