From 5840bd2378fb0eb7d875535b461df14fdbcff65c Mon Sep 17 00:00:00 2001 From: Doredla Sudheer Kumar 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 --- .../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 @@ -275,6 +275,14 @@ typedef struct /* Function Declarations */ /* ========================================================================== */ +static int32_t EthApp_addRemoteCoreStaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId); + +static void EthApp_delRemoteCoreStaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId); + void appLogPrintf(const char *format, ...); static void EthApp_waitForDebugger(void); @@ -882,6 +890,10 @@ static int32_t EthApp_initEthFw(void) } } + /* Set static configuration functions */ + ethFwCfg.addStaticCfg = &EthApp_addRemoteCoreStaticCfg; + ethFwCfg.delStaticCfg = &EthApp_delRemoteCoreStaticCfg; + /* Initialize the EthFw */ if (status == ETHAPP_OK) { @@ -905,6 +917,160 @@ static int32_t EthApp_initEthFw(void) return status; } +static int32_t EthApp_addMpu10StaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId) +{ + const uint8_t dstMacAddr[ENET_MAC_ADDR_LEN] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05}; + CpswAle_SetPolicerEntryInArgs polInArgs; + CpswAle_SetPolicerEntryOutArgs polOutArgs; + CpswAle_SetUcastEntryInArgs ucastInArgs; + Enet_IoctlPrms prms; + uint32_t entry; + int32_t status; + + ucastInArgs.addr.vlanId = 0U; + EnetUtils_copyMacAddr(&ucastInArgs.addr.addr[0], &dstMacAddr[0]); + + ucastInArgs.info.portNum = CPSW_ALE_HOST_PORT_NUM; + ucastInArgs.info.blocked = false; + ucastInArgs.info.secure = false; + ucastInArgs.info.super = false; + ucastInArgs.info.ageable = false; + ucastInArgs.info.trunk = false; + + ENET_IOCTL_SET_INOUT_ARGS(&prms, &ucastInArgs, &entry); + + status = Enet_ioctl(hEnet, gEthAppObj.coreId, CPSW_ALE_IOCTL_ADD_UCAST, &prms); + if (status != ENET_SOK) + { + appLogPrintf("Failed to add ucast entry: %d\n", status); + } + + + polInArgs.policerMatch.policerMatchEnMask = 0U; + + /* Add policer entry for unicast dstmac */ + + polInArgs.policerMatch.policerMatchEnMask = CPSW_ALE_POLICER_MATCH_MACDST; + polInArgs.policerMatch.dstMacAddrInfo.portNum = CPSW_ALE_HOST_PORT_NUM; + polInArgs.policerMatch.dstMacAddrInfo.addr.vlanId = 0U; + EnetUtils_copyMacAddr(&polInArgs.policerMatch.dstMacAddrInfo.addr.addr[0], &dstMacAddr[0]); + + polInArgs.threadIdEn = true; + polInArgs.threadId = flowId; + polInArgs.peakRateInBitsPerSec = 0U; + polInArgs.commitRateInBitsPerSec = 0U; + + ENET_IOCTL_SET_INOUT_ARGS(&prms, &polInArgs, &polOutArgs); + + status = Enet_ioctl(hEnet, gEthAppObj.coreId, CPSW_ALE_IOCTL_SET_POLICER, &prms); + if (status != ENET_SOK) + { + appLogPrintf("Failed to register MACDST policer: %d\n", status); + } + + return status; +} + +static void EthApp_delMpu10StaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId) +{ + const uint8_t dstMacAddr[ENET_MAC_ADDR_LEN] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05}; + CpswAle_DelPolicerEntryInArgs polInArgs; + CpswAle_PolicerMatchParams policerMatch; + CpswAle_PolicerEntryOutArgs polOutArgs; + Enet_IoctlPrms prms; + int32_t status; + + polInArgs.policerMatch.policerMatchEnMask = 0U; + + /* Delete policer entry for unicast dstmac */ + + polInArgs.policerMatch.policerMatchEnMask = CPSW_ALE_POLICER_MATCH_MACDST; + polInArgs.policerMatch.dstMacAddrInfo.portNum = CPSW_ALE_HOST_PORT_NUM; + polInArgs.policerMatch.dstMacAddrInfo.addr.vlanId = 0U; + EnetUtils_copyMacAddr(&polInArgs.policerMatch.dstMacAddrInfo.addr.addr[0], &dstMacAddr[0]); + + polInArgs.aleEntryMask = CPSW_ALE_POLICER_MATCH_PORT; + + ENET_IOCTL_SET_IN_ARGS(&prms, &polInArgs); + + status = Enet_ioctl(hEnet, gEthAppObj.coreId, CPSW_ALE_IOCTL_DEL_POLICER, &prms); + if (status != ENET_SOK) + { + appLogPrintf("Failed to delete PORT2 | MACDST policer: %d\n", status); + } + + /* Check if any policer entry is available with DSTMAC entry*/ + memset(&policerMatch, 0, sizeof(policerMatch)); + + policerMatch.policerMatchEnMask = CPSW_ALE_POLICER_MATCH_MACDST; + policerMatch.dstMacAddrInfo.portNum = CPSW_ALE_HOST_PORT_NUM; + policerMatch.dstMacAddrInfo.addr.vlanId = 0U; + EnetUtils_copyMacAddr(&policerMatch.dstMacAddrInfo.addr.addr[0], &dstMacAddr[0]); + + ENET_IOCTL_SET_INOUT_ARGS(&prms, &policerMatch, &polOutArgs); + + status = Enet_ioctl(hEnet, gEthAppObj.coreId, CPSW_ALE_IOCTL_GET_POLICER, &prms); + + /* Delete DSTMAC entry when no policer dependes on MAC entry*/ + if(status != ENET_SOK) + { + CpswAle_MacAddrInfo removeInArgs; + EnetUtils_copyMacAddr(&removeInArgs.addr[0U], &dstMacAddr[0U]); + removeInArgs.vlanId = 0; + + ENET_IOCTL_SET_IN_ARGS(&prms, &removeInArgs); + status = Enet_ioctl(hEnet, gEthAppObj.coreId, CPSW_ALE_IOCTL_REMOVE_ADDR, &prms); + if (status != ENET_SOK) + { + appLogPrintf("Failed to remove ucast entry: %d\n", status); + } + } + else + { + appLogPrintf("Found policer depends on DST MAC entry, keeping entry: %d\n", status); + } +} + +static int32_t EthApp_addRemoteCoreStaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId) +{ + int32_t status = ENET_SOK; + + switch (coreId) + { + case IPC_MPU1_0: + appLogPrintf("Add static config for mpu1_0\n"); + status = EthApp_addMpu10StaticCfg(hEnet, coreId, flowId); + break; + + default: + break; + } + + return status; +} + +static void EthApp_delRemoteCoreStaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId) +{ + switch (coreId) + { + case IPC_MPU1_0: + appLogPrintf("Delete static config for mpu1_0\n"); + EthApp_delMpu10StaticCfg(hEnet, coreId, flowId); + break; + + default: + break; + } +} + static int32_t EthApp_initRemoteServices(void) { int32_t status; diff --git a/ethfw/ethfw/ethfw.h b/ethfw/ethfw/ethfw.h index 3efe2ede..144794d6 100644 --- a/ethfw/ethfw/ethfw.h +++ b/ethfw/ethfw/ethfw.h @@ -260,6 +260,35 @@ typedef int32_t (*EthFw_setPortCfg)(Enet_MacPort macPort, EnetPhy_Cfg *phyCfg, EnetMacPort_LinkCfg *linkCfg); +/*! + * \brief Add static configuration. + * + * Add static configuration that is applicable only to specific remote cores. + * + * \param hEnet Handle to Enet LLD + * \param coreId Remote core's IPC core id + * \param flowId Remote core's flow id + * + * \return 0 if no error. Negative value otherwise. + */ +typedef int32_t (*EthFw_addStaticCfg)(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId); + +/*! + * \brief Delete static configuration. + * + * Delete static configuration that is applicable only to specific remote cores. + * + * \param hEnet Handle to Enet LLD + * \param coreId Remote core's IPC core id + * \param flowId Remote core's flow id + */ +typedef void (*EthFw_delStaticCfg)(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId); + + /*! * \brief Ethernet Firmware configuration * @@ -307,6 +336,13 @@ typedef struct EthFw_Config_s /*! Callback function for application to set port link parameters * (MII, PHY, speed, duplexity, etc) */ EthFw_setPortCfg setPortCfg; + + /* Add static configuration that is applicable only to specific remote cores */ + EthFw_addStaticCfg addStaticCfg; + + /* Delete static configuration that is applicable only to specific remote cores */ + EthFw_delStaticCfg delStaticCfg; + } EthFw_Config; /*! diff --git a/ethfw/ethfw/src/ethfw.c b/ethfw/ethfw/src/ethfw.c index 3aa264ed..d2111a55 100644 --- a/ethfw/ethfw/src/ethfw.c +++ b/ethfw/ethfw/src/ethfw.c @@ -227,6 +227,13 @@ typedef struct EthFw_Obj_s /*! Callback function for application to set port link parameters */ EthFw_setPortCfg setPortCfg; + + /* Add static configuration that is applicable only to specific remote cores */ + EthFw_addStaticCfg addStaticCfg; + + /* Delete static configuration that is applicable only to specific remote cores */ + EthFw_delStaticCfg delStaticCfg; + } EthFw_Obj; /* ========================================================================== */ @@ -812,6 +819,10 @@ void EthFw_initConfigParams(Enet_Type enetType, memset(config, 0, sizeof(*config)); + /* Initialize Static config function pointers */ + config->addStaticCfg = NULL; + config->delStaticCfg = NULL; + /* MAC port ownership */ config->ports = NULL; config->numPorts = 0U; @@ -874,6 +885,10 @@ EthFw_Handle EthFw_init(Enet_Type enetType, memset(&gEthFwObj, 0, sizeof(gEthFwObj)); + /* Save static config function pointers */ + gEthFwObj.addStaticCfg = config->addStaticCfg; + gEthFwObj.delStaticCfg = config->delStaticCfg; + /* Save config parameters */ gEthFwObj.cpswCfg = config->cpswCfg; @@ -1083,6 +1098,10 @@ int32_t EthFw_initRemoteConfig(EthFw_Handle hEthFw) cfg.dfltVlanIdMacOnlyPorts = gEthFwObj.dfltVlanIdMacOnlyPorts; cfg.dfltVlanIdSwitchPorts = gEthFwObj.dfltVlanIdSwitchPorts; + /* Static configuration callbacks */ + cfg.addStaticCfg = gEthFwObj.addStaticCfg; + cfg.delStaticCfg = gEthFwObj.delStaticCfg; + status = CpswProxyServer_init(&cfg); if (status != ENET_SOK) { diff --git a/ethfw/ethremotecfg/server/include/cpsw_proxy_server.h b/ethfw/ethremotecfg/server/include/cpsw_proxy_server.h index cc220666..ac0605fc 100644 --- a/ethfw/ethremotecfg/server/include/cpsw_proxy_server.h +++ b/ethfw/ethremotecfg/server/include/cpsw_proxy_server.h @@ -291,6 +291,34 @@ typedef struct CpswProxyServer_RsvdMcastCfg_s uint32_t numMacAddr; } CpswProxyServer_RsvdMcastCfg; +/*! + * \brief Add static configuration. + * + * Add static configuration that is applicable only to specific remote cores. + * + * \param hEnet Handle to Enet LLD + * \param coreId Remote core's IPC core id + * \param flowId Remote core's flow id + * + * \return 0 if no error. Negative value otherwise. + */ +typedef int32_t (*CpswProxyServer_addStaticCfg)(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId); + +/*! + * \brief Delete static configuration. + * + * Delete static configuration that is applicable only to specific remote cores. + * + * \param hEnet Handle to Enet LLD + * \param coreId Remote core's IPC core id + * \param flowId Remote core's flow id + */ +typedef void (*CpswProxyServer_delStaticCfg)(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId); + /*! * \brief Cpsw Proxy Server Remote Configuration structure * @@ -349,6 +377,13 @@ typedef struct CpswProxyServer_Config_s /*! Reserved multicast configuration */ CpswProxyServer_RsvdMcastCfg rsvdMcastCfg; + + /* Add static configuration that is applicable only to specific remote cores */ + CpswProxyServer_addStaticCfg addStaticCfg; + + /* Delete static configuration that is applicable only to specific remote cores */ + CpswProxyServer_delStaticCfg delStaticCfg; + } CpswProxyServer_Config_t; /*! diff --git a/ethfw/ethremotecfg/server/src/cpsw_proxy_server.c b/ethfw/ethremotecfg/server/src/cpsw_proxy_server.c index 341c4990..2346573c 100644 --- a/ethfw/ethremotecfg/server/src/cpsw_proxy_server.c +++ b/ethfw/ethremotecfg/server/src/cpsw_proxy_server.c @@ -194,6 +194,10 @@ typedef struct CpswProxyServer_Obj_s CpswProxyServer_SharedMcastTable sharedMcastTbl; CpswProxyServer_FilterAddMacSharedCb filterAddMacSharedCb; CpswProxyServer_FilterDelMacSharedCb filterDelMacSharedCb; + /* Add static configuration that is applicable only to specific remote cores */ + CpswProxyServer_addStaticCfg addStaticCfg; + /* Delete static configuration that is applicable only to specific remote cores */ + CpswProxyServer_delStaticCfg delStaticCfg; uint32_t alePortMask; uint32_t aleMacOnlyPortMask; uint16_t dfltVlanIdMacOnlyPorts; @@ -751,6 +755,17 @@ static int32_t CpswProxyServer_registerMacHandlerCb(EthRemoteCfg_VirtPort virtPo { appLogPrintf("EnetAppUtils_regDstMacRxFlow() failed CPSW_ALE_IOCTL_SET_POLICER: %d\n", status); } + if (ENET_SOK == status) + { + if (hProxyServer->addStaticCfg != NULL) + { + status = hProxyServer->addStaticCfg(hEnet, host_id, flow_idx_offset); + if (ENET_SOK != status) + { + appLogPrintf("Failed to add static config for coreId=%u: %d\n", host_id, status); + } + } + } } else { @@ -773,12 +788,15 @@ static int32_t CpswProxyServer_unregisterMacHandlerCb(EthRemoteCfg_VirtPort virt u8 *mac_address, uint32_t flow_idx) { + CpswProxyServer_Obj *hProxyServer; Enet_Handle hEnet = (Enet_Handle)((uintptr_t)handle); Enet_MacPort macPort = EthRemoteCfg_getMacPort(virtPort); bool isSwitchPort = EthRemoteCfg_isSwitchPort(virtPort); uint32_t start_flow_idx, flow_idx_offset; int32_t status; + hProxyServer = CpswProxyServer_getHandle(); + CpswProxyServer_validateHandle(hEnet); EnetAppUtils_absFlowIdx2FlowIdxOffset(hEnet, host_id, flow_idx, &start_flow_idx, &flow_idx_offset); appLogPrintf("Function:%s,HostId:%u,Handle:%p,CoreKey:%x, MacAddress:%x:%x:%x:%x:%x:%x, FlowIdx:%u, FlowIdOffset:%u\n", @@ -802,6 +820,13 @@ static int32_t CpswProxyServer_unregisterMacHandlerCb(EthRemoteCfg_VirtPort virt { appLogPrintf("Failed EnetAppUtils_unregDstMacRxFlow: %d\n", status); } + if (ENET_SOK == status) + { + if (hProxyServer->delStaticCfg != NULL) + { + hProxyServer->delStaticCfg(hEnet, host_id, flow_idx_offset); + } + } } else { @@ -2428,6 +2453,9 @@ int32_t CpswProxyServer_init(CpswProxyServer_Config_t *cfg) appLogPrintf("CpswProxyServer: initialization %s (core: mcu2_0)\r\n", (status == CPSWPROXYSERVER_SOK) ? "completed" : "failed"); + hProxyServer->addStaticCfg = cfg->addStaticCfg; + hProxyServer->delStaticCfg = cfg->delStaticCfg; + return status; } -- 2.17.1