📄 nicdevice.c
字号:
/*******************************************************************************
*** Note: Copy rights resevered to Beijing Pacific Linkair Communications Co.
***
*** File Name: NICDevice.c
*** Purpose : Supply the NIC EEPROM Accessing Layer Routines and some other definitions
***
*** Author : Guangzhao Tian
*** Modified : By Guangzhao Tian at 2000/9/7
***
**/
#include "NICMacro.h"
#include "NICWinReg.h"
#include "NICCommand.h"
#include "NICEeprom.h"
#include "NICData.h"
#include "NICHelper.h"
#include "NICExport.h"
/*******************************************************************************
* NIC_DeviceStart - start the device
* This function start the NIC Device
*/
NIC_STATUS NIC_DeviceStart(IN PNIC_INFORMATION pAdapter)
{
NIC_STATUS nicStatus;
USHORT diagnostics;
ULONG dmaControl;
DebugMsg("\n***********\nNow Start Adapter ... \n ");
/* Clear the statistics from the hardware.*/
DebugMsg(" Now Clear Statices by reading them! ... ");
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, CARRIER_LOST_REGISTER);
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, SQE_ERRORS_REGISTER);
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, MULTIPLE_COLLISIONS_REGISTER);
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, SINGLE_COLLISIONS_REGISTER);
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, LATE_COLLISIONS_REGISTER);
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, RX_OVERRUNS_REGISTER);
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, FRAMES_TRANSMITTED_OK_REGISTER);
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, FRAMES_RECEIVED_OK_REGISTER);
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, FRAMES_DEFERRED_REGISTER);
NIC_READ_PORT_UCHAR(pAdapter->IoBaseAddress, UPPER_FRAMES_OK_REGISTER);
NIC_READ_PORT_USHORT(pAdapter->IoBaseAddress, BYTES_RECEIVED_OK_REGISTER);
NIC_READ_PORT_USHORT(pAdapter->IoBaseAddress, BYTES_TRANSMITTED_OK_REGISTER);
DebugMsg(" Done ! \n");
/* Enable upper bytes counting in diagnostics register.
NIC_COMMAND(pAdapter->IoBaseAddress,
COMMAND_SELECT_REGISTER_WINDOW | REGISTER_WINDOW_4);
NIC_READ_PORT_USHORT( pAdapter->IoBaseAddress,
NETWORK_DIAGNOSTICS_REGISTER,diagnostics );
diagnostics |= NETWORK_DIAGNOSTICS_UPPER_BYTES_ENABLE;
NIC_WRITE_PORT_USHORT(pAdapter->IoBaseAddress,NETWORK_DIAGNOSTICS_REGISTER,diagnostics);*/
/* Enable counter speed in DMA control.
NIC_READ_PORT_ULONG(pAdapter->IoBaseAddress, DMA_CONTROL_REGISTER,dmaControl );
if (100000000 == pAdapter->Hardware.LinkSpeed)
dmaControl |= DMA_CONTROL_COUNTER_SPEED;
NIC_WRITE_PORT_ULONG(pAdapter->IoBaseAddress,DMA_CONTROL_REGISTER,dmaControl); */
/* Enable the statistics back. */
DebugMsg(" Now Enable Statistics Register ...");
NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_STATISTICS_ENABLE);
DebugMsg(" Done ! \n");
/* Acknowledge any pending interrupts. */
DebugMsg(" Now Acknowedge all Interrupts ...");
NIC_ACKNOWLEDGE_ALL_INTERRUPT(pAdapter->IoBaseAddress);
DebugMsg(" Done ! \n");
/* Enable indication for all interrupts.
DebugMsg(" Now Enable all Interrupt Indications ...");
NIC_ENABLE_ALL_INTERRUPT_INDICATION(pAdapter->IoBaseAddress);
DebugMsg(" Done ! \n"); */
/* Enable all interrupts to the host.
DebugMsg(" Now Unmask all Interrupts ...");
NIC_UNMASK_ALL_INTERRUPT(pAdapter->IoBaseAddress);
DebugMsg(" Done ! \n"); */
/* Enable the transmit and receive engines.*/
DebugMsg(" Now Enable Receive Engine ...");
NIC_COMMAND(pAdapter->IoBaseAddress, COMMAND_RX_ENABLE);
DebugMsg(" Done ! \n");
DebugMsg(" Now Enable Transmite Engine ...");
NIC_COMMAND(pAdapter->IoBaseAddress, COMMAND_TX_ENABLE);
DebugMsg(" Done ! \n");
DebugMsg("Start Adapter -- Done ! \n**************\n ");
return NIC_STATUS_SUCCESS;
}
/*******************************************************************************
* NIC_DeviceReset - reset the device
* This function write to Global Reset Register and wait for command complete
*/
NIC_STATUS NIC_DeviceReset (IN NIC_INFORMATION * pAdapter)
{
DebugMsg("\n*************\nNow Reset the NIC Device...\n");
/* issue the reset command */
if(NIC_STATUS_FAILURE==NIC_COMMAND_WAIT (pAdapter, COMMAND_GLOBAL_RESET) )
{
DebugMsg(" Device Resetting Failuer ! \n ");
return NIC_STATUS_FAILURE;
}
DebugMsg("Device Resetted, Wait a minute ....\n");
/* wait for a while */
NIC_DELAY(NIC_RESETWAITTIME);
DebugMsg("Device Resetted Successfully ! \n**************\n");
return NIC_STATUS_SUCCESS;
}
/************************************************************************
* NIC_DeviceStop - stop the device
* This function stops the adapter and frees up any buffers allocated to the
* upload and download descriptors.
*/
NIC_STATUS NIC_DeviceStop (IN NIC_INFORMATION * pAdapter)
{
int ix;
USHORT wMediatStatus;
DebugMsg("\n*********\nNow Stop the Device ...\n");
/* Mask and Acknownedge all Interruptes */
DebugMsg(" Now Mask and Acknowledge all the Interruptes ...");
NIC_MASK_ALL_INTERRUPT(pAdapter->IoBaseAddress) ;
NIC_ACKNOWLEDGE_ALL_INTERRUPT(pAdapter->IoBaseAddress);
DebugMsg(" Done ! \n");
/* Disable transmit and receive.*/
DebugMsg(" Now Diable Tx , Rx and Statistics ...");
NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_TX_DISABLE);
NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_RX_DISABLE);
NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_STATISTICS_DISABLE);
DebugMsg(" Done ! \n");
/** Select Window 4 ****/
DebugMsg(" Now Switch to Reg Win 4 ...");
NIC_COMMAND(pAdapter->IoBaseAddress , COMMAND_SELECT_REGISTER_WINDOW | REGISTER_WINDOW_4);
DebugMsg(" Done ! \n");
DebugMsg(" Now Wait for Tx in Progress gone off ...");
/* Wait for the transmit in progress to go off. */
for (ix = 0; ix < NIC_WAITTIMES; ix++)
{
wMediatStatus = NIC_READ_PORT_USHORT(pAdapter->IoBaseAddress,MEDIA_STATUS_REGISTER);
if(! (wMediatStatus & MEDIA_STATUS_TX_IN_PROGRESS) ) break;
NIC_DELAY(NIC_TIMEOUT);
}
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");
DebugMsg(" Now Wait for Rx in Progress gone off ...");
/* Wait for the receive in prograss to go quiet. */
for (ix = 0; ix < NIC_WAITTIMES; ix++)
{
wMediatStatus = NIC_READ_PORT_USHORT(pAdapter->IoBaseAddress,MEDIA_STATUS_REGISTER);
if(! (wMediatStatus & MEDIA_STATUS_CARRIER_SENSE) ) break;
NIC_DELAY(NIC_TIMEOUT);
}
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");
DebugMsg(" Now Try to reset the NIC Card ...");
/* Issue Global reset. */
NIC_COMMAND_WAIT ( pAdapter ,
COMMAND_GLOBAL_RESET | GLOBAL_RESET_MASK_VCO_RESET |
GLOBAL_RESET_MASK_TP_AUI_RESET | GLOBAL_RESET_MASK_ENDEC_RESET |
GLOBAL_RESET_MASK_AISM_RESET | GLOBAL_RESET_MASK_SMB_RESET );
DebugMsg(" Done ! \n");
/* DebugMsg("Now wait a minute for Resetting Completed !\n");
NIC_DELAY(NIC_RESETWAITTIME); */
DebugMsg(" Now Try to reset the Tx ...");
/*reset the Tx and Rx*/
NIC_COMMAND_WAIT(pAdapter, COMMAND_TX_RESET);
DebugMsg(" Done !\n");
DebugMsg(" Now Try to reset the Rx...");
NIC_COMMAND_WAIT(pAdapter, COMMAND_RX_RESET);
DebugMsg(" Done !\n");
DebugMsg("Stop the Device -- Done! \n******************\n");
return;
}
/** Above are Routines for Controlling the NIC Card Device
*** End of NICDevice.c
****************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -