📄 ixethacccodeletmain.c
字号:
/** * @file IxEthAccCodeletMain.c * * @date 22 April 2004 * * @brief This file contains the implementation of the Ethernet Access Codelet. * * Descriptions of the functions used in this codelet is contained in * IxEthAccCodelet_p.h * * IxEthAccCodelet API Functions: * ixEthAccCodeletInit() * ixEthAccCodeletUninit() * ixEthAccCodeletRxSink() * ixEthAccCodeletSwLoopback() * ixEthAccCodeletTxGenRxSinkLoopback() * ixEthAccCodeletPhyLoopback() * ixEthAccCodeletBridge() * ixEthAccCodeletBridgeQoS() * ixEthAccCodeletBridgeFirewall() * ixEthAccCodeletDBLearning() * ixEthAccCodeletSwBridgeWiFi() * ixEthAccCodeletShow() * * * @par * IXP400 SW Release version 2.3 * * -- 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 --*//* * Put the system defined include files required. */#ifdef __vxworks#include <end.h> /* END drivers */#include <endLib.h> /* END drivers */#endif/* * Put the user defined include files required. */#include "IxOsal.h"#include "IxQMgr.h"#include "IxNpeDl.h"#include "IxNpeMh.h"#include "IxFeatureCtrl.h"#include "IxEthDB.h"#include "IxEthAccCodelet.h"/* Includes all variables globally used in the codelet. * * EXTERN is defined before IxEthAccCodeletGlobal_p.h is included: * Global variables are defined for this file and set as extern * in the other files (default). As a result, only one instance of * the variable is created in this file and there is no declaration * duplication. */#define EXTERN#include "IxEthAccCodelet_p.h"#ifdef __wince#include "pkfuncs.h"#include "oalintr.h"#endif/* correct rounding for the operation A * B / C * without losing accuracy . This is based on the * approximation float(x)/float(y)+0.5 ~= (x + y/2)/y */#ifdef _DIAB_TOOLUINT64 __inline__ IX_ETHACC_CODELET_MULDIV(UINT64 A, UINT64 B, UINT64 C){ return ((((A)*(B)) + (( (INT64) C)+1)/2) / (C));}#else #define IX_ETHACC_CODELET_MULDIV(A,B,C) ((((A)*(B)) + ((C)+1)/2) / (C))#endif/* * @def IX_ETHACC_CODELET_XCLOCK_FREQ * * 2133 is the xclock frequency (timer block) * * @note: The conversion from APB bus cycles to microseconds * is approximated by (cycles/66). The exact value * is (cycles*32/2133) */#define IX_ETHACC_CODELET_XCLOCK_FREQ 2133/* * @def IX_ETHACC_CODELET_PCLOCK_DIVIDER * * 32 is the pclock divider value (timer block) * * @note: The conversion from APB bus cycles to microseconds * is approximated by (cycles/66). The exact value * is (cycles*32/2133) */#define IX_ETHACC_CODELET_PCLOCK_DIVIDER 32/* * @def IX_ETHACC_CODELET_USEC_PER_SEC * * Number of microsecond per second */#define IX_ETHACC_CODELET_USEC_PER_SEC 1000000/** * ETH_NPE_IMAGEIDS */UINT32 ETH_NPEA_IMAGEID = IX_NPEDL_NPEIMAGE_NPEA_ETH_MACFILTERLEARN_HSSCHAN_COEXIST;UINT32 ETH_NPEB_IMAGEID = IX_NPEDL_NPEIMAGE_NPEB_ETH_LEARN_FILTER_SPAN_MASK_FIREWALL_VLAN_QOS_EXTMIB;UINT32 ETH_NPEC_IMAGEID = IX_NPEDL_NPEIMAGE_NPEC_ETH_LEARN_FILTER_SPAN_MASK_FIREWALL_VLAN_QOS_EXTMIB;/* * Variable declarations global to this file only. */PRIVATE IxOsalMutex ixEthAccCodeletStatsPollTaskRunning;PRIVATE volatile BOOL ixEthAccCodeletTrafficPollEnabled;PRIVATE volatile BOOL ixEthAccCodeletStatsPollTaskStop;PRIVATE BOOL ixEthAccCodeletHardwareExists[IX_ETHACC_CODELET_MAX_PORT];PRIVATE BOOL ixEthAccCodeletInitialised = FALSE;/* * Static function prototypes. */PRIVATE void ixEthAccCodeletStatsPollTask(void* arg, void** ptrRetObj);PRIVATE IX_STATUS ixEthAccCodeletLoop(void);/* * Function definition: ixEthAccCodeletMain() * * See header file for documentation. */PUBLIC IX_STATUSixEthAccCodeletMain(IxEthAccCodeletOperation operationType, IxEthAccPortId inPort, IxEthAccPortId outPort){ if( inPort >= IX_ETHACC_CODELET_MAX_PORT || outPort >= IX_ETHACC_CODELET_MAX_PORT) { printf("ERROR: Invalid input. Please choose again...\n "); printf("in/out port IDs must be in the range 0 to %d\n",IX_ETHACC_CODELET_MAX_PORT - 1); return IX_FAIL ; } if (IX_SUCCESS != ixEthAccCodeletInit(operationType,inPort,outPort)) { printf("ixEthAccCodeletInit() fails ! Exit \n") ; return IX_FAIL ; } switch (operationType) { case IX_ETHACC_CODELET_RX_SINK : if (IX_SUCCESS != ixEthAccCodeletRxSink()) { printf("ixEthAccCodeletRxSink() fails ! Exit \n") ; return IX_FAIL ; } /* Dump Stats */ ixEthAccCodeletShow(); break ; case IX_ETHACC_CODELET_SW_LOOPBACK : if (IX_SUCCESS != ixEthAccCodeletSwLoopback()) { printf("ixEthAccCodeletSwLoopback() fails ! Exit \n") ; return IX_FAIL ; } /* Dump Stats */ ixEthAccCodeletShow(); break ; case IX_ETHACC_CODELET_TXGEN_RXSINK : if (IX_SUCCESS != ixEthAccCodeletTxGenRxSinkLoopback(inPort,outPort)) { printf("ixEthAccCodeletTxGenRxSinkLoopback() fails ! Exit \n") ; return IX_FAIL ; } /* Dump Stats */ ixEthAccCodeletShow(); break ; case IX_ETHACC_CODELET_PHY_LOOPBACK : if(IX_SUCCESS != ixEthAccCodeletPhyLoopback()) { printf("ixEthAccCodeletPhyLoopback() fails ! Exit \n") ; return IX_FAIL ; } /* Dump Stats */ ixEthAccCodeletShow(); break; case IX_ETHACC_CODELET_BRIDGE : if(IX_SUCCESS != ixEthAccCodeletSwBridge(inPort,outPort)) { printf("ixEthAccCodeletBridge() fails ! Exit \n") ; return IX_FAIL ; } /* Dump Stats */ ixEthAccCodeletShow(); break; case IX_ETHACC_CODELET_BRIDGE_QOS : if(IX_SUCCESS != ixEthAccCodeletSwBridgeQoS(inPort,outPort)) { printf("ixEthAccCodeletBridgeQoS() fails ! Exit \n") ; return IX_FAIL ; } /* Dump Stats */ ixEthAccCodeletShow(); break; case IX_ETHACC_CODELET_BRIDGE_FIREWALL : if(IX_SUCCESS != ixEthAccCodeletSwBridgeFirewall(inPort,outPort)) { printf("ixEthAccCodeletBridgeFirewall() fails ! Exit \n") ; return IX_FAIL ; } /* Dump Stats */ ixEthAccCodeletShow(); break; case IX_ETHACC_CODELET_ETH_LEARNING : if (IX_SUCCESS != ixEthAccCodeletDBLearning()) { printf("ixEthAccCodeletDBLearning() fails ! Exit \n") ; return IX_FAIL ; } /* Dump Stats */ ixEthAccCodeletShow(); break ; case IX_ETHACC_CODELET_BRIDGE_WIFI : if (IX_SUCCESS != ixEthAccCodeletSwBridgeWiFi(inPort,outPort)) { printf("ixEthAccCodeletSwBridgeWiFi() fails ! Exit \n"); return IX_FAIL; } /* Dump Stats */ ixEthAccCodeletShow(); break; default: printf("ERROR: Invalid input. Please choose again...\n "); printf(">ixEthAccCodeletMain(operationType,inPort,outPort)\n"); printf("Where operationType : %d = Rx Sink\n", IX_ETHACC_CODELET_RX_SINK); printf(" %d = Sw Loopback\n", IX_ETHACC_CODELET_SW_LOOPBACK); printf(" %d = Tx Gen/Rx Sink Loopback\n", IX_ETHACC_CODELET_TXGEN_RXSINK); printf(" %d = Perform PHY loopback on the same port\n",IX_ETHACC_CODELET_PHY_LOOPBACK); printf(" %d = Bridge\n",IX_ETHACC_CODELET_BRIDGE); printf(" %d = Bridge + QoS\n",IX_ETHACC_CODELET_BRIDGE_QOS); printf(" %d = Bridge + Firewall\n",IX_ETHACC_CODELET_BRIDGE_FIREWALL); printf(" %d = Eth DB Learning\n", IX_ETHACC_CODELET_ETH_LEARNING); printf(" %d = Bridge + WiFi header conversion\n", IX_ETHACC_CODELET_BRIDGE_WIFI); return IX_FAIL ; } return IX_SUCCESS ;}/* * Function definition: ixEthAccCodeletInit() * * See header file for documentation. */IX_STATUS ixEthAccCodeletInit(IxEthAccCodeletOperation operationType, IxEthAccPortId inPort, IxEthAccPortId outPort){ IxEthAccPortId portId; IxOsalThread statsPollThread; IxOsalThreadAttr threadAttr; threadAttr.name = "Codelet Stats"; threadAttr.stackSize = 32 * 1024; /* 32kbytes */ threadAttr.priority = 128;#ifdef __ixp46X /* Set the expansion bus fuse register to enable MUX for NPEA MII */ { UINT32 expbusCtrlReg; expbusCtrlReg = ixFeatureCtrlRead (); expbusCtrlReg |= ((unsigned long)1<<8); ixFeatureCtrlWrite (expbusCtrlReg); }#endif /* check the component is already initialized */ if(ixEthAccCodeletInitialised) { printf("CodeletMain: Ethernet codelet already initialised\n"); return(IX_SUCCESS); }#ifdef __vxworks /* When the ixe drivers are running, the codelets * cannot run. */ for (portId = 0; portId < IX_ETHACC_CODELET_MAX_PORT; portId++) { if (endFindByName ("ixe", portId) != NULL) { printf("CodeletMain: FAIL: Driver ixe%d detected\n",portId); return IX_FAIL; } }#endif /* Initialize NPE IMAGE ID here again to prevent confusion in multiple * ixEthAccCodeletMain() calls with different operationType. */ ETH_NPEA_IMAGEID = IX_NPEDL_NPEIMAGE_NPEA_ETH_MACFILTERLEARN_HSSCHAN_COEXIST; ETH_NPEB_IMAGEID = IX_NPEDL_NPEIMAGE_NPEB_ETH_LEARN_FILTER_SPAN_MASK_FIREWALL_VLAN_QOS_EXTMIB; ETH_NPEC_IMAGEID = IX_NPEDL_NPEIMAGE_NPEC_ETH_LEARN_FILTER_SPAN_MASK_FIREWALL_VLAN_QOS_EXTMIB; /* Create mutexes for thread control */ ixEthAccCodeletStatsPollTaskStop = TRUE; ixOsalMutexInit (&ixEthAccCodeletStatsPollTaskRunning); /* Initialise MBUF pool */ if(ixEthAccCodeletMemPoolInit() != IX_SUCCESS) { printf("CodeletMain: Error initialising mBuf pool\n"); return (IX_FAIL); } /* Check Silicon stepping */ printf("Checking Silicon stepping...\n"); if (ixFeatureCtrlDeviceRead() == IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X) { if ((ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK) == IX_FEATURE_CTRL_SILICON_TYPE_B0) { /* * If it is B0 Silicon, we only enable port when its corresponding * Eth Coprocessor is available. */ if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) == IX_FEATURE_CTRL_COMPONENT_ENABLED) { ixEthAccCodeletHardwareExists[IX_ETH_PORT_1] = TRUE; } if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH1) == IX_FEATURE_CTRL_COMPONENT_ENABLED) { ixEthAccCodeletHardwareExists[IX_ETH_PORT_2] = TRUE; } } else if ((ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK) == IX_FEATURE_CTRL_SILICON_TYPE_A0) { /* * If it is A0 Silicon, we enable both as both Eth Coprocessors * are available. */ ixEthAccCodeletHardwareExists[IX_ETH_PORT_1] = TRUE; ixEthAccCodeletHardwareExists[IX_ETH_PORT_2] = TRUE; } else { printf("CodeletMain: Error. Operation for other silicon stepping is undefined!.\n"); return (IX_FAIL); } } else if (ixFeatureCtrlDeviceRead() == IX_FEATURE_CTRL_DEVICE_TYPE_IXP46X) { ixEthAccCodeletHardwareExists[IX_ETH_PORT_1] = TRUE; ixEthAccCodeletHardwareExists[IX_ETH_PORT_2] = TRUE;#ifdef __ixp46X ixEthAccCodeletHardwareExists[IX_ETH_PORT_3] = TRUE;#endif } /*********************************************************************** *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -