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

📄 if_enp.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* if_enp.c - CMC ENP 10/L Ethernet network interface driver *//* Copyright 1984-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------03d,15jul97,spm  added ARP request to SIOCSIFADDR ioctl handler;                 added support for promiscuous mode to SIOCSIFFLAGS03c,25apr97,gnn  added multicast by turning on promiscuous mode.03b,07apr97,spm  code cleanup, corrected statistics, and upgraded to BSD 4.403a,16dec96,map  doc: fixed ENP-10/L jumper diagram [SPR# 3025]02z,14oct93,wmd  Added htons() for pPacketType assignments (SPR #2060).02y,11aug93,jmm  Changed ioctl.h and socket.h to sys/ioctl.h and sys/socket.h02x,19feb93,jdi  documentation cleanup.02w,02feb93,dzb  updated copyright.  removed HK68/V2F referrence (SPR #1876). 02v,13oct92,rfs  Added documentation.02u,16sep92,rfs  Reinstated interrupting of the ENP after putting outgoing                 packets on the transmit ring, even though the documentation                 is conflicting on this action, and some boards work fine                 without it.02t,09sep92,gae  documentation tweaks.02s,04sep92,ccc  added address modifier parameter to attach() routine.02r,06aug92,rfs  Functional changes:                   Eliminated init() routine.  Added errno setting for all                   error cases in the attach() routine.  Added rejection of                   multiple attach() calls per unit.  Eliminated obsolete use                   of transmit output queue.  Moved driver control structures                   to BSS.  Corrected the ioctl() routine.  Added Tx semaphore.                   Added write pipe flushing.  Added rejection of work if the                   interface flags are down.  Revised Rx event handling.                 Cosmetic changes:                   Changed name of driver control structure, changed all                   references to it, changed name of all pointers to it.  Added                   many comments.  Typedef'd common structures and changed all                   usages to the new type.  General cleanup and convention                   adherence.02q,27jul92,ccc  used sysBusToLocalAdrs() to compute bus address,                 fixed warnings.02p,18jul92,smb  Changed errno.h to errnoLib.h.02o,26may92,rrr  the tree shuffle                  -changed includes to have absolute path from h/02n,05may92,wmd  changed LITTLE_ENDIAN to _LITTLE_ENDIAN, BYTE_ORDER to                 _BYTE_ORDER, cleaned up ansi warnings.02m,15jan92,wmd  Added conditional to use ntohl for little Endian in enpput()                 and initialized pEnpDev->enp_mode with 0x8000 (960 only).02l,17oct91,yao  added support for CPU32.02k,04oct91,rrr  passed through the ansification filter                  -changed functions to ansi style                  -changed includes to have absolute path from h/                  -fixed #else and #endif                  -changed READ, WRITE UPDATE to O_RDONLY O_WRONLY O_RDWR                  -changed VOID to void                  -changed copyright notice02j,22aug91,hdn  fixed bug in enpgetaddr.02i,19jun91,km   some modifications for 960 -- not verified correct.                 +gae  compiled in enpShow; added enpDump for debug.                 fixed some usages of ENPDEVICE_OLD (for old CMC LINK-10 ROMs).02h,29apr91,hdn  use SIZEOF_ETHERHEADER instead of sizeof(ether_header).02g,10apr91,jdi  documentation cleanup; doc review by elh.02f,25oct90,gae  made access of "lost carrier" 32-bit register be two 16-bit                 access -- some boards generate a bus error.02e,20oct90,gae  added detection of "lost carrier"; added but ifdef'd out                 enpShow routine; cleanup.02d,02oct90,hjb  de-linted.02c,19sep90,dab  made enpinit() return int.  made bcopy_to_mbufs() call in                 enpread() to use width of 1 for 680[01]0 cpus.02b,26aug90,hjb  added a hack to avoid prob caused when copying data from                 hkv2f a word at a time into ENP memory starting at an odd-byte                 boundary.02a,10aug90,dnw  added forward declarations for void functions.                 added include of if_subr.h.01z,11jul90,hjb  removed code that uses gotIp which is no longer necessary.                 made enpread() void.  changed references to do_protocol()                 to do_protocol_with_type().01y,26jun90,hjb  copy_from_mbufs() & m_freem() fix; fixed enpattach() error msg01x,07may90,hjb  changed bcopy_to_mbufs to copy 16 bits at a time.01w,19apr90,hjb  deleted param.h, modifications for bcopy_from_mbufs().01v,22mar90,hjb  changed copy_to_mbuf() to bcopy_to_mbuf() with argument                 bcopyBytes() to fix the problems associated with using                 ENP with hkv2f caused by bcopy'ing more than a byte at a time                 over VME.01u,18mar90,hjb  reduction of redundant code and addition of cluster support.01t,06aug89,gae  changed iv68k.h to iv.h.01s,25may89,hjb  enpioctl() SIOCSIFFLAGS, check for IFF_UP before calling                 enpinit().01r,24may89,rdc  enpintr no longer does netJobAdd if task level is                 already processing packets. (fixes netRing overflows)                 enpoutput now bumps if_opackets.01q,17apr89,del  fixed comment in enpgetaddr.01q,13apr89,del  fixed problem introduced by CMC when they changed to                 version 4.0 Link-10 roms.01p,05aug88,dnw  fixed oversight in enpreset in 01o.01o,04aug88,dnw  fixed bug causing occasional initialization failure.                 simplified reset.01n,23jun88,rdc  added IFF_BROADCAST to if_flags.01m,05jun88,dnw  changed enp_softc to array of ptrs to descriptors.                 increased NENP from 1 to 4.01l,30may88,dnw  changed to v4 names.01k,22feb88,jcf  made kernel independent.01j,20feb88,dnw  cleanup, lint.01i,10feb88,rdc  re-installed enpreset which i accidently trashed in 01g.                 optimized packet reception by calling ipintr only once                 for a bunch of packets.01h,14jan88,jcf  extended maximum firmware initialization wait to 15 seconds01g,05jan88,rdc  added include of systm.h01f,20nov87,ecs  lint           &dnw  changed enpattach to take int vec num instead of vec adrs.01e,19nov87,dnw  changed to program interrupt vector.                 changed initial wait loop to use vxMemProbe.01d,08nov87,dnw  added output hook code.                 changed calling sequence to input hook.01c,21oct87,ecs  delinted01b,28aug87,dnw  removed unnecessary includes.                 added input hook code.                 clean up.01a,21jul87,rdc  adapted from cmc's 4.2 driver.*//*This module implements the CMC ENP 10/L Ethernet network interface driver.This driver is designed to be moderately generic, operating unmodified across the range of architectures and targets supported by VxWorks.To achieve this, the driver must be given several target-specificparameters.  These parameters, and the mechanisms used to communicate themto the driver, are detailed below.  This driver supports up to fourindividual units per CPU.BOARD LAYOUTThe diagram below shows the relevant jumpers for VxWorks configuration.Default values are: I/O address 0x00de0000, Standard Addressing (A24),interrupt level 3..bS______________________________              _______________________________|             P1             |    ENP-10    |             P2              ||                            ----------------                             ||                   ::::X::                L                              ||                   INT LVL                L INT ACK                      ||                                          R                              ||                                                                         ||                                                                         ||                                                                         ||                                                                         ||                                                                         ||                                                                         ||                                                                         ||   "                                                                     ||   " IO ADRS                                                             ||   -                                            -------  -------         ||   "                                           |  ROM  ||  ROM  |        ||   "                                           |LINK-10||LINK-10|        ||   "                                           |       ||       |        ||   "                                           | HIGH  ||  LOW  |        ||                                               |  U4   ||  U3   |        ||                                                ---^---  ---^---         ||_________________________________________________________________________|.bE.bS______________________________              _______________________________|             P1             |  ENP-10/L    |             P2              ||  JP17    JP16      JP15    ----------------                ----------   ||  X:XX=_: ::X::::   ::::X::          " JP14                |  ROM     |  ||          ADRS BITS INT LVL          " ADRS BITS (EXT)     > LINK-10  |  ||                                     "                     |  LOW  U63|  ||    JP12                             "                      ==========   ||  " STD/                             "                     |  ROM     |  ||  " EXT                              "                     > LINK-10  |  ||  "                                  "                     |  HIGH U62|  ||  "                                  "                      ----------   ||  -                                  _ JP13 TIMEOUT                      ||                                     " JP13 TIMEOUT*                     ||  "                                                                      ||  " INT ACK                                                              ||  - JP11                                                                 ||            _. JP7 SYSCLOCK                                              ||            ._ JP7 SYSCLOCK*                                             ||      ._ JP8                                                             ||                                                                         ||                                                                         ||                                                                         ||_________________________________________________________________________|.bEEXTERNAL 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 enpattach(), which publishes the `enp'interface and initializes the driver and device.TARGET-SPECIFIC PARAMETERS.iP "base VME address of ENP memory"This parameter is passed to the driver by enpattach().The ENP board presents an area of its memory to the VME bus.  Thisaddress is jumper selectable on the ENP.  This parameter is the same asthe address selected on the ENP..iP "VME address modifier code"This parameter is passed to the driver by enpattach().It specifies the AM (address modifier) code to use when the driver accessesthe VME address space of the ENP board..iP "interrupt vector"This parameter is passed to the driver by enpattach().It specifies the interrupt vector to be used by the driverto service an interrupt from the ENP board.  The driver will connectthe interrupt handler to this vector by calling intConnect()..iP "interrupt level"This parameter is passed to the driver by enpattach().It specifies the interrupt level that is associated with theinterrupt vector.  The driver enables the interrupt from the ENP bycalling sysIntEnable() and passing this parameter..LPSYSTEM RESOURCE USAGEWhen implemented, this driver requires the following system resources:    - one mutual exclusion semaphore    - one interrupt vector    - 76 bytes in the initialized data section (data)    - 808 bytes in the uninitialized data section (BSS)The above data and BSS requirements are for the MC68020 architecture and may vary for other architectures.  Code size (text) varies greatly betweenarchitectures and is therefore not quoted here.The ENP board provides the buffers for all packets transmitted and received.Therefore, the driver does not require any system memory to share with thedevice.  This also eliminates all data cache coherency issues.SEE ALSO: ifLib*/#include "vxWorks.h"#include "net/mbuf.h"#include "net/protosw.h"#include "sys/ioctl.h"#include "sys/socket.h"#include "errnoLib.h"#include "net/uio.h"#include "net/if.h"#include "net/route.h"#include "netinet/in.h"#include "netinet/in_systm.h"#include "netinet/ip.h"#include "netinet/ip_var.h"#include "netinet/in_var.h"#include "netinet/if_ether.h"#include "drv/netif/if_enp.h"#include "etherLib.h"#include "vme.h"#include "iv.h"#include "iosLib.h"#include "ioLib.h"#include "memLib.h"#include "net/systm.h"#include "net/if_subr.h"#include "sysLib.h"#include "vxLib.h"#include "stdio.h"#include "intLib.h"#include "logLib.h"#include "string.h"#include "netLib.h"#include "stdlib.h"#include "semLib.h"#include "cacheLib.h"/***** LOCAL DEFINITIONS *****/#undef ENP_DEBUG            /* define to display error/status messages */#define MAX_UNITS    4                  /* max units to support *//* Typedefs for external structures that are not typedef'd in their .h files */typedef struct mbuf MBUF;typedef struct arpcom IDR;                  /* Interface Data Record wrapper */typedef struct ifnet IFNET;                 /* real Interface Data Record */typedef struct sockaddr SOCK;#ifdef BSD43_DRIVER/* The Ethernet header */typedef struct enet_hdr    {    char dst [6];    char src [6];    u_short type;    } ENET_HDR;#endif#define ENET_HDR_SIZ        sizeof(ENET_HDR)#define ENET_HDR_REAL_SIZ   14/* The definition of the driver control structure */typedef struct drv_ctrl    {    IDR         idr;                    /* interface data record */    BOOL        attached;               /* TRUE if attach() has succeeded */    ENPDEVICE   *enpAddr;               /* VME address of board */    ENPSTAT     enpStat;                /* duplicate copy of ENP statisics */    ULONG       lostCarrier;            /* statistic counter */    int         enpIntLevel;            /* VME interrupt level */    int         enpIntVec;              /* VME interrupt vector */    BOOL        taskLevelActive;        /* netTask processing packets */#ifdef BSD43_DRIVER    SEM_ID      TxSem;                  /* transmitter semaphore */#endif    } DRV_CTRL;/***** LOCALS *****//* The array of driver control structures, one per unit supported */LOCAL DRV_CTRL drvCtrl [MAX_UNITS];/*LOCAL*/ BOOL enpNewROM;       /* TRUE if LINK-10 v4.0 or higher *//***** FUNCTION DECLARATIONS *****//* those not defined in header files */extern int splimp (void);extern void splx (int spl);/* forward static functions */static int enpIoctl (IDR *pIDR, int cmd, caddr_t data);#ifdef BSD43_DRIVERstatic int enpOutput (IDR *pIDR, MBUF *pMbuf, SOCK *dst);#elseLOCAL void enpTxStartup (DRV_CTRL * pDrvCtrl);#endifstatic int enpringput (RING *rp, BCB *pBCB);static int enpringget (RING *rp);static void enpIntr (int unit);static void enpRxEvent (int unit);static void enpgetaddr (int unit);static BOOL enpringempty (RING *rp);#ifdef BSD43_DRIVERstatic BOOL convertDestAddr            (            IDR *pIDR,            SOCK *pDestSktAddr,            char *pDestEnetAddr,            u_short *pPacketType,            MBUF *pMbuf            );#endifstatic STATUS enpReset (int unit);static STATUS enpRxPktProcess (int unit);/********************************************************************************* enpattach - publish the `enp' network interface and initialize the driver and device** This routine publishes the `enp' interface by filling in a network * interface record and adding this record to the system list.  It also* initializes the driver and the device to the operational state.** RETURNS: OK or ERROR.*/STATUS enpattach    (    int unit,           /* unit number                     */    char *addr,         /* address of enp's shared memory  */    int ivec,           /* interrupt vector to connect to  */    int ilevel,         /* interrupt level                 */    int enpAddrAm       /* address VME address modifier */    )    {    int        delay;    short      status;    int        temp;    ENPDEVICE  *pEnpDev;    char       *enpBase;

⌨️ 快捷键说明

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