?? smsc111.c
字號:
}
}
// IP address save again
pAdapter->ucPermanentAddress[0] = ReadWord(pAdapter,ADDR0) & 0xFF;
pAdapter->ucPermanentAddress[1] = ReadWord(pAdapter,ADDR0) >> 8;
pAdapter->ucPermanentAddress[2] = ReadWord(pAdapter,ADDR1) & 0xFF;
pAdapter->ucPermanentAddress[3] = ReadWord(pAdapter,ADDR1) >> 8;
pAdapter->ucPermanentAddress[4] = ReadWord(pAdapter,ADDR2) & 0xFF;
pAdapter->ucPermanentAddress[5] = ReadWord(pAdapter,ADDR2) >> 8;
#endif // for ROM
RETAILMSG(1,
(TEXT("CELAN: PermanentAddress [ %02x-%02x-%02x-%02x-%02x-%02x ]\r\n"),
pAdapter->ucPermanentAddress[0],
pAdapter->ucPermanentAddress[1],
pAdapter->ucPermanentAddress[2],
pAdapter->ucPermanentAddress[3],
pAdapter->ucPermanentAddress[4],
pAdapter->ucPermanentAddress[5]));
//
// Use the burned in address as the station address, unless the
// registry specified an override value.
//
if ((pAdapter->ucStationAddress[0] == 0x00) &&
(pAdapter->ucStationAddress[1] == 0x00) &&
(pAdapter->ucStationAddress[2] == 0x00) &&
(pAdapter->ucStationAddress[3] == 0x00) &&
(pAdapter->ucStationAddress[4] == 0x00) &&
(pAdapter->ucStationAddress[5] == 0x00)
)
{
pAdapter->ucStationAddress[0] = pAdapter->ucPermanentAddress[0];
pAdapter->ucStationAddress[1] = pAdapter->ucPermanentAddress[1];
pAdapter->ucStationAddress[2] = pAdapter->ucPermanentAddress[2];
pAdapter->ucStationAddress[3] = pAdapter->ucPermanentAddress[3];
pAdapter->ucStationAddress[4] = pAdapter->ucPermanentAddress[4];
pAdapter->ucStationAddress[5] = pAdapter->ucPermanentAddress[5];
}
RETAILMSG (1, (TEXT ("CELAN: StationAddress [ %02x-%02x-%02x-%02x-%02x-%02x ]\r\n"), pAdapter->ucStationAddress[0], pAdapter->ucStationAddress[1], pAdapter->ucStationAddress[2], pAdapter->ucStationAddress[3], pAdapter->ucStationAddress[4], pAdapter->ucStationAddress[5]));
}
/*
* Description:
* Sets up the SMSC91C111.
*
* Arguments:
* pAdapter - Pointer to the adapter structure.
*
* Return Value:
* TRUE if successful.
*/
BOOLEAN
CardSetup (IN PSMSC111_ADAPTER pAdapter)
{
UINT uiIndex;
WORD wRcr;
UINT uiDelay;
USHORT usPhy;
DEBUGMSG (ZONE_FUNCTION, (TEXT ("+CELAN: CardSetup\r\n")));
SelectBank (pAdapter,BANK0);
WriteWord (pAdapter,RCR, RCR_SOFTRESET);
Sleep (10);
wRcr = ReadWord (pAdapter,RCR);
if ((wRcr & RCR_SOFTRESET) != RCR_SOFTRESET)
{
DEBUGMSG (ZONE_ERROR, (TEXT ("CELAN: CardSetup: CardReset - RCR = 0x%x, Expected 0x%x\r\n"), wRcr, (RCR_SOFTRESET)));
return (FALSE);
}
WriteWord (pAdapter,RCR, 0);
Sleep (10);
// Initialize the control register
DEBUGMSG (ZONE_INIT, (TEXT ("CELAN: CardSetup: Initializing Control register\r\n")));
SelectBank (pAdapter,BANK1);
WriteWord (pAdapter,CONTROL, CTL_AUTO_RELEASE | CTL_ONE_1 | CTL_TE_ENABLE | CTL_ONE_2 | CTL_LE_ENABLE);
// Wait for some time. Read back again.
// for(glbl_tmp = 0; glbl_tmp < 1000000000; glbl_tmp ++);
// SelectBank(BANK0);
// SelectBank(BANK1);
DEBUGMSG (ZONE_INIT, (TEXT ("CELAN: CardSetup: CONFIG register re-reads back 0x%x\r\n"), ReadWord(pAdapter,CONFIG) ));
//
// Set Loopback Mode
//
DEBUGMSG (ZONE_INIT, (TEXT ("CELAN: CardSetup: Initializing loopback mode\r\n")));
SelectBank (pAdapter,BANK0);
pAdapter->usNicTransmitConfig = TCR_LOOP;
WriteWord (pAdapter,TCR, pAdapter->usNicTransmitConfig);
//
// Clear all pending interrupts
//
DEBUGMSG (ZONE_INIT, (TEXT ("CELAN: CardSetup: Clearing pending interrupts\r\n")));
SelectBank (pAdapter,BANK2);
WriteWord (pAdapter,INTERRUPT_REGISTER, ReadWord (pAdapter,INTERRUPT_REGISTER));
//
// Set Station Address
//
DEBUGMSG (ZONE_INIT, (TEXT ("CELAN: CardSetup: Initializing station address registers\r\n")));
SelectBank (pAdapter,BANK1);
WriteWord (pAdapter,ADDR0, (UINT16)(pAdapter->ucStationAddress[0] | (pAdapter->ucStationAddress[1] << 8)));
WriteWord (pAdapter,ADDR1, (UINT16)(pAdapter->ucStationAddress[2] | (pAdapter->ucStationAddress[3] << 8)));
WriteWord (pAdapter,ADDR2, (UINT16)(pAdapter->ucStationAddress[4] | (pAdapter->ucStationAddress[5] << 8)));
//
// Write out the multicast addresses
//
SelectBank (pAdapter,BANK3);
for (uiIndex = 0; uiIndex < sizeof (pAdapter->ucNicMulticastRegs); uiIndex += 2)
WriteWord (pAdapter,MULTICAST1 + uiIndex, (USHORT)((pAdapter->ulPacketFilter & NDIS_PACKET_TYPE_ALL_MULTICAST) ? 0xffff : pAdapter->ucNicMulticastRegs[uiIndex] | pAdapter->ucNicMulticastRegs[uiIndex + 1] << 8));
//
// Reset the PHY.
//
for (uiDelay = 0; uiDelay < 10; uiDelay++){ //Can not take out this loop. It fix the following reset problem.
usPhy = Smsc111ReadPhy (pAdapter, PHY_CONTROL);
DEBUGMSG (ZONE_INIT, (TEXT ("CELAN: CardSetup: PHY_CONTOL register is 0x%x\r\n"),usPhy));
if (!(usPhy & PHY_CTRL_RESET))
break;
}
DEBUGMSG (ZONE_INIT, (TEXT ("CELAN: CardSetup: Resetting PHY\r\n")));
Smsc111WritePhy (pAdapter, PHY_CONTROL, PHY_CTRL_RESET);
for (uiDelay = 0; uiDelay < 100; uiDelay++)
{
usPhy = Smsc111ReadPhy (pAdapter, PHY_CONTROL);
if (!(usPhy & PHY_CTRL_RESET))
break;
Sleep (10);
}
DEBUGMSG (ZONE_INIT, (TEXT ("CELAN: CardSetup: Done Resetting PHY, usPhy = 0x%x\r\n"), usPhy));
if (usPhy & PHY_CTRL_RESET)
return (FALSE);
//
// Wait for the autonegotiation to complete
//
for (uiDelay = 0; uiDelay < 10; uiDelay++)
{
usPhy = Smsc111ReadPhy (pAdapter, PHY_STATUS);
if (usPhy & PHY_STAT_ANCOMPLETE)
break;
Sleep (10);
}
//
// Force the PHY into restricted modes (for debugging)
//
#if 0
Smsc111WritePhy (pAdapter, PHY_ANADVERTISE, Smsc111ReadPhy (pAdapter, PHY_ANADVERTISE) & ~(PHY_ANA_100FDX | PHY_ANA_10FDX)); // Disable full duplex
// Smsc111WritePhy (pAdapter, PHY_ANADVERTISE, Smsc111ReadPhy (pAdapter, PHY_ANADVERTISE) & ~(PHY_ANA_100FDX | PHY_ANA_100HDX)); // Disable 100Mb/s
//
// Restart the autonegotiation
//
Smsc111WritePhy (pAdapter, PHY_CONTROL, Smsc111ReadPhy (pAdapter, PHY_CONTROL) | PHY_CTRL_ANRESTART);
//
// Wait for the autonegotiation to complete
//
for (uiDelay = 0; uiDelay < 10; uiDelay++)
{
usPhy = Smsc111ReadPhy (pAdapter, PHY_STATUS);
if (usPhy & PHY_STAT_ANCOMPLETE)
break;
Sleep (10);
}
#endif
//
// Reset the Isolation bit in the PHY, and adjust the TCR based on the PHY autonegotiation.
//
usPhy = Smsc111ReadPhy (pAdapter, PHY_CONTROL);
Smsc111WritePhy (pAdapter, PHY_CONTROL, (UINT16)(usPhy & ~PHY_CTRL_ISOLATION));
pAdapter->usNicTransmitConfig = TCR_PAD_ENABLE | TCR_ENABLE;
if (usPhy & PHY_CTRL_DUPLEX)
pAdapter->usNicTransmitConfig |= TCR_SWFDUP;
SelectBank (pAdapter,BANK0);
WriteWord (pAdapter,TCR, pAdapter->usNicTransmitConfig);
//
// Set Interrupt Mask Register
//
DEBUGMSG (ZONE_INIT, (TEXT ("CELAN: CardSetup: Initializing Interrupt Mask register %02x\r\n"), pAdapter->usNicInterruptMask));
SelectBank (pAdapter,BANK2);
WriteWord (pAdapter,INTERRUPT_REGISTER, pAdapter->usNicInterruptMask);
DEBUGMSG(ZONE_FUNCTION, (TEXT("-CELAN: CardSetup\r\n")));
//
// NOTE: Still in loopback mode.
//
return (TRUE);
}
/*
* Description:
* Starts the SMSC91C111.
*
* Arguments:
* pAdapter - Pointer to the adapter structure.
*
* Return Value:
* None.
*/
#pragma NDIS_PAGEABLE_FUNCTION(CardStart)
VOID
CardStart (IN PSMSC111_ADAPTER pAdapter)
{
DEBUGMSG (ZONE_FUNCTION, (TEXT ("+CELAN: CardStart\r\n")));
// Initialize the trasmit control register
SelectBank (pAdapter,BANK0);
WriteWord (pAdapter,TCR, pAdapter->usNicTransmitConfig);
//
// Initialize the receive control register
//
SelectBank (pAdapter,BANK0);
WriteWord (pAdapter,RCR, pAdapter->usNicReceiveConfig);
LAN91C111Init(pAdapter);
DEBUGMSG (ZONE_FUNCTION, (TEXT ("-CELAN: CardStart\r\n")));
}
/*
* Description:
* Erases and refills the card multicast registers. Used when
* an address has been deleted and all bits must be recomputed.
*
* Arguments:
* pAdapter - Pointer to the adapter structure.
*
* Return Value:
* None.
*/
VOID
CardFillMulticastRegs (IN PSMSC111_ADAPTER pAdapter)
{
UINT uiIndex;
UCHAR ucByte, ucBit;
DEBUGMSG (ZONE_FUNCTION, (TEXT ("+CELAN: CardFillMulticastRegs\r\n")));
//
// First turn all bits off.
//
for (uiIndex = 0; uiIndex < sizeof (pAdapter->ucNicMulticastRegs); uiIndex++)
pAdapter->ucNicMulticastRegs[uiIndex] = 0;
//
// Now turn on the bit for each address in the multicast list.
//
for (uiIndex = 0; uiIndex < DEFAULT_MULTICASTLISTMAX; uiIndex++)
{
CardGetMulticastBit (pAdapter->ucAddresses[uiIndex], &ucByte, &ucBit);
pAdapter->ucNicMulticastRegs[ucByte] |= ucBit;
}
DEBUGMSG (ZONE_FUNCTION, (TEXT ("-CELAN: CardFillMulticastRegs\r\n")));
}
/*
* Description:
* Turns on all the bits in the multicast registers. Used when
* the card must receive all multicast packets.
*
* Arguments:
* pSynchronizeContext - Pointer to the adapter block
*
* Return Value:
* None.
*/
BOOLEAN
SyncCardSetAllMulticast (IN PVOID pSynchronizeContext)
{
UINT uiIndex;
PSMSC111_ADAPTER pAdapter = ((PSMSC111_ADAPTER)pSynchronizeContext);
DEBUGMSG (ZONE_FUNCTION, (TEXT ("+CELAN: SyncCardSetAllMulticast\r\n")));
SelectBank (pAdapter,BANK3);
for (uiIndex = 0; uiIndex < sizeof (pAdapter->ucNicMulticastRegs); uiIndex += 2)
WriteWord (pAdapter,MULTICAST1 + uiIndex, 0xffff);
DEBUGMSG (ZONE_FUNCTION, (TEXT ("-CELAN: CardSetAllMulticast\r\n")));
return (FALSE);
}
/*
* Description:
* Sets the eight bytes in the card multicast registers.
*
* Arguments:
* pSynchronizeContext - Pointer to the adapter block
*
* Return Value:
* None.
*/
BOOLEAN
SyncCardCopyMulticastRegs (IN PVOID pSynchronizeContext)
{
UINT uiIndex;
PSMSC111_ADAPTER pAdapter = ((PSMSC111_ADAPTER)pSynchronizeContext);
DEBUGMSG (ZONE_FUNCTION, (TEXT ("+CELAN: SyncCardCopyMulticastRegs\r\n")));
SelectBank (pAdapter,BANK3);
for (uiIndex = 0; uiIndex < sizeof (pAdapter->ucNicMulticastRegs); uiIndex += 2)
WriteWord (pAdapter,MULTICAST1 + uiIndex, (UINT16)(pAdapter->ucNicMulticastRegs[uiIndex] | (pAdapter->ucNicMulticastRegs[uiIndex + 1] << 8)));
DEBUGMSG (ZONE_FUNCTION, (TEXT("Multicast bits\r\n")));
for (uiIndex = 0; uiIndex < sizeof (pAdapter->ucNicMulticastRegs); uiIndex++)
DEBUGMSG (ZONE_FUNCTION, (TEXT ("%02x "), pAdapter->ucNicMulticastRegs[uiIndex]));
DEBUGMSG (ZONE_FUNCTION, (TEXT ("\r\n")));
DEBUGMSG (ZONE_FUNCTION, (TEXT ("-CELAN: SyncCardCopyMulticastRegs\r\n")));
return (FALSE);
}
/*
* Description:
* Sets the value of the "receive configuration" NIC register to
* the value of Adapter->NicReceiveConfig.
*
* Arguments:
* pSynchronizeContext - Pointer to the adapter block
*
* Return Value:
* None.
*/
BOOLEAN
SyncCardSetReceiveConfig (IN PVOID pSynchronizeContext)
{
PSMSC111_ADAPTER pAdapter = ((PSMSC111_ADAPTER)pSynchronizeContext);
DEBUGMSG (ZONE_FUNCTION, (TEXT ("+CELAN: SyncCardSetReceiveConfig\r\n")));
SelectBank (pAdapter,BANK0);
WriteWord (pAdapter,RCR, pAdapter->usNicReceiveConfig);
DEBUGMSG (ZONE_FUNCTION, (TEXT ("-CELAN: SyncCardSetReceiveConfig\r\n")));
return (FALSE);
}
/*
* Description:
* Runs the AUTODIN II CRC algorithm on buffer Buffer of length Length.
*
* Arguments:
* pBuffer - The input buffer
* uiLength - The length of the input
*
* Return Value:
* The 32-bit CRC value.
*/
ULONG
CardComputeCrc (IN PUCHAR pBuffer, IN UINT uiLength)
{
ULONG ulCrc, ulCarry;
UINT uiByteIndex, uiBitIndex;
UCHAR ucCurByte;
DEBUGMSG (ZONE_FUNCTION, (TEXT ("+CELAN: CardComputeCrc\r\n")));
ulCrc = 0xffffffff;
for (uiByteIndex = 0; uiByteIndex < uiLength; uiByteIndex++)
{
ucCurByte = pBuffer[uiByteIndex];
for (uiBitIndex = 0; uiBitIndex < 8; uiBitIndex++)
{
ulCarry = ((ulCrc & 0x80000000) ? 1 : 0) ^ (ucCurByte & 0x01);
ulCrc <<= 1;
ucCurByte >>= 1;
if (ulCarry)
ulCrc = (ulCrc ^ 0x04c11db6) | ulCarry;
}
}
DEBUGMSG (ZONE_FUNCTION, (TEXT ("-CELAN: CardComputeCrc\r\n")));
return (ulCrc);
}
/*
* Description:
* For a given multicast address, returns the byte and bit in
* the card multicast registers that it hashes to. Calls
* CardComputeCrc() to determine the CRC value.
*
* Arguments:
* ucAddress - The MAC address to hash.
* pByte - Pointer to the byte offset in the multicast registers.
* pValue - Pointer to the value for the multicast register. Will have a 1 in the relevant bit.
*
* Return Value:
* None.
*/
VOID
CardGetMulticastBit(IN UCHAR ucAddress[ETHER_LENGTH_OF_ADDRESS], OUT PUCHAR pByte, OUT PUCHAR pValue)
{
ULONG ulCrc;
UINT uiBitNumber;
DEBUGMSG (ZONE_FUNCTION, (TEXT ("+CELAN: CardGetMulticastBit\r\n")));
//
// First compute the CRC.
//
ulCrc = CardComputeCrc (ucAddress, ETHER_LENGTH_
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -