?? addresstable.c
字號:
/*******************************************************************************
* Copyright 2002, GALILEO TECHNOLOGY, LTD. *
* THIS CODE CONTAINS CONFIDENTIAL INFORMATION OF MARVELL. *
* NO RIGHTS ARE GRANTED HEREIN UNDER ANY PATENT, MASK WORK RIGHT OR COPYRIGHT *
* OF MARVELL OR ANY THIRD PARTY. MARVELL RESERVES THE RIGHT AT ITS SOLE *
* DISCRETION TO REQUEST THAT THIS CODE BE IMMEDIATELY RETURNED TO MARVELL. *
* THIS CODE IS PROVIDED "AS IS". MARVELL MAKES NO WARRANTIES, EXPRESSED, *
* IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, COMPLETENESS OR PERFORMANCE. *
* *
* MARVELL COMPRISES MARVELL TECHNOLOGY GROUP LTD. (MTGL) AND ITS SUBSIDIARIES, *
* MARVELL INTERNATIONAL LTD. (MIL), MARVELL TECHNOLOGY, INC. (MTI), MARVELL *
* SEMICONDUCTOR, INC. (MSI), MARVELL ASIA PTE LTD. (MAPL), MARVELL JAPAN K.K. *
* (MJKK), GALILEO TECHNOLOGY LTD. (GTL) AND GALILEO TECHNOLOGY, INC. (GTI). *
********************************************************************************
* addressTable.c - this file has all the functions of the address table
*
* DESCRIPTION:
* None.
*
* DEPENDENCIES:
* None.
*
*******************************************************************************/
/* includes */
#include "ethernet.h"
#include "addressTable.h"
/* #include <string.h>
#include <stdio.h> */
/* defines */
/* typedefs */
/* locals */
ADRS_TABLE_STATUS enableFiltering (ETH_PORT_INFO *pEthPortCtrl, int port);
ADRS_TABLE_STATUS disableFiltering(ETH_PORT_INFO *pEthPortCtrl, int port);
ADRS_TABLE_STATUS findFirstAddressTableEntry(int port,
unsigned int* startEntry,
char* resultBuffer);
unsigned int addressTableHashMode[MAX_ETH_PORT_NUM];
unsigned int addressTableHashSize[MAX_ETH_PORT_NUM];
unsigned int addressTableBase[MAX_ETH_PORT_NUM];
/*****************************************************************************
*
* ADRS_TABLE_STATUS initAddressTable
*
* This function will initialize the address table
* and will enableFiltering.
* Inputs
* hashMode - hash mode 0 or hash mode 1.
* hashSize - the size of the hash table (0=8K ,1=1/2K)
* hashDefaultMode - 0 = discard addresses not found in the address table ,
* 1 = pass addresses not found in the address table.
* port - ETHERNET port number.
* Outputs
* address table is allocated and initialized.
* ADRS_TABLE_OK if success.
* ADRS_TABLE_ERROR if fail to make the assignment.
*/
ADRS_TABLE_STATUS initAddressTable(ETH_PORT_INFO *pEthPortCtrl,
int port,
int hashMode,
int hashSize,
int hashDefaultMode,
unsigned int baseAddr)
{
unsigned int hashLengh[MAX_ETH_PORT_NUM];
hashLengh[0] = EIGHT_K;
hashLengh[1] = HALF_K;
addressTableHashMode[port] = hashMode;
addressTableHashSize[port] = hashSize;
/* allocate memory for the address table */
addressTableBase[port] = baseAddr;
/* GT_REG_WRITE(ETH_HASH_TABLE_POINTER_REG(port),
VIRTUAL_TO_PHY(addressTableBase[port])); assaf, old */
PORT_REG_WRITE(HASH_TABLE_POINTER_REGISTER,
pEthPortCtrl->portVirtToPhys(addressTableBase[port]));
/* fill all the address table with 0's */
memset((void*)addressTableBase[port],0,hashLengh[hashSize]*MAC_ENTRY_SIZE);
/* set hash size hash mode and HDM in the PCR */
/* Clear register fields */
ethernetResetConfigReg(pEthPortCtrl, (1 << HASH_DEFUALT_MODE) |
(1 << HASH_MODE) | (1 << HASH_SIZE));
/*etherGetDefaultPortConfReg (&portControlReg,port);
portControlReg = portControlReg & ~(1 << HASH_DEFUALT_MODE);
portControlReg = portControlReg & ~(1 << HASH_MODE);
portControlReg = portControlReg & ~(1 << HASH_SIZE);*/
/* Set register fields with values */
ethernetSetConfigReg(pEthPortCtrl, (hashDefaultMode << HASH_DEFUALT_MODE) |
(hashMode << HASH_MODE) | (hashSize << HASH_SIZE));
/*portControlReg = portControlReg |
(hashDefaultMode<<HASH_DEFUALT_MODE) |
(hashMode << HASH_MODE) |
(hashSize << HASH_SIZE);
etherModifyDefaultPortConfReg(&portControlReg,port);
etherSetPortConfReg(&portControlReg,port);
*/
/* enableFiltering */
if (!(pEthPortCtrl->portConfig & ETH_PROMISCUOUS_MODE))
{
enableFiltering(pEthPortCtrl, port);
}
return ADRS_TABLE_OK;
}
/*****************************************************************************
*
* ADRS_TABLE_STATUS addAddressTableEntry(int port,unsigned int macH,unsigned int macL,
* unsigned int rd,unsigned int skip)
*
* This function will add an entry to the address table.
* depends on the hash mode and hash size that was initialized.
* Inputs
* port - ETHERNET port number.
* macH - the 2 most significant bytes of the MAC address.
* macL - the 4 least significant bytes of the MAC address.
* skip - if 1 , skip this address.
* rd - the RD field in the address table.
* Outputs
* address table entry is added.
* ADRS_TABLE_OK if success.
* ADRS_TABLE_ERROR if fail to make the assignment.
*/
ADRS_TABLE_STATUS addAddressTableEntry(int port,
unsigned int macH,
unsigned int macL,
unsigned int rd,
unsigned int skip)
{
unsigned int addressHighValue;
unsigned int addressLowValue;
void* entryNumber;
int hashBase = addressTableBase[port];
int i;
unsigned int addressLowRead;
unsigned int addressHighRead;
entryNumber = (void*)(hashBase + MAC_ENTRY_SIZE*hashTableFunction(macH,macL,
(int)addressTableHashSize[port],
(int)addressTableHashMode[port]));
addressLowValue = VALID | (skip<<SKIP_BIT) | (rd<<2) |
(((macH>>8)&0xf)<<3) |
(((macH>>12)&0xf)<<7) |
(((macH>>0)&0xf)<<11) |
(((macH>>4)&0xf)<<15) |
(((macL>>24)&0xf)<<19) |
(((macL>>28)&0xf)<<23) |
(((macL>>16)&0xf)<<27) |
((((macL>>20)&0x1)<<31));
addressHighValue = ((macL>>21)&0x7) |
(((macL>>8)&0xf)<<3) |
(((macL>>12)&0xf)<<7) |
(((macL>>0)&0xf)<<11) |
(((macL>>4)&0xf)<<15);
/* find a free place */
for(i = 0 ; i < HOP_NUMBER ; i++)
{
addressLowRead = *(unsigned int*)(entryNumber+i*MAC_ENTRY_SIZE+4);
if((!(addressLowRead & VALID))/* || (addressLowRead & SKIP)*/)
{
entryNumber = entryNumber+i*MAC_ENTRY_SIZE;
break;
}
else /* if the address is the same locate it at the same position */
{
addressHighRead = *(unsigned int*)(entryNumber+i*MAC_ENTRY_SIZE);
if(((addressLowRead>>3)&0x1fffffff)==
((addressLowValue>>3)&0x1fffffff)
&& ((addressHighRead)==(addressHighValue)))
{
entryNumber = entryNumber+i*MAC_ENTRY_SIZE;
break;
}
}
}
if(i == HOP_NUMBER)
{
printf("The address table section is full\n");
return ADRS_TABLE_ERROR;
}
/* write the address to the address table */
*(unsigned int*)(entryNumber) = addressLowValue;
*(unsigned int*)(entryNumber+4) = addressHighValue;
return ADRS_TABLE_OK;
}
/*****************************************************************************
*
* int hashTableFunction(unsigned int macH,unsigned int macL,int HashSize,
* int hash_mode)
*
* This function will calculate the hash function of the address.
* depends on the hash mode and hash size.
* Inputs
* macH - the 2 most significant bytes of the MAC address.
* macL - the 4 least significant bytes of the MAC address.
* hashMode - hash mode 0 or hash mode 1.
* hashSize - the size of the hash table (0=8K ,1=1/2K).
* Outputs
* return the caculated entry.
* ADRS_TABLE_OK if success.
* ADRS_TABLE_ERROR if fail to make the assignment.
*/
int hashTableFunction(unsigned int macH,unsigned int macL,
int HashSize,int hash_mode)
{
unsigned int hashResult;
unsigned int ethernetAddH;
unsigned int ethernetAddL;
unsigned int ethernetAdd0;
unsigned int ethernetAdd1;
unsigned int ethernetAdd2;
unsigned int ethernetAdd3;
unsigned int ethernetAddHSwapped = 0;
unsigned int ethernetAddLSwapped = 0;
ethernetAddH = NIBBLE_SWAPPING_16_BIT(macH);
ethernetAddL = NIBBLE_SWAPPING_32_BIT(macL);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -