📄 ixethdbevents.c
字号:
/** * @file IxEthDBEvents.c * * @brief Implementation of the event processor component * * @par * IXP400 SW Release version 2.1 * * -- Copyright Notice -- * * @par * Copyright (c) 2001-2005, Intel Corporation. * All rights reserved. * * @par * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the Intel Corporation nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * * @par * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * @par * -- End of Copyright Notice -- */#include <IxNpeMh.h>#include <IxFeatureCtrl.h>#include "IxEthDB_p.h"/* forward prototype declarations */IX_ETH_DB_PUBLIC void ixEthDBEventProcessorLoop(void *); IX_ETH_DB_PUBLIC void ixEthDBNPEEventCallback(IxNpeMhNpeId npeID, IxNpeMhMessage msg);IX_ETH_DB_PRIVATE void ixEthDBProcessEvent(PortEvent *local_event, IxEthDBPortMap triggerPorts);IX_ETH_DB_PRIVATE IxEthDBStatus ixEthDBTriggerPortUpdate(UINT32 eventType, IxEthDBMacAddr *macAddr, IxEthDBPortId portID, BOOL staticEntry);IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBStartLearningFunction(void);IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBStopLearningFunction(void);/* data */IX_ETH_DB_PRIVATE IxOsalSemaphore eventQueueSemaphore;IX_ETH_DB_PRIVATE PortEventQueue eventQueue;IX_ETH_DB_PRIVATE IxOsalMutex eventQueueLock;IX_ETH_DB_PRIVATE IxOsalMutex portUpdateLock;IX_ETH_DB_PRIVATE BOOL ixEthDBLearningShutdown = FALSE;IX_ETH_DB_PRIVATE BOOL ixEthDBEventProcessorRunning = FALSE;/* imported data */extern HashTable dbHashtable;/** * @brief initializes the event processor * * Initializes the event processor queue and processing thread. * Called from ixEthDBInit() DB-subcomponent master init function. * * @warning do not call directly * * @retval IX_ETH_DB_SUCCESS initialization was successful * @retval IX_ETH_DB_FAIL initialization failed (OSAL or mutex init failure) * * @internal */IX_ETH_DB_PUBLICIxEthDBStatus ixEthDBEventProcessorInit(void){ if (ixOsalMutexInit(&portUpdateLock) != IX_SUCCESS) { return IX_ETH_DB_FAIL; } if (ixOsalMutexInit(&eventQueueLock) != IX_SUCCESS) { return IX_ETH_DB_FAIL; } if (IX_FEATURE_CTRL_SWCONFIG_ENABLED == ixFeatureCtrlSwConfigurationCheck (IX_FEATURECTRL_ETH_LEARNING)) { /* start processor loop thread */ if (ixEthDBStartLearningFunction() != IX_ETH_DB_SUCCESS) { return IX_ETH_DB_FAIL; } } return IX_ETH_DB_SUCCESS;}/** * @brief initializes the event queue and the event processor * * This function is called by the component initialization * function, ixEthDBInit(). * * @warning do not call directly * * @return IX_ETH_DB_SUCCESS if the operation completed * successfully or IX_ETH_DB_FAIL otherwise * * @internal */IX_ETH_DB_PUBLICIxEthDBStatus ixEthDBStartLearningFunction(void){ IxOsalThread eventProcessorThread; IxOsalThreadAttr threadAttr; threadAttr.name = "EthDB event thread"; threadAttr.stackSize = 32 * 1024; /* 32kbytes */ threadAttr.priority = 128; /* reset event queue */ ixOsalMutexLock(&eventQueueLock, IX_OSAL_WAIT_FOREVER); RESET_QUEUE(&eventQueue); ixOsalMutexUnlock(&eventQueueLock); /* init event queue semaphore */ if (ixOsalSemaphoreInit(&eventQueueSemaphore, 0) != IX_SUCCESS) { return IX_ETH_DB_FAIL; } ixEthDBLearningShutdown = FALSE; /* create processor loop thread */ if (ixOsalThreadCreate(&eventProcessorThread, &threadAttr, ixEthDBEventProcessorLoop, NULL) != IX_SUCCESS) { return IX_ETH_DB_FAIL; } /* start event processor */ ixOsalThreadStart(&eventProcessorThread); return IX_ETH_DB_SUCCESS;}/** * @brief stops the event processor * * Stops the event processor and frees the event queue semaphore * Called by the component de-initialization function, ixEthDBUnload() * * @warning do not call directly * * @return IX_ETH_DB_SUCCESS if the operation completed * successfully or IX_ETH_DB_FAIL otherwise; * * @internal */IX_ETH_DB_PUBLICIxEthDBStatus ixEthDBStopLearningFunction(void){ if (IX_FEATURE_CTRL_SWCONFIG_ENABLED == ixFeatureCtrlSwConfigurationCheck (IX_FEATURECTRL_ETH_LEARNING)) { ixEthDBLearningShutdown = TRUE; /* wake up event processing loop to actually process the shutdown event */ ixOsalSemaphorePost(&eventQueueSemaphore); if (ixOsalSemaphoreDestroy(&eventQueueSemaphore) != IX_SUCCESS) { return IX_ETH_DB_FAIL; } return IX_ETH_DB_SUCCESS; } return IX_ETH_DB_FEATURE_UNAVAILABLE;}/** * @brief default NPE event processing callback * * @param npeID ID of the NPE that generated the event * @param msg NPE message (encapsulated event) * * Creates an event object on the Ethernet event processor queue * and signals the new event by incrementing the event queue semaphore. * Events are processed by @ref ixEthDBEventProcessorLoop() which runs * at user level. * * @see ixEthDBEventProcessorLoop() * * @warning do not call directly * * @internal */IX_ETH_DB_PUBLICvoid ixEthDBNPEEventCallback(IxNpeMhNpeId npeID, IxNpeMhMessage msg){ PortEvent *local_event; IX_ETH_DB_IRQ_EVENTS_TRACE("DB: (Events) new event received by processor callback from port %d, id 0x%X\n", IX_ETHNPE_NODE_AND_PORT_TO_PHYSICAL_ID(npeID,0), NPE_MSG_ID(msg), 0, 0, 0, 0); if (CAN_ENQUEUE(&eventQueue)) { TEST_FIXTURE_LOCK_EVENT_QUEUE; local_event = QUEUE_HEAD(&eventQueue); /* create event structure on queue */ local_event->eventType = NPE_MSG_ID(msg); local_event->portID = IX_ETHNPE_NODE_AND_PORT_TO_PHYSICAL_ID(npeID,0); /* update queue */ PUSH_UPDATE_QUEUE(&eventQueue); TEST_FIXTURE_UNLOCK_EVENT_QUEUE; IX_ETH_DB_IRQ_EVENTS_TRACE("DB: (Events) Waking up main processor loop...\n", 0, 0, 0, 0, 0, 0); /* increment event queue semaphore */ ixOsalSemaphorePost(&eventQueueSemaphore); } else { IX_ETH_DB_IRQ_EVENTS_TRACE("DB: (Events) Warning: could not enqueue event (overflow)\n", 0, 0, 0, 0, 0, 0); }}/** * @brief Ethernet event processor loop * * Extracts at most EVENT_PROCESSING_LIMIT batches of events and * sends them for processing to @ref ixEthDBProcessEvent(). * Triggers port updates which normally follow learning events. * * @warning do not call directly, executes in separate thread * * @internal */IX_ETH_DB_PUBLICvoid ixEthDBEventProcessorLoop(void *unused1){ IxEthDBPortMap triggerPorts; IxEthDBPortId portIndex; ixEthDBEventProcessorRunning = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -