From 4850b72c76d1bfc1ed88b8633b9266bd32275edc Mon Sep 17 00:00:00 2001 From: Vineet Roy 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, char *sendBuff); +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); + /* ========================================================================== */ /* Extern variables */ /* ========================================================================== */ @@ -563,6 +571,11 @@ static int32_t EthApp_initEthFw(void) ethFwCfg.ports[i].portNum); } + /* Set static configuration functions */ + ethFwCfg.addStaticCfg = &EthApp_addRemoteCoreStaticCfg; + ethFwCfg.delStaticCfg = &EthApp_delRemoteCoreStaticCfg; + + /* Initialize the EthFw */ gEthAppObj.hEthFw = EthFw_init(gEthAppObj.enetType, ðFwCfg); if (gEthAppObj.hEthFw == NULL) @@ -815,3 +828,162 @@ void EthApp_traceBufCacheWb(void) } } } + + +static int32_t EthApp_addMpu10StaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId) +{ + const uint8_t mcastAddr[ENET_MAC_ADDR_LEN] = {0x01, 0x99, 0xc2, 0x00, 0x01, 0x0E}; + CpswAle_SetPolicerEntryInArgs polInArgs; + CpswAle_SetPolicerEntryOutArgs polOutArgs; + CpswAle_SetMcastEntryInArgs mcastInArgs; + Enet_IoctlPrms prms; + uint32_t entry; + int32_t 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_1); + polInArgs.policerMatch.portIsTrunk = false; + + 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], &mcastAddr[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 PORT1 | MACDST policer: %d\n", status); + } + + /* Add policer entry for port 3 and dstmac */ + if (status == ENET_SOK) + { + polInArgs.policerMatch.portNum = CPSW_ALE_MACPORT_TO_ALEPORT(ENET_MAC_PORT_3); + + 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 | MACDST policer: %d\n", status); + } + } + + /* Add multicast entry with port mask: host port, MAC port 1 and MAC port 3 */ + if (status == ENET_SOK) + { + mcastInArgs.addr.vlanId = 0U; + EnetUtils_copyMacAddr(&mcastInArgs.addr.addr[0], &mcastAddr[0]); + + mcastInArgs.info.super = false; + mcastInArgs.info.fwdState = CPSW_ALE_FWDSTLVL_FWD; + mcastInArgs.info.portMask = (CPSW_ALE_HOST_PORT_MASK | + CPSW_ALE_MACPORT_TO_PORTMASK(ENET_MAC_PORT_1) | + CPSW_ALE_MACPORT_TO_PORTMASK(ENET_MAC_PORT_3)); + mcastInArgs.info.numIgnBits = 0U; + + ENET_IOCTL_SET_INOUT_ARGS(&prms, &mcastInArgs, &entry); + + status = Enet_ioctl(hEnet, gEthAppObj.coreId, CPSW_ALE_IOCTL_ADD_MCAST, &prms); + if (status != ENET_SOK) + { + appLogPrintf("Failed to add mcast ports: %d\n", status); + } + } + + return status; +} + +static void EthApp_delMpu10StaticCfg(Enet_Handle hEnet, + uint32_t coreId, + uint32_t flowId) +{ + const uint8_t mcastAddr[ENET_MAC_ADDR_LEN] = {0x01, 0x80, 0xc2, 0x00, 0x01, 0x0E}; + CpswAle_DelPolicerEntryInArgs polInArgs; + Enet_IoctlPrms prms; + int32_t status; + + 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_1); + polInArgs.policerMatch.portIsTrunk = false; + + 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], &mcastAddr[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 PORT1 | MACDST policer: %d\n", status); + } + + /* Delete policer entry for port 3 and dstmac */ + if (status == ENET_SOK) + { + 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 | MACDST policer: %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; + } +} diff --git a/ethfw/ethfw.h b/ethfw/ethfw.h index ef4a8c9..cafab00 100644 --- a/ethfw/ethfw.h +++ b/ethfw/ethfw.h @@ -178,6 +178,35 @@ typedef struct EthFw_PortConfig_s EnetPort_VlanCfg vlanCfg; } EthFw_Port; +/*! + * \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 * @@ -195,6 +224,12 @@ typedef struct EthFw_Config_s /*! Number of MAC ports owned by EthFw, that is, the size of * EthFw_Config::ports array */ uint32_t numPorts; + + /* 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/src/ethfw.c b/ethfw/src/ethfw.c index f8eeb7e..e12e425 100644 --- a/ethfw/src/ethfw.c +++ b/ethfw/src/ethfw.c @@ -182,6 +182,12 @@ typedef struct EthFw_Obj_s /* Handle to PTP stack */ TimeSyncPtp_Handle timeSyncPtp; + /* 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; /* ========================================================================== */ @@ -268,6 +274,10 @@ void EthFw_initConfigParams(Enet_Type enetType, CpswHostPort_Cfg *hostPortCfg = &cpswCfg->hostPortCfg; EnetRm_ResCfg *resCfg = &cpswCfg->resCfg; + /* Initialize Static config function pointers */ + config->addStaticCfg = NULL; + config->delStaticCfg = NULL; + /* MAC port ownership */ config->ports = NULL; config->numPorts = 0U; @@ -306,6 +316,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; gEthFwObj.numPorts = config->numPorts; @@ -419,6 +433,10 @@ int32_t EthFw_initRemoteConfig(EthFw_Handle hEthFw) cfg.notifyServiceRemoteCoreId[0] = IPC_MPU1_0; cfg.notifyServiceRemoteCoreId[1] = IPC_MCU2_1; + /* Static configuration callbacks */ + cfg.addStaticCfg = gEthFwObj.addStaticCfg; + cfg.delStaticCfg = gEthFwObj.delStaticCfg; + status = CpswProxyServer_init(&cfg); if (status != ENET_SOK) { diff --git a/ethremotecfg/server/include/cpsw_proxy_server.h b/ethremotecfg/server/include/cpsw_proxy_server.h index c1acfa9..23098f1 100644 --- a/ethremotecfg/server/include/cpsw_proxy_server.h +++ b/ethremotecfg/server/include/cpsw_proxy_server.h @@ -162,6 +162,34 @@ typedef struct CpswProxyServer_RemoteCoreConfig_s char serverName[ETHREMOTECFG_SERVER_MAX_NAME_LEN]; } CpswProxyServer_RemoteCoreConfig; +/*! + * \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 * @@ -199,6 +227,12 @@ typedef struct CpswProxyServer_Config_s /*! Remote Core configuration */ CpswProxyServer_RemoteCoreConfig remoteCoreCfg[ETHREMOTECFG_SERVER_MAX_INSTANCES]; + + /* 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/ethremotecfg/server/src/cpsw_proxy_server.c b/ethremotecfg/server/src/cpsw_proxy_server.c index 4c01eaa..295b781 100644 --- a/ethremotecfg/server/src/cpsw_proxy_server.c +++ b/ethremotecfg/server/src/cpsw_proxy_server.c @@ -184,6 +184,12 @@ typedef struct CpswProxyServer_Obj_s SemaphoreP_Handle rdevStartSem; CpswProxyServer_EthDriverObj ethDrvObj; CpswProxyServer_NotifyServiceObj notifyServiceObj; + + /* 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_Obj; /* ========================================================================== */ @@ -592,10 +598,13 @@ static int32_t CpswProxyServer_registerMacHandlerCb(uint32_t host_id, u8 *mac_address, uint32_t flow_idx) { + CpswProxyServer_Obj *hProxyServer; int32_t status; Enet_Handle hEnet = (Enet_Handle)((uintptr_t)handle); uint32_t start_flow_idx, flow_idx_offset; + 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, FlowIdxOffset:%u\n", @@ -618,6 +627,23 @@ static int32_t CpswProxyServer_registerMacHandlerCb(uint32_t host_id, appLogPrintf("EnetAppUtils_regDstMacRxFlow() failed CPSW_ALE_IOCTL_SET_POLICER: %d\n", status); status = RPMSG_KDRV_TP_ETHSWITCH_CMDSTATUS_EFAIL; } + + 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); + } + } + } + + if (status != ENET_SOK) + { + status = RPMSG_KDRV_TP_ETHSWITCH_CMDSTATUS_EFAIL; + } else { status = RPMSG_KDRV_TP_ETHSWITCH_CMDSTATUS_OK; @@ -632,10 +658,13 @@ static int32_t CpswProxyServer_unregisterMacHandlerCb(uint32_t host_id, u8 *mac_address, uint32_t flow_idx) { + CpswProxyServer_Obj *hProxyServer; int32_t status; Enet_Handle hEnet = (Enet_Handle)((uintptr_t)handle); uint32_t start_flow_idx, flow_idx_offset; + 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", @@ -653,6 +682,19 @@ static int32_t CpswProxyServer_unregisterMacHandlerCb(uint32_t host_id, flow_idx_offset); status = EnetAppUtils_unregDstMacRxFlow(hEnet, core_key, host_id, start_flow_idx, flow_idx_offset, mac_address); + if (status != ENET_SOK) + { + appLogPrintf("Failed EnetAppUtils_unregDstMacRxFlow: %d\n", status); + } + + if (ENET_SOK == status) + { + if (hProxyServer->delStaticCfg != NULL) + { + hProxyServer->delStaticCfg(hEnet, host_id, flow_idx_offset); + } + } + if (status != ENET_SOK) { appLogPrintf("Failed EnetAppUtils_unregDstMacRxFlow: %d\n", status); @@ -1657,6 +1699,10 @@ int32_t CpswProxyServer_init(CpswProxyServer_Config_t *cfg) hProxyServer->initDone = true; appLogPrintf("Remote demo device (core : mcu2_0) .....\r\n"); + + hProxyServer->addStaticCfg = cfg->addStaticCfg; + hProxyServer->delStaticCfg = cfg->delStaticCfg; + return ENET_SOK; } -- 2.25.1