📄 nicmedia.c
字号:
/*******************************************************************************
*** Note: Copy rights resevered to Beijing Pacific Linkair Communications Co.
***
*** File Name: NICMedia.c
*** Purpose : Setup the Media
***
*** Author : Guangzhao Tian
*** Modified : By Guangzhao Tian at 2000/9/11
***
**/
#include "NICMacro.h"
#include "NICWinReg.h"
#include "NICCommand.h"
#include "NICEeprom.h"
#include "NICData.h"
#include "NICHelper.h"
#include "NICMii.h"
#include "NICExport.h"
/****************************************************************************************
*** This routine checks whether autoselection is specified.
*** If it does, it calls MainAutoSelectionRoutine ,
*** else, for non-autoselect case, calls ProgramMII.
**/
NIC_STATUS NIC_MediaSetup(IN PNIC_INFORMATION pAdapter )
{
USHORT wOptionAvailable = 0;
ULONG InternalConfig = 0;
ULONG InternalConfigNew=0;
ULONG InternalConfig0 = 0;
ULONG InternalConfig1 = 0;
NIC_STATUS nicStatus;
USHORT MacControl = 0;
BOOLEAN Handles100Mbit = FALSE;
DebugMsg("\n******************\nNow We will Setup the Media... \n");
pAdapter->LinkInfo.ConfigConnector = CONNECTOR_UNKNOWN;
pAdapter->LinkInfo.Connector = CONNECTOR_UNKNOWN;
pAdapter->LinkInfo.AutoSelect = FALSE;
pAdapter->LinkInfo.FullDuplexEnable=FALSE;
pAdapter->LinkInfo.FullDuplexEnable=FALSE;
pAdapter->LinkInfo.FlowControlSupported=TRUE;
/* Read the MEDIA OPTIONS to see what connectors are available */
NIC_COMMAND ( pAdapter->IoBaseAddress , COMMAND_SELECT_REGISTER_WINDOW | REGISTER_WINDOW_3);
wOptionAvailable = NIC_READ_PORT_USHORT( pAdapter->IoBaseAddress , MEDIA_OPTIONS_REGISTER );
pAdapter->LinkInfo.MediaOptions=wOptionAvailable;
/* Read the internal config through EEPROM since reset invalidates the normal register value. */
if ( NIC_STATUS_SUCCESS != NIC_EEPROMRead (pAdapter,EEPROM_INTERNAL_CONFIG_WORD_0,
(PUSHORT)&InternalConfig0 ) )
{ return NIC_STATUS_FAILURE; }
if ( NIC_STATUS_SUCCESS != NIC_EEPROMRead(pAdapter, EEPROM_INTERNAL_CONFIG_WORD_1,
(PUSHORT)&InternalConfig1) )
{ return NIC_STATUS_FAILURE; }
InternalConfig = InternalConfig0 | (InternalConfig1 <<16);
/* Read the current value of the InternalConfig register. If it's different
from the EEPROM values, than write it out using the EEPROM values.
This is done since a global reset may invalidate the register value on
some ASICs. Also, writing to InternalConfig may reset the PHY on some ASICs. */
NIC_COMMAND(pAdapter->IoBaseAddress ,COMMAND_SELECT_REGISTER_WINDOW | REGISTER_WINDOW_3);
InternalConfigNew = NIC_READ_PORT_ULONG( pAdapter->IoBaseAddress,INTERNAL_CONFIG_REGISTER );
if (InternalConfig != InternalConfigNew)
{
NIC_WRITE_PORT_ULONG(pAdapter->IoBaseAddress ,INTERNAL_CONFIG_REGISTER,InternalConfig);
}
pAdapter->LinkInfo.ConfigConnector =(InternalConfig & INTERNAL_CONFIG_TRANSCEIVER_MASK) >> 20;
/* Now try to decied the Link Info Params, first Get the connector to use.
if (pAdapter->LinkInfo.ConfigConnector == CONNECTOR_UNKNOWN) */
{
pAdapter->LinkInfo.Connector = pAdapter->LinkInfo.ConfigConnector;
if (InternalConfig & INTERNAL_CONFIG_AUTO_SELECT) pAdapter->LinkInfo.AutoSelect = TRUE;
}
/* If auto selection of connector was specified, do it now... */
if (pAdapter->LinkInfo.AutoSelect)
{
DebugMsg(" Set the Adapter media in Auto Select Mode ... \n");
NIC_COMMAND(pAdapter->IoBaseAddress, COMMAND_STATISTICS_DISABLE);
NIC_MediaAutoSelect(pAdapter, wOptionAvailable);
DebugMsg(" Auto Select Mode Setting Done ! \n");
}
else
{
/* MII connector needs to be initialized and the data rates
set up even in the non-autoselect case */
DebugMsg(" Set the Adapter media in forced-mode ... \n");
if ( (pAdapter->LinkInfo.Connector == CONNECTOR_MII ) ||
(pAdapter->LinkInfo.Connector == CONNECTOR_AUTONEGOTIATION ) )
{
NIC_MediaProgramMII(pAdapter, CONNECTOR_MII);
}
else
{
if ( (pAdapter->LinkInfo.Connector == CONNECTOR_100BASEFX) ||
(pAdapter->LinkInfo.Connector == CONNECTOR_100BASETX ) )
{
pAdapter->LinkInfo.LinkSpeed = LINK_SPEED_100;
}
else
{
pAdapter->LinkInfo.LinkSpeed = LINK_SPEED_10;
}
}
/*Set up the Internal Config Register using the Connector Value
gotten from Internal Config Register*/
NIC_MediaSetupConnector(pAdapter, pAdapter->LinkInfo.Connector);
DebugMsg(" Forced Mode Setting Done ! \n");
}
/* Check link speed and duplex settings before doing anything else.
If the call succeeds, we know the link is up, so we'll update the link state. */
DebugMsg(" Link Speed Get ...");
if ( NIC_MIILinkSpeedGet(pAdapter, &Handles100Mbit) )
{
pAdapter->LinkInfo.LinkSpeed = (Handles100Mbit) ? LINK_SPEED_100 : LINK_SPEED_10;
pAdapter->LinkInfo.LinkState = LINK_UP;
}
else
pAdapter->LinkInfo.LinkState = LINK_DOWN_AT_INIT;
DebugMsg(" Done ! \n");
/* Set up duplex mode */
DebugMsg(" Setup Duplex Mode ...");
NIC_COMMAND( pAdapter, COMMAND_SELECT_REGISTER_WINDOW | REGISTER_WINDOW_3);
MacControl = NIC_READ_PORT_USHORT(pAdapter, MAC_CONTROL_REGISTER);
if (pAdapter->LinkInfo.FullDuplexEnable)
{
/* Set Full duplex in MacControl register */
MacControl |= MAC_CONTROL_FULL_DUPLEX_ENABLE;
DebugMsg(" Changed link to full duplex. \n");
/* Since we're switching to full duplex, enable flow control.*/
if (pAdapter->LinkInfo.FlowControlSupported)
{
MacControl |= MAC_CONTROL_FLOW_CONTROL_ENABLE;
pAdapter->LinkInfo.FlowControlEnable = TRUE;
}
}
else
{
/* Set Half duplex in MacControl register */
MacControl &= ~MAC_CONTROL_FULL_DUPLEX_ENABLE;
DebugMsg(" Change link to half duplex ! \n");
/* Since we're switching to half duplex, disable flow control */
if (pAdapter->LinkInfo.FlowControlSupported)
{
MacControl &= ~ MAC_CONTROL_FLOW_CONTROL_ENABLE;
pAdapter->LinkInfo.FlowControlEnable = FALSE;
}
}
NIC_WRITE_PORT_USHORT(pAdapter,MAC_CONTROL_REGISTER,MacControl);
DebugMsg(" Done ! \n");
if (NIC_TxResetAndEnable(pAdapter) != NIC_STATUS_SUCCESS)
{
DebugMsg(" Error: cannot Reset and Enable Tx after setup the media ! \n");
return NIC_STATUS_FAILURE;
}
if (NIC_RxResetAndEnable(pAdapter) != NIC_STATUS_SUCCESS)
{
DebugMsg(" Error: cannot Reset and Enable Rx after setup the media ! \n");
return NIC_STATUS_FAILURE;
}
/*This is for advertisement of flow control. We only need to call this if the adapter
is using flow control, in Autoselect mode and not a Tornado board.
if ( ( pAdapter->Hardware.AutoSelect && pAdapter->LinkInfo.FlowControlEnable) &&
(pAdapter->Hardware.DeviceId != NIC_PCI_DEVICE_ID_9200) &&
(pAdapter->Hardware.DeviceId != NIC_PCI_DEVICE_ID_9805))
{
tc90x_FlowControl(pAdapter);
} */
DebugMsg("Media setup-- Done! \n********************************\n");
return NIC_STATUS_SUCCESS;
}
/***********************************************************************************
**** If autoselection is set, determine the connector and link speed
*** by trying the various transceiver types.
**/
NIC_STATUS NIC_MediaAutoSelect(IN PNIC_INFORMATION pAdapter,IN USHORT Options)
{
USHORT index;
pAdapter->LinkInfo.Connector = CONNECTOR_UNKNOWN;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -