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

📄 rtl8019end.c

📁 s2410测试程序,源码,用来深入了解三星2410芯片
💻 C
📖 第 1 页 / 共 5 页
字号:
/* rtl8019End.c - RTL8019 END network interface driver *//* Copyright 1984-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01o,24jan02,rcs  added support for user setting the "Configuration Register A"                 or "Configuration Register B" from the load end string.01n,14jan02,dat  Removing warnings from Diab compiler01m,05dec00,dat  merge from sustaining to tor2_0_x01l,30nov00,pai  corrected the handling of EIOCSFLAGS ioctl (SPR #29423).01k,30nov00,pai  IFF_UP flag set in rtl8019Start routine (SPR #32034, 34433).01j,10may00,pai  Discontinued use of splnet() (SPR #28366).  The rtl8019Send()                 routine now returns END_ERR_BLOCK instead of ERROR so that                 upper-level protocols will clean up passed in mBlk.01i,28jul99,jkf  cleaned up warnings, fixed multicast support. (SPR#27921)01h,31mar99,sbs  changed atoi to strtoul for offset parameter parsing.                 (SPR #26208)01g,29mar99,dat  SPR 26119, documentation, usage of .bS/.bE01f,09feb99,fle  doc : fixed a problem with end of library description01e,27jan99,dat  removed most of the lint. (more work needed)01d,11aug98,mem  rewrote part of the overwrite recovery handling to		 avoid locking up the driver.01c,20may98,mem  added additional debug tracing, removed free of		 pMblk in rtl8019PollSend().01b,06may98,mem  integrated changes from Brian Nash.01a,16mar98,mem	 written, based on drv/netif/if_ene.c.*//*DESCRIPTIONThis module implements the RTL8019 Ethernet network interface driver.EXTERNAL INTERFACEThe only external interface is the rtl8019EndLoad() routine, which expectsthe <initString> parameter as input.  This parameter passes in acolon-delimited string of the format:<unit>:<adrs>:<vecNum>:<intLvl>:<byteAccess>:<usePromEnetAddr>:<offset>The rtl8019EndLoad() function uses strtok() to parse the string.TARGET-SPECIFIC PARAMETERS.IP <unit>A convenient holdover from the former model.  This parameter is used onlyin the string name for the driver..IP <adrs>Tells the driver where to find the rtl8019..IP <vecNum>Configures the rtl8019 device to generate hardware interruptsfor various events within the device. Thus, it containsan interrupt handler routine.  The driver calls sysIntConnect() to connectits interrupt handler to the interrupt vector generated as a result ofthe rtl8019 interrupt..IP <intLvl>This parameter is passed to an external support routine, sysLanIntEnable(),which is described below in "External Support Requirements." This routineis called during as part of driver's initialization.  It handles anyboard-specific operations required to allow the servicing of a rtl8019interrupt on targets that use additional interrupt controller devices tohelp organize and service the various interrupt sources.  This parametermakes it possible for this driver to avoid all board-specific knowledge ofsuch devices..IP <byteAccess>Tells the driver the RTL8019 is jumpered to operate in 8-bit mode.Requires that SYS_IN_WORD_STRING() and SYS_OUT_WORD_STRING() bewritten to properly access the device in this mode..IP <usePromEnetAddr>Attempt to get the ethernet address for the device from the on-chip(board) PROM attached to the RTL8019.  Will fall back to using theBSP-supplied ethernet address if this parameter is 0 or if unable toread the ethernet address..IP <offset>Specifies the memory alignment offset.EXTERNAL SUPPORT REQUIREMENTSThis driver requires several external support functions, defined as macros:.CS    SYS_INT_CONNECT(pDrvCtrl, routine, arg)    SYS_INT_DISCONNECT (pDrvCtrl, routine, arg)    SYS_INT_ENABLE(pDrvCtrl)    SYS_IN_CHAR(pDrvCtrl, reg, pData)    SYS_OUT_CHAR(pDrvCtrl, reg, pData)    SYS_IN_WORD_STRING(pDrvCtrl, reg, pData)    SYS_OUT_WORD_STRING(pDrvCtrl, reg, pData).CEThese macros allow the driver to be customized for BSPs that usespecial versions of these routines.The macro SYS_INT_CONNECT is used to connect the interrupt handler tothe appropriate vector.  By default it is the routine intConnect().The macro SYS_INT_DISCONNECT is used to disconnect the interrupt handler priorto unloading the module.  By default this is a dummy routine thatreturns OK.The macro SYS_INT_ENABLE is used to enable the interrupt level for theend device.  It is called once during initialization.  By default this isthe routine sysLanIntEnable(), defined in the module sysLib.o.The macro SYS_ENET_ADDR_GET is used to get the ethernet address (MAC)for the device.  The single argument to this routine is the END_DEVICEpointer.  By default this routine copies the ethernet address stored inthe global variable rtl8019EndEnetAddr into the END_DEVICE structure.The macros SYS_IN_CHAR, SYS_OUT_CHAR, SYS_IN_WORD_STRING andSYS_OUT_WORD_STRING are used for accessing the rtl8019 device.  Thedefault macros map these operations onto sysInByte(), sysOutByte(),sysInWordString() and sysOutWordString().INCLUDES:end.h endLib.h etherMultiLib.hSEE ALSO: muxLib, endLib.I "Writing and Enhanced Network Driver"INTERNAL: We are using the DP83905 manual as our reference. It is RTL8019 compatible.*/#include "vxWorks.h"#include "endLib.h"			/* Common END structures. */#include "etherMultiLib.h"#include "netLib.h"#include "cacheLib.h"#include "lstLib.h"			/* Needed to maintain protocol list. */#include "iv.h"#include "stdlib.h"#include "sysLib.h"#include "intLib.h"#include "taskLib.h"#include "rtl8019End.h"			/* Common defines. *//***** LOCAL DEFINITIONS *****//*#define RTL8019_ALL_INTS    (IM_RST | IM_XDCE | IM_CNTE | IM_OVWE | IM_TXEE | IM_RXEE | IM_PTXE | IM_PRXE)*/#define RTL8019_ALL_INTS    ( IM_CNTE | IM_OVWE | IM_TXEE | IM_RXEE | IM_PTXE | IM_PRXE)/* * AUTODIN-II, FDDI, ethernet polynomial for 32 bit CRC. * * The polynomial is expressed: * *   ( x^32 + x^26 + x^23 + x^22 + x^16 + *     x^12 + x^11 + x^10 + x^8  + x^7  + *            x^5  + x^4  + x^2  + x^1  + 1 ) = 0x04c11db7 * * Where x = base 2 (binary) and x^32 is ignored for CRC. * (x^32, is not in 32 bit value (ends at x^31) */#define CRC32_POLYNOMIAL	0x04c11db7/* Configuration items */#define END_SPEED		10000000/* Naming items */#define RTL8019_DEV_NAME	"rtl"#define RTL8019_DEV_NAME_LEN	4#define RTL8019_RX_BUFS		64#define ARCH_S3C2410/* * Default macro definitions for BSP interface. * These macros can be redefined in a wrapper file, to generate * a new module with an optimized interface. *//* Macro to connect interrupt handler to vector */#ifndef SYS_INT_CONNECT#define SYS_INT_CONNECT(pDrvCtrl,rtn,arg,pResult) \	{ \	IMPORT STATUS sysIntConnect(); \	*pResult = intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC (pDrvCtrl->ivec), \			     rtn, (int)arg); \	}#endif/* Macro to disconnect interrupt handler from vector */#ifndef SYS_INT_DISCONNECT#define SYS_INT_DISCONNECT(pDrvCtrl,rtn,arg,pResult) \	{ \	*pResult = OK; /* HELP: need a real routine */ \	}#endif/* Macro to enable the appropriate interrupt level */#ifndef SYS_INT_ENABLE#define SYS_INT_ENABLE(pDrvCtrl) \	{ \	IMPORT void sysLanIntEnable(); \	sysLanIntEnable (pDrvCtrl->ilevel); \	}#endif/* Macro to get the ethernet address from the BSP */#ifndef SYS_ENET_ADDR_GET#define SYS_ENET_ADDR_GET(pDevice) \	rtl8019EnetAddrGet(pDevice)#endif/* * Macros to do a short (UINT16) access to the chip. Default * assumes a normal memory mapped device. * CPU_FAMILY is used to avoid conflict between x86 and non * x86 defintitions (proper) of these macro's.  This is * to avoid some compiler warnings. */#if     (CPU_FAMILY == I80X86)/* sysLib.h uses two declarations of sys<Blah>WordString */#ifndef SYS_OUT_CHAR#define SYS_OUT_CHAR(pDrvCtrl,addr,value) \	sysOutByte((pDrvCtrl)->base + (int) (addr),(char) (value))#endif#ifndef SYS_IN_CHAR#define SYS_IN_CHAR(pDrvCtrl,addr,pData) \	(*(pData) = (UCHAR) sysInByte((pDrvCtrl)->base + (int) (addr)))#endif/* sysLib.h head setsup to declarations of sys<Blah>WordString */#ifndef SYS_IN_WORD_STRING#define SYS_IN_WORD_STRING(pDrvCtrl,addr,pData,len) \	(sysInWordString ((pDrvCtrl)->base + (int) (addr), (short *)(pData), \			  (len)))#endif#ifndef SYS_OUT_WORD_STRING#define SYS_OUT_WORD_STRING(pDrvCtrl,addr,pData,len) \	(sysOutWordString ((pDrvCtrl)->base + (int) (addr), (short *)(pData), \			   (len)))#endif#else /* #if     (CPU_FAMILY == I80X86) */#ifndef SYS_OUT_CHAR#define SYS_OUT_CHAR(pDrvCtrl,addr,value) \    	sysOutByte((pDrvCtrl)->base + (UINT) (addr), (value))#endif#ifndef SYS_IN_CHAR#define SYS_IN_CHAR(pDrvCtrl,addr,pData) \    	(*(pData) = (UCHAR) sysInByte((pDrvCtrl)->base + (UINT) (addr)))#endif#ifndef SYS_IN_WORD_STRING#define SYS_IN_WORD_STRING(pDrvCtrl,addr,pData,len) \    	(sysInWordString ((pDrvCtrl)->base + (UINT) (addr),  \			  (UINT16 *)(pData), (len)))#endif#ifndef SYS_OUT_WORD_STRING#define SYS_OUT_WORD_STRING(pDrvCtrl,addr,pData,len) \    	(sysOutWordString ((pDrvCtrl)->base + (UINT) (addr), \			   (UINT16 *) (pData), (len)))#endif#endif /* #if     (CPU_FAMILY == I80X86) */#ifndef SYS_IN_BYTE_STRING#define SYS_IN_BYTE_STRING(pDrvCtrl,addr,pData,len) \    	(sysInByteString ((pDrvCtrl)->base + (UINT) (addr),  \			  (UCHAR *)(pData), (len)))#endif#ifndef SYS_OUT_BYTE_STRING#define SYS_OUT_BYTE_STRING(pDrvCtrl,addr,pData,len) \    	(sysOutByteString ((pDrvCtrl)->base + (UINT) (addr), \			   (UCHAR *) (pData), (len)))#endif/* A shortcut for getting the hardware address from the MIB II stuff. */#define END_HADDR(pEnd)	\		((pEnd)->mib2Tbl.ifPhysAddress.phyAddress)#define END_HADDR_LEN(pEnd) \		((pEnd)->mib2Tbl.ifPhysAddress.addrLength)/* Statistics we gather from the RTL8019 */typedef struct    {    UINT collisions;    UINT crcs;    UINT aligns;    UINT missed;    UINT overruns;    UINT disabled;    UINT deferring;    UINT underruns;    UINT aborts;    UINT outofwindow;    UINT heartbeats;    UINT badPacket;    UINT shortPacket;    UINT tnoerror;    UINT rnoerror;    UINT terror;    UINT rerror;    UINT overwrite;    UINT wrapped;    UINT interrupts;    UINT reset;    UINT strayint;    UINT jabber;    } RTL8019_STAT;/* * The definition of the driver control structure.  The packetBuf[] * array needs to be kept at least word-aligned as it gets passed to * SYS_OUT_WORD_STRING() and some architectures cannot handle * misaligned accesses. */typedef struct rtl8019_device    {    END_OBJ		endObj;		/* The class we inherit from. */    END_ERR		lastError;	/* Last error passed to muxError */    int			lastIntError;	/* last interrupt signalled error */    int			unit;		/* unit number */    int			ivec;		/* interrupt vector */    int			ilevel;		/* interrupt level */    int			byteAccess;	/* 8-bit access mode */    int			usePromEnetAddr;/* enet addr from PROM */    ULONG		base;		/* base address */    int			offset;		/* offset for memory alignment */    char		packetBuf [RTL8019_BUFSIZ];	/* long-aligned */    volatile long	flags;		/* Our local flags. */    volatile UCHAR	current;	/* current-page reg at interrupt */    volatile ULONG	imask;		/* interrupt mask */    volatile RTL8019_STAT stats;		/* RTL8019 stats */    UCHAR		enetAddr[6];	/* ethernet address */    UCHAR		mcastFilter[8];	/* multicast filter */    UCHAR		nextPacket;	/* where the next received packet is */    CL_POOL_ID		clPoolId;    int                 configRegA;     /* configuration register A */    int                 configRegB;     /* configuration register B */} RTL8019END_DEVICE;/* Definitions for the flags field */#define END_PROMISCUOUS_FLAG	0x01#define END_RECV_HANDLING_FLAG	0x02#define END_TX_IN_PROGRESS	0x04#define END_TX_BLOCKED		0x08#define END_POLLING		0x10#define END_OVERWRITE		0x20#define END_OVERWRITE2		0x40/***** DEBUG MACROS *****/#undef DEBUG#ifdef DEBUG#   include "stdio.h"#   include "logLib.h"	#define DBG_PRINTF(X)	printf X	#define DUMP_DATA(X,Y)  hex_dump(X,Y)	#define ERR_PRINTF(X)	printf X	#define UDELAY(X)	#define DUMP_IOCTL_CODE(X)   DBG_PRINTF(("IOCTRL:"#X"=0x%08x\n", X))#else	#define DBG_PRINTF(X)	#define DUMP_DATA(X,Y)	#define ERR_PRINTF(X)	printf X	#define DUMP_IOCTL_CODE(X)	#define UDELAY(X)#endif /* ENDDEBUG *//***** LOCALS *****/char rtl8019EnetAddr[6] = {0x08,0x0e,0x3e,0x26,0x0a,0x5b};/* imports *//*IMPORT char 	rtl8019EnetAddr[];*/IMPORT int 	endMultiLstCnt (END_OBJ *);/* forward static functions */LOCAL STATUS	rtl8019Verify (RTL8019END_DEVICE * pDrvCtrl);LOCAL void	rtl8019Int (RTL8019END_DEVICE* pDrvCtrl);LOCAL void	rtl8019HandleRcvInt (RTL8019END_DEVICE* pDrvCtrl);LOCAL void	rtl8019Config (RTL8019END_DEVICE* pDrvCtrl,			      int intEnable);LOCAL void	rtl8019OverwriteRecover (RTL8019END_DEVICE* pDrvCtrl,					UCHAR cmdStatus);LOCAL int	rtl8019PacketGet (RTL8019END_DEVICE* pDrvCtrl, char *pData);LOCAL void	rtl8019AddrFilterSet (RTL8019END_DEVICE* pDrvCtrl);LOCAL UINT32 	rtl8019CrcWork (UINT8 inChar, UINT32 inCrc);LOCAL void	rtl8019EnetAddrGet (RTL8019END_DEVICE* pDrvCtrl);LOCAL UCHAR	rtl8019GetCurr (RTL8019END_DEVICE* pDrvCtrl);LOCAL void	rtl8019DataIn (RTL8019END_DEVICE* pDrvCtrl, int eneAddress,			      int len, char* pData);LOCAL void	rtl8019DataOut (RTL8019END_DEVICE* pDrvCtrl, char* pData,			       int len, int eneAddress);LOCAL STATUS	rtl8019Parse (RTL8019END_DEVICE* pDrvCtrl, char* initString);LOCAL STATUS	rtl8019MemInit (RTL8019END_DEVICE* pDrvCtrl);LOCAL STATUS	rtl8019PollStart (RTL8019END_DEVICE* pDrvCtrl);LOCAL STATUS	rtl8019PollStop (RTL8019END_DEVICE* pDrvCtrl);/* END Specific interfaces. *//* This is the only externally visible interface. */END_OBJ * 	rtl8019EndLoad (char* initString, void *pBSP);LOCAL STATUS	rtl8019Start (void* pCookie);LOCAL STATUS	rtl8019Stop (void* pCookie);LOCAL STATUS	rtl8019Unload (void *pCookie);LOCAL int	rtl8019Ioctl (void *pCookie, int cmd, caddr_t data);LOCAL STATUS	rtl8019Send (void *pCookie, M_BLK_ID pBuf);LOCAL STATUS	rtl8019MCastAdd (void *pCookie, char* pAddress);LOCAL STATUS	rtl8019MCastDel (void *pCookie, char* pAddress);LOCAL STATUS	rtl8019MCastGet (void *pCookie, MULTI_TABLE* pTable);LOCAL STATUS	rtl8019PollSend (void *pCookie, M_BLK_ID pBuf);LOCAL STATUS	rtl8019PollRecv (void *pCookie, M_BLK_ID pBuf);/* * Declare our function table.  This is static across all driver * instances. */LOCAL NET_FUNCS rtl8019FuncTable =    {    (FUNCPTR) rtl8019Start,	/* Function to start the device. */    (FUNCPTR) rtl8019Stop,	/* Function to stop the device. */    (FUNCPTR) rtl8019Unload,	/* Unloading function for the driver. */    (FUNCPTR) rtl8019Ioctl,	/* Ioctl function for the driver. */    (FUNCPTR) rtl8019Send,	/* Send function for the driver. */    (FUNCPTR) rtl8019MCastAdd,	/* Multicast address add function for the */				/* driver. */    (FUNCPTR) rtl8019MCastDel,	/* Multicast address delete function for */				/* the driver. */    (FUNCPTR) rtl8019MCastGet,	/* Multicast table retrieve function for */				/* the driver. */    (FUNCPTR) rtl8019PollSend,	/* Polling send function for the driver. */    (FUNCPTR) rtl8019PollRecv,	/* Polling receive function for the driver. */    endEtherAddressForm, /* put address info into a NET_BUFFER */    endEtherPacketDataGet, /* get pointer to data in NET_BUFFER */    endEtherPacketAddrGet  /* Get packet addresses. */

⌨️ 快捷键说明

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