📄 vchip8950.c
字号:
// pTxBuff += pFrag->BuffLength;
// }
/* Increment to the next transmit descriptor (with wrap-around) */
pTxDesc++;
if ( pTxDesc == pCD->pTxDescLimit )
{
pTxDesc = pCD->pTxDesc;
}
/* Save the transmit request in the transmit request table */
pTxReq = &pCD->TxReq[pCD->TxReqIndex];
pTxReq->SendID = SendID;
pTxReq->StartIndex = (WORD)(pCD->pTxDescNext - pCD->pTxDesc);
pTxReq->DescCount = DescCount;
/* Increment to the next entry in the transmit request table */
pCD->TxReqIndex++;
if ( pCD->TxReqIndex == TXREQCOUNT )
{
pCD->TxReqIndex = 0;
}
/* Update the pointer to the next transmit descriptor */
pCD->pTxDescNext = pTxDesc;
/* Update the number of transmit descriptors available */
pCD->TxDescAvail -= DescCount;
/* Set the End-of-Frame bit in the last transmit descriptor */
if ( pTxDesc == pCD->pTxDesc )
pTxDesc = pCD->pTxDescLimit;
pTxDesc--;
pTxDesc->BufIndx |= TxDesc_EOF;
/* Enqueue the transmit descriptors to the chip */
WriteDWord(OpReg_TxDEQ, DescCount );
return FALSE; /* Transmit buffers are not held, can be released immiately*/
}
/******************************************************************************
*
* VchipGetConfig()
*
******************************************************************************/
BOOL VchipGetConfig( PCHIP pChip)
{
pChip->Config.EthernetAddr.Part[0]=0x0000;
pChip->Config.EthernetAddr.Part[1]=0x2401;
pChip->Config.EthernetAddr.Part[2]=0x0300;
/* Get duplex mode from auto-negotiation control */
pChip->Config.RequestedDuplexMode = DUPLEX_AUTO_NEGOTIATE;
pChip->Config.RequestedMediaSpeed = MEDIA_AUTO_DETECT;
pChip->Config.LookAheadSize = (WORD)UNSPECIFIED;
pChip->Config.CurrentDuplexMode = DUPLEX_NONE;
pChip->Config.DetectedMediaType = MEDIA_NONE;
/* The maximum number of outstanding transmits is the number of entries */
/* in the Transmit Request table */
pChip->Config.MaxTxCount = TXREQCOUNT;
/* The maximum number of outstanding receives is the number of entries */
/* in the Receive Status Queue */
pChip->Config.MaxRxCount = RXSTATCOUNT;
pChip->Config.IntLine = 9; //default interrupt line
/* QQQQ */
//pChip->Config.Memoryize = 2048;
return TRUE;
}
/******************************************************************************
*
* VchipMulticastAddAll()
*
******************************************************************************/
void VchipMulticastAddAll( PCHIP pChip )
{
DWORD RxControl;
/* Get the current settings of the receiver control register */
RxControl=ReadDWord( OpReg_RxCTL );
/* Turn off the receiver while changing the hash table */
WriteDWord( OpReg_RxCTL, RxControl & ~RxCTL_SerRxON );
/* Set all the bits in the hash table */
WriteByte( OpReg_AFP, AFP_Hash );
WriteDWord( OpReg_HashTb , 0xFFFFFFFF );
WriteDWord( OpReg_HashTb+4, 0xFFFFFFFF );
/* Turn the receiver back on */
WriteDWord(OpReg_RxCTL, RxControl );
}
/******************************************************************************
*
* VchipMulticastDeleteAll()
*
******************************************************************************/
void VchipMulticastDeleteAll( PCHIP pChip )
{
DWORD RxControl;
/* Get the current settings of the receiver control register */
RxControl=ReadDWord( OpReg_RxCTL );
/* Turn off the receiver while changing the hash table */
WriteDWord( OpReg_RxCTL, RxControl & ~RxCTL_SerRxON );
/* Clear all the bits in the hash table */
WriteByte(OpReg_AFP, AFP_Hash );
WriteDWord( OpReg_HashTb , 0 );
WriteDWord( OpReg_HashTb+4, 0 );
/* Turn the receiver back on */
WriteDWord( OpReg_RxCTL, RxControl );
}
/******************************************************************************
*
* VchipMulticastAdd()
*
******************************************************************************/
void VchipMulticastAdd( PCHIP pChip, PEA pMulticastAddr )
{
DWORD RxControl;
DWORD HashTable;
BYTE HashIndex;
DWORD HashValue;
HashTable = OpReg_HashTb;
/* Calculate the hash index for this multicast address */
HashIndex = CalculateHashIndex( (BYTE *)pMulticastAddr );
/* If the hash index is in the second double word of the hash table */
if ( HashIndex >= 32 )
{
HashTable += 4;
HashIndex -= 32;
}
/* Get the current settings of the receiver control register */
RxControl=ReadDWord( OpReg_RxCTL );
/* Turn off the receiver while changing the hash table */
WriteDWord( OpReg_RxCTL, RxControl & ~RxCTL_SerRxON );
/* Set the hash bit in the hash table */
WriteByte( OpReg_AFP, AFP_Hash );
HashValue = ReadDWord( HashTable);
WriteDWord( HashTable, HashValue | (1L<<HashIndex) );
/* Turn the receiver back on */
WriteDWord( OpReg_RxCTL, RxControl );
}
/******************************************************************************
*
* VchipMulticastDelete()
*
******************************************************************************/
void VchipMulticastDelete( PCHIP pChip, PEA pMulticastAddr )
{
DWORD RxControl;
DWORD HashTable;
BYTE HashIndex;
DWORD HashValue;
HashTable = OpReg_HashTb;
/* Calculate the hash index for this multicast address */
HashIndex = CalculateHashIndex( (BYTE *)pMulticastAddr );
/* If the hash index is in the second double word of the hash table */
if ( HashIndex >= 32 )
{
HashTable += 4;
HashIndex -= 32;
}
/* Get the current settings of the receiver control register */
RxControl=ReadDWord( OpReg_RxCTL );
/* Turn off the receiver while changing the hash table */
WriteDWord( OpReg_RxCTL, RxControl & ~RxCTL_SerRxON );
/* Clear the hash bit in the hash table */
WriteByte(OpReg_AFP, AFP_Hash );
HashValue=ReadDWord( HashTable );
WriteDWord( HashTable, HashValue & ~(1L<<HashIndex) );
/* Turn the receiver back on */
WriteDWord( OpReg_RxCTL, RxControl );
}
/******************************************************************************
*
* CalculateHashIndex()
***********************************************************************/
static BYTE CalculateHashIndex( BYTE *pMulticastAddr )
{
DWORD CRC;
BYTE HashIndex;
BYTE AddrByte;
DWORD HighBit;
int Byte;
int Bit;
/* Prime the CRC */
CRC = CRC_PRIME;
/* For each of the six bytes of the multicast address */
for ( Byte=0; Byte<6; Byte++ )
{
AddrByte = *pMulticastAddr++;
/* For each bit of the byte */
for ( Bit=8; Bit>0; Bit-- )
{
HighBit = CRC >> 31;
CRC <<= 1;
if ( HighBit ^ (AddrByte & 1) )
{
CRC ^= CRC_POLYNOMIAL;
CRC |= 1;
}
AddrByte >>= 1;
}
}
/* Take the least significant six bits of the CRC and copy them */
/* to the HashIndex in reverse order. */
for( Bit=0,HashIndex=0; Bit<6; Bit++ )
{
HashIndex <<= 1;
HashIndex |= (BYTE)(CRC & 1);
CRC >>= 1;
}
return HashIndex;
}
/******************************************************************************
*
* VchipShutdown()
*
******************************************************************************/
void VchipShutdown( PCHIP pChip )
{
PCD pCD;
pCD = pChip->pData;
VominiStopTimer( pChip, pCD->DaemonTimer );
VchipReset( pChip );
}
/******************************************************************************
*
* GetMACAddrFromEEPROM()
*
******************************************************************************/
static BOOL GetMACAddrFromEEPROM(WORD *MAC_ADDRESS)
{
int i;
DWORD status;
/* check if EEPROM engine is inactive (0) ? If active(1), wait for inactive.*/
for ( i=0; i<MAXLOOP; i++)
{
status=(*(volatile ULONG *)( OpReg_EEPROM_CTL));
if ( (status & EEPROM_EEST) == 0 )
{
break;
}
}
if ( status & EEPROM_EEST)
{
return FALSE; /* EEPROM Error?*/
}
status=(*(volatile ULONG *)( OpReg_EEPROM_CTL));
if ( (status & EEPROM_EELD) == 0)
{
return FALSE; /* EEPROM Load Error?*/
}
MAC_ADDRESS[0]=ReadWord(OpReg_IndAd );
MAC_ADDRESS[1]=ReadWord(OpReg_IndAd+2);
MAC_ADDRESS[2]=ReadWord(OpReg_IndAd+4);
return TRUE;
}
/***************************************************************************
*
* DumpRegisters():
*
***************************************************************************/
static void DumpRegisters(void)
{
volatile DWORD b32;
volatile WORD b16;
volatile BYTE b8;
int i;
b32=ReadDWord( OpReg_RxCTL);
DbgPrint("RxCTL (0x0000): 0x%x \r\n", b32);
b8=ReadByte( OpReg_TxCTL);
DbgPrint("TxCTL (0x0004): 0x%x \r\n", b8);
b8=ReadByte( OpReg_TestCTL);
DbgPrint("TestCTL (0x0008): 0x%x \r\n", b8);
b16=ReadWord( OpReg_MIICmd);
DbgPrint("MIICmd (0x0010): 0x%x \r\n", b16);
b16=ReadWord( OpReg_MIIData);
DbgPrint("MIIData (0x0014): 0x%x \r\n", b16);
b8=ReadByte( OpReg_MIISts);
DbgPrint("MIISts (0x0018): 0x%x \r\n\r\n", b8);
b8=ReadByte( OpReg_SelfCTL);
DbgPrint("SelfCTL (0x0020): 0x%x \r\n", b8);
b32=ReadDWord( OpReg_IntEn);
DbgPrint("IntEn (0x0024): 0x%x \r\n", b32);
b32=ReadDWord( OpReg_IntStsP);
DbgPrint("IntStsPreserve (0x0028): 0x%x \r\n", b32);
b32=ReadDWord( OpReg_IntStsC);
DbgPrint("IntStsClear (0x002C): 0x%x \r\n\r\n", b32);
b32=ReadDWord( OpReg_GT);
DbgPrint("GeneralTimer (0x0040): 0x%x \r\n\r\n", b32);
b32=ReadDWord( OpReg_FCT);
DbgPrint("FlowCtlTimer (0x0044): 0x%x \r\n", b32);
b32=ReadDWord( OpReg_FCF);
DbgPrint("FlowCtlFormat (0x0048): 0x%x \r\n\r\n", b32);
b32=ReadDWord( OpReg_FERMask);
DbgPrint("FlowCtlFormat (0x0064): 0x%x \r\n", b32);
b16=ReadWord( OpReg_TxCollCnt);
DbgPrint("TxCollCnt (0x0070): 0x%x \r\n", b16);
b16=ReadWord( OpReg_RxMissCnt);
DbgPrint("RxMissCnt (0x0074): 0x%x \r\n", b16);
b16=ReadWord( OpReg_RxRuntCnt);
DbgPrint("RxRuntCnt (0x0078): 0x%x \r\n\r\n", b16);
b16=ReadWord( OpReg_BMCTL);
DbgPrint("BMCTL (0x0080): 0x%x \r\n", b16);
b8=ReadByte( OpReg_BMSts);
DbgPrint("BusMasterSts (0x0084): 0x%x \r\n\r\n", b8);
b32=ReadDWord( OpReg_RxBCA);
DbgPrint("RxBuffCurrAddr (0x0088): 0x%x \r\n", b32);
b32=ReadDWord( OpReg_TxBCA);
DbgPrint("TxBuffCurrAddr (0x008c): 0x%x \r\n\r\n", b32);
b32=ReadDWord( OpReg_RxDBA);
DbgPrint("RxDescQBaseAddr (0x0090): 0x%x \r\n", b32);
b16=ReadWord( OpReg_RxDBL);
DbgPrint("RxDescQBaseLen (0x0094): 0x%x \r\n", b16);
b16=ReadWord( OpReg_RxDCL);
DbgPrint("RxDescQCurrLen (0x0096): 0x%x \r\n", b16);
b32=ReadDWord( OpReg_RxDCA);
i=0;
// i= (b32 -(unsigned long)gCD.RxDescPhysAddr)/8;
DbgPrint("RxDescCurrAddr (0x0098): 0x%x index=%d\r\n", b32, i);
b32=ReadDWord( OpReg_RxDEQ);
DbgPrint("RxDescEnQ (0x009c): 0x%x \r\n\r\n", b32);
b32=ReadDWord( OpReg_RxSBA);
DbgPrint("RxStsBaseAddr (0x00a0): 0x%x \r\n",b32);
b16=ReadWord( OpReg_RxSBL);
DbgPrint("RxStsBaseLen (0x00a4): 0x%x \r\n", b16);
b16=ReadWord( OpReg_RxSCL);
DbgPrint("RxStsCurrLen (0x00a6): 0x%x \r\n", b16);
b32=ReadDWord( OpReg_RxSCA);
i=0;
// i= (b32 -(unsigned long)gCD.RxStatPhysAddr)/8;
DbgPrint("RxStsCurrAddr (0x00a8): 0x%x index=%d\r\n", b32, i);
b32=ReadDWord( OpReg_RxSEQ);
DbgPrint("RxStsEnQ (0x00ac): 0x%x \r\n\r\n", b32);
b32=ReadDWord( OpReg_TxDBA);
DbgPrint("TxDescQBaseAddr (0x00b0): 0x%x \r\n", b32);
b16=ReadWord( OpReg_TxDBL);
DbgPrint("TxDescBaseLen (0x00b4): 0x%x \r\n", b16);
b16=ReadWord( OpReg_TxDCL);
DbgPrint("TxDescQCurrLen (0x00b6): 0x%x \r\n", b16);
b32=ReadDWord( OpReg_TxDCA);
i=0;
// i= (b32 -(unsigned long)gCD.TxDescPhysAddr)/8;
DbgPrint("TxDescCurrAddr (0x00b8): 0x%x index=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -