eth8xxc.c

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 1,543 行 · 第 1/4 页

C
1,543
字号
    NdisMRegisterAdapterShutdownHandler(Adapter->MiniportAdapterHandle,
                    Adapter,
                    eth8xxShutdown);

    /* Initialization completed successfully. */
    DEBUGMSG(ZONE_INIT | ZONE_FUNCTION,
    (TEXT("-ETH8XX: eth8xxRegisterAdapter\r\n")));

    return(NDIS_STATUS_SUCCESS);

    /* Code to unwind what has already been set up when a part of
     * initialization fails, which is jumped into at various
     * points based on where the failure occured. Jumping to
     * a higher-numbered failure point will execute the code
     * for that block and all lower-numbered ones.
     */

fail3:
    /* Take us out of the AdapterQueue. */
    if (eth8xxMiniportBlock.AdapterQueue == Adapter)
    {
        eth8xxMiniportBlock.AdapterQueue = Adapter->NextAdapter;

    } else {

        TmpAdapter = eth8xxMiniportBlock.AdapterQueue;
        while (TmpAdapter->NextAdapter != Adapter)
    {
            TmpAdapter = TmpAdapter->NextAdapter;
        }
        TmpAdapter->NextAdapter = Adapter->NextAdapter;
    }
    /* Ethernet interrupts already enabled, so turn them off. */
    HW_Block_Interrupts(Adapter);

fail2:
    DEBUGMSG(ZONE_INIT|ZONE_FUNCTION,(TEXT("-ETH8XX:eth8xxRegisterAdap\r\n")));
    return(status);
}


/*----------------------------------------------------------------------*/
VOID eth8xxShutdown(IN NDIS_HANDLE MiniportAdapterContext)
/*++

Description:

    eth8xxShutdown is called to restore an adapter to its initial state
    so that it is ready to be reinitialized when the machine is rebooted.
    We need to unblock any threads and terminate any loops.

Arguments:

    MiniportAdapterContext - the context value that the miniport
                 returned from eth8xxInitialize
                 (actually a pointer to an ETH8XX_ADAPTER)

Return Value:

    None

--*/    
{
    PETH8XX_ADAPTER Adapter =
        PETH8XX_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);

    DEBUGMSG(ZONE_INIT|ZONE_FUNCTION,(TEXT("+ETH8XX:eth8xxShutdown\r\n")));
RETAILMSG(1,(TEXT("+ETH8XX:eth8xxShutdown\r\n")));

    Adapter->Status = SHUTDOWN;
    HW_Stop(Adapter);

    DEBUGMSG(ZONE_INIT|ZONE_FUNCTION,(TEXT("-ETH8XX:eth8xxShutdown\r\n")));
}


/*----------------------------------------------------------------------*/
VOID eth8xxHalt(IN NDIS_HANDLE MiniportAdapterContext)
/*++

Description:

    ETH8XXHalt removes an adapter that was previously initialized.

Arguments:

    MiniportAdapterContext - the context value that the miniport
                 returned from eth8xxInitialize
                 (actually a pointer to an ETH8XX_ADAPTER)

Return Value:

    None

--*/
{
    PETH8XX_ADAPTER Adapter =
    PETH8XX_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);

    DEBUGMSG(ZONE_INIT|ZONE_FUNCTION,(TEXT("+ETH8XX:eth8xxHalt\r\n")));
RETAILMSG(1,(TEXT("+ETH8XX:eth8xxHalt\r\n")));

    /* Shut down the chip. */
    HW_Stop(Adapter);

    /* Disconnect the interrupt line. */
    NdisMDeregisterInterrupt(&Adapter->Interrupt);

    /* Deregister the shutdown handler function. */
    NdisMDeregisterAdapterShutdownHandler(MiniportAdapterContext);

    /* Remove the adapter from the global queue of adapters. */
    if (eth8xxMiniportBlock.AdapterQueue == Adapter)
    {
        eth8xxMiniportBlock.AdapterQueue = Adapter->NextAdapter;

    } else {

        PETH8XX_ADAPTER TmpAdapter = eth8xxMiniportBlock.AdapterQueue;
        while (TmpAdapter->NextAdapter != Adapter)
    {
            TmpAdapter = TmpAdapter->NextAdapter;
        }
        TmpAdapter->NextAdapter = TmpAdapter->NextAdapter->NextAdapter;
    }

    /* was this the last NIC? */
    if ((eth8xxMiniportBlock.AdapterQueue == NULL) &&
    (eth8xxMiniportBlock.NdisWrapperHandle))
    {
    NdisTerminateWrapper(eth8xxMiniportBlock.NdisWrapperHandle, NULL);
    eth8xxMiniportBlock.NdisWrapperHandle = NULL;
    }

    /* Free up the memory. */
    NdisFreeMemory(Adapter, sizeof(ETH8XX_ADAPTER), 0);

    DEBUGMSG(ZONE_INIT|ZONE_FUNCTION,(TEXT("-ETH8XX:eth8xxHalt\r\n")));
    return;
}


/*----------------------------------------------------------------------*/
NDIS_STATUS eth8xxReset(OUT PBOOLEAN    AddressingReset,
                        IN  NDIS_HANDLE MiniportAdapterContext)
/*++

Description:

    The ETH8XXReset request instructs the miniport to issue a
    hardware reset to the network adapter.  The driver also
    resets its software state. See the description of NdisMReset()
    for a detailed description of this request.

Arguments:

    AddressingReset        - does the adapter need the addressing
                             information reloaded?
    MiniportAdapterContext - the context value that the miniport
                 returned from eth8xxInitialize
                 (actually a pointer to an ETH8XX_ADAPTER)

Return Value:

    NDIS_STATUS_SUCCESS - adapter reset successful
    NDIS_STATUS_FAILURE - otherwise

--*/
{
    PETH8XX_ADAPTER  Adapter =
    PETH8XX_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);
    NDIS_STATUS      rc = NDIS_STATUS_SUCCESS;

    DEBUGMSG(ZONE_INIT | ZONE_FUNCTION, (TEXT("+ETH8XX:eth8xxReset\r\n")));
RETAILMSG(1, (TEXT("+ETH8XX:eth8xxReset\r\n")));

    if (!HW_Reset(Adapter))
    {
    rc = NDIS_STATUS_FAILURE;
    }

    /* Let NDIS call eth8xxSetInformation() to restore setup information. */
    *AddressingReset = TRUE;

    DEBUGMSG(ZONE_INIT | ZONE_FUNCTION, (TEXT("-ETH8XX:eth8xxReset\r\n")));

    /* Reset complete. */
    return(rc);
}


/*----------------------------------------------------------------------*/
NDIS_STATUS eth8xxQueryInformation(IN NDIS_HANDLE MiniportAdapterContext,
                                   IN NDIS_OID    Oid,
                                   IN PVOID       InformationBuffer,
                                   IN ULONG       InformationBufferLength,
                                   OUT PULONG     BytesWritten,
                                   OUT PULONG     BytesNeeded)
/*++

Description:

    The ETH8XXQueryInformation process a Query request for
    NDIS_OIDs that are specific to the Driver.

Arguments:

    MiniportAdapterContext  - the context value that the miniport
                  returned from eth8xxInitialize
                  (actually a pointer to an ETH8XX_ADAPTER)
    Oid                     - the NDIS OID to process
    InformationBuffer       - a pointer into the buffer into which to
                              store the result of this query
    InformationBufferLength - a pointer to the number of bytes left in
                      the buffer
    BytesWritten            - a pointer to the number of bytes written
                              into the buffer
    BytesNeeded             - if there is not enough room in the buffer
                              then this will contain the number of bytes
                  needed to complete the request

Return Value:

    NDIS_STATUS_SUCCESS        - if the request information was obtained
    NDIS_STATUS_INVALID_LENGTH - if the buffer supplied was too small to
                     hold the requested information

--*/
{
    /* Pointer to the adapter structure. */
    PETH8XX_ADAPTER      Adapter        =
    PETH8XX_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);
    UINT                 BytesLeft      = InformationBufferLength;
    PUCHAR               InfoBuffer     = (PUCHAR)(InformationBuffer);
    NDIS_STATUS          Rc             = NDIS_STATUS_SUCCESS;
    ULONG                GenericULong;
    USHORT               GenericUShort;
    UCHAR                GenericArray[ETH_LENGTH_OF_ADDRESS];
    UINT                 MoveBytes      = sizeof(ULONG);
    PVOID                MoveSource     = (PVOID)(&GenericULong);
    NDIS_HARDWARE_STATUS HardwareStatus = NdisHardwareStatusReady;
    NDIS_MEDIUM          Medium         = NdisMedium802_3;

    DEBUGMSG(ZONE_INIT | ZONE_FUNCTION,
    (TEXT("+ETH8XX:eth8xxQuery: 0x%X\r\n"), Oid));

    /* Switch on the request type. */
    switch (Oid)
    {
        case OID_GEN_MAC_OPTIONS:
            GenericULong = (ULONG)(NDIS_MAC_OPTION_TRANSFERS_NOT_PEND
                 |         NDIS_MAC_OPTION_RECEIVE_SERIALIZED
             |         NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA
             |         NDIS_MAC_OPTION_NO_LOOPBACK
             );
            break;
        case OID_GEN_SUPPORTED_LIST:
            MoveSource = (PVOID)(eth8xxSupportedOids);
            MoveBytes  = sizeof(eth8xxSupportedOids);
            break;
        case OID_GEN_HARDWARE_STATUS:
            HardwareStatus = NdisHardwareStatusReady;
            MoveSource     = (PVOID)(&HardwareStatus);
            MoveBytes      = sizeof(NDIS_HARDWARE_STATUS);
            break;
        case OID_GEN_MEDIA_SUPPORTED:
        case OID_GEN_MEDIA_IN_USE:
            MoveSource = (PVOID) (&Medium);
            MoveBytes = sizeof(NDIS_MEDIUM);
            break;
        case OID_GEN_MAXIMUM_LOOKAHEAD:
            GenericULong = ETH8XX_MAX_LOOKAHEAD;
            break;
        case OID_GEN_MAXIMUM_FRAME_SIZE:
            GenericULong = ETH_MAX_DATA_SIZE;
            break;
        case OID_GEN_MAXIMUM_TOTAL_SIZE:
            GenericULong = ETH_HEADER_SIZE + ETH_MAX_DATA_SIZE;
            break;
        case OID_GEN_LINK_SPEED:
            GenericULong = (ULONG)(10000000);   /* 10 Mbps */
            break;
        case OID_GEN_TRANSMIT_BUFFER_SPACE:
            GenericULong = (ULONG)(Adapter->NbrTxBuffers
                 * Adapter->MaxTxBufferSize);
            break;
        case OID_GEN_RECEIVE_BUFFER_SPACE:
            GenericULong = (ULONG)(Adapter->NbrRxBuffers 
                 * Adapter->MaxRxBufferSize);
            break;
        case OID_GEN_TRANSMIT_BLOCK_SIZE:
            GenericULong = (ULONG)(Adapter->MaxTxBufferSize);
            break;
        case OID_GEN_RECEIVE_BLOCK_SIZE:
            GenericULong = (ULONG)(Adapter->MaxRxBufferSize);
            break;
        case OID_GEN_VENDOR_ID:
            NdisMoveMemory((PVOID)&GenericULong, Adapter->PermAddr, 3);
            GenericULong &= 0xFFFFFF00;
            MoveSource = (PVOID)(&GenericULong);
            MoveBytes = sizeof(GenericULong);
            break;
        case OID_GEN_VENDOR_DESCRIPTION:
            MoveSource = (PVOID)"Motorola MPC8xx Ethernet";
            MoveBytes = 25;
            break;
        case OID_GEN_DRIVER_VERSION:
            GenericUShort = ((USHORT)ETH8XX_NDIS_MAJOR_VERSION << 8)
              | ETH8XX_NDIS_MINOR_VERSION;
            MoveSource = (PVOID)(&GenericUShort);
            MoveBytes = sizeof(GenericUShort);
            break;
        case OID_GEN_CURRENT_LOOKAHEAD:
            GenericULong = (ULONG)(Adapter->MaxLookAhead);
            break;
        case OID_802_3_PERMANENT_ADDRESS:
            NdisMoveMemory((PCHAR)GenericArray, Adapter->PermAddr,
                           ETH_LENGTH_OF_ADDRESS);
            MoveSource = (PVOID)(GenericArray);
            MoveBytes = ETH_LENGTH_OF_ADDRESS;
            break;
        case OID_802_3_CURRENT_ADDRESS:
            NdisMoveMemory((PCHAR)GenericArray, Adapter->StationAddr,
                           ETH_LENGTH_OF_ADDRESS);
            MoveSource = (PVOID)(GenericArray);
            MoveBytes = ETH_LENGTH_OF_ADDRESS;
            break;
        case OID_802_3_MAXIMUM_LIST_SIZE:
            GenericULong = (ULONG) (Adapter->MulticastListMax);
            break;
        case OID_GEN_XMIT_OK:
            GenericULong = (UINT)(Adapter->FramesXmitGood);
            break;
        case OID_GEN_RCV_OK:
            GenericULong = (UINT)(Adapter->FramesRcvGood);
            break;
        case OID_GEN_XMIT_ERROR:
            GenericULong = (UINT)(Adapter->FramesXmitBad);
            break;
        case OID_GEN_RCV_ERROR:
            GenericULong = (UINT)(Adapter->CrcErrors);
            break;
        case OID_GEN_RCV_NO_BUFFER:
            GenericULong = (UINT)(Adapter->MissedPackets);
            break;
        case OID_802_3_RCV_ERROR_ALIGNMENT:
            GenericULong = (UINT)(Adapter->FrameAlignmentErrors);
            break;
        case OID_802_3_XMIT_ONE_COLLISION:
            GenericULong = (UINT)(Adapter->FramesXmitOneCollision);
            break;
        case OID_802_3_XMIT_MORE_COLLISIONS:
            GenericULong = (UINT)(Adapter->FramesXmitManyCollisions);
            break;
        default:
            Rc = NDIS_STATUS_INVALID_OID;
            break;
    }

    if (Rc == NDIS_STATUS_SUCCESS)
    {
        if (MoveBytes > BytesLeft)
    {
            /* Not enough room in InformationBuffer. Punt. */
            *BytesNeeded    = MoveBytes;
            (*BytesWritten) = 0;
            Rc = NDIS_STATUS_INVALID_LENGTH;

        } else {

        NdisMoveMemory(InfoBuffer, MoveSource, MoveBytes);
        (*BytesWritten) += MoveBytes;
        *BytesNeeded     = 0;
    }
    }

    DEBUGMSG(ZONE_INIT | ZONE_FUNCTION,
    (TEXT("-ETH8XX:eth8xxQuery\r\n")));

    return(Rc);
}


/*----------------------------------------------------------------------*/
NDIS_STATUS eth8xxSetInformation(IN NDIS_HANDLE MiniportAdapterContext,
                                 IN NDIS_OID    Oid,

⌨️ 快捷键说明

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