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

📄 nicrxntx.c

📁 3com 3c905网卡驱动硬件部分源码
💻 C
字号:
/*******************************************************************************
*** Note: Copy rights resevered to Beijing Pacific Linkair Communications Co. 
***
*** File Name: NICNicRxnTx.c
*** Purpose  : Rx and Tx routines
***
*** Author   : Guangzhao Tian
*** Modified : By Guangzhao Tian at 2000/9/12
***
**/

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

/**********************************************
*** This routine resets the transmitter.
**/
NIC_STATUS NIC_TxReset ( IN PNIC_INFORMATION pAdapter )
{
  	int	ix;
	USHORT  wMediatStatus;
	ULONG   lDMAControl;

    DebugMsg(" Now try to reset the Tx ... \n");

	/* Disable transmit .*/
	NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_TX_DISABLE);
	
	/** Select Window  4 ****/
	NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_SELECT_REGISTER_WINDOW | REGISTER_WINDOW_4);

     DebugMsg(" Now wait the Transmit in progress to go die ...");
	/* Wait for the transmit in progress to go off. */
    for (ix = 0; ix < NIC_TIMEOUT; ix++)
	{
       wMediatStatus= NIC_READ_PORT_USHORT(pAdapter->IoBaseAddress,MEDIA_STATUS_REGISTER);

		if(! (wMediatStatus & MEDIA_STATUS_TX_IN_PROGRESS) ) break;
		NIC_DELAY(NIC_WAITTIMES);
	}

    if (ix == NIC_TIMEOUT)
	{
		DebugMsg("\n  It seems the Tx in progress will Never Complete ! \n");
		DebugMsg("  We will esaped from this trap. \n");
	 	return NIC_STATUS_FAILURE; 
	}
     DebugMsg("  Done ! \n");

   /* Issue down stall and delay 100 miliseconds for PCI retries to be over */
     NIC_COMMAND_WAIT(pAdapter, COMMAND_DOWN_STALL);
     NIC_DELAY(NIC_RESETWAITTIME);

     DebugMsg(" Now wait the Download Engine go die ...");
   /* Wait for download engine to stop */
    for (ix = 0; ix < NIC_TIMEOUT; ix++)
	{
        lDMAControl=NIC_READ_PORT_ULONG(pAdapter->IoBaseAddress,DMA_CONTROL_REGISTER);

		if(! (lDMAControl & DMA_CONTROL_DOWN_IN_PROGRESS) ) break;
		NIC_DELAY(NIC_WAITTIMES);
	}

    if (ix == NIC_TIMEOUT)
	{
		DebugMsg("\n It seems the Download Engine will Never get tired! \n");
		DebugMsg(" We will esaped from this trap. !\n");
	 	return NIC_STATUS_FAILURE; 
	}
       DebugMsg(" Done ! \n");

 	
    /*reset the Tx */
     DebugMsg(" Now Issue the Tx Reset command ...");
	NIC_COMMAND_WAIT(pAdapter, COMMAND_TX_RESET);
	 DebugMsg(" Done ! \n");

	return NIC_STATUS_SUCCESS;
}

/** Reset and Enable the Trasimiter */
NIC_STATUS NIC_TxResetAndEnable ( IN PNIC_INFORMATION pAdapter )
{
	NIC_STATUS nicStatus;

    DebugMsg(" Now Try to reset and enable the Tx ... \n");
 	if ( NIC_STATUS_SUCCESS != NIC_TxReset (pAdapter) ) 
	{
       DebugMsg(" Tx Reset Failed, cannot contine ! \n") ;
       return NIC_STATUS_FAILURE;
	}

      DebugMsg(" Now Enable the Tx ...");
 	NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_TX_ENABLE);
      DebugMsg(" Done ! \n");

    DebugMsg(" Tx Reset and Enable --- Done ! \n");

	return NIC_STATUS_SUCCESS;
}

/** Reset  the Receiver */
NIC_STATUS NIC_RxReset ( IN PNIC_INFORMATION pAdapter )
{
  	int	ix;
	USHORT  wMediatStatus;

    DebugMsg("Now try to Reset the Rx ... \n");

	/* Disable  receive.*/
      DebugMsg("  First Disable it ...");
 	NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_RX_DISABLE);
	  DebugMsg("   Done ! \n");

	/** Select Window  4 ****/
	NIC_COMMAND(pAdapter->IoBaseAddress ,COMMAND_SELECT_REGISTER_WINDOW | REGISTER_WINDOW_4);

	/* Wait for the receive in prograss to go quiet. */
      DebugMsg(" Wait for the receive in progress to go quiet...");
    for (ix = 0; ix < NIC_TIMEOUT; ix++)
	{
        wMediatStatus=NIC_READ_PORT_USHORT(pAdapter->IoBaseAddress,MEDIA_STATUS_REGISTER);

		if(! (wMediatStatus & MEDIA_STATUS_CARRIER_SENSE) ) break;
		NIC_DELAY(NIC_WAITTIMES);
	}

    if (ix == NIC_TIMEOUT)
	{
		DebugMsg("\n It seems the Rx in progress will Never Complete ! \n");
		DebugMsg(" We will esaped from this trap. \n");
	 	return NIC_STATUS_FAILURE; 
	}
      DebugMsg(" Done ! \n");

 	/*reset the  Rx*/
     DebugMsg(" Now try to Issue Rx Reset Command and wait a while...");
	NIC_COMMAND_WAIT(pAdapter, COMMAND_RX_RESET);
     DebugMsg("  Done ! \n");

    DebugMsg("Rx Reset--- Done ! \n");

	return NIC_STATUS_SUCCESS;
}

/** Reset and Enable the Receiver */
NIC_STATUS NIC_RxResetAndEnable ( IN PNIC_INFORMATION pAdapter )
{
	NIC_STATUS nicStatus;

     DebugMsg(" Now try to Reset and Enable Rx ...");

 	if ( NIC_STATUS_SUCCESS != NIC_RxReset (pAdapter) ) 
	{
         DebugMsg("\n Rx reset Failed , Cannot contine ! \n");
         return NIC_STATUS_FAILURE;
	}

	NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_RX_ENABLE);

     DebugMsg(" Done ! \n");

	return NIC_STATUS_SUCCESS;
}

/***********************************************************
*** This routine sends the packet 
***/

BOOLEAN NIC_TxSendPacket( IN PNIC_INFORMATION pAdapter , IN UCHAR * PDataBuffer, IN DWORD nLength)
{	
 	PDPD_LIST_ENTRY pDPD;

    DebugMsg("Now send Data Packet: Addr:0x%08X, Len: %D ...\n ", (ULONG) PDataBuffer, nLength);
 
	if ( (PDPD_LIST_ENTRY) pAdapter->Resources.pTailDPD->pNext == pAdapter->Resources.pHeadDPD)
	{	
		pAdapter->Resources.DPDRingFull = TRUE;
        DebugMsg(" DPD List Full, please wait a while and try again ! \n");
		return FALSE;
	}

	/* Get the free DPD from the DPD ring */
	pDPD = pAdapter->Resources.pTailDPD;
	pDPD->FrameStartHeader = 0; 
	pDPD->DPDFragNode[0].nFragAddrPCI = Virt_to_Bus(PDataBuffer);

	pDPD->DPDFragNode[0].nFragLength = nLength | 0x80000000;

    pDPD->FrameStartHeader |= (ULONG)(FSH_ROUND_UP_DEFEAT); 
   
	pDPD->DownNextPointerPCI = 0; 
 
    NIC_COMMAND_WAIT(pAdapter, COMMAND_DOWN_STALL);
/*	pAdapter->BytesInDPDQueue += packetLength;  
	pAdapter->Resources.pTailDPD->pPrevious->DownNextPointertPCI = pDPD->ThisDPDAddrPCI; */
	pAdapter->Resources.pTailDPD = pDPD->pNext;  /* lets the pTailDPD move on */
    NIC_COMMAND(pAdapter, COMMAND_DOWN_UNSTALL);

    DebugMsg(" Data Packet Written to DPD List for Downloading ! \n");
	return TRUE;
}

/******************************************************************************
*** Load UPD and DPD List header into registers
**/
NIC_STATUS NIC_RxTxReady (IN PNIC_INFORMATION pAdapter)
{
	/* ------------ Give download structures to the adapter -----
	** Stall the download engine.*/

	NIC_STATUS nicStatus;

	PDPD_LIST_ENTRY pDPD;
    PDPD_LIST_ENTRY pHeadDPD;

	nicStatus = NIC_COMMAND_WAIT(pAdapter, COMMAND_DOWN_STALL);

	if (nicStatus != NIC_STATUS_SUCCESS)
	{   return NIC_STATUS_FAILURE; 	}

    /* Use the head DPD to mark it as dummy.*/
	pDPD = pAdapter->Resources.pHeadDPD;
	pDPD ->FrameStartHeader = FSH_DPD_EMPTY;

	/* Now move head and tail to next one. 
	pAdapter->Resouces.pHeadDPD = pDPD->pNext;  
	pAdapter->Resouces.pTailDPD = pDPD->pNext;  */
    /*???? Why ????*/

	/* Write the first DPD address to the hardware.*/
	NIC_WRITE_PORT_ULONG(pAdapter->IoBaseAddress,DOWN_LIST_POINTER_REGISTER,(ULONG) pDPD->ThisDPDAddrPCI);

	/* Enable down polling on the hardware.
	NIC_WRITE_PORT_UCHAR(pAdapter->IoBaseAddress,DOWN_POLL_REGISTER,(UCHAR)pAdapter->Resources.DownPollRate);*/

	/* Unstall the download engine.*/
	NIC_COMMAND(pAdapter->IoBaseAddress, COMMAND_DOWN_UNSTALL);

	/******** ------------ Give upload structures to the adapter -------
	** Stall the upload engine.
	*/
	nicStatus = NIC_COMMAND_WAIT(pAdapter, COMMAND_UP_STALL);

	if (nicStatus != NIC_STATUS_SUCCESS) 
	{   return NIC_STATUS_FAILURE;	}

	/** Give the address of the first UPD to the adapter.* */
 	NIC_WRITE_PORT_ULONG(pAdapter->IoBaseAddress,UP_LIST_POINTER_REGISTER,
                                       (ULONG) pAdapter->Resources.pHeadUPD->ThisUPDAddrPCI);
	
	/* Write the up poll register.*/
 	NIC_WRITE_PORT_UCHAR(pAdapter->IoBaseAddress,UP_POLL_REGISTER, 8);

	/** Unstall the download engine.**/
	NIC_COMMAND(pAdapter->IoBaseAddress, COMMAND_UP_UNSTALL);

	return NIC_STATUS_SUCCESS;
}

/**  Above are routines of Rx and Tx
***  End of NICRxnTx.c
************************************************************************************************/

⌨️ 快捷键说明

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