📄 ixethdbvlan.c
字号:
/** * @file IxEthDBVlan.c * * @brief Implementation of the VLAN API * * @par * IXP400 SW Release version 2.0 * * -- Copyright Notice -- * * @par * Copyright 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 "IxEthDB.h"#include "IxEthDB_p.h"/* forward prototypes */IX_ETH_DB_PUBLICIxEthDBStatus ixEthDBUpdateTrafficClass(IxEthDBPortId portID, UINT32 classIndex);IX_ETH_DB_PUBLICIxEthDBStatus ixEthDBVlanTableGet(IxEthDBPortId portID, IxEthDBVlanSet portVlanTable, IxEthDBVlanSet vlanSet);/* contants used by various functions as "action" parameter */#define ADD_VLAN (0x1)#define REMOVE_VLAN (0x2)/** * @brief adds or removes a VLAN from a VLAN set * * @param vlanID VLAN ID to add or remove * @param table VLAN set to add into or remove from * @param action ADD_VLAN or REMOVE_VLAN * * @internal */IX_ETH_DB_PRIVATEvoid ixEthDBLocalVlanMembershipChange(UINT32 vlanID, IxEthDBVlanSet table, UINT32 action){ UINT32 setOffset; /* add/remove VID to membership table */ setOffset = VLAN_SET_OFFSET(vlanID); /* we need 9 bits to index the 512 byte membership array */ if (action == ADD_VLAN) { table[setOffset] |= 1 << VLAN_SET_MASK(vlanID); } else if (action == REMOVE_VLAN) { table[setOffset] &= ~(1 << VLAN_SET_MASK(vlanID)); }}/** * @brief updates a set of 8 VLANs in an NPE * * @param portID ID of the port * @param setOffset offset of the 8 VLANs * * This function updates the VLAN membership table * and Transmit Tagging Info table for 8 consecutive * VLAN IDs indexed by setOffset. * * For example, a setOffset of 0 indexes VLAN IDs 0 * through 7, 1 indexes VLAN IDs 8 through 9 etc. * * @return IX_ETH_DB_SUCCESS if the operation completed * successfully or an appropriate error message otherwise * * @internal */IX_ETH_DB_PRIVATEIxEthDBStatus ixEthDBVlanTableEntryUpdate(IxEthDBPortId portID, UINT32 setOffset){ PortInfo *portInfo = &ixEthDBPortInfo[portID]; IxNpeMhMessage message; IX_STATUS result; FILL_SETPORTVLANTABLEENTRY_MSG(message, IX_ETH_DB_PORT_ID_TO_NPE_LOGICAL_ID(portID), 2 * setOffset, portInfo->vlanMembership[setOffset], portInfo->transmitTaggingInfo[setOffset]); IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result); return result;}/** * @brief updates a VLAN range in an NPE * * @param portID ID of the port * * This function is similar to @ref ixEthDBVlanTableEntryUpdate * except that it can update more than one VLAN set (up to * the entire VLAN membership and TTI tables if the offset is 0 * and length is sizeof (IxEthDBVlanSet) (512 bytes). * * Updating the NPE via this method is slower as it requires * a memory copy from SDRAM, hence it is recommended that the * ixEthDBVlanTableEntryUpdate function is used where possible. * * @return IX_ETH_DB_SUCCESS if the operation completed * successfully or an appropriate error message otherwise * * @internal */IX_ETH_DB_PRIVATEIxEthDBStatus ixEthDBVlanTableRangeUpdate(IxEthDBPortId portID){ PortInfo *portInfo = &ixEthDBPortInfo[portID]; UINT8 *vlanUpdateZone = (UINT8 *) portInfo->updateMethod.vlanUpdateZone; IxNpeMhMessage message; UINT32 setIndex; IX_STATUS result; /* copy membership info and transmit tagging into into exchange area */ for (setIndex = 0 ; setIndex < sizeof (portInfo->vlanMembership) ; setIndex++) { /* membership and TTI data are interleaved */ vlanUpdateZone[setIndex * 2] = portInfo->vlanMembership[setIndex]; vlanUpdateZone[setIndex * 2 + 1] = portInfo->transmitTaggingInfo[setIndex]; } IX_OSAL_CACHE_FLUSH(vlanUpdateZone, FULL_VLAN_BYTE_SIZE); /* build NPE message */ FILL_SETPORTVLANTABLERANGE_MSG(message, IX_ETH_DB_PORT_ID_TO_NPE_LOGICAL_ID(portID), 0, 0, IX_OSAL_MMU_VIRT_TO_PHYS(vlanUpdateZone)); /* send message */ IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result); return result;}/** * @brief adds or removes a VLAN from a port's VLAN membership table * or Transmit Tagging Information table * * @param portID ID of the port * @param vlanID VLAN ID to add or remove * @param table to add or remove from * @param action ADD_VLAN or REMOVE_VLAN * * @return IX_ETH_DB_SUCCESS if the operation completed * successfully or an appropriate error message otherwise * * @internal */IX_ETH_DB_PRIVATEIxEthDBStatus ixEthDBPortVlanMembershipChange(IxEthDBPortId portID, IxEthDBVlanId vlanID, IxEthDBVlanSet table, UINT32 action){ /* change VLAN in local membership table */ ixEthDBLocalVlanMembershipChange(vlanID, table, action); /* send updated entry to NPE */ return ixEthDBVlanTableEntryUpdate(portID, VLAN_SET_OFFSET(vlanID));}/** * @brief sets the default port VLAN tag (the lower 3 bytes are the PVID) * * @param portID ID of the port * @param vlanTag port VLAN tag (802.1Q tag) * * Note that this function is documented in the main component * header file, IxEthDB.h. * * @return IX_ETH_DB_SUCCESS if the operation completed successfully * or an appropriate error message otherwise */IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortVlanTagSet(IxEthDBPortId portID, IxEthDBVlanTag vlanTag){ IxNpeMhMessage message; IX_STATUS result; IX_ETH_DB_CHECK_PORT(portID); IX_ETH_DB_CHECK_SINGLE_NPE(portID); IX_ETH_DB_CHECK_VLAN_TAG(vlanTag); IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_VLAN_QOS); /* add VLAN ID to local membership table */ ixEthDBPortVlanMembershipChange(portID, vlanTag & IX_ETH_DB_802_1Q_VLAN_MASK, ixEthDBPortInfo[portID].vlanMembership, ADD_VLAN); /* set tag in portInfo */ ixEthDBPortInfo[portID].vlanTag = vlanTag; /* build VLAN_SetDefaultRxVID message */ FILL_SETDEFAULTRXVID_MSG(message, IX_ETH_DB_PORT_ID_TO_NPE_LOGICAL_ID(portID), IX_IEEE802_1Q_VLAN_TPID, vlanTag); IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result); return result;}/** * @brief retrieves the default port VLAN tag (the lower 3 bytes are the PVID) * * @param portID ID of the port * @param vlanTag address to write the port VLAN tag (802.1Q tag) into * * Note that this function is documented in the main component * header file, IxEthDB.h. * * @return IX_ETH_DB_SUCCESS if the operation completed successfully * or an appropriate error message otherwise */IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortVlanTagGet(IxEthDBPortId portID, IxEthDBVlanTag *vlanTag){ IX_ETH_DB_CHECK_PORT(portID); IX_ETH_DB_CHECK_SINGLE_NPE(portID); IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_VLAN_QOS); IX_ETH_DB_CHECK_REFERENCE(vlanTag); *vlanTag = ixEthDBPortInfo[portID].vlanTag; return IX_ETH_DB_SUCCESS;}/** * @brief sets the VLAN tag (the lower 3 bytes are the PVID) of a * database filtering record * * @param portID ID of the port * @param vlanTag VLAN tag (802.1Q tag) * * Important: filtering records are automatically converted to * IX_ETH_DB_FILTERING_VLAN record when added a VLAN tag. * * Note that this function is documented in the main component * header file, IxEthDB.h. * * @return IX_ETH_DB_SUCCESS if the operation completed successfully * or an appropriate error message otherwise */IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBVlanTagSet(IxEthDBMacAddr *macAddr, IxEthDBVlanTag vlanTag){ HashNode *searchResult; MacDescriptor *descriptor; IX_ETH_DB_CHECK_REFERENCE(macAddr); IX_ETH_DB_CHECK_VLAN_TAG(vlanTag); searchResult = ixEthDBSearch(macAddr, IX_ETH_DB_ALL_FILTERING_RECORDS); if (searchResult == NULL) { return IX_ETH_DB_NO_SUCH_ADDR; } descriptor = (MacDescriptor *) searchResult->data; /* set record type to VLAN if not already set */ descriptor->type = IX_ETH_DB_FILTERING_VLAN_RECORD; /* add vlan tag */ descriptor->recordData.filteringVlanData.ieee802_1qTag = vlanTag; /* transaction completed */ ixEthDBReleaseHashNode(searchResult); return IX_ETH_DB_SUCCESS;}/** * @brief retrieves the VLAN tag (the lower 3 bytes are the PVID) from a * database VLAN filtering record * * @param portID ID of the port * @param vlanTag address to write the VLAN tag (802.1Q tag) into * * Note that this function is documented in the main component * header file, IxEthDB.h. * * @return IX_ETH_DB_SUCCESS if the operation completed successfully * or an appropriate error message otherwise */IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBVlanTagGet(IxEthDBMacAddr *macAddr, IxEthDBVlanTag *vlanTag){ HashNode *searchResult; MacDescriptor *descriptor; IX_ETH_DB_CHECK_REFERENCE(macAddr); IX_ETH_DB_CHECK_REFERENCE(vlanTag); searchResult = ixEthDBSearch(macAddr, IX_ETH_DB_FILTERING_VLAN_RECORD); if (searchResult == NULL) { return IX_ETH_DB_NO_SUCH_ADDR; } descriptor = (MacDescriptor *) searchResult->data; /* get vlan tag */ *vlanTag = descriptor->recordData.filteringVlanData.ieee802_1qTag; /* transaction completed */ ixEthDBReleaseHashNode(searchResult); return IX_ETH_DB_SUCCESS;}/** * @brief adds a VLAN to a port's VLAN membership table * * @param portID ID of the port * @param vlanID VLAN ID to add * * Note that this function is documented in the main component * header file, IxEthDB.h. * * @return IX_ETH_DB_SUCCESS if the operation completed successfully * or an appropriate error message otherwise */IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortVlanMembershipAdd(IxEthDBPortId portID, IxEthDBVlanId vlanID){ IX_ETH_DB_CHECK_PORT(portID); IX_ETH_DB_CHECK_SINGLE_NPE(portID); IX_ETH_DB_CHECK_VLAN_ID(vlanID); IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_VLAN_QOS); return ixEthDBPortVlanMembershipChange(portID, vlanID, ixEthDBPortInfo[portID].vlanMembership, ADD_VLAN);}/** * @brief removes a VLAN from a port's VLAN membership table * * @param portID ID of the port * @param vlanID VLAN ID to remove * * Note that this function is documented in the main component * header file, IxEthDB.h. * * @return IX_ETH_DB_SUCCESS if the operation completed successfully * or an appropriate error message otherwise */IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortVlanMembershipRemove(IxEthDBPortId portID, IxEthDBVlanId vlanID){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -