📄 ne2000end.c
字号:
/* ne2000End.c - NE2000 END network interface driver */
/* Copyright 1984-2002 Wind River Systems, Inc. */
#include "copyright_wrs.h"
/*
modification history
--------------------
01o,23jul04,a_m BSP定制 for 多刃剑开发板
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 compiler
01m,05dec00,dat merge from sustaining to tor2_0_x
01l,30nov00,pai corrected the handling of EIOCSFLAGS ioctl (SPR #29423).
01k,30nov00,pai IFF_UP flag set in ne2000Start routine (SPR #32034, 34433).
01j,10may00,pai Discontinued use of splnet() (SPR #28366). The ne2000Send()
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/.bE
01f,09feb99,fle doc : fixed a problem with end of library description
01e,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 ne2000PollSend().
01b,06may98,mem integrated changes from Brian Nash.
01a,16mar98,mem written, based on drv/netif/if_ene.c.
*/
/*
DESCRIPTION
This module implements the NE2000 Ethernet network interface driver.
EXTERNAL INTERFACE
The only external interface is the ne2000EndLoad() routine, which expects
the <initString> parameter as input. This parameter passes in a
colon-delimited string of the format:
<unit>:<adrs>:<vecNum>:<intLvl>:<byteAccess>:<usePromEnetAddr>:<offset>
The ne2000EndLoad() function uses strtok() to parse the string.
TARGET-SPECIFIC PARAMETERS
.IP <unit>
A convenient holdover from the former model. This parameter is used only
in the string name for the driver.
.IP <adrs>
Tells the driver where to find the ne2000.
.IP <vecNum>
Configures the ne2000 device to generate hardware interrupts
for various events within the device. Thus, it contains
an interrupt handler routine. The driver calls sysIntConnect() to connect
its interrupt handler to the interrupt vector generated as a result of
the ne2000 interrupt.
.IP <intLvl>
This parameter is passed to an external support routine, sysLanIntEnable(),
which is described below in "External Support Requirements." This routine
is called during as part of driver's initialization. It handles any
board-specific operations required to allow the servicing of a ne2000
interrupt on targets that use additional interrupt controller devices to
help organize and service the various interrupt sources. This parameter
makes it possible for this driver to avoid all board-specific knowledge of
such devices.
.IP <byteAccess>
Tells the driver the NE2000 is jumpered to operate in 8-bit mode.
Requires that SYS_IN_WORD_STRING() and SYS_OUT_WORD_STRING() be
written 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 NE2000. Will fall back to using the
BSP-supplied ethernet address if this parameter is 0 or if unable to
read the ethernet address.
.IP <offset>
Specifies the memory alignment offset.
EXTERNAL SUPPORT REQUIREMENTS
This 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)
.CE
These macros allow the driver to be customized for BSPs that use
special versions of these routines.
The macro SYS_INT_CONNECT is used to connect the interrupt handler to
the appropriate vector. By default it is the routine intConnect().
The macro SYS_INT_DISCONNECT is used to disconnect the interrupt handler prior
to unloading the module. By default this is a dummy routine that
returns OK.
The macro SYS_INT_ENABLE is used to enable the interrupt level for the
end device. It is called once during initialization. By default this is
the 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_DEVICE
pointer. By default this routine copies the ethernet address stored in
the global variable ne2000EndEnetAddr into the END_DEVICE structure.
The macros SYS_IN_CHAR, SYS_OUT_CHAR, SYS_IN_WORD_STRING and
SYS_OUT_WORD_STRING are used for accessing the ne2000 device. The
default macros map these operations onto sysInByte(), sysOutByte(),
sysInWordString() and sysOutWordString().
INCLUDES:
end.h endLib.h etherMultiLib.h
SEE ALSO: muxLib, endLib
.I "Writing and Enhanced Network Driver"
INTERNAL: We are using the DP83905 manual as our reference. It is
NE2000 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 "ne2000End.h" /* Common defines. : 包含BSP目录的定制头文件*/
/***** LOCAL DEFINITIONS *****/
#define NE2000_ALL_INTS (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 NE2000_DEV_NAME "ene"
#define NE2000_DEV_NAME_LEN 4
/*
* 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 */
/* : 名称替换sysIntConnect->intConnect,其他相同 */
#ifndef SYS_INT_CONNECT
#define SYS_INT_CONNECT(pDrvCtrl,rtn,arg,pResult) \
{ \
IMPORT STATUS intConnect(); \
*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 */
/* : 名称替换sysLanIntEnable->intEnable,返回类型不同void->STATUS */
#ifndef SYS_INT_ENABLE
#define SYS_INT_ENABLE(pDrvCtrl) \
{ \
IMPORT STATUS intEnable(); \
intEnable (pDrvCtrl->ilevel); \
}
#endif
/* Macro to get the ethernet address from the BSP */
#ifndef SYS_ENET_ADDR_GET
#define SYS_ENET_ADDR_GET(pDevice) \
ne2000EnetAddrGet(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) */
/* 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 NE2000 */
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;
} NE2000_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 ne2000_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 [NE2000_BUFSIZ]; /* long-aligned */
volatile long flags; /* Our local flags. */
volatile UCHAR current; /* current-page reg at interrupt */
volatile ULONG imask; /* interrupt mask */
volatile NE2000_STAT stats; /* NE2000 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 */
} NE2000END_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"
int endDebug = 0;
# define ENDLOGMSG(x) \
do { \
if (endDebug) \
logMsg x; \
} while (0)
#else
# define ENDLOGMSG(x)
#endif /* ENDDEBUG */
/***** LOCALS *****/
/* imports */
IMPORT char ne2000EnetAddr[];
IMPORT int endMultiLstCnt (END_OBJ *);
/* forward static functions */
LOCAL void ne2000Int (NE2000END_DEVICE* pDrvCtrl);
LOCAL void ne2000HandleRcvInt (NE2000END_DEVICE* pDrvCtrl);
LOCAL void ne2000Config (NE2000END_DEVICE* pDrvCtrl,
int intEnable);
LOCAL void ne2000OverwriteRecover (NE2000END_DEVICE* pDrvCtrl,
UCHAR cmdStatus);
LOCAL int ne2000PacketGet (NE2000END_DEVICE* pDrvCtrl, char *pData);
LOCAL void ne2000AddrFilterSet (NE2000END_DEVICE* pDrvCtrl);
LOCAL UINT32 ne2000CrcWork (UINT8 inChar, UINT32 inCrc);
LOCAL void ne2000EnetAddrGet (NE2000END_DEVICE* pDrvCtrl);
LOCAL UCHAR ne2000GetCurr (NE2000END_DEVICE* pDrvCtrl);
LOCAL void ne2000DataIn (NE2000END_DEVICE* pDrvCtrl, int eneAddress,
int len, char* pData);
LOCAL void ne2000DataOut (NE2000END_DEVICE* pDrvCtrl, char* pData,
int len, int eneAddress);
LOCAL STATUS ne2000Parse (NE2000END_DEVICE* pDrvCtrl, char* initString);
LOCAL STATUS ne2000MemInit (NE2000END_DEVICE* pDrvCtrl);
LOCAL STATUS ne2000PollStart (NE2000END_DEVICE* pDrvCtrl);
LOCAL STATUS ne2000PollStop (NE2000END_DEVICE* pDrvCtrl);
/* END Specific interfaces. */
/* This is the only externally visible interface. */
END_OBJ * ne2000EndLoad (char* initString, void *pBSP);
LOCAL STATUS ne2000Start (void* pCookie);
LOCAL STATUS ne2000Stop (void* pCookie);
LOCAL STATUS ne2000Unload (void *pCookie);
LOCAL int ne2000Ioctl (void *pCookie, int cmd, caddr_t data);
LOCAL STATUS ne2000Send (void *pCookie, M_BLK_ID pBuf);
LOCAL STATUS ne2000MCastAdd (void *pCookie, char* pAddress);
LOCAL STATUS ne2000MCastDel (void *pCookie, char* pAddress);
LOCAL STATUS ne2000MCastGet (void *pCookie, MULTI_TABLE* pTable);
LOCAL STATUS ne2000PollSend (void *pCookie, M_BLK_ID pBuf);
LOCAL STATUS ne2000PollRecv (void *pCookie, M_BLK_ID pBuf);
/*
* Declare our function table. This is static across all driver
* instances.
*/
LOCAL NET_FUNCS ne2000FuncTable =
{
(FUNCPTR) ne2000Start, /* Function to start the device. */
(FUNCPTR) ne2000Stop, /* Function to stop the device. */
(FUNCPTR) ne2000Unload, /* Unloading function for the driver. */
(FUNCPTR) ne2000Ioctl, /* Ioctl function for the driver. */
(FUNCPTR) ne2000Send, /* Send function for the driver. */
(FUNCPTR) ne2000MCastAdd, /* Multicast address add function for the */
/* driver. */
(FUNCPTR) ne2000MCastDel, /* Multicast address delete function for */
/* the driver. */
(FUNCPTR) ne2000MCastGet, /* Multicast table retrieve function for */
/* the driver. */
(FUNCPTR) ne2000PollSend, /* Polling send function for the driver. */
(FUNCPTR) ne2000PollRecv, /* Polling receive function for the driver. */
endEtherAddressForm, /* put address info into a NET_BUFFER */
(FUNCPTR) endEtherPacketDataGet, /* get pointer to data in NET_BUFFER */
(FUNCPTR) endEtherPacketAddrGet /* Get packet addresses. */
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -