⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 physet.c

📁 e100bex网卡驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
** COPYRIGHT (C) 1994-1997 INTEL CORPORATION                               **
** DEVELOPED FOR MICROSOFT BY INTEL CORP., HILLSBORO, OREGON               **
** HTTP://WWW.INTEL.COM/                                                   **
** THIS FILE IS PART OF THE INTEL ETHEREXPRESS PRO/100B(TM) AND            **
** ETHEREXPRESS PRO/100+(TM) NDIS 5.0 MINIPORT SAMPLE DRIVER               **
****************************************************************************/

/****************************************************************************
Module Name:
    physet.c

This driver runs on the following hardware:
    - 82557/82558 based PCI 10/100Mb ethernet adapters
    (aka Intel EtherExpress(TM) PRO Adapters)

Environment:
    Kernel Mode - Or whatever is the equivalent on WinNT

Revision History
    - JCB 8/14/97 Example Driver Created
*****************************************************************************/

#include "precomp.h"
#pragma hdrstop
#pragma warning (disable: 4514)

//-----------------------------------------------------------------------------
// Procedure:   PhyDetect
//
// Description: This routine will detect what phy we are using, set the line
//              speed, FDX or HDX, and configure the phy if necessary.
//
//              The following combinations are supported:
//              - TX or T4 PHY alone at PHY address 1
//              - T4 or TX PHY at address 1 and MII PHY at address 0
//              - 82503 alone (10Base-T mode, no full duplex support)
//              - 82503 and MII PHY (TX or T4) at address 0
//
//              The sequence / priority of detection is as follows:
//                  If there is a PHY Address override use that address.
//                  else scan based on the 'Connector' setting.
//                      Switch Connector
//                          0 = AutoScan
//                          1 = Onboard TPE only
//                          2 = MII connector only
//
//              Each of the above cases is explained below.
//
//              AutoScan means:
//                Look for link on addresses 1, 0, 2..31 (in that order).  Use the first
//                address found that has link.
//                If link is not found then use the first valid PHY found in the same scan
//                order 1,0,2..31.  NOTE: this means that NO LINK or Multi-link cases will
//                default to the onboard PHY (address 1).
//
//              Onboard TPE only:
//                Phy address is set to 1 (No Scanning).
//
//              MII connector only means:
//                Look for link on addresses 0, 2..31 (again in that order, Note address 1 is
//                NOT scanned).   Use the first address found that has link.
//                If link is not found then use the first valid Phy found in the same scan
//                order 0, 2..31.
//                In the AutoScan case above we should always find a valid PHY at address 1,
//                there is no such guarantee here, so, If NO Phy is found then the driver
//                should default to address 0 and continue to load.  Note: External
//                transceivers should be at address 0 but our early Nitro3 testing found
//                transceivers at several non-zero addresses (6,10,14).
//
//
//   NWAY
//              Additionally auto-negotiation capable (NWAY) and parallel
//              detection PHYs are supported. The flow-chart is described in
//              the 82557 software writer's manual.
//
//   NOTE:  1.  All PHY MDI registers are read in polled mode.
//          2.  The routines assume that the 82557 has been RESET and we have
//              obtained the virtual memory address of the CSR.
//          3.  PhyDetect will not RESET the PHY.
//          4.  If FORCEFDX is set, SPEED should also be set. The driver will
//              check the values for inconsistency with the detected PHY
//              technology.
//          5.  PHY 1 (the PHY on the adapter) MUST be at address 1.
//          6.  Driver ignores FORCEFDX and SPEED overrides if a 503 interface
//              is detected.
//
//
// Arguments:
//      Adapter - ptr to Adapter object instance
//
// Result:
// Returns:
//      TRUE - If a Phy was detected, and configured correctly.
//      FALSE - If a valid phy could not be detected and configured.
//-----------------------------------------------------------------------------

BOOLEAN
PhyDetect(
          IN PD100_ADAPTER Adapter
          )

{
    USHORT      MdiControlReg, MdiStatusReg;
    UCHAR       FoundPhyAt = 0xff;
    UCHAR       i, j;
    char        LookForLink;

    DEBUGFUNC("PhyDetect");

    INITSTR(("\n"));

    // Check for a phy address over-ride of 32 which indicates a 503
    if (Adapter->PhyAddress == 32)
    {
        // 503 interface over-ride
        INITSTR(("   503 serial component over-ride\n"));

        Adapter->PhyAddress = 32;

        // Record the current speed and duplex.  We will be in half duplex
        // mode unless the user used the force full duplex over-ride.
        Adapter->AiLineSpeedCur = 10;
        Adapter->AiDuplexCur = (USHORT) Adapter->AiForceDpx;
        if (!Adapter->AiDuplexCur)
            Adapter->AiDuplexCur = 1;

        return (TRUE);
    }

    // Check for other phy address over-rides.
    //   If the Phy Address is between 0-31 then there is an over-ride.
    //   Or the connector was set to 1
    if ( (Adapter->PhyAddress < 32) || (Adapter->Connector == CONNECTOR_TPE) )
    {   // User Override nothing to do but setup Phy and leave

        if ( (Adapter->PhyAddress > 32) && (Adapter->Connector == CONNECTOR_TPE) )
        {
            Adapter->PhyAddress = 1;  // Connector was forced

            // Isolate all other PHYs and unisolate this one
            SelectPhy(Adapter, Adapter->PhyAddress, FALSE);

        }
        INITSTR(("   Phy address Override to address %d\n", Adapter->PhyAddress));

#if DBG
        // Read the MDI control register at override address.
        MdiRead(Adapter, MDI_CONTROL_REG, Adapter->PhyAddress, &MdiControlReg);

        // Read the status register at override address.
        MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, &MdiStatusReg);
        // Read the status register again because of sticky bits
        MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, &MdiStatusReg);

        // check if we found a valid phy
        if (!((MdiControlReg == 0xffff) || ((MdiStatusReg == 0) && (MdiControlReg == 0))))
        {
            // we have a valid phy1
            INITSTR(("   Over-ride address %d has a valid Phy.\n", Adapter->PhyAddress));

            // Read the status register again
            MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, &MdiStatusReg);

            // If there is a valid link then use this Phy.
            if (MdiStatusReg & MDI_SR_LINK_STATUS)
            {
                INITSTR(("   Phy at address %d has link\n", Adapter->PhyAddress));

            }

        }
        else
        {
            // no PHY at over-ride address
            INITSTR(("   Over-ride address %d has no Phy!!!!\n", Adapter->PhyAddress));

        }
#endif
        return (SetupPhy(Adapter));

    }
    else // Need to scan - No address over-ride and Connector is AUTO or MII
    {
        for (LookForLink=1; LookForLink>=0 ;LookForLink-- )
        {
            // For each PhyAddress 0 - 31
            for (i=0; i<32; i++)
            {
                if (LookForLink)
                {
                    // Phy Addresses must be tested in the order 1,0,2..31.
                    switch (i)
                    {
                    case 0:
                        Adapter->PhyAddress = 1;
                        break;
                    case 1:
                        Adapter->PhyAddress = 0;
                        break;
                    default:
                        Adapter->PhyAddress = i;
                        break;
                    }

                    // Skip OnBoard for MII only case
                    if ((Adapter->PhyAddress == 1)&&(Adapter->Connector == CONNECTOR_MII)) continue;

                    INITSTR(("   Scanning Phy address %d for link\n", Adapter->PhyAddress));

                    // Read the MDI control register
                    MdiRead(Adapter, MDI_CONTROL_REG, Adapter->PhyAddress, &MdiControlReg);

                    // Read the status register
                    MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, &MdiStatusReg);
                    MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, &MdiStatusReg);   // Sticky Bits
                }
                else
                {   // Not looking for link
                    if (FoundPhyAt < 32)
                        Adapter->PhyAddress = FoundPhyAt;
                    else  // No valid PHYs were found last time so just default
                        if (Adapter->Connector == CONNECTOR_MII)
                            Adapter->PhyAddress = 0;  // Default for MII
                        else // assume a 503 interface
                        {
                            Adapter->PhyAddress = 32;

                            // Record the current speed and duplex.  We will be in half duplex
                            // mode unless the user used the force full duplex over-ride.
                            Adapter->AiLineSpeedCur = 10;
                            Adapter->AiDuplexCur = (USHORT) Adapter->AiForceDpx;
                            if (!Adapter->AiDuplexCur)
                                Adapter->AiDuplexCur = 1;

                            return (TRUE);
                        }

                        INITSTR(("   No Links Found!!\n"));
                }

                // check if we found a valid phy or on !LookForLink pass
                if ( !( (MdiControlReg == 0xffff) || ((MdiStatusReg == 0) && (MdiControlReg == 0))
                    ) || (!LookForLink)
                    )
                {   // Valid phy or Not looking for Link

#if DBG
                    if (!( (MdiControlReg == 0xffff) || ((MdiStatusReg == 0) && (MdiControlReg == 0))
                        )
                        )
                    {
                        INITSTR(("      Found a Phy at address %d\n", Adapter->PhyAddress));
                    }
#endif
                    // Store highest priority phy found for NO link case
                    if (i < FoundPhyAt && FoundPhyAt != 1)
                    {
                        // this phy is higher priority
                        FoundPhyAt = (UCHAR) Adapter->PhyAddress;
                    }

                    // Select Phy before checking link status
                    // NOTE: may take up to 3.5 Sec if LookForLink == TRUE
                    SelectPhy(Adapter, Adapter->PhyAddress, (BOOLEAN)LookForLink);

                    // Read the MDI control register
                    MdiRead(Adapter, MDI_CONTROL_REG, Adapter->PhyAddress, &MdiControlReg);

                    // Read the status register
                    MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, &MdiStatusReg);
                    MdiRead(Adapter, MDI_STATUS_REG, Adapter->PhyAddress, &MdiStatusReg);

                    // If there is a valid link or we alreadry tried once then use this Phy.
                    if ((MdiStatusReg & MDI_SR_LINK_STATUS) || (!LookForLink))
                    {
#if DBG
                        if (MdiStatusReg & MDI_SR_LINK_STATUS)
                        {
                            INITSTR(("   Using Phy at address %d with link\n", Adapter->PhyAddress));
                        }
                        else
                        {
                            INITSTR(("   Using Phy at address %d WITHOUT link!!!\n", Adapter->PhyAddress));
                        }
#endif

                        return (SetupPhy(Adapter));    // Exit with Link Path
                    }
                } // End if valid PHY
            } // End for each PHY address
        } // End LookForLink
    } // End else scan

    return (FALSE);
}


//***************************************************************************
//
// Name:            SelectPhy
//
// Description:     This routine will Isolate all Phy addresses on the MII
//                  Bus except for the one address to be 'selected'.  This
//                  Phy address will be un-isolated and auto-negotiation will
//                  be enabled, started, and completed.  The Phy will NOT be
//                  reset and the speed will NOT be set to any value (that is
//                  done in SetupPhy).
//
// Arguments:       SelectPhyAddress - PhyAddress to select
//                  WaitAutoNeg      - Flag TRUE = Wait for Auto Negociation to complete.
//                                          FALSE = don't wait. Good for 'No Link' case.
//
// Returns:         Nothing
//
// Modification log:
// Date      Who  Description
// --------  ---  --------------------------------------------------------
//***************************************************************************
VOID
SelectPhy(
          IN PD100_ADAPTER Adapter,
          IN UINT SelectPhyAddress,
          IN BOOLEAN WaitAutoNeg
          )
{
    UCHAR i;
    USHORT      MdiControlReg, MdiStatusReg;


    // Isolate all other phys and unisolate the one to query
    for (i = 0; i < 32; i++ )
    {
        if (i != SelectPhyAddress)
        {
            // isolate this phy
            MdiWrite(Adapter, MDI_CONTROL_REG, i, MDI_CR_ISOLATE);
            // wait 100 microseconds for the phy to isolate.
            NdisStallExecution(100);
        }
    }

    // unisolate the phy to query

    // Read the MDI control register
    MdiRead(Adapter, MDI_CONTROL_REG, SelectPhyAddress, &MdiControlReg);

    // Set/Clear bit unisolate this phy
    MdiControlReg &= ~MDI_CR_ISOLATE;             // Clear the Isolate Bit

    // issue the command to unisolate this Phy
    MdiWrite(Adapter, MDI_CONTROL_REG, SelectPhyAddress, MdiControlReg);

    // sticky bits on link
    MdiRead(Adapter, MDI_STATUS_REG, SelectPhyAddress, &MdiStatusReg);
    MdiRead(Adapter, MDI_STATUS_REG, SelectPhyAddress, &MdiStatusReg);

    // if we have link, don't mess with the phy
    if (MdiStatusReg & MDI_SR_LINK_STATUS)
        return;

    // Read the MDI control register
    MdiRead(Adapter, MDI_CONTROL_REG, SelectPhyAddress, &MdiControlReg);

    // set Restart auto-negotiation
    MdiControlReg |= MDI_CR_AUTO_SELECT;          // Set Auto Neg Enable
    MdiControlReg |= MDI_CR_RESTART_AUTO_NEG;     // Restart Auto Neg

    // restart the auto-negotion process
    MdiWrite(Adapter, MDI_CONTROL_REG, SelectPhyAddress, MdiControlReg);

    // wait 200 microseconds for the phy to unisolate.
    NdisStallExecution(200);

    if (WaitAutoNeg)
    {
        // wait for auto-negotiation to complete (up to 3.5 seconds)
        for (i = RENEGOTIATE_TIME; i != 0; i-- )
        {
            // Read the status register twice because of sticky bits
            MdiRead(Adapter, MDI_STATUS_REG, SelectPhyAddress, &MdiStatusReg);
            MdiRead(Adapter, MDI_STATUS_REG, SelectPhyAddress, &MdiStatusReg);

            if (MdiStatusReg & MDI_SR_AUTO_NEG_COMPLETE)
                break;

            D100StallExecution(100);
        }
    }
}

//-----------------------------------------------------------------------------
// Procedure:   SetupPhy
//
// Description: This routine will setup phy 1 or phy 0 so that it is configured
//              to match a speed and duplex over-ride option.  If speed or
//              duplex mode is not explicitly specified in the registry, the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -