📄 physet.c
字号:
MdiControlReg &= ~(MDI_CR_AUTO_SELECT | MDI_CR_FULL_HALF);
MdiControlReg |= MDI_CR_10_100;
ForcePhySetting = TRUE;
Adapter->AiForceDpx = 1;
}
}
}
if (ForcePhySetting == FALSE)
{
DBGPRINT(MP_INFO, (" Can't force speed=%d, duplex=%d\n",Adapter->AiTempSpeed, Adapter->AiForceDpx));
return(NDIS_STATUS_FAILURE);
}
//
// Write the MDI control register with our new Phy configuration
//
MdiWrite(Adapter, MDI_CONTROL_REG, Adapter->PhyAddress, MdiControlReg);
//
// wait 100 milliseconds for auto-negotiation to complete
//
MP_STALL_EXECUTION(100);
}
//
// Find out specifically what Phy this is. We do this because for certain
// phys there are specific bits that must be set so that the phy and the
// 82557 work together properly.
//
MdiRead(Adapter, PHY_ID_REG_1, Adapter->PhyAddress, FALSE, &MdiIdLowReg);
MdiRead(Adapter, PHY_ID_REG_2, Adapter->PhyAddress, FALSE, &MdiIdHighReg);
PhyId = ((UINT) MdiIdLowReg | ((UINT) MdiIdHighReg << 16));
DBGPRINT(MP_INFO, (" Phy ID is %x\n", PhyId));
//
// And out the revsion field of the Phy ID so that we'll be able to detect
// future revs of the same Phy.
//
PhyId &= PHY_MODEL_REV_ID_MASK;
//
// Handle the National TX
//
if (PhyId == PHY_NSC_TX)
{
DBGPRINT(MP_INFO, (" Found a NSC TX Phy\n"));
MdiRead(Adapter, NSC_CONG_CONTROL_REG, Adapter->PhyAddress, FALSE, &MdiMiscReg);
MdiMiscReg |= (NSC_TX_CONG_TXREADY | NSC_TX_CONG_F_CONNECT);
//
// If we are configured to do congestion control, then enable the
// congestion control bit in the National Phy
//
if (Adapter->Congest)
MdiMiscReg |= NSC_TX_CONG_ENABLE;
else
MdiMiscReg &= ~NSC_TX_CONG_ENABLE;
MdiWrite(Adapter, NSC_CONG_CONTROL_REG, Adapter->PhyAddress, MdiMiscReg);
}
FindPhySpeedAndDpx(Adapter, PhyId);
DBGPRINT(MP_WARN, (" Current Speed=%d, Current Duplex=%d\n",Adapter->usLinkSpeed, Adapter->usDuplexMode));
return(NDIS_STATUS_SUCCESS);
}
//-----------------------------------------------------------------------------
// Procedure: FindPhySpeedAndDpx
//
// Description: This routine will figure out what line speed and duplex mode
// the PHY is currently using.
//
// Arguments:
// Adapter - ptr to Adapter object instance
// PhyId - The ID of the PHY in question.
//
// Returns:
// NOTHING
//-----------------------------------------------------------------------------
VOID FindPhySpeedAndDpx(
IN PMP_ADAPTER Adapter,
IN UINT PhyId
)
{
USHORT MdiStatusReg = 0;
USHORT MdiMiscReg = 0;
USHORT MdiOwnAdReg = 0;
USHORT MdiLinkPartnerAdReg = 0;
//
// If there was a speed and/or duplex override, then set our current
// value accordingly
//
Adapter->usLinkSpeed = Adapter->AiTempSpeed;
Adapter->usDuplexMode = (USHORT) Adapter->AiForceDpx;
//
// If speed and duplex were forced, then we know our current settings, so
// we'll just return. Otherwise, we'll need to figure out what NWAY set
// us to.
//
if (Adapter->usLinkSpeed && Adapter->usDuplexMode)
{
return;
}
//
// If we didn't have a valid link, then we'll assume that our current
// speed is 10mb half-duplex.
//
//
// Read the status register twice because of sticky bits
//
MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, FALSE, &MdiStatusReg);
MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, FALSE, &MdiStatusReg);
//
// If there wasn't a valid link then use default speed & duplex
//
if (!(MdiStatusReg & MDI_SR_LINK_STATUS))
{
DBGPRINT(MP_INFO, (" Link Not found for speed detection!!! Using defaults.\n"));
Adapter->usLinkSpeed = 10;
Adapter->usDuplexMode = 1;
return;
}
//
// If this is an Intel PHY (a T4 PHY_100 or a TX PHY_TX), then read bits
// 1 and 0 of extended register 0, to get the current speed and duplex
// settings.
//
if ((PhyId == PHY_100_A) || (PhyId == PHY_100_C) || (PhyId == PHY_TX_ID))
{
DBGPRINT(MP_INFO, (" Detecting Speed/Dpx for an Intel PHY\n"));
//
// Read extended register 0
//
MdiRead(Adapter, EXTENDED_REG_0, Adapter->PhyAddress, FALSE, &MdiMiscReg);
//
// Get current speed setting
//
if (MdiMiscReg & PHY_100_ER0_SPEED_INDIC)
{
Adapter->usLinkSpeed = 100;
}
else
{
Adapter->usLinkSpeed = 10;
}
//
//
// Get current duplex setting -- if bit is set then FDX is enabled
//
if (MdiMiscReg & PHY_100_ER0_FDX_INDIC)
{
Adapter->usDuplexMode = 2;
}
else
{
Adapter->usDuplexMode = 1;
}
return;
}
//
// Read our link partner's advertisement register
//
MdiRead(Adapter,
AUTO_NEG_LINK_PARTNER_REG,
Adapter->PhyAddress,
FALSE,
&MdiLinkPartnerAdReg);
//
// See if Auto-Negotiation was complete (bit 5, reg 1)
//
MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, FALSE, &MdiStatusReg);
//
// If a True NWAY connection was made, then we can detect speed/duplex by
// ANDing our adapter's advertised abilities with our link partner's
// advertised ablilities, and then assuming that the highest common
// denominator was chosed by NWAY.
//
if ((MdiLinkPartnerAdReg & NWAY_LP_ABILITY) &&
(MdiStatusReg & MDI_SR_AUTO_NEG_COMPLETE))
{
DBGPRINT(MP_INFO, (" Detecting Speed/Dpx from NWAY connection\n"));
//
// Read our advertisement register
//
MdiRead(Adapter, AUTO_NEG_ADVERTISE_REG, Adapter->PhyAddress, FALSE, &MdiOwnAdReg);
//
// AND the two advertisement registers together, and get rid of any
// extraneous bits.
//
MdiOwnAdReg &= (MdiLinkPartnerAdReg & NWAY_LP_ABILITY);
//
// Get speed setting
//
if (MdiOwnAdReg & (NWAY_AD_TX_HALF_DPX | NWAY_AD_TX_FULL_DPX | NWAY_AD_T4_CAPABLE))
{
Adapter->usLinkSpeed = 100;
}
else
{
Adapter->usLinkSpeed = 10;
}
//
// Get duplex setting -- use priority resolution algorithm
//
if (MdiOwnAdReg & (NWAY_AD_T4_CAPABLE))
{
Adapter->usDuplexMode = 1;
return;
}
else if (MdiOwnAdReg & (NWAY_AD_TX_FULL_DPX))
{
Adapter->usDuplexMode = 2;
return;
}
else if (MdiOwnAdReg & (NWAY_AD_TX_HALF_DPX))
{
Adapter->usDuplexMode = 1;
return;
}
else if (MdiOwnAdReg & (NWAY_AD_10T_FULL_DPX))
{
Adapter->usDuplexMode = 2;
return;
}
else
{
Adapter->usDuplexMode = 1;
return;
}
}
//
// If we are connected to a non-NWAY repeater or hub, and the line
// speed was determined automatically by parallel detection, then we have
// no way of knowing exactly what speed the PHY is set to unless that PHY
// has a propietary register which indicates speed in this situation. The
// NSC TX PHY does have such a register. Also, since NWAY didn't establish
// the connection, the duplex setting should HALF duplex.
//
Adapter->usDuplexMode = 1;
if (PhyId == PHY_NSC_TX)
{
DBGPRINT(MP_INFO, (" Detecting Speed/Dpx from non-NWAY NSC connection\n"));
//
// Read register 25 to get the SPEED_10 bit
//
MdiRead(Adapter, NSC_SPEED_IND_REG, Adapter->PhyAddress, FALSE, &MdiMiscReg);
//
// If bit 6 was set then we're at 10mb
//
if (MdiMiscReg & NSC_TX_SPD_INDC_SPEED)
{
Adapter->usLinkSpeed = 10;
}
else
{
Adapter->usLinkSpeed = 100;
}
}
//
// If we don't know what line speed we are set at, then we'll default to
// 10mbs
//
else
{
Adapter->usLinkSpeed = 10;
}
}
//-----------------------------------------------------------------------------
// Procedure: ResetPhy
//
// Description: This routine will reset the PHY that the adapter is currently
// configured to use.
//
// Arguments:
// Adapter - ptr to Adapter object instance
//
// Returns:
// NOTHING
//-----------------------------------------------------------------------------
VOID ResetPhy(
IN PMP_ADAPTER Adapter
)
{
USHORT MdiControlReg;
//
// Reset the Phy, enable auto-negotiation, and restart auto-negotiation.
//
MdiControlReg = (MDI_CR_AUTO_SELECT | MDI_CR_RESTART_AUTO_NEG | MDI_CR_RESET);
//
// Write the MDI control register with our new Phy configuration
//
MdiWrite(Adapter, MDI_CONTROL_REG, Adapter->PhyAddress, MdiControlReg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -