From ab6202a076f88e0990e4e782ca8b9b53dfc5e423 Mon Sep 17 00:00:00 2001 From: Sudheer Doredla Date: Wed, 4 Jan 2023 17:30:17 +0530 Subject: [PATCH] Vlan Configuration Signed-off-by: Sudheer Doredla --- .../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 @@ * 1 x MAC address for mcu2_1 virtual switch port (AUTOSAR) */ #define ETHAPP_MAC_ADDR_POOL_SIZE (6U) +#define TEST_VID_A72 (100U) + /* Define A72_QNX_OS if A72 is running Qnx. Qnx doesn't load resource table. */ /* #define A72_QNX_OS */ @@ -265,6 +267,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); @@ -854,6 +864,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) { @@ -877,6 +891,172 @@ static int32_t EthApp_initEthFw(void) return status; } +static int32_t EthApp_addMpu10StaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId) +{ + CpswAle_SetPolicerEntryInArgs polInArgs; + CpswAle_SetPolicerEntryOutArgs polOutArgs; + Enet_IoctlPrms prms; + int32_t status; + + CpswAle_VlanEntryInfo inArgs; + uint32_t outArgs; + + /* Add VLAN entry */ + memset(&inArgs, 0U, sizeof (CpswAle_VlanEntryInfo)); + inArgs.vlanIdInfo.vlanId = TEST_VID_A72; + inArgs.vlanIdInfo.tagType = ENET_VLAN_TAG_TYPE_INNER; + inArgs.vlanMemberList = (1 << CPSW_ALE_MACPORT_TO_ALEPORT(ENET_MAC_PORT_3)) | CPSW_ALE_HOST_PORT_MASK; + inArgs.unregMcastFloodMask = (1 << CPSW_ALE_MACPORT_TO_ALEPORT(ENET_MAC_PORT_3)) | CPSW_ALE_HOST_PORT_MASK; + inArgs.regMcastFloodMask = (1 << CPSW_ALE_MACPORT_TO_ALEPORT(ENET_MAC_PORT_3)) | CPSW_ALE_HOST_PORT_MASK; + inArgs.forceUntaggedEgressMask = 0; + inArgs.noLearnMask = 0U; + inArgs.vidIngressCheck = true; + inArgs.limitIPNxtHdr = false; + inArgs.disallowIPFrag = false; + + ENET_IOCTL_SET_INOUT_ARGS(&prms, &inArgs, &outArgs); + + status = Enet_ioctl(hEnet, gEthAppObj.coreId, CPSW_ALE_IOCTL_ADD_VLAN, &prms); + if (status != ENET_SOK) + { + appLogPrintf("%s() failed ADD_VLAN ioctl failed: %d\n", __func__, status); + } + + polInArgs.policerMatch.policerMatchEnMask = 0U; + + /* Add policer entry for port 1 and dstmac */ + polInArgs.policerMatch.policerMatchEnMask = CPSW_ALE_POLICER_MATCH_PORT; + polInArgs.policerMatch.portNum = CPSW_ALE_MACPORT_TO_ALEPORT(ENET_MAC_PORT_3); + polInArgs.policerMatch.portIsTrunk = false; + + polInArgs.policerMatch.policerMatchEnMask |= CPSW_ALE_POLICER_MATCH_IVLAN; + polInArgs.policerMatch.ivlanId = TEST_VID_A72; + + 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 PORT3 | VLAN policer: %d\n", status); + } + return status; +} + +static void EthApp_delMpu10StaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId) +{ + CpswAle_DelPolicerEntryInArgs polInArgs; + Enet_IoctlPrms prms; + int32_t status; + + CpswAle_PolicerEntryOutArgs polOutArgs; + CpswAle_PolicerMatchParams policerMatch; + + CpswAle_VlanEntryInfo inArgs; + + + polInArgs.policerMatch.policerMatchEnMask = 0U; + + /* Delete policer entry for port 1 and dstmac */ + polInArgs.policerMatch.policerMatchEnMask = CPSW_ALE_POLICER_MATCH_PORT; + polInArgs.policerMatch.portNum = CPSW_ALE_MACPORT_TO_ALEPORT(ENET_MAC_PORT_3); + polInArgs.policerMatch.portIsTrunk = false; + + polInArgs.policerMatch.policerMatchEnMask |= CPSW_ALE_POLICER_MATCH_IVLAN; + polInArgs.policerMatch.ivlanId = TEST_VID_A72; + + polInArgs.aleEntryMask = CPSW_ALE_POLICER_MATCH_PORT; + polInArgs.policerMatch.portNum = CPSW_ALE_MACPORT_TO_ALEPORT(ENET_MAC_PORT_3); + 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 PORT3 | VLAN policer: %d\n", status); + } + + /* Check if any policer entry is available with VLAN entry*/ + memset(&policerMatch, 0, sizeof(policerMatch)); + + policerMatch.policerMatchEnMask = CPSW_ALE_POLICER_MATCH_PORT; + policerMatch.portNum = CPSW_ALE_MACPORT_TO_ALEPORT(ENET_MAC_PORT_3); + policerMatch.portIsTrunk = false; + + policerMatch.policerMatchEnMask |= CPSW_ALE_POLICER_MATCH_IVLAN; + policerMatch.ivlanId = TEST_VID_A72; + + ENET_IOCTL_SET_INOUT_ARGS(&prms, &policerMatch, &polOutArgs); + + status = Enet_ioctl(hEnet, gEthAppObj.coreId, CPSW_ALE_IOCTL_GET_POLICER, &prms); + + /* Delete VLAN entry when no policer dependes on VLAN entry*/ + if(status != ENET_SOK) + { + memset(&inArgs, 0U, sizeof (CpswAle_VlanEntryInfo)); + inArgs.vlanIdInfo.vlanId = TEST_VID_A72; + inArgs.vlanIdInfo.tagType = ENET_VLAN_TAG_TYPE_INNER; + + ENET_IOCTL_SET_IN_ARGS(&prms, &inArgs); + + status = Enet_ioctl(hEnet, gEthAppObj.coreId, CPSW_ALE_IOCTL_REMOVE_VLAN, &prms); + + if (status != ENET_SOK) + { + appLogPrintf("Failed to delete VLAN entry: %d\n", status); + } + } + else + { + appLogPrintf("Found policer depends on VLAN 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..af441fe1 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,14 @@ 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 72888d4a..dc27d58a 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,11 @@ 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 +886,11 @@ 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 +1100,11 @@ 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..4eabafc3 100644 --- a/ethfw/ethremotecfg/server/include/cpsw_proxy_server.h +++ b/ethfw/ethremotecfg/server/include/cpsw_proxy_server.h @@ -291,6 +291,36 @@ 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 +379,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 497c2043..76f92c6f 100644 --- a/ethfw/ethremotecfg/server/src/cpsw_proxy_server.c +++ b/ethfw/ethremotecfg/server/src/cpsw_proxy_server.c @@ -189,6 +189,14 @@ 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; @@ -758,6 +766,18 @@ static int32_t CpswProxyServer_registerMacHandlerCb(EthRemoteCfg_VirtPort virtPo flow_idx_offset); } + 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); + } + } + } + return CPSWPROXY_ENET2RPMSG_ERR(status); } @@ -768,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", @@ -808,6 +831,13 @@ static int32_t CpswProxyServer_unregisterMacHandlerCb(EthRemoteCfg_VirtPort virt start_flow_idx, flow_idx_offset); } + if (ENET_SOK == status) + { + if (hProxyServer->delStaticCfg != NULL) + { + hProxyServer->delStaticCfg(hEnet, host_id, flow_idx_offset); + } + } return CPSWPROXY_ENET2RPMSG_ERR(status); } @@ -2423,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