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

📄 mbcend.c

📁 Tornado 2.0.2 source code!vxworks的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* mbcEnd.c - Motorola 68302fads END network interface driver *//* Copyright 1996-2000 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01e,11jun00,ham  removed reference to etherLib.01d,27jan00,dat  fixed use of NULL01c,29mar99,dat  SPR 26119, documentation, usage of .bS/.bE01b,13mar99,db   suppressed warnings. integrated driver(SPR #25386)01a,28jan99,dra  written.*//*DESCRIPTIONThis is a driver for the Ethernet controller on the 68EN302 chip.  The devicesupports a 16-bit interface, data rates up to 10 Mbps, a dual-ported RAM, andtransparent DMA.  The dual-ported RAM is used for a 64-entry CAM table, and a128-entry buffer descriptor table.  The CAM table is used to set the Ethernetaddress of the Ethernet device or to program multicast addresses.  The bufferdescriptor table is partitioned into fixed-size transmit and receive tables.The DMA operation is transparent and transfers data between the internal FIFOsand external buffers pointed to by the receive and transmit-buffer descriptorsduring transmits and receives.The driver requires that the memory used for transmit and receive buffers beallocated in cache-safe RAM area.  Up to 61 multicast addresses are supported.  Multicast addresses aresupported by adding the multicast ethernet addresses to the addresstable in the ethernet part.  If more than 61 multicast addresses aredesired, address hashing must be used (the address table holds 62entries at most). However, address hashing does not appear to work inthis ethernet part.A glitch in the EN302 Rev 0.1 device causes the Ethernet transmitter tolock up from time to time. The driver uses a watchdog timer to reset theEthernet device when the device runs out of transmit buffers and cannotrecover within 20 clock ticks.BOARD LAYOUTThis device is on-chip.  No jumpering diagram is necessary.  EXTERNAL INTERFACEThe only external interface is the mbcEndLoad() routine, which expectsthe <initString> parameter as input.  This parameter passes in a colon-delimited string of the format:unit:memAddr:ivec:txBdNum:rxBdNum:dmaParms:bufBase:offsetTARGET-SPECIFIC PARAMETERS.IP <unit>A convenient holdover from the former model.  This parameter is used onlyin the string name for the driver..IP <memAddr>This parameter is the base address of the Ethernet module. The driveraddresses all other Ethernet device registers as offsets from this address..IP <ivec>The interrupt vector to be used in connecting the interrupt handler..IP <txBdNum>The number of transmit buffer descriptors to use..IP <rxBdNum>The number of receive buffer descriptors to use.The number of transmit and receive buffer descriptors (BDs) used isconfigurable by the user while attaching the driver.  Each BD is 8bytes in size and resides in the chip's dual-ported memory, while itsassociated buffer, 1520 bytes in size, resides in cache-safeconventional RAM. A minimum of 2 receive and 2 transmit BDs should beallocated.  If this parameter is 0, a default of 32 BDs will be used.The maximum number of BDs depends on how the dual-ported BD RAM ispartitioned.  The 128 BDs in the dual-ported BD RAM can partitionedinto transmit and receive BD regions with 8, 16, 32, or 64 transmitBDs and corresponding 120, 112, 96, or 64 receive BDs..IP <dmaParms>Ethernet DMA parameters.This parameter is used to specify the settings of burst limit, water-mark, andtransmit early, which control the Ethernet DMA, and is used to set the EDMAregister..IP <bufBase>Base address of the buffer pool.This parameter is used to notify the driver that space for thetransmit and receive buffers need not be allocated, but should betaken from a cache-coherent private memory space provided by the userat the given address.  The user should be aware that memory used forbuffers must be 4-byte aligned and non-cacheable.  All the buffersmust fit in the given memory space; no checking will be performed.Each buffer is 1520 bytes.  If this parameter is "NULL", space forbuffers will be obtained by calling cacheDmaMalloc() in mbcMemInit()..IP <offset>Specifies the memory alignment offset..LPEXTERNAL 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_OUT_SHORT(pDrvCtrl, reg, data)    SYS_IN_SHORT(pDrvCtrl, reg, pData).CEThere are default values in the source code for these macros.  They presumememory-mapped accesses to the device registers and the normal intConnect(),and intEnable() BSP functions.  The first argument to each is the devicecontroller structure. Thus, each has access back to all the device-specificinformation.  Having the pointer in the macro facilitates the addition of new features to this driver.SYSTEM RESOURCE USAGEThe driver requires the following system resources:    - one watchdog timer    - one interrupt vector    - 52 bytes in the initialized data section (data)    - 0 bytes in the uninitialized data section (bss)The above data and BSS requirements are for the MC68000 architectureand can vary for other architectures.  Code size (text) varies greatly between architectures and is therefore not quoted here.If the driver allocates the memory shared with the Ethernet deviceunit, it does so by calling the cacheDmaMalloc() routine.  For thedefault case of 32 transmit buffers, 32 receive buffers, the totalsize requested is roughly 100,000 bytes.  If a memory region isprovided to the driver, the size of this region is adjustable to suituser needs.This driver can only operate if the shared memory region is non-cacheable,or if the hardware implements bus snooping.  The driver cannot maintaincache coherency for the device because the buffers are asynchronouslymodified by both the driver and the device, and these fields may share thesame cache line.  Additionally, the chip's dual-ported RAM must bedeclared as non-cacheable memory where applicable.INCLUDES:end.h endLib.h etherMultiLib.hSEE ALSO: muxLib, endLib.I "Writing and Enhanced Network Driver"*//* includes */#include "vxWorks.h"#include "stdlib.h"#include "cacheLib.h"#include "intLib.h"#include "end.h"			/* Common END structures. */#include "endLib.h"#include "lstLib.h"			/* Needed to maintain protocol list. */#include "wdLib.h"#include "iv.h"#include "semLib.h"#include "logLib.h"#include "netLib.h"#include "stdio.h"#include "sysLib.h"#include "errno.h"#include "errnoLib.h"#include "memLib.h"#include "iosLib.h"#undef	ETHER_MAP_IP_MULTICAST#include "etherMultiLib.h"		/* multicast stuff. */#include "net/mbuf.h"#include "net/unixLib.h"#include "net/protosw.h"#include "net/systm.h"#include "net/if_subr.h"#include "net/route.h"#include "sys/socket.h"#include "sys/ioctl.h"#include "sys/times.h"#include "drv/end/mbcEnd.h"/* defines */#define FRAME_MAX	1518	/* maximum frame size */#define FRAME_MIN	64	/* minimum frame size */#define ENET_ADDR_SIZE	6	/* size of ethernet src/dst addresses */#define TX_BD_MIN	2	/* minimum number of Tx buffer descriptors */#define RX_BD_MIN	2	/* minimum number of Rx buffer descriptors */#define TX_BD_DEFAULT	0x20	/* default number of Tx buffer descriptors */#define RX_BD_DEFAULT	0x20	/* default number of Rx buffer descriptors */#define WD_TIMEOUT	20	/* number of clock ticks for reset timeout */#define MBC_BUFSIZ      (1520)#define MBC_MIN_FBUF	(1520)		/* min first buffer size */#define EH_SIZE		(14)#define MBC_SPEED_10M	10000000	/* 10Mbs */#define MBC_SPEED	MBC_SPEED_10M/* Cache macros */#define MBC_CACHE_INVALIDATE(address, len) \        CACHE_DRV_INVALIDATE (&pDrvCtrl->cacheFuncs, (address), (len))#define MBC_CACHE_PHYS_TO_VIRT(address) \        CACHE_DRV_PHYS_TO_VIRT (&pDrvCtrl->cacheFuncs, (address))#define MBC_CACHE_VIRT_TO_PHYS(address) \        CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs, (address))/* * 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 */LOCAL void dummyIsr (void) { };#ifndef SYS_INT_DISCONNECT#define SYS_INT_DISCONNECT(pDrvCtrl,rtn,arg,pResult) \    { \    IMPORT STATUS intConnect(); \    *pResult = intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC ((pDrvCtrl)->ivec), \			    dummyIsr, (int)(arg)); \    }#endif/* Macro to get the ethernet address from the BSP */#ifndef SYS_ENET_ADDR_GET#define SYS_ENET_ADDR_GET(pAddress) \    { \    sysEnetAddrGet (pDrvCtrl->unit, (char *) (pAddress)); \    }#endif /* SYS_ENET_ADDR_GET *//* * Macros to do a short (UINT16) access to the chip. Default * assumes a normal memory mapped device. */#ifndef SYS_OUT_SHORT#define SYS_OUT_SHORT(pDrvCtrl, addr, value) \	(*(volatile UINT16 *)((pDrvCtrl)->memAddr + (addr)) = (value))#endif#ifndef SYS_IN_SHORT#define SYS_IN_SHORT(pDrvCtrl, addr, pData) \	(*(pData) = (*(volatile UINT16 *)((pDrvCtrl)->memAddr + (addr))))#endif#ifndef SYS_UPDATE_SHORT#define SYS_UPDATE_SHORT(pDrvCtrl, addr, val) \	((*(volatile UINT16 *)((pDrvCtrl)->memAddr + (addr))) |= (val))#endif#ifndef SYS_RESET_SHORT#define SYS_RESET_SHORT(pDrvCtrl, addr, val) \	((*(volatile UINT16 *)((pDrvCtrl)->memAddr + (addr))) &= ~(val))#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)/* Definitions for the flags field */#define MBC_POLLING		0x1#define MBC_MEM_ALLOC_FLAG      0x2/* DEBUG MACROS */#undef DRV_DEBUG#ifdef	DRV_DEBUG#define DRV_DEBUG_OFF		0x0000#define DRV_DEBUG_RX		0x0001#define	DRV_DEBUG_TX		0x0002#define DRV_DEBUG_INT		0x0004#define	DRV_DEBUG_POLL		(DRV_DEBUG_POLL_RX | DRV_DEBUG_POLL_TX)#define	DRV_DEBUG_POLL_RX	0x0008#define	DRV_DEBUG_POLL_TX	0x0010#define	DRV_DEBUG_LOAD		0x0020#define	DRV_DEBUG_IOCTL		0x0040#define	DRV_DEBUG_MULTI		0x0080#define	DRV_DEBUG_ERROR		0x0100int	mbcDebug = DRV_DEBUG_ERROR;#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)		\    do								\        {							\	if (mbcDebug & (FLG))					\	    logMsg (X0, X1, X2, X3, X4, X5, X6);		\	}							\    while (0)#define DRV_PRINT(FLG, X)					\    do								\        {							\	if (mbcDebug & (FLG))					\	    printf X;						\	}							\    while (0)#else /* DRV_DEBUG */    #define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)	do {} while (0)#define DRV_PRINT(FLG, X)				do {} while (0)    #endif /* DRV_DEBUG */	/* typedefs */typedef struct free_args    {    void *	arg1;    void *	arg2;    } FREE_ARGS;        /* The definition of the driver control structure */typedef struct MBC_DEVICE    {    END_OBJ     end;			/* The class we inherit from. */    int		unit;			/* unit number */    int         ivec;                   /* interrupt vector */    WDOG_ID	wdId;			/* watchdog id */    UCHAR *	memAddr;		/* address of mbc's shared memory */    int		txBdNum;		/* number of tx buffer descriptors */    int		rxBdNum;		/* number of rx buffer descriptors */    int		dmaParms;		/* DMA parameters */    int         offset;			/* packet data offset */    UCHAR	enetAddr[6];		/* ethernet address */        ULONG	flags;			/* Our local flags. */    BOOL	txBlocked;		/* TX is blocked */    BOOL	txCleaning;		/* TX is being cleaned */    BOOL	rxHandling;		/* rcv task is scheduled */    char *	bufBase;		/* address of memory pool; */    int		bdSize;			/* buffer descriptor size */    MBC_BD *	txBdBase;		/* transmit BD array address */    MBC_BD *	rxBdBase;		/* receive BD array address */    int		txBdNext;		/* next transmit BD to fill */    int		txClNext;		/* next transmit BD to clean */    int		rxBdNext;		/* next receive BD to read */    int		resetCounter;		/* number of times the device reset */    CACHE_FUNCS cacheFuncs;             /* cache function pointers */    UCHAR	mcastFilter[8];		/* multicast address mask */    FUNCPTR     freeRtn[128];           /* Array of free routines. */    struct free_args    freeData[128];  /* Array of free arguments */                                        /* to the free routines. */    CL_POOL_ID	pClPoolId;		/* cluster pool */    } MBC_DEVICE;/* globals */IMPORT STATUS	sysEnetAddrGet (int unit, char * addr);IMPORT int	endMultiLstCnt (END_OBJ * pEnd);/* locals *//* forward static functions */LOCAL void	mbcReset	(MBC_DEVICE * pDrvCtrl);LOCAL void	mbcInt		(MBC_DEVICE * pDrvCtrl);LOCAL void	mbcHandleRcvInt (MBC_DEVICE * pDrvCtrl);LOCAL STATUS	mbcRecv		(MBC_DEVICE * pDrvCtrl, char * pData);LOCAL void	mbcConfig	(MBC_DEVICE * pDrvCtrl);LOCAL STATUS	mbcInit		(MBC_DEVICE * pDrvCtrl);LOCAL void	mbcAddrFilterSet(MBC_DEVICE * pDrvCtrl);LOCAL void	mbcScrubTRing	(MBC_DEVICE * pDrvCtrl);LOCAL STATUS	mbcPollStart	(MBC_DEVICE * pDrvCtrl);LOCAL STATUS	mbcPollStop	(MBC_DEVICE * pDrvCtrl);LOCAL void	mbcDeviceRestart(MBC_DEVICE * pDrvCtrl);LOCAL STATUS	mbcParse	(MBC_DEVICE * pDrvCtrl, char * initString);LOCAL STATUS	mbcMemInit	(MBC_DEVICE * pDrvCtrl);/* END Specific interfaces. *//* This is the only externally visible interface. */END_OBJ * 	mbcEndLoad	(char * initString);LOCAL STATUS	mbcStart	(void * pDrvCtrl);LOCAL STATUS	mbcStop		(void * pDrvCtrl);LOCAL STATUS	mbcUnload	(void * pDrvCtrl);LOCAL int	mbcIoctl	(void * pDrvCtrl, int cmd, caddr_t data);LOCAL STATUS	mbcSend		(void * pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS	mbcMCastAdd	(void * pDrvCtrl, char * pAddress);LOCAL STATUS	mbcMCastDel	(void * pDrvCtrl, char * pAddress);LOCAL STATUS	mbcMCastGet	(void * pDrvCtrl, MULTI_TABLE * pTable);LOCAL STATUS	mbcPollSend	(void * pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS	mbcPollRcv	(void * pDrvCtrl, M_BLK_ID pBuf);/* * Declare our function table.  This is static across all driver * instances. */LOCAL NET_FUNCS mbcFuncTable =    {    (FUNCPTR) mbcStart,	   /* Function to start the device. */    (FUNCPTR) mbcStop,	   /* Function to stop the device. */    (FUNCPTR) mbcUnload,   /* Unloading function for the driver. */    (FUNCPTR) mbcIoctl,	   /* Ioctl function for the driver. */    (FUNCPTR) mbcSend,	   /* Send function for the driver. */    (FUNCPTR) mbcMCastAdd, /* Multicast add function for the  driver*/    (FUNCPTR) mbcMCastDel, /* Multicast delete function for driver */    (FUNCPTR) mbcMCastGet, /* Multicast retrieve function for driver*/    (FUNCPTR) mbcPollSend, /* Polling send function */    (FUNCPTR) mbcPollRcv,  /* Polling receive function */    endEtherAddressForm,   /* put address info into a NET_BUFFER */    endEtherPacketDataGet, /* get pointer to data in NET_BUFFER */    endEtherPacketAddrGet  /* Get packet addresses. */    };/******************************************************************************** mbcEndLoad - initialize the driver and device** This routine initializes the driver and the device to the operational state.* All of the device specific parameters are passed in the initString.*

⌨️ 快捷键说明

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