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

📄 nicpci.c

📁 3com 3c905网卡驱动硬件部分源码
💻 C
字号:
/*******************************************************************************
*** Note: Copy rights resevered to Beijing Pacific Linkair Communications Co. 
***
*** File Name: NICPCI.c
*** Purpose  : Supply the PCI Bus Interface Routines
***
*** Author   : Guangzhao Tian
*** Modified : By Guangzhao Tian at 2000/9/21
***
**/

/*includes */
#include "uhal.h"
#include "pcilib.h"

#include "NICMacro.h"
#include "NICWinReg.h"
#include "NICCommand.h"
#include "NICEeprom.h"
#include "NICMemory.h"
#include "NICData.h"
#include "NICHelper.h"
#include "NICExport.h"

/**************************************************************************
*** Initnilize the PCI Bus ,and find our 3c905B-TX NCI Card 
**/
BOOLEAN PCI_BusInitilize(IN NIC_INFORMATION * pAdapter)
{
  	DWORD nBus, nSlot, nFunc;

	/* initialise the PCI bus */
        DebugMsg("Now try to Initialize PCI Bus ...\n");
   	PCIr_Init ();
    	DebugMsg("PCI Bus Initialize --- Done ! \n");  
  
   	/* look for the 3COM 3c905b ethernet device */
        DebugMsg("Now try to find our card ...\n");
 	if(PCIr_FindDevice (VENDOR_ID_3COM,DEVICE_ID_3C905B,0,&nBus, &nSlot, &nFunc)!=0)
   	{
	 	DebugMsg(" Failed to Find 3COM Ethernet Device, Initialization Failed ! \n");
     	pAdapter->PCIInfo.bPCIIntilized =FALSE;
     	return FALSE;
   	}
	 
	/* found it, tell the world */
	 DebugMsg("3COM Ethernet Device 3c905B-TX Found at [%02d:%02d:%02d] ! \n",nBus, nSlot, nFunc);
   
    pAdapter->PCIInfo.BusNo 	 = nBus;
    pAdapter->PCIInfo.SlotNo	 = nSlot;
    pAdapter->PCIInfo.FunctionNo = nFunc;

   	pAdapter->PCIInfo.bPCIIntilized = TRUE;

    DebugMsg(" PCI Bus Initialize -- Done ! \n");
}

/**************************************************************************
*** Get the Fundemental PCI Information by calling uHal Routines from ARM Co. 
**/
BOOLEAN PCI_CongfigInfoGet(IN NIC_INFORMATION * pAdapter)
{
    DebugMsg("\n*****************\nNow get PCI Config Information !\n");
    if( pAdapter->PCIInfo.bPCIIntilized ==FALSE)  
    {
       DebugMsg(" PCI Bus not yet Initialieze, do it now ...\n");
       if(FALSE== PCI_BusInitilize(pAdapter) )
       { 
          DebugMsg(" Since Initilization not done, this operation cannot contine ! \n");
           return FALSE;
       }
     }

    DebugMsg(" PCI Info Get-- Done ! \n");
    
    DebugMsg(" Now begin to get PCI Inforamtions ! \n");

  	pAdapter->PCIInfo.VerdorID        = PCI_RegRead16( pAdapter, PCI_VENDOR_ID       );

  	pAdapter->PCIInfo.DeviceID        = PCI_RegRead16( pAdapter, PCI_DEVICE_ID       );

  	pAdapter->PCIInfo.ClassCode       = PCI_RegRead32( pAdapter, PCI_CLASS_ID        );

  	pAdapter->PCIInfo.CacheLineSize   = PCI_RegRead8 ( pAdapter, PCI_CACHE_LINE_SIZE );

  	pAdapter->PCIInfo.IoBaseAddress   = PCI_RegRead32( pAdapter, PCI_MEM_BAR         ) & ~0x0F ;

  	pAdapter->PCIInfo.MemBaseAddress  = PCI_RegRead32( pAdapter, PCI_MEM_BAR + 4     ) & ~0x0F ;

	pAdapter->PCIInfo.InterruptVector = PCI_RegRead8 ( pAdapter, PCI_INTERRUPT_LINE  );

	pAdapter->PCIInfo.InterruptPin    = PCI_RegRead8 ( pAdapter, PCI_INTERRUPT_PIN   );

    DebugMsg(" NIC Card PCI Config Parameters: \n");

    DebugMsg(" \t  VerdorID: 0x%08X \t DeviceID: 0x%08X \n",
                                                   pAdapter->PCIInfo.VerdorID, pAdapter->PCIInfo.DeviceID );
    DebugMsg(" \t  ClassCode: 0x%08X \t CacheLineSize: 0x%08X \n",
                                                   pAdapter->PCIInfo.ClassCode, pAdapter->PCIInfo.CacheLineSize );
    DebugMsg(" \t  IoBaseAddress: 0x%08X \t MemBaseAddress: 0x%08X \n", 
                                                   pAdapter->PCIInfo.IoBaseAddress, pAdapter->PCIInfo.MemBaseAddress );
    DebugMsg(" \t  InterruptVector: 0x%08X \t InterruptPin: 0x%08X \n", 
                                                   pAdapter->PCIInfo.InterruptVector, pAdapter->PCIInfo.InterruptPin );
 
    DebugMsg(" \tPCISatuese: 0x%08X \t PCICommand: 0x%08X \n",
                          PCI_RegRead16( pAdapter, PCI_STATUS),PCI_RegRead16( pAdapter, PCI_COMMAND) );

    DebugMsg(" PCI Information Gotten -- Done ! \n************\n");

  	return TRUE;
}


/*********************************************************************************
***  Following are PCI Inforamation Accessing Routines 
**/

DWORD  PCI_RegRead32(IN NIC_INFORMATION * pAdapter, DWORD RegOffset )
{
    return uHALr_PCICfgRead32 ( pAdapter->PCIInfo.BusNo     , pAdapter->PCIInfo.SlotNo,
                                pAdapter->PCIInfo.FunctionNo, RegOffset);
}

WORD  PCI_RegRead16(IN NIC_INFORMATION * pAdapter, DWORD RegOffset )
{
    return uHALr_PCICfgRead16 ( pAdapter->PCIInfo.BusNo     , pAdapter->PCIInfo.SlotNo,
                                pAdapter->PCIInfo.FunctionNo, RegOffset);
}

BYTE  PCI_RegRead8(IN NIC_INFORMATION * pAdapter, DWORD RegOffset )
{

    return uHALr_PCICfgRead8 ( pAdapter->PCIInfo.BusNo     , pAdapter->PCIInfo.SlotNo,
                                pAdapter->PCIInfo.FunctionNo, RegOffset);
}

/**  Above are routines for NCI PCI Accessing
***  End of NICPCI.c
***************************************************************************************/

⌨️ 快捷键说明

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