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

📄 lan9118.h

📁 SMSC9118网卡驱动
💻 H
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************
   
	Copyright (c) 2004-2005 SMSC. All rights reserved.

	Use of this source code is subject to the terms of the SMSC Software
	License Agreement (SLA) under which you licensed this software product.	 
	If you did not accept the terms of the SLA, you are not authorized to use
	this source code. 

	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.
	 
	File name   : lan9118.h 
	Description : lan9118 Header File

	History	    :
		03-16-05 WH			First Release
		08-12-05 MDG		ver 1.01 
			- add LED1 inversion, add PHY work around
		11-07-05 WH			ver 1.02
			- Fixed middle buffer handling bug
			  (Driver didn't handle middle buffers correctly if it is less than 
               4bytes size)
			- workaround for Multicast bug
			- Workaround for MAC RXEN bug
		11-17-05 WH			ver 1.03
			- 1.02 didn't have 1.01 patches
			- 1.03 is 1.02 + 1.01
		12-06-05 WH			ver 1.04
			- Fixed RX doesn't work on Silicon A1 (REV_ID = 0x011x0002)
			- Support SMSC9118x/117x/116x/115x family
		02-27-05 WH			ver 1.05
			- Fixing External Phy bug that doesn't work with 117x/115x
		03-23-05 WH			ver 1.06
			- Put the variable to avoid PHY_WORKAROUND for External PHY
			- Change product name to 9118x->9218, 9115x->9215
		07-26-06 WH, MDG, NL		ver 1.07
			- Add RXE and TXE interrupt handlers
			- Workaround Code for direct GPIO connection from 9118 family 
			  Interrupt (Level Interrupt -> Edge Interrupt)
			- Change GPT interrupt interval to 200mSec from 50mSec
			- clean up un-used SH3 code
		08-25-06  WH, MDG, NL       ver 1.08
		    - Fixed RXE and TXE interrupt handlers bug
			- support for direct and nondirect Interrupt
*****************************************************************************/

#ifndef LAN9118_H
#define LAN9118_H

//#define USE_GPIO
#include "OS.h"

#ifdef USE_GPIO
#define	GPIO0		0x01UL
#define	GPIO1		0x02UL
#define	GPIO2		0x04UL
#define	GPIO3		0x08UL
#define	GPIO4		0x10UL
#define SET_GPIO(dwLanBase,gpioBit) 			\
{												\
	DWORD dwGPIO_CFG;							\
	dwGPIO_CFG = GetRegDW(dwLanBase, GPIO_CFG);	\
	dwGPIO_CFG |= gpioBit; 						\
	SetRegDW(dwLanBase, GPIO_CFG, dwGPIO_CFG); 	\
}

#define CLEAR_GPIO(dwLanBase,gpioBit)			\
{												\
	DWORD dwGPIO_CFG;							\
	dwGPIO_CFG = GetRegDW(dwLanBase, GPIO_CFG);	\
	dwGPIO_CFG &=~ (gpioBit);					\
	SetRegDW(dwLanBase, GPIO_CFG, dwGPIO_CFG); 	\
}

#else

#define SET_GPIO(dwLanBase,gpioBit)
#define CLEAR_GPIO(dwLanBase,gpioBit)

// Can only work-around LED1 if it's NOT being used for debug purposes
#define	USE_LED1_WORK_AROUND		// 10/100 LED link-state inversion
#endif
#define	USE_PHY_WORK_AROUND		// output polarity inversion

#ifdef USE_LED1_WORK_AROUND
#define GPIO_CFG_LED1_DIS_ (GPIO_CFG_GPIOBUF0_|GPIO_CFG_GPIODIR0_|GPIO_CFG_GPIOD0_)
#endif

#define LINKMODE_ANEG					0x40UL
#define LINKMODE_ASYM_PAUSE 			0x20UL
#define LINKMODE_SYM_PAUSE				0x10UL
#define LINKMODE_100_FD 				0x08UL
#define LINKMODE_100_HD 				0x04UL
#define LINKMODE_10_FD					0x02UL
#define LINKMODE_10_HD					0x01UL
#define LINKMODE_DEFAULT				0x7FUL

/*
STRUCTURE: LAN9118_DATA
	This structure is used by the chip layer.
	It remembers where to access registers.
	It remembers revision IDs if there are subtle
	  differences between them.
	It remembers modes of operation.
	It will start tx and rx queue information
	And it may be used for other things that
	  have not been conceived yet.
	The members of this structure should be 
	considered private and only excessable from 
	the Lan_xxx functions
*/
typedef struct _LAN9118_DATA {
	DWORD dwLanBase;
	DWORD dwIdRev;
	DWORD dwFpgaRev;

	BOOLEAN LanInitialized;
	BOOLEAN InterruptsInitialized;
	BOOLEAN TxInitialized;
	BOOLEAN SoftwareInterruptSignal;
	BOOLEAN PhyInitialized;

	BYTE bPadding1[3];
	DWORD dwPhyId;

	BYTE bPhyAddress;
	BYTE bPhyModel;
	BYTE bPhyRev;
	BYTE bPadding2;

#define LINK_NO_LINK		(0UL)
#define LINK_10MPS_HALF 	(1UL)
#define LINK_10MPS_FULL 	(2UL)
#define LINK_100MPS_HALF	(3UL)
#define LINK_100MPS_FULL	(4UL)
#define LINK_AUTO_NEGOTIATE (5UL)
	DWORD dwLinkMode;
	DWORD dwRemoteFaultCount;

	DWORD dwMacAddrHigh16;
	DWORD dwMacAddrLow32;
#ifdef USE_LED1_WORK_AROUND
	DWORD dwOriginalGpioCfg;
	BOOLEAN LED1NotYetRestored;
	BYTE  bPadding3[3];		// for lint
#endif
#ifdef USE_PHY_WORK_AROUND
#define MIN_PACKET_SIZE (64UL)
	DWORD dwTxStartMargen;
	BYTE LoopBackTxPacket[MIN_PACKET_SIZE];
	DWORD dwTxEndMargen;
	DWORD dwRxStartMargen;
	BYTE LoopBackRxPacket[MIN_PACKET_SIZE];
	DWORD dwRxEndMargen;
	DWORD dwResetCount;
#endif

} LAN9118_DATA, *PLAN9118_DATA;
typedef const LAN9118_DATA * const CPCLAN9118_DATA;

/*
FUNCTION: Lan_WriteTxFifo
	This function is used to write a buffer to the
	Tx Fifo in PIO mode.
	This function is only intended to be called 
	  from with in other Lan_xxx functions.
*/
void Lan_WriteTxFifo(const DWORD dwLanBase, const DWORD * const pdwBuf, const DWORD dwDwordCount);

/*
FUNCTION: Lan_ReadRxFifo
	This function is used to read a buffer to the 
	Rx Fifo in PIO mode.
	This function is only intended to be called
	  from with in other Lan_xxx functions.
*/
inline void Lan_ReadRxFifo(const DWORD dwLanBase, DWORD * const pdwBuf, const DWORD dwDwordCount);

/*
FUNCTION: Lan_GetMacRegDW
	This function is used to read a Mac Register.
	This function is only intended to be called
	  from with in other Lan_xxx functions.
*/
inline DWORD Lan_GetMacRegDW(
	const DWORD dwLanBase, 
	const DWORD dwOffset);
#define LanReadMac(dwOffset)	\
		Lan_GetMacRegDW(pLan9118Data->dwLanBase, (dwOffset))

/*
FUNCTION: Lan_SetMacRegDW
	This function is used to write a Mac register.
	This function is only intended to be called
	  from with in other Lan_xxx functions.
*/
inline void Lan_SetMacRegDW(
	const DWORD dwLanBase, 
	const DWORD dwOffset, 
	const DWORD dwVal);
#define LanWriteMac(dwOffset, dwValue)	\
		Lan_SetMacRegDW(pLan9118Data->dwLanBase, (dwOffset), (dwValue))

/*
FUNCTION: Lan_GetMiiRegW, Lan_GetPhyRegW
	This function is used to read a Mii/Phy register.
	This function is only intended to be called 
	  from with in other Lan_xxx functions.
*/
inline WORD Lan_GetMiiRegW(
	const DWORD dwLanBase,
	const DWORD dwPhyAddress,
	const DWORD dwMiiIndex);
#define Lan_GetPhyRegW(LanBase, PhyAddr, Index) \
		Lan_GetMiiRegW(LanBase, (DWORD)PhyAddr, Index)
#define LanReadPhy(MiiIndex) \
		Lan_GetPhyRegW(pLan9118Data->dwLanBase, (DWORD)pLan9118Data->bPhyAddress, (MiiIndex))
#define AdapterReadPhy(MiiIndex) \
		Lan_GetPhyRegW(pAdapter->lan9118_data.dwLanBase, (DWORD)pAdapter->lan9118_data.bPhyAddress, (MiiIndex))

/*
FUNCTION: Lan_SetMiiRegW, Lan_SetPhyRegW
	This function is used to write a Mii/Phy register.
	This function is only intended to be called
	  from with in other Lan_xxx functions.
*/
inline void Lan_SetMiiRegW(
	const DWORD dwLanBase,
	const DWORD dwPhyAddress,
	const DWORD dwMiiIndex,
	const WORD wVal);
#define Lan_SetPhyRegW Lan_SetMiiRegW
#define LanWritePhy(MiiIndex, Value) \
		Lan_SetPhyRegW(pLan9118Data->dwLanBase, (DWORD)pLan9118Data->bPhyAddress, (MiiIndex), (Value))
#define AdapterWritePhy(MiiIndex, Value) \
		Lan_SetPhyRegW(pAdapter->lan9118_data.dwLanBase, (DWORD)pAdapter->lan9118_data.bPhyAddress, (MiiIndex), (WORD)(Value))

/*
FUNCTION: Lan_ShowRegs
	This function is used to display the registers. 
	Except the phy.
*/
void Lan_ShowRegs(const DWORD dwLanBase);

/*
FUNCTION: Lan_ShowMiiRegs, Lan_ShowPhyRegs
	This function is used to display the registers
	in the phy.
*/
void Lan_ShowMiiRegs(const DWORD dwLanBase, const DWORD dwPhyAddr);
#define Lan_ShowPhyRegs Lan_ShowMiiRegs

/*
FUNCTION: Lan_Initialize
  This function should be the first Lan_xxx function called
  It begins to initialize the LAN9118_DATA structure.
  It reads some ID values from the chip.
  It resets the chip.

RETURN VALUE:
	returns TRUE on Success,
	returns FALSE on Failure,
*/
BOOL Lan_Initialize(PLAN9118_DATA const pLan9118Data, const DWORD dwLanBase);

/*
FUNCTION: Lan_InitializePhy
  This function should be called after Lan_InitializeInterrupts.
  Continues to initialize the LAN9118_DATA structure.
  It reads some phy ID values from the phy
  It resets the phy.
  It initializes phy interrupts
RETURN VALUE:
  returns TRUE on Success,
  returns FALSE on Failure
*/
BOOL Lan_InitializePhy(PLAN9118_DATA pLan9118Data, BYTE bPhyAddress);

/*
FUNCTION: Lan_RequestLink
  This function should be called after Lan_InitializePhy
  It begins the interrupt driven process of establishing a link.
  It works with Lan_HandlePhyInterrupt and requires 
  Lan_HandlePhyInterrupt to be called with in the interrupt 
	handler when PHY_INT bit is set in the INT_STS register.
*/
void Lan_RequestLink(
	PLAN9118_DATA pLan9118Data,
	DWORD dwLinkRequest);

/*
FUNCTION: Lan_HandlePhyInterrupt
  This function should be called inside the interrupt handler when
	the PHY_INT bit is set in the INT_STS register.
  This function will handle and clear that interrupt status.
  It is used mainly in managing the link state.
*/
void Lan_HandlePhyInterrupt(PLAN9118_DATA pLan9118Data);

/*
FUNCTION: Lan_EstablishLink
  This function similar to Lan_RequestLink except that it is
  not interrupt driven. This function will not return until 
  either the link is established or link can not be established.
RETURN VALUE:
	returns TRUE on success.
	returns FALSE on failure.
*/
BOOL Lan_EstablishLink(PLAN9118_DATA pLan9118Data, const DWORD linkRequest);

/*
FUNCTION: Lan_GetLinkMode
  Gets the link mode from the PHY,
  Stores it in LAN9118_DATA and also returns it.
RETURN VALUE:
  one of the following link modes
	LINK_NO_LINK

⌨️ 快捷键说明

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