📄 ixethacccodeletswbridgeqos.c
字号:
/** * @file IxEthAccCodeletSwBridgeQoS.c * * @date 22 April 2004 * * @brief This file contains the implementation of the Ethernet Access * Codelet that implements a simple bridge between two Ethernet ports, * with VLAN tagged frames being prioritized over untagged frames * * <pre> * * The setup is as follows * * VLAN tagged network ----- first Port ---+ * | * | * Bridge on Xscale * | * untagged | * 10 Mb/s network -------- second Port ---+ * link * * * The first port is configured to accept both VLAN tagged and untagged * frames from the network. All egress non VLAN frames will be filled * with the default VLAN tag for this port. VLAN tags are stripped out * from ingress frames. * * The second port disacrds all recieved tagged frames from the network * and allows only untagged frames to enter the bridge. * * Because the second port is configured as 10Mb/s, congestion is * expected to occur when processing traffic from the first port * to the second port. * * </pre> * * @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. */#include "IxOsal.h"/* * Put the user defined include files required. */#include "IxEthAcc.h"#include "IxEthDB.h"#include "IxEthAccCodelet.h"#include "IxEthAccCodelet_p.h"/** * Range of VLAN IDs from Min to Max that will be accepted on the VLAN * enabled port */#define IX_ETHACC_CODELET_VLANID_MIN (100)#define IX_ETHACC_CODELET_VLANID_MAX (200)/* This is the maximum number of transmits allowed before the QoS bridge * begins throttling receive. Thus this value must be less than the * rx replenish pool size for one port. */#define IX_ETHACC_CODELET_QOS_BRIDGE_MAX_PENDING_TX (128)/** * Default VLAN ID for untagged frames received on the VLAN enabled port */#define IX_ETHACC_CODELET_VLANID_DEFAULT (150)/* prototype for TxDone callback */extern void ixEthTxFrameDoneQMCallback(UINT32 qId, UINT32 callbackId);/** * UINT32 array of pendingTx counters for each port * tells the rx callback how many transmits are pending completion */UINT32 pendingTx[IX_ETHACC_CODELET_MAX_PORT];/** * @fn void ixEthAccCodeletSwBridgeQoSTxCB() * * Transmit done callback for Bridge Operation. Transmitted frames are put * on the rx free queue of the other port. * */PRIVATE void ixEthAccCodeletSwBridgeQoSTxCB(UINT32 cbTag, IX_OSAL_MBUF* mBufPtr){ IxEthAccPortId thisPortId = (IxEthAccPortId)(cbTag & 0xffff); IxEthAccPortId otherPortId = (IxEthAccPortId)(cbTag>>16); /* * Put the mbuf on the rx freeQ of the other port since it was * received there initially. */ ixEthAccCodeletStats[thisPortId].txCount++; /* one tx that was pending is now complete */ pendingTx[thisPortId]--; /* reset the frame length */ ixEthAccCodeletMbufChainSizeSet(mBufPtr); /* replenish the other port */ if(ixEthAccPortRxFreeReplenish(otherPortId, mBufPtr) !=IX_SUCCESS) { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "SwBridgeQos: Error replenishing RX free q for port %u\n", (UINT32)(1 - cbTag), 0, 0, 0, 0, 0); }}/** * @fn void ixEthAccCodeletSwBridgeQoSTaggedToUntaggedRxCB() * * Receive callback for Bridge Operation. Received frames are * retransmitted on the other port with the priority of the rx frame. * */PRIVATE void ixEthAccCodeletSwBridgeQoSTaggedToUntaggedRxCB(UINT32 cbTag, IX_OSAL_MBUF* mBufPtr, UINT32 destPortId){ IxEthAccPortId thisPortId = (IxEthAccPortId)(cbTag & 0xffff); IxEthAccPortId otherPortId = (IxEthAccPortId)(cbTag>>16); /* Extract the priority of the incoming buffer header */ IxEthAccTxPriority priority = (IX_ETH_DB_GET_QOS_PRIORITY(IX_ETHACC_NE_VLANTCI(mBufPtr))); ixEthAccCodeletStats[thisPortId].rxCount++; /* This frame is untagged on Rx, just clear the flags * to bypass VLAN processing on the Tx path */ IX_ETHACC_NE_FLAGS(mBufPtr) = 0; /* this while loop is what throttles the receive processing to keep the RxFree queue * form becoming empty when we receive faster than transmitting */ while(pendingTx[otherPortId] >= IX_ETHACC_CODELET_QOS_BRIDGE_MAX_PENDING_TX) { ixEthTxFrameDoneQMCallback(0,0); } /* Transmit the buffer on the other port with its own priority */ if(ixEthAccPortTxFrameSubmit(otherPortId, mBufPtr, priority) !=IX_ETH_ACC_SUCCESS) { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "SwBridgeQos: Tx Buffer submission failed on port %u\n", (UINT32)(1 - cbTag), 0, 0, 0, 0, 0); } /* incriment pendingTx */ pendingTx[otherPortId]++;}/** * @fn void ixEthAccCodeletSwBridgeQoSUntaggedToTaggedRxCB() * * Receive callback for Bridge Operation. Received frames are * retransmitted on the other port with the priority of the rx frame. * */PRIVATE void ixEthAccCodeletSwBridgeQoSUntaggedToTaggedRxCB(UINT32 cbTag, IX_OSAL_MBUF* mBufPtr, UINT32 destPortId){ IxEthAccPortId thisPortId = (IxEthAccPortId)(cbTag & 0xffff); IxEthAccPortId otherPortId = (IxEthAccPortId)(cbTag>>16); IxEthAccTxPriority priority = (IX_ETH_DB_GET_QOS_PRIORITY(IX_ETHACC_CODELET_VLANID_DEFAULT)); ixEthAccCodeletStats[thisPortId].rxCount++; /* Set the VLAN information for this frame : the outgoing frame * is tagged with the default tagging rules for this port */ IX_ETHACC_NE_FLAGS(mBufPtr) = IX_ETHACC_NE_VLANENABLEMASK; IX_ETHACC_NE_VLANTCI(mBufPtr) = IX_ETHACC_CODELET_VLANID_DEFAULT; /* Transmit the buffer on the other port */ if(ixEthAccPortTxFrameSubmit(otherPortId, mBufPtr, priority) !=IX_ETH_ACC_SUCCESS) { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "SwBridgeQos: Tx Buffer submission failed on port %u\n", (UINT32)(1 - cbTag), 0, 0, 0, 0, 0); }}/* * Function definition: ixEthAccCodeletSwBridgeQoSStart() * * Configure QoS and Start bridge datapath */IX_STATUS ixEthAccCodeletSwBridgeQoSStart(IxEthAccPortId firstPortId, IxEthAccPortId secondPortId){ UINT32 firstPortCbTag = firstPortId | (secondPortId << 16); UINT32 secondPortCbTag = secondPortId | (firstPortId << 16); IxEthDBPriorityTable priorityTable = { 0,1,2,3,4,5,6,7}; IxEthDBFeature featureSet = 0; if (firstPortId == secondPortId) { printf("SwBridgeQoS: Cannot configure a Bridge Operation between port %u and port %u (ports must be different)\n", firstPortId, secondPortId); return (IX_FAIL); } /* initialize pendingTx for both ports */ pendingTx[firstPortId] = pendingTx[secondPortId] = 0; /* register the rx/tx callback */ if ( ixEthAccCodeletPortConfigure(firstPortId, ixEthAccCodeletSwBridgeQoSTaggedToUntaggedRxCB, (IxEthAccPortMultiBufferRxCallback) NULL, ixEthAccCodeletSwBridgeQoSTxCB, firstPortCbTag) != IX_SUCCESS) { printf("SwBridgeQoS: Failed to configure the Bridge Operation for port %u\n", firstPortId); return (IX_FAIL); } if ( ixEthAccCodeletPortConfigure(secondPortId, ixEthAccCodeletSwBridgeQoSUntaggedToTaggedRxCB, NULL, ixEthAccCodeletSwBridgeQoSTxCB, secondPortCbTag) != IX_SUCCESS) { printf("SwBridgeQoS: Failed to configure the Bridge Operation for port %u\n", secondPortId); return (IX_FAIL); } /* Enable the VLAN/QoS Feature in EthDB for each port but first * check that the Firmware downloaded to the NPE can support it */ ixEthDBFeatureCapabilityGet((IxEthDBPortId)firstPortId, &featureSet); if ((featureSet & IX_ETH_DB_VLAN_QOS) == 0) { printf("SwBridgeQoS: Port %u NPE image not VLAN/QoS capable\n", firstPortId); return (IX_FAIL); } if ( ixEthDBFeatureEnable((IxEthDBPortId)firstPortId, IX_ETH_DB_VLAN_QOS, TRUE) != IX_ETH_DB_SUCCESS ) { printf("SwBridgeQoS: Failed to enable VLAN/QoS on port %u\n", firstPortId); return (IX_FAIL); } /* Enable the EthDB Port in order to configure and download the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -