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

📄 ndis4cs8950.c

📁 EP9315开发板的Wince6.0的BSP包文件
💻 C
📖 第 1 页 / 共 3 页
字号:
//**********************************************************************
//                                                                      
// Filename: ndis3cs8950.c
//                                                                      
// Description: 
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to 
// use this source code. For a copy of the EULA, please see the 
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved                       
//                                                                      
//**********************************************************************


#include "ndis4cs8950.h"
#include "cs8950hw.h"
#include "csDma.h"
#include <oalintr.h>
#include <NKINTR.H>
#include <haluser.h>

BYTE        NDISVerMajor;
BYTE        NDISVerMinor;


//#define     ETHMSG           NKDbgPrintfW

#define     USEETHMSG			0        


//****************************************************************************
//
// Function prototypes for functions local to this file
//
//****************************************************************************


#pragma NDIS_INIT_FUNCTION(DriverEntry)
//****************************************************************************
// DriverEntry()
//****************************************************************************
// Routine Description:
//
//     This is the primary initialization routine for the driver.
//     It is simply responsible for the intializing the wrapper and registering
//     the MAC.  It then calls a system and architecture specific routine that
//     will initialize and register each adapter.
//
// Arguments:
//
//     DriverObject - Pointer to driver object created by the system.
//
// Return Value:
//
//     The status of the operation.
//
//

NTSTATUS DriverEntry
(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
)
{
    BOOL bCS8950KitlEnabled;
    BOOL bReturn;

    //
    // Receives the status of the NdisRegisterMac operation.
    //
    NDIS_STATUS Status;
    NDIS_HANDLE CrystalWrapperHandle;
    NDIS_MINIPORT_CHARACTERISTICS CrystalChar;

    //
    // Check to see if the CS8950 is used for kitl.  
    // If so, print out some debug messages and fail to load.
    //
    bReturn = HalIsCS8950UsedForKitl(&bCS8950KitlEnabled);

    if(bCS8950KitlEnabled || !bReturn)
    {
        NKDbgPrintfW(L"\r\n");
        NKDbgPrintfW(L"*****************************************************************\r\n");
        NKDbgPrintfW(L"* Warning: The CS8950 Ethernet NDIS driver has been disabled    *\r\n");
        NKDbgPrintfW(L"*          because the CS8950 Ethernet KITL driver is enabled.  *\r\n");
        NKDbgPrintfW(L"*          Please remove Kitl, Kernel Debugger and CE Target    *\r\n");
        NKDbgPrintfW(L"*          Control from the Platform->Settings->Build Options.  *\r\n");
        NKDbgPrintfW(L"*****************************************************************\r\n");
        NKDbgPrintfW(L"\r\n");
        return NDIS_STATUS_FAILURE;
    }

 
    NdisZeroMemory( &CrystalChar, sizeof(CrystalChar));

    //
    // Initialize the wrapper.
    //

    NdisMInitializeWrapper(
                &CrystalWrapperHandle,
                DriverObject,
                RegistryPath,
                NULL
                );

//    CrystalDriver.WrapperHandle = CrystalWrapperHandle;

    //
    // Initialize the miniport characteristics for the call to
    // NdisMRegisterMiniport.
    //
    NDISVerMajor = CRYSTAL_NDIS_MAJOR_VERSION;
    NDISVerMinor = CRYSTAL_NDIS_MINOR_VERSION;
    CrystalChar.MajorNdisVersion = CRYSTAL_NDIS_MAJOR_VERSION;
    CrystalChar.MinorNdisVersion = CRYSTAL_NDIS_MINOR_VERSION;
    CrystalChar.InitializeHandler = CrystalInitialize;
    CrystalChar.CheckForHangHandler = CrystalCheckForHang;
    CrystalChar.DisableInterruptHandler = CrystalDisableInterrupt;
    CrystalChar.EnableInterruptHandler = CrystalEnableInterrupt;
    CrystalChar.HaltHandler = CrystalHalt;
    CrystalChar.HandleInterruptHandler = CrystalHandleInterrupt;
    CrystalChar.ISRHandler = CrystalInterruptService;
    CrystalChar.QueryInformationHandler = CrystalQueryInformation;
    CrystalChar.ReconfigureHandler = NULL;
    CrystalChar.ResetHandler = CrystalReset;
    CrystalChar.SendHandler = CrystalSend;
    CrystalChar.SetInformationHandler = CrystalSetInformation;
    CrystalChar.TransferDataHandler = CrystalTransferData;

    CrystalChar.ReturnPacketHandler = CrystalGetReturnedPacket;
    CrystalChar.SendPacketsHandler = CrystalSendPackets;
    CrystalChar.AllocateCompleteHandler = NULL;


    Status = NdisMRegisterMiniport(
                 CrystalWrapperHandle,
                 &CrystalChar,
                 sizeof(CrystalChar)
                 );

    if (Status == NDIS_STATUS_SUCCESS) {
       return NDIS_STATUS_SUCCESS;
    }


    //
    // We can only get here if something went wrong with registering
    // the mac or *all* of the adapters.
    //

    NdisTerminateWrapper(CrystalWrapperHandle, NULL);

    return NDIS_STATUS_FAILURE;

}



#pragma NDIS_PAGABLE_FUNCTION(CrystalInitialize)
//****************************************************************************
// CrystalInitialize()
//****************************************************************************
// Routine Description:
//
//     CrystalInitialize adds finds and initializes the adapter.
// 
// Arguments:
//
//     OpenErrorStatus - Extra status bytes for opening token ring adapters.
//
//     SelectedMediumIndex - Index of the media type chosen by the driver.
// 
//     MediumArray - Array of media types for the driver to chose from.
//
//     MediumArraySize - Number of entries in the array.
//
//     MiniportAdapterHandle - Handle for passing to the wrapper when
//        referring to this adapter.
// 
//     ConfigurationHandle - A handle to pass to NdisOpenConfiguration.
//
// Return Value:
//
//     NDIS_STATUS_SUCCESS
//     NDIS_STATUS_FAILURE
//     NDIS_STATUS_UNSUPPORTED_MEDIA
// 
// Assumptions:
//
//   The NDIS3 spec states that the miniport driver will not re-entered during
//   CrystalInitialize().
//
static NDIS_STATUS CrystalInitialize
(
    OUT PNDIS_STATUS OpenErrorStatus,
    OUT PUINT SelectedMediumIndex,
    IN PNDIS_MEDIUM MediumArray,
    IN UINT MediumArraySize,
    IN NDIS_HANDLE MiniportAdapterHandle,
    IN NDIS_HANDLE ConfigurationHandle
)
{
    
    UINT i;
    NDIS_STATUS Status=NDIS_STATUS_SUCCESS;
    NDIS_HANDLE ConfigHandle;
    WORD Result;
    WORD InterruptMode = NdisInterruptLatched;
    PVOMINIPDATA pOSD;
    BYTE InterruptSharing = FALSE; /* Interrupt Sharing needs work */
    PVPMINIPDATA pvMini_Context;
    PCHIP  pChip;
    PCD    pData;
    NDIS_PHYSICAL_ADDRESS Temp = NDIS_PHYSICAL_ADDRESS_CONST(-1, -1);
    int    step;

    for (step=1; step<20 && Status==NDIS_STATUS_SUCCESS; step++) 
    {
        switch (step) 
        {
            case 1:
              //
              // Search for the 802.3 media type
              //
              Status=NDIS_STATUS_UNSUPPORTED_MEDIA;
              for (i=0; i<MediumArraySize && Status!=NDIS_STATUS_SUCCESS; i++) {
                  if (MediumArray[i] == NdisMedium802_3) {
                      *SelectedMediumIndex = i;
                      Status=NDIS_STATUS_SUCCESS;
                  } /* endif */
     
              } /* endfor */
            break;
            case 2:

              Status = NdisAllocateMemory(
                              (PVOID)&pChip,
                              (ULONG) sizeof(CHIP),
                              0,
                              Temp
                              );
             
              if (Status != NDIS_STATUS_SUCCESS) {
                 NdisWriteErrorLogEntry(
                    MiniportAdapterHandle,
                    NDIS_ERROR_CODE_OUT_OF_RESOURCES,
                    2,
                    2,
                    2
                    );

                 Status=NDIS_ERROR_CODE_OUT_OF_RESOURCES;
              } /* endif */
            break;
            case 3:
              //
              //zero CHIP cntl blk and set up pointers
              //
              NdisZeroMemory( pChip, sizeof(CHIP) );
              pvMini_Context        =  pChip->pPSD  = &pChip->higherdata;    
              pOSD                  =  pChip->pOSD  = &pChip->timerdata;    
              pData                 =  pChip->pData = &pChip->lowerdata;   
              //
              //setup some of the "higher" cntl blk
              //
              pvMini_Context->pChip =  pChip;
              pvMini_Context->vpMiniportAdapterHandle = MiniportAdapterHandle;
              pvMini_Context->pChip->pPSD = pvMini_Context;
              pvMini_Context->pChip->Config.LookAheadSize = (WORD)UNSPECIFIED;
              pvMini_Context->ProtocolLookahead = VP_MAX_FRAMESIZE - VP_HEADERSIZE;
              pvMini_Context->CableConnected = NdisMediaStateDisconnected;
              pvMini_Context->CurrentState = NdisHardwareStatusNotReady;

            break;
            case 4:
              VominiStartup( pOSD, MiniportAdapterHandle );
            break;
            case 5:
              NdisMSetAttributes(
                  MiniportAdapterHandle,
                  (NDIS_HANDLE)pvMini_Context,
                  TRUE,  //BUS_MASTER DMA
                  NdisInterfaceInternal
                  );
            break;
            case 6:
               //
               // Open the configuration information.
               //
               NdisOpenConfiguration(
                 &Status,
                 &ConfigHandle,
                 ConfigurationHandle
                 );
            break;
            case 7:
              // Do Nothing
            break;
     
            case 8:
                Result = VchipGetConfig( pvMini_Context->pChip);
                if (Result != TRUE) 
                {
                    Status=NDIS_STATUS_FAILURE;
                } /* endif */
            break;
            case 9:
                NdisMoveMemory(&pvMini_Context->PermanentNetworkAddress,
                              &pvMini_Context->pChip->Config.EthernetAddr,
                              (ULONG) ETH_LENGTH_OF_ADDRESS);
            break;
            case 10:
                if (GetNetworkAddress(ConfigHandle, pvMini_Context->CurrentNetworkAddress) ==
                                                                      NDIS_STATUS_SUCCESS) 
                {
                    NdisMoveMemory
                    (
                        &(pvMini_Context->pChip->Config.EthernetAddr),
                        pvMini_Context->CurrentNetworkAddress,
                        (ULONG)ETH_LENGTH_OF_ADDRESS
                    );
                    NdisMoveMemory
                    (
                        pvMini_Context->PermanentNetworkAddress,
                        pvMini_Context->CurrentNetworkAddress,
                        (ULONG)ETH_LENGTH_OF_ADDRESS
                    );
                } 
                else if(HalGetMacAddress((PSHORT)pvMini_Context->CurrentNetworkAddress))
                {
                    NdisMoveMemory
                    (
                        &(pvMini_Context->pChip->Config.EthernetAddr),
                        pvMini_Context->CurrentNetworkAddress,
                        (ULONG)ETH_LENGTH_OF_ADDRESS
                    );
                    NdisMoveMemory
                    (
                        pvMini_Context->PermanentNetworkAddress,
                        pvMini_Context->CurrentNetworkAddress,
                        (ULONG)ETH_LENGTH_OF_ADDRESS
                    );
                }
                else 
                {
                    NdisMoveMemory
                    (
                        &pvMini_Context->CurrentNetworkAddress,
                        &pvMini_Context->PermanentNetworkAddress,
                        (ULONG)ETH_LENGTH_OF_ADDRESS
                    );
                }
                #if 0
                RETAILMSG
                (
                    1, 
                    (
                        L"EthernetAddr = %2x %2x %2x \r\n",
                        pvMini_Context->pChip->Config.EthernetAddr.Part[0],
                        pvMini_Context->pChip->Config.EthernetAddr.Part[1],
                        pvMini_Context->pChip->Config.EthernetAddr.Part[2]
                    )
                );
                RETAILMSG
                (
                    1, 
                    (
                        L"CurrentNetworkAddress = %2x %2x %2x \r\n",
                        ((USHORT *)pvMini_Context->CurrentNetworkAddress)[0],
                        ((USHORT *)pvMini_Context->CurrentNetworkAddress)[1],
                        ((USHORT *)pvMini_Context->CurrentNetworkAddress)[2]
                    )
                );
                RETAILMSG
                (
                    1, 
                    (
                        L"PermanentNetworkAddress = %2x %2x %2x \r\n",
                        ((USHORT *)pvMini_Context->PermanentNetworkAddress)[0],
                        ((USHORT *)pvMini_Context->PermanentNetworkAddress)[1],
                        ((USHORT *)pvMini_Context->PermanentNetworkAddress)[2]
                    )
                );
                #endif // 0
            break;

            case 11:
                //
                // Get the duplex mode from the registry
                //
                pvMini_Context->pChip->Config.RequestedDuplexMode=GetDuplexMode(ConfigHandle);          
     
                //
                // Get the media speed from the registry
                //
                pvMini_Context->pChip->Config.RequestedMediaSpeed=GetMediaSpeed(ConfigHandle);
            break;
            case 12:
                NdisCloseConfiguration(ConfigHandle);
            break;
            case 13:
                Status = NdisMRegisterInterrupt
                (
                     &(pData->InterruptObject),
                     MiniportAdapterHandle,
                     SYSINTR_ETHER,  //Default Interrupt Line number
                     0,      // Not used
                     FALSE,  // RequestIsr
                     FALSE,  // SharedInterrupt
                     NdisInterruptLevelSensitive // Level or Edge
                );

                if (Status != NDIS_STATUS_SUCCESS) 
                {
                   NdisWriteErrorLogEntry
                     (
                       MiniportAdapterHandle,
                       NDIS_ERROR_CODE_INTERRUPT_CONNECT,
                       2,
                       Status,
                       pvMini_Context->pChip->Config.IntLine
                       );
                } /* endif */
            break;
            case 14:
                // Initialize the contiguous physical memory used for DMA Tx and Rx.
                if ( DMAInitMem(pChip) == TRUE ) {
                    Status= NDIS_STATUS_SUCCESS; }
                else {
                    Status= NDIS_STATUS_FAILURE;}
            break;
            case 15:
              /* do nothing */
            break;
            case 16:
               /* do nothing */
            break;

⌨️ 快捷键说明

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