📄 if_fn.c
字号:
/* if_fn.c - Fujitsu MB86960 NICE Ethernet network interface driver *//* Copyright 1992-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01v,15jul97,spm added ARP request to SIOCSIFADDR ioctl handler01u,07apr97,spm code cleanup, corrected statistics, and upgraded to BSD 4.401t,02mar95,jdi fixed line break in fnattach() title.01s,05jul94,vin removed spl calls, fixed collision control01r,10may94,vin fixed input parameter passed to etherInputHook01q,04mar94,vin added input & output hooks, removed explicit copying from mbufs in the fnOutput(). Alternate scheme to detect transmit done implemented which negates the requirement for processing the transmit done interrupt. 01p,07jul93,rfs Fixed SPR #2374.01o,11aug93,jmm Changed ioctl.h and socket.h to sys/ioctl.h and sys/socket.h01n,19feb93,jdi documentation cleanup.01m,22oct92,rfs Fixed SPR #1710.01l,13oct92,rfs Added documentation.01k,02oct92,rfs Made multiple attach calls return OK, not ERROR.01j,09sep92,gae documentation tweaks.01i,31aug92,rfs Free MBUFs on output if flags down.01h,16jul92,rfs Consolidated attach() and init().01g,11jul92,jwt incorporated JDI documentation cleanup; SPARC #ifdefs.01f,16jun92,jwt passed through the ansification filter -changed includes to have absolute path from h/ -fixed #else and #endif -changed copyright notice -fixed path names for #include files.01e,14may92,rfs Added semaphore for transmitter access. Added one-time-only calling of the attach() and init() routines. Reduced size of SRAM buffer.01d,14apr92,rfs Changed Rx to only look at "good packet" status bit. Changed all splnet() to splimp().01c,25mar92,jwt enhanced interrupt and cache support; cleanup.01b,24mar92,rfs Moved sysEnet* () support routines to the sysLib. Changed the attach and init routines to support new method of obtaining board specific parameters. Changed name of the NICE device header file. Changed the name of the support routines called to access ASI space.01a,10mar92,rfs Created from mule driver source.*//*This module implements the Fujitsu MB86960 NICE Ethernet network interfacedriver.This driver is non-generic and has only been run on the Fujitsu SPARCliteEvaluation Board. It currently supports only unit number zero.The driver must be given several target-specific parameters, and some externalsupport routines must be provided. These parameters, and the mechanisms usedto communicate them to the driver, are detailed below.BOARD LAYOUTThis device is on-board. No jumpering diagram is necessary.EXTERNAL INTERFACEThis driver provides the standard external interface with the followingexceptions. All initialization is performed within the attach routine;there is no separate initialization routine. Therefore, in the global interfacestructure, the function pointer to the initialization routine is NULL.The only user-callable routine is fnattach(), which publishes the `fn'interface and initializes the driver and device.TARGET-SPECIFIC PARAMETERSExternal support routines provide all parameters:.iP "device I/O address"This parameter specifies the base address of the device's I/O registerset. This address is assumed to live in SPARClite alternate addressspace..iP "interrupt vector"This parameter specifies the interrupt vector to be used by the driverto service an interrupt from the NICE device. The driver will connectthe interrupt handler to this vector by calling intConnect()..iP "Ethernet address"This parameter specifies the unique, six-byte address assigned to theVxWorks target on the Ethernet..LPEXTERNAL SUPPORT REQUIREMENTSThis driver requires five external support functions:.iP "char *sysEnetIOAddrGet (int unit)" "" 9 -1This routine returns the base address of the NICEcontrol registers. The driver calls this routine once, using fnattach()..iP "int sysEnetVectGet (int unit)"This routine returns the interrupt vector numberto be used to connect the driver's interrupt handler.The driver calls this routine once, using fnattach()..iP "STATUS sysEnetAddrGet (int unit, char *pCopy)"This routine provides the six-byte Ethernet addressused by <unit>. It must copy the six-byteaddress to the space provided by <pCopy>. It returns OK, or ERROR if it fails.The driver calls this routine once, using fnattach()..iP "void sysEnetIntEnable (int unit), void sysEnetIntDisable (int unit)"These routines enable or disable the interrupt from the NICE for thespecified <unit>. Typically, this involves interrupt controller hardware,either internal or external to the CPU. The driver calls these routines only during initialization, using fnattach()..LPSYSTEM RESOURCE USAGEWhen implemented, this driver requires the following system resources: - one mutual exclusion semaphore - one interrupt vector - 3944 bytes in text section (text) - 0 bytes in the initialized data section (data) - 3152 bytes in the uninitialized data section (BSS)The above data and BSS requirements are for the SPARClite architecture and mayvary for other architectures. Code size (text) varies greatly betweenarchitectures and is therefore not quoted here.The NICE device maintains a private buffer for all packets transmitted andreceived. Therefore, the driver does not require any system memory to sharewith the device. This also eliminates all data cache coherency issues.SEE ALSO: ifLib*//* includes */#include "vxWorks.h" /* direct references */#include "sys/types.h" /* direct references */#include "sys/ioctl.h" /* direct references */#include "sys/socket.h" /* direct references */#include "net/mbuf.h" /* direct references */#include "net/if.h" /* direct and indirect references */#include "net/if_subr.h"#include "netinet/in.h" /* indirect references only */#include "netinet/in_systm.h" /* indirect references only */#include "netinet/in_var.h" /* direct references */#include "netinet/if_ether.h" /* direct references */#include "iv.h" /* direct references */#include "errno.h" /* direct references */#include "semLib.h" /* direct references */#include "intLib.h"#include "logLib.h"#include "netLib.h"#include "etherLib.h"#include "stdio.h"#include "drv/netif/if_fn.h" /* device description *//***** COMPILATION SWITCHES *****/#undef FN_DEBUG/* defines */#define MAX_UNITS 1 /* maximum units supported */ #define DRV_CTRL_SIZ sizeof (DRV_CTRL)#define ENET_HDR_REAL_SIZ 14/* Pre-defined interrupt masks */#define NORM_INTRMASK (DLCR3_RX_PKT | DLCR3_OVR_FLO) #define NO_RX_INTRMASK (DLCR3_OVR_FLO)/* Start transmission */#define KICK_TRANSMIT (BMR10_TMST | BMR11_MASK16 | BMR11_RST_TX16 \ | BMR11_OPT_16_COLL | 0x0100) /* typedefs */typedef struct arpcom IDR;typedef struct nice_ctrl /* Driver control structure */ { IDR idr; /* interface data record */ BOOL attached; /* indicates unit is attached */ char *pDev; /* ptr to the device registers */ int vector; /* vector number to use */#ifdef BSD43_DRIVER SEM_ID TxSem; /* transmitter semaphore */#endif } DRV_CTRL;/* shorthand for struct members */#define fn_if idr.ac_if#define fn_enaddr idr.ac_enaddr/* Debug support */#ifdef FN_DEBUG#define DEBUG_SPEC (fnDebug & 0x01) /* debug special routines */#define DEBUG_TX (fnDebug & 0x02) /* debug transmit routines */#define DEBUG_RX (fnDebug & 0x04) /* debug receive routines */#define DEBUG_INTR (fnDebug & 0x08) /* debug interrupt routines */#endif /* FN_DEBUG *//* globals */#ifdef FN_DEBUGint fnDebug; /* set this from shell to select debugging */#endif /* FN_DEBUG *//* External functions not defined in any header files. * Some of these are the functions required of the BSP modules. */extern char * sysEnetIOAddrGet ();extern int sysEnetVectGet ();extern STATUS sysEnetAddrGet ();extern STATUS sysEnetIntEnable ();extern STATUS sysEnetIntDisable ();extern STATUS sysEnetIntAck ();extern BOOL arpresolve ();/* External functions that access the alternate address space that the * device lives in. */#if (CPU_FAMILY == SPARC)extern u_short sysAsiGeth();extern void sysAsiSeth();#endif/* locals *//* driver control structures, one per unit */ LOCAL DRV_CTRL drvCtrl [MAX_UNITS]; LOCAL int overFlowCnt; /* overFlow Count */LOCAL int rcvPktError; /* receive packet error *//* forward declarations */LOCAL int fnIoctl (struct ifnet * pIfnet, int cmd, char * pArgs);LOCAL int fnReset (int unit);#ifdef BSD43_DRIVERLOCAL int fnOutput (struct arpcom * pIDR, struct mbuf * pMbuf, struct sockaddr * pDest);#elseLOCAL int fnTxStartup (DRV_CTRL *pDrvCtrl);#endifLOCAL void fnRxEvent (DRV_CTRL *pDrvCtrl);LOCAL BOOL fnRxMore (DRV_CTRL *pDrvCtrl);LOCAL STATUS fnRxProcessPkt (DRV_CTRL *pDrvCtrl);LOCAL void fnIntr (int unit);#ifdef BSD43_DRIVERLOCAL BOOL convertDestAddr (IDR *pIdr, struct sockaddr * pDestSktAddr, char * pDestEnetAddr, u_short * pPacketType, struct mbuf * pMbuf);#endif/********************************************************************************* fnattach - publish the `fn' network interface and initialize the driver and device** The routine publishes the `fn' interface by filling in a network interface* record and adding this record to the system list. This routine also* initializes the driver and the device to the operational state.** RETURNS: OK or ERROR.*/STATUS fnattach ( int unit /* unit number */ ) { char * pDev; /* ptr to the device */ DRV_CTRL * pDrvCtrl; /* Sanity check the unit number */ if (unit < 0 || unit >= MAX_UNITS) return (ERROR); /* Ensure single invocation per system life */ pDrvCtrl = & drvCtrl [unit]; if (pDrvCtrl->attached) return (OK); /* Publish our existence as an available interface */#ifdef BSD43_DRIVER ether_attach (&pDrvCtrl->fn_if, unit, "fn", NULL, fnIoctl, fnOutput, fnReset);#else ether_attach ( &pDrvCtrl->fn_if, unit, "fn", (FUNCPTR) NULL, (FUNCPTR) fnIoctl, (FUNCPTR) ether_output, (FUNCPTR) fnReset ); pDrvCtrl->fn_if.if_start = (FUNCPTR)fnTxStartup;#endif { /* Driver initialization */ /* First obtain the board and unit specific info from the BSP. */ pDev = sysEnetIOAddrGet (unit); if (pDev == NULL) { printf ("fn: error obtaining IO addr\n"); return (ERROR); } pDrvCtrl->pDev = pDev; /* save ptr in ctrl struct */ pDrvCtrl->vector = sysEnetVectGet (unit); if (pDrvCtrl->vector == NULL) { printf ("fn: error obtaining interrupt vector\n"); return (ERROR); } if (sysEnetAddrGet (unit, pDrvCtrl->fn_enaddr) == ERROR) { printf ("fn: error obtaining Ethernet address\n"); return (ERROR); }#ifdef BSD43_DRIVER pDrvCtrl->TxSem = semMCreate ( SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE ); if (pDrvCtrl->TxSem == NULL) { printf ("fn: error creating transmitter semaphore\n"); return (ERROR); }#endif /* Connect the interrupt routine. */ intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC (pDrvCtrl->vector), fnIntr, unit); } /* End block */ { /* device initialization */ /* Block local variables */ u_short temp; /* scratch pad */ /* initial setup of config register 1 */#if (CPU_FAMILY == SPARC) sysAsiSeth (pDev + NICE_CONFIG, DLCR6_DISABLE_DLC | /* resets things */ DLCR6_BIT_6 | /* just do it */ DLCR6_SYS_BUS_16 | /* use 16 bits */ DLCR6_BUF_BUS_16 | /* use 16 bits */ DLCR6_TBS_4KB | /* Tx buf is 4kb */ DLCR6_BS_16KB | /* total buf is 16k */ DLCR7_CNF_NICE | /* normal NICE mode */ DLCR7_PWRDN_OFF | /* normal power mode */ DLCR7_BIT_4 | /* just do it */ DLCR7_REG_BNK_DLC | /* map node ID regs */ DLCR7_ENDIAN_LITTLE /* device is little */ );#endif /* Mask off all interrupts and clear all event flags. */ #if (CPU_FAMILY == SPARC) sysAsiSeth (pDev + NICE_INTRMASK, 0); sysAsiSeth (pDev + NICE_STATUS, 0xffff);#endif /* Disable device interrupt at system level and clear any pended. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -