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

📄 init.c

📁 e100bex网卡驱动程序
💻 C
📖 第 1 页 / 共 4 页
字号:
                  // Arguments:
                  //      Adapter - ptr to Adapter object instance
//
// Returns:
//      TRUE - If 82557 chip was initialized
//      FALSE - If 82557 failed initialization
//-----------------------------------------------------------------------------

BOOLEAN
InitializeD100(
               IN PD100_ADAPTER Adapter
               )

{
    DEBUGFUNC("InitializeD100");

    INITSTR(("\n"));

    // Issue a software reset to the D100
    (void) SoftwareReset(Adapter);

    // Load the CU BASE (set to 0, because we use linear mode)
    Adapter->CSRAddress->ScbGeneralPointer = 0;
    D100IssueScbCommand(Adapter, SCB_CUC_LOAD_BASE, FALSE);

    // Wait for the SCB command word to clear before we set the general pointer
    WaitScb(Adapter);

    // Load the RU BASE (set to 0, because we use linear mode)
    Adapter->CSRAddress->ScbGeneralPointer = 0;
    D100IssueScbCommand(Adapter, SCB_RUC_LOAD_BASE, FALSE);

    // Configure the adapter
    if (!Configure(Adapter))
        return (FALSE);

    // Wait 500 milliseconds
    D100StallExecution(500);

    if (!SetupIAAddress(Adapter))
        return (FALSE);

    // Clear the internal counters
    ClearAllCounters(Adapter);

    return (TRUE);
}


//-----------------------------------------------------------------------------
// Procedure:   Configure
//
// Description: This routine will issue a configure command to the 82557.
//              This command will be executed in polled mode.  The
//              Configuration parameters that are user configurable will
//              have been set when the driver parsed the configuration
//              parameters out of the registry.
//
// Arguments:
//      Adapter - ptr to Adapter object instance
//
// Returns:
//      TRUE - If the configure command was successfully issued and completed
//      FALSE - If the configure command failed to complete properly
//-----------------------------------------------------------------------------

BOOLEAN
Configure(
          IN PD100_ADAPTER Adapter
          )

{
    UINT    i;

    DEBUGFUNC("Configure");

    INITSTR(("\n"));

    // Init the packet filter to directed and multicast.
    Adapter->PacketFilter = NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_MULTICAST;

    // Setup the non-transmit command block header for the configure command.
    Adapter->NonTxCmdBlockHdr->CbStatus = 0;
    Adapter->NonTxCmdBlockHdr->CbCommand = CB_CONFIGURE;
    Adapter->NonTxCmdBlockHdr->CbLinkPointer = DRIVER_NULL;

    // Fill in the configure command data.

    // First fill in the static (end user can't change) config bytes
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[0] = CB_557_CFIG_DEFAULT_PARM0;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[2] = CB_557_CFIG_DEFAULT_PARM2;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[3] = CB_557_CFIG_DEFAULT_PARM3;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[6] = CB_557_CFIG_DEFAULT_PARM6;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[9] = CB_557_CFIG_DEFAULT_PARM9;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[10] = CB_557_CFIG_DEFAULT_PARM10;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[11] = CB_557_CFIG_DEFAULT_PARM11;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[12] = CB_557_CFIG_DEFAULT_PARM12;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[13] = CB_557_CFIG_DEFAULT_PARM13;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[14] = CB_557_CFIG_DEFAULT_PARM14;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[16] = CB_557_CFIG_DEFAULT_PARM16;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[17] = CB_557_CFIG_DEFAULT_PARM17;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[18] = CB_557_CFIG_DEFAULT_PARM18;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[20] = CB_557_CFIG_DEFAULT_PARM20;
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[21] = CB_557_CFIG_DEFAULT_PARM21;

    // Now fill in the rest of the configuration bytes (the bytes that contain
    // user configurable parameters).

    // Set the Tx and Rx Fifo limits
    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[1] =
        (UCHAR) ((Adapter->AiTxFifo << 4) | Adapter->AiRxFifo);

    if (Adapter->MWIEnable)
    {
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[3] |= CB_CFIG_B3_MWI_ENABLE;
    }

    // Set the Tx and Rx DMA maximum byte count fields.
    if ((Adapter->AiRxDmaCount) || (Adapter->AiTxDmaCount))
    {
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[4] =
            Adapter->AiRxDmaCount;
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[5] =
            (UCHAR) (Adapter->AiTxDmaCount | CB_CFIG_DMBC_EN);
    }
    else
    {
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[4] =
            CB_557_CFIG_DEFAULT_PARM4;
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[5] =
            CB_557_CFIG_DEFAULT_PARM5;
    }


    Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[7] =
        (UCHAR) ((CB_557_CFIG_DEFAULT_PARM7 & (~CB_CFIG_URUN_RETRY)) |
        (Adapter->AiUnderrunRetry << 1)
        );

    // Setup for MII or 503 operation.  The CRS+CDT bit should only be set
    // when operating in 503 mode.
    if (Adapter->PhyAddress == 32)
    {
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[8] =
            (CB_557_CFIG_DEFAULT_PARM8 & (~CB_CFIG_503_MII));
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[15] =
            (CB_557_CFIG_DEFAULT_PARM15 | CB_CFIG_CRS_OR_CDT);
    }
    else
    {
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[8] =
            (CB_557_CFIG_DEFAULT_PARM8 | CB_CFIG_503_MII);
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[15] =
            (CB_557_CFIG_DEFAULT_PARM15 & (~CB_CFIG_CRS_OR_CDT));
    }


    // Setup Full duplex stuff

    // If forced to half duplex
    if (Adapter->AiForceDpx == 1)
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[19] =
        (CB_557_CFIG_DEFAULT_PARM19 &
        (~(CB_CFIG_FORCE_FDX| CB_CFIG_FDX_ENABLE)));

    // If forced to full duplex
    else if (Adapter->AiForceDpx == 2)
        Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[19] =
        (CB_557_CFIG_DEFAULT_PARM19 | CB_CFIG_FORCE_FDX);

    // If auto-duplex
    else
    {
        // We must force full duplex on if we are using PHY 0, and we are
        // supposed to run in FDX mode.  We do this because the D100 has only
        // one FDX# input pin, and that pin will be connected to PHY 1.
        if ((Adapter->PhyAddress == 0) && (Adapter->AiDuplexCur == 2))
            Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[19] =
            (CB_557_CFIG_DEFAULT_PARM19 | CB_CFIG_FORCE_FDX);
        else
            Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[19] =
            CB_557_CFIG_DEFAULT_PARM19;
    }

    //
    // Store the current setting for BROADCAST/PROMISCUOS modes
    Adapter->OldParameterField = CB_557_CFIG_DEFAULT_PARM15;

    // display the config info to the debugger
    INITSTR(("Issuing Configure command\n"));
    INITSTR(("Config Block at virt addr %x, phys address %x\n",
        &Adapter->NonTxCmdBlockHdr->CbStatus, Adapter->NonTxCmdBlockPhys));

    for (i=0; i < CB_CFIG_BYTE_COUNT; i++)
        INITSTR(("  Config byte %x = %.2x\n", i, Adapter->NonTxCmdBlock->NonTxCb.Config.ConfigBytes[i]));

    // Wait for the SCB command word to clear before we set the general pointer
    WaitScb(Adapter);

    ASSERT(Adapter->CSRAddress->ScbCommandLow == 0)
        Adapter->CSRAddress->ScbGeneralPointer = Adapter->NonTxCmdBlockPhys;

    // Submit the configure command to the chip, and wait for it to complete.
    if (!D100SubmitCommandBlockAndWait(Adapter))
        return (FALSE);
    else
        return (TRUE);
}


//-----------------------------------------------------------------------------
// Procedure:   SetupIAAddress
//
// Description: This routine will issue the IA setup command.  This command
//              will notify the 82557 (D100) of what its individual (node)
//              address is.  This command will be executed in polled mode.
//
// Arguments:
//      Adapter - ptr to Adapter object instance
//
// Returns:
//      TRUE - If the IA setup command was successfully issued and completed
//      FALSE - If the IA setup command failed to complete properly
//-----------------------------------------------------------------------------

BOOLEAN
SetupIAAddress(
               IN PD100_ADAPTER Adapter
               )

{
    UINT        i;

    DEBUGFUNC("SetupIAAddress");


    // Individual Address Setup
    Adapter->NonTxCmdBlockHdr->CbStatus = 0;
    Adapter->NonTxCmdBlockHdr->CbCommand = CB_IA_ADDRESS;
    Adapter->NonTxCmdBlockHdr->CbLinkPointer = DRIVER_NULL;

    // Copy in the station's individual address
    for (i = 0; i < ETH_LENGTH_OF_ADDRESS; i++)
        Adapter->NonTxCmdBlock->NonTxCb.Setup.IaAddress[i] = Adapter->AiNodeAddress[i];

    // Update the command list pointer.  We don't need to do a WaitSCB here
    // because this command is either issued immediately after a reset, or
    // after another command that runs in polled mode.  This guarantees that
    // the low byte of the SCB command word will be clear.  The only commands
    // that don't run in polled mode are transmit and RU-start commands.
    ASSERT(Adapter->CSRAddress->ScbCommandLow == 0)
        Adapter->CSRAddress->ScbGeneralPointer = Adapter->NonTxCmdBlockPhys;

    // Submit the IA configure command to the chip, and wait for it to complete.
    if (D100SubmitCommandBlockAndWait(Adapter) == FALSE)
    {
        TRACESTR(Adapter, ("IA setup failed\n"));
        return (FALSE);
    }

    else
        return (TRUE);
}


//-----------------------------------------------------------------------------
// Procedure:   ClearAllCounters
//
// Description: This routine will clear the 82596/82556 error statistic
//              counters.
//
// Arguments:
//      Adapter - ptr to Adapter object instance
//
// Returns:
//-----------------------------------------------------------------------------

VOID
ClearAllCounters(
                 IN PD100_ADAPTER Adapter
                 )

{
    UINT    counter;
    DEBUGFUNC("ClearAllCounters");

    INITSTR(("\n"));


    // Load the dump counters pointer.  Since this command is generated only
    // after the IA setup has complete, we don't need to wait for the SCB
    // command word to clear
    ASSERT(Adapter->CSRAddress->ScbCommandLow == 0)
        Adapter->CSRAddress->ScbGeneralPointer = Adapter->StatsCounterPhys;

    // Issue the load dump counters address command
    D100IssueScbCommand(Adapter, SCB_CUC_DUMP_ADDR, FALSE);

    // Now dump and reset all of the statistics
    D100IssueScbCommand(Adapter, SCB_CUC_DUMP_RST_STAT, TRUE);

    // Now wait for the dump/reset to complete
    for (counter = 100000; counter != 0; counter--)
    {
        if (Adapter->StatsCounters->CommandComplete == 0xA007)
            break;
        NdisStallExecution(20);
    }
    if (!counter)
    {
        HARDWARE_NOT_RESPONDING (Adapter);
        return;
    }

    // init packet counts
    Adapter->GoodTransmits = 0;
    Adapter->GoodReceives = 0;

    // init transmit error counts
    Adapter->TxAbortExcessCollisions = 0;
    Adapter->TxLateCollisions = 0;
    Adapter->TxDmaUnderrun = 0;
    Adapter->TxLostCRS = 0;
    Adapter->TxOKButDeferred = 0;
    Adapter->OneRetry = 0;
    Adapter->MoreThanOneRetry = 0;
    Adapter->TotalRetries = 0;

    // init receive error counts
    Adapter->RcvCrcErrors = 0;
    Adapter->RcvAlignmentErrors = 0;
    Adapter->RcvResourceErrors = 0;
    Adapter->RcvDmaOverrunErrors = 0;
    Adapter->RcvCdtFrames = 0;
    Adapter->RcvRuntErrors = 0;
}

⌨️ 快捷键说明

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