ixethaccend.c
来自「ixEthAccEnd END network interface driver」· C语言 代码 · 共 1,681 行 · 第 1/4 页
C
1,681 行
/* ixEthAccEnd.c - ixEthAccEnd END network interface driver *//* Copyright 1984-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01q,28oct02,jb Deal with chained xmit buffers01p,25oct02,jb Tuning shutdown01o,17oct02,jb Revise buffer mgmnt to allow loaning01n,18sep02,jb Changing Rx buffer queue size01m,18sep02,jb Adding cache mgmt to xmit and rearranging cache mgmt for recv01l,01aug02,jb Fixing sysToMonitor, adding Multicast support, .etc01k,31jul02,jb Fixing name errors01j,31jul02,jb Adding rx Buffer list overflow checking01i,17jul02,jb Renamed file, renaming bsp specific routines to segregate CSR library01h,12oct99,dat SPR 28492, fixed ixEthAccEndSend.01i,29mar99,dat documentation, SPR 26119. fixed .bS/.bE usage01h,28feb99,pul changed the prototype for END NET functions, to have END_OBJ reference as the first argument rather than device object, fix for SPR#2428501g,17feb99,dat documentation, removed beta warning01f,29sep98,dat Fixed problem in PollRx relating to SPR 22325.01e,28sep98,dat SPR 22325, system mode transition, plus fixed warnings and IxEthAccEnd is now compilable (SPR 22204).01d,17jul98,db changed "holder" in ixEthAccEndParse from char** to char *. fixed references to "holder" in ixEthAccEndParse(spr #21464).01c,15oct97,gnn revised to reflect the latest API changes.01b,05may97,dat added TODO's for documentation and macros.01a,04feb97,gnn written.*//*DESCRIPTIONThe 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 sysIxEthAccEndEnetAddr into the END_DEVICE structure.INCLUDES:end.h endLib.h etherMultiLib.hSEE ALSO: LoadLib, 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 "etherLib.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 "IxEthAcc.h"#include "IxNpeDl.h"#include "config.h"#ifdef INCLUDE_IXETHACCENDIMPORT int endMultiLstCnt (END_OBJ* pEnd);IMPORT void dumpMbufPtr(M_BLK *mBufPtr);IMPORT IX_STATUS ixdp425EthLibInit();IMPORT IX_STATUS ixdp425EthPhysInit(int port);IMPORT BOOL ixdp425EthLibInitialised;IMPORT UINT32 ixEthAccPhyAddresses[IX_ETH_ACC_NUMBER_OF_PORTS];/* Defines cacheability of mBlks/mBufs and cBlks */#undef IXE_CACHED_BUFFERS_ENABLE /* DO NOT ENABLE THIS - Not tested */#define IXP425_END_CACHE_INVALIDATE(address, len) cacheInvalidate(DATA_CACHE,address,len)#define IXP425_END_CACHE_FLUSH(address, len) cacheFlush(DATA_CACHE,address,len)#define IXP425_END_CACHE_PHYS_TO_VIRT(address) (address)#define IXP425_END_CACHE_VIRT_TO_PHYS(address) (address)/* defines *//* Configuration items */#define IXP_EH_SIZE ENET_HDR_REAL_SIZ#define END_BUFSIZ (ETHERMTU + IXP_EH_SIZE + 6)#define END_SPEED_10M 10000000 /* 10Mbs */#define END_SPEED_100M 100000000 /* 100Mbs */#define END_SPEED END_SPEED_10M/* * 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 *//* 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 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) \ { \ ixEthAccPortUnicastMacAddressGet((IxEthAccPortId)pDevice->unit, \ (IxEthAccMacAddr *)&pDevice->enetAddr); \ }#endif/* * Macros to do a short (UINT16) access to the chip. Default * assumes a normal memory mapped device. */#ifndef IxEthAccEnd_OUT_SHORT #define IxEthAccEnd_OUT_SHORT(pDrvCtrl,addr,value) \ (*(USHORT *)addr = value)#endif#ifndef IxEthAccEnd_IN_SHORT #define IxEthAccEnd_IN_SHORT(pDrvCtrl,addr,pData) \ (*pData = *addr)#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)/* Max buffer list count */#define MAX_IX_ETH_ACC_REC_BUF (IXETHACC_MBLKS)/* typedefs *//* Que to manage multiple receive buffer's per call to ixEthAccEndHandleRcvInt */typedef struct ix_rec_buffer_queue { struct ix_rec_buffer_queue *ix_rec_next; M_BLK *ix_rec_buf; }IX_ETH_ACC_REC_BUF;/* The definition of the driver control structure */typedef struct end_device { END_OBJ end; /* The class we inherit from. */ int unit; /* unit number */ int ivec; /* interrupt vector */ int ilevel; /* interrupt level */ char* pShMem; /* real ptr to shared memory */ long flags; /* Our local flags. */ UCHAR enetAddr[6]; /* ethernet address */ CACHE_FUNCS cacheFuncs; /* cache function pointers */ CL_POOL_ID pClPoolId; /* cluster pool */ IX_ETH_ACC_REC_BUF recBufList[MAX_IX_ETH_ACC_REC_BUF + 1]; IX_ETH_ACC_REC_BUF *recNext; int rxBufsAlloc; /* The number of cblk/mblk pairs allocated for NPE */ int rxBufsActive; /* The number of cblk/mblk pairs owned by NPE */ int rxHandling; /* rcv task is scheduled */ int rxMaxHandling; /* rcv task is scheduled */ } END_DEVICE;/* Definitions for the flags field */#define IxEthAccEnd_PROMISCUOUS 0x1#define IxEthAccEnd_POLLING 0x2/* Status register bits, returned by ixEthAccEndStatusRead() */#define IxEthAccEnd_RINT 0x1 /* Rx interrupt pending */#define IxEthAccEnd_TINT 0x2 /* Tx interrupt pending */#define IxEthAccEnd_RXON 0x4 /* Rx on (enabled) */#define IxEthAccEnd_VALID_INT 0x3 /* Any valid interrupt pending */#define IxEthAccEnd_MIN_FBUF (IX_ETHACC_RX_MBUF_MIN_SIZE) /* min first buffer size *//* DEBUG MACROS */#undef DEBUG#undef IXP_DRV_DEBUG#ifdef DEBUG #define LOGMSG(x,a,b,c,d,e,f) \ {\ logMsg (x,a,b,c,d,e,f); \ }#else #define LOGMSG(x,a,b,c,d,e,f)#endif /* ENDDEBUG */#ifdef IXP_DRV_DEBUG #define IXP_DRV_DEBUG_OFF 0x0000 #define IXP_DRV_DEBUG_RX 0x0001 #define IXP_DRV_DEBUG_TX 0x0002 #define IXP_DRV_DEBUG_INT 0x0004 #define IXP_DRV_DEBUG_POLL (IXP_DRV_DEBUG_POLL_RX | IXP_DRV_DEBUG_POLL_TX) #define IXP_DRV_DEBUG_POLL_RX 0x0008 #define IXP_DRV_DEBUG_POLL_TX 0x0010 #define IXP_DRV_DEBUG_LOAD 0x0020 #define IXP_DRV_DEBUG_IOCTL 0x0040 #define IXP_DRV_DEBUG_BUFINIT 0x0080 #define IXP_DRV_DEBUG_ERROR 0x0100 #define IXP_DRV_DEBUG_RX_HANDLING 0x0200 #define IXP_DRV_DEBUG_POLL_REDIR 0x10000 #define IXP_DRV_DEBUG_LOG_NVRAM 0x20000int IxEthAccEndDebug = IXP_DRV_DEBUG_RX | IXP_DRV_DEBUG_TX ; #define IXP_DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6) \ if (IxEthAccEndDebug & FLG) \ logMsg(X0, X1, X2, X3, X4, X5, X6); #define IXP_DRV_PRINT(FLG,X) \ if (IxEthAccEndDebug & FLG) printf X;#else /*IXP_DRV_DEBUG*/ #define IXP_DRV_LOG(DBG_SW, X0, X1, X2, X3, X4, X5, X6) #define IXP_DRV_PRINT(DBG_SW,X)#endif /*IXP_DRV_DEBUG*//* LOCALS */LOCAL BOOL ixEthAccShutdown = 0;/* forward static functions */LOCAL void ixEthAccEndReset (END_DEVICE *pDrvCtrl);LOCAL void ixEthAccEndHandleRcvInt (END_DEVICE *pDrvCtrl, IX_ETH_ACC_REC_BUF *pBufList);LOCAL void ixEthAccEndConfig (END_DEVICE *pDrvCtrl);#ifdef IXE_ETHACC_POLL_ENABLELOCAL UINT ixEthAccEndStatusRead (END_DEVICE *pDrvCtrl);#endif /* IXE_ETHACC_POLL_ENABLE *//* END Specific interfaces. *//* This is the only externally visible interface. */END_OBJ* ixEthAccEndLoad (char* initString, void* unUsed);LOCAL STATUS ixEthAccEndStart (END_OBJ* pDrvCtrl);LOCAL STATUS ixEthAccEndStop (END_DEVICE* pDrvCtrl);LOCAL STATUS ixEthAccEndIoctl (END_DEVICE * pDrvCtrl, int cmd, caddr_t data);LOCAL STATUS ixEthAccEndUnload (END_DEVICE* pDrvCtrl);LOCAL STATUS ixEthAccEndSend (END_DEVICE* pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS ixEthAccEndMCastAdd (END_DEVICE* pDrvCtrl, char* pAddress);LOCAL STATUS ixEthAccEndMCastDel (END_DEVICE* pDrvCtrl, char* pAddress);LOCAL STATUS ixEthAccEndMCastGet (END_DEVICE* pDrvCtrl, MULTI_TABLE* pTable);LOCAL STATUS ixEthAccEndPollStart (END_DEVICE* pDrvCtrl);LOCAL STATUS ixEthAccEndPollStop (END_DEVICE* pDrvCtrl);LOCAL STATUS ixEthAccEndPollSend (END_DEVICE* pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS ixEthAccEndPollRcv (END_DEVICE* pDrvCtrl, M_BLK_ID pBuf);LOCAL void ixEthAccEndAddrFilterSet(END_DEVICE *pDrvCtrl);LOCAL STATUS ixEthAccEndParse ();LOCAL STATUS ixEthAccEndMemInit ();LOCAL void ixEthAccEndTxDoneCallback(UINT32 callbackTag, M_BLK *buffer);LOCAL void ixEthAccEndRxCallback(UINT32 callbackTag, M_BLK *buffer);/* * Declare our function table. This is static across all driver * instances. */LOCAL NET_FUNCS ixEthAccEndFuncTable ={ (FUNCPTR) ixEthAccEndStart, /* Function to start the device. */ (FUNCPTR) ixEthAccEndStop, /* Function to stop the device. */ (FUNCPTR) ixEthAccEndUnload, /* Unloading function for the driver. */ (FUNCPTR) ixEthAccEndIoctl, /* Ioctl function for the driver. */ (FUNCPTR) ixEthAccEndSend, /* Send function for the driver. */ (FUNCPTR) ixEthAccEndMCastAdd, /* Multicast add function for the */ /* driver. */ (FUNCPTR) ixEthAccEndMCastDel, /* Multicast delete function for */ /* the driver. */ (FUNCPTR) ixEthAccEndMCastGet, /* Multicast retrieve function for */ /* the driver. */ (FUNCPTR) ixEthAccEndPollSend, /* Polling send function */ (FUNCPTR) ixEthAccEndPollRcv, /* Polling receive function */ endEtherAddressForm, /* put address info into a NET_BUFFER */ endEtherPacketDataGet, /* get pointer to data in NET_BUFFER */ endEtherPacketAddrGet /* Get packet addresses. */};END_DEVICE *ixEthAccpDrvCtrl[2];CL_DESC IxEthAccEndClDescTbl[] = /* network cluster pool configuration table */{ /* clusterSize num memArea memSize ----------- ---- ------- ------- {ETHERMTU + IXP_EH_SIZE + 6, 0, NULL, 0} */ {IX_ETHACC_RX_MBUF_MIN_SIZE, 0, NULL, 0}};#ifdef IXP_DRV_DEBUG_LOG#define IXETHACC_BUF_HISTORY_CNT 4096struct IxEthAccBuffDebug { M_BLK_ID pMhdr; char *pData; char *pClist; int pSize;};struct IxEthAccBuffDebug ixEthAccTxBufs[2][IXETHACC_BUF_HISTORY_CNT];int ixEthAccTxBufsIndex[2] = { 0,0 };struct IxEthAccBuffDebug ixEthAccRxBufs[2][IXETHACC_BUF_HISTORY_CNT];int ixEthAccRxBufsIndex[2] = { 0,0 };struct IxEthAccBuffDebug ixEthAccRtnRxBufs[2][IXETHACC_BUF_HISTORY_CNT];int ixEthAccRtnRxBufsIndex[2] = { 0,0 };#endif /* IXP_DRV_DEBUG_LOG *//********************************************************************************* ixEthAccEndLoad - 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.** The string contains the target specific parameters like this:** "register addr:int vector:int level:shmem addr:shmem size:shmem width"** RETURNS: An END object pointer or NULL on error.*/END_OBJ* ixEthAccEndLoad(char* initString, /* String to be parsed by the driver. */void* unUsed){ END_DEVICE *pDrvCtrl; IX_ETH_ACC_REC_BUF *rBufList; UINT32 index; if (initString == NULL) { IXP_DRV_LOG (IXP_DRV_DEBUG_LOAD,"Failed to load IXP425 Ethernet END, null init string was given\n",0,0,0,0,0,0); return NULL; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?