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

📄 if_esmc.c

📁 Tornado 2.0.2 source code!vxworks的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* if_esmc.c - Ampro Ethernet2 SMC-91c9x Ethernet network interface driver *//* Copyright 1984-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01d,15jul97,spm  removed driver initialization from ioctl support (SPR #8831)01c,15may97,spm  reverted to bcopy routines for mbufs in BSD 4.401b,07apr97,spm  code cleanup, corrected statistics, and upgraded to BSD 4.401a,07may96,hdn  written.*//*DESCRIPTIONThis module implements the Ampro Ethernet2 SMC-91c9x Ethernet networkinterface driver.CONFIGURATIONThe W3 and W4 jumper should be set for IO address and IRQ.The defined I/O address and IRQ in config.h must match the one storedin EEROM and the jumper setting. BOARD LAYOUTThe diagram below shows the relevant jumpers for VxWorks configuration..bS        ___________________________________        |             * * * *             |        |  ______                         |        |  |    |                         |        |  | U1 | W1  W3                  |        |  |PROM| X   "                   |        |  |    | .   -                   |        |  |    |     -                   |        |  |    |     -                   |        |  |____|                         |        |                                 |        |                W4               |        |                "                |        |                "                |        |                -                |        |                -                |        |_________________________________|          W1:  Boot PROM Size      W3:  IO-address, IRQ, Media      W4:  IRQ Group Selection.bEEXTERNAL INTERFACEThe only user-callable routines are esmcattach():.iP esmcattach() 14publishes the `esmc' interface and initializes the driver and device..LPThe last parameter of esmcattach(), <mode>, is a receive mode.If it is 0, a packet is received in the interrupt level.  If it is 1,a packet is received in the task level.  Receiving packets in the interruptlevel requires about 10K bytes of memory, but minimize a risk of dropping packets.  Receiving packets in the task level doesn't require extramemory, but might have a risk of dropping packets.INTERNALA driver implementation for this board faces two conflicting networkinterface design goals:  (1) minimizing the time spent at interrupt level,and (2) servicing the board's input without dropping packets.Receive overrun affects significantly for the performance.  It dependson CPU power and network traffic of your hardware and software.And also it depends on the memory size of the chip, 91cxx series.Importance of performance penalty for dropping packets by the receiveoverrun and time spent at the interrupt level is different for each person.  So there is a configurable flag to decide a receive mode which is thelast parameter of esmcattach() function.*/#include "vxWorks.h"#include "net/mbuf.h"#include "net/protosw.h"#include "net/unixLib.h"#include "ioctl.h"#include "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 "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"#include "tickLib.h"#include "drv/netif/if_esmc.h"#undef	ESMC_DEBUG    /* define to include debug messages */#define	NESMC			2	/* max number of ESMC controllers */#define	ESMC_SHOW		TRUE	/* show routine */#define	ESMC_USE_LONG		TRUE	/* use long word IO access */#define ATTACHMENT_DEFAULT      0       /* use card as configured */#define ATTACHMENT_AUI          1       /* AUI  (thick, DIX, DB-15) */#define ATTACHMENT_BNC          2       /* BNC  (thin, 10BASE-2) */#define ATTACHMENT_RJ45         3       /* RJ-45 (twisted pair, TPE, 10BASE-T)*/#define RX_MODE_INTERRUPT	0	/* receive in interrupt level */#define RX_MODE_TASK		1	/* receive in task level *//* globals *//* locals */LOCAL ESMC_SOFTC esmc_softc [NESMC];LOCAL char * pName[12] =    {    NULL,       NULL,       NULL, "SMC91C90/91C92",    "SMC91C94",	"SMC91C95", NULL, "SMC91C100",     NULL,       NULL,       NULL, NULL    };  /* forward static functions */LOCAL int    esmcInit		(int unit);LOCAL void   esmcReset		(int unit);LOCAL int    esmcIoctl		(struct ifnet *ifp, int cmd, caddr_t data);#ifdef BSD43_DRIVERLOCAL int    esmcOutput		(struct ifnet *ifp, struct mbuf *m0, 				 struct sockaddr *dst);#endifLOCAL void   esmcIntr		(int unit);LOCAL void   esmcGet		(int unit);LOCAL void   esmcGetInt		(int unit);LOCAL void   esmcGetTask	(int unit);#ifdef BSD43_DRIVERLOCAL void   esmcPut		(int unit);#elseLOCAL void   esmcPut		(ESMC_SOFTC *sc);#endifLOCAL STATUS esmcChipInit	(int unit);LOCAL void   esmcChipReset	(int unit);/********************************************************************************* esmcattach - publish the `esmc' network interface and initialize the driver.** This routine attaches an `esmc' Ethernet interface to the network if the* device exists.  It makes the interface available by filling in the network* interface record.  The system will initialize the interface when it is ready* to accept packets.** RETURNS: OK or ERROR.** SEE ALSO: ifLib, netShow*/STATUS esmcattach     (    int unit,           /* unit number */    int ioAddr,         /* address of esmc's shared memory */    int intVec,         /* interrupt vector to connect to */    int intLevel,       /* interrupt level */    int config,		/* 0: Autodetect  1: AUI  2: BNC  3: RJ45 */    int mode		/* 0: rx in interrupt   1: rx in task(netTask) */    )    {    FAST ESMC_SOFTC *sc = &esmc_softc[unit];    if ((UINT)unit >= NESMC)	{        errnoSet (S_iosLib_CONTROLLER_NOT_PRESENT);	return (ERROR);	}    sc->ioAddr		= ioAddr;    sc->intVec		= intVec;    sc->intLevel	= intLevel;    sc->config		= config;    sc->flags		= 0;    sc->mode		= mode;    sc->pBuft		= (char *)(((u_int)sc->buft + 3) & ~0x03);    if (sc->mode == RX_MODE_INTERRUPT)			/* RX int */	{        sc->bufi	= malloc (ESMC_BUFSIZE_INT + 8);        sc->pBufi	= (char *)(((u_int)sc->bufi + 3) & ~0x03);        sc->pStart	= sc->pBufi;			/* start pointer */        sc->pEnd	= sc->pBufi + ESMC_BUFSIZE_INT;	/* end pointer */        sc->pIn		= sc->pBufi;			/* input pointer */        sc->pOut	= sc->pBufi;			/* output pointer */        sc->indexIn	= 0;				/* input index */        sc->indexOut	= 0;				/* output index */        sc->nIndex	= ESMC_INDEXES;			/* indexes */        if (sc->bufi == NULL)	    return (ERROR);        bzero (sc->pBufi, ESMC_BUFSIZE_INT);	}    semBInit (&sc->esmcSyncSem, SEM_Q_FIFO, SEM_EMPTY);    (void) intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC (intVec), 		       (VOIDFUNCPTR)esmcIntr, unit);#ifdef BSD43_DRIVER    ether_attach (&sc->es_if, unit, "esmc", (FUNCPTR)esmcInit, 	  (FUNCPTR)esmcIoctl, (FUNCPTR)esmcOutput, (FUNCPTR)esmcReset);#else    ether_attach (                 &sc->es_if,                  unit,                  "esmc",                  (FUNCPTR)esmcInit, 	         (FUNCPTR)esmcIoctl,                  (FUNCPTR)ether_output,                  (FUNCPTR)esmcReset                 );    sc->es_if.if_start = (FUNCPTR)esmcPut;#endif    esmcInit (unit);    return (OK);    }/********************************************************************************* esmcReset - reset the interface** RETURNS: N/A*/LOCAL void esmcReset     (    int unit     )    {    FAST ESMC_SOFTC *sc   = &esmc_softc [unit];    int s = splnet ();    sysIntDisablePIC (sc->intLevel);    sc->es_if.if_flags = 0;    splx (s);    }/********************************************************************************* esmcInit - initialize esmc** Restart the link level software on the board and mark the interface up.** RETURNS: 0*/LOCAL int esmcInit     (    int unit     )    {    FAST ESMC_SOFTC *sc = &esmc_softc[unit];    int s = splnet ();    esmcChipInit (unit);    sysIntEnablePIC (sc->intLevel);    sc->es_if.if_flags |= IFF_UP|IFF_RUNNING;	/* open for business*/    splx (s);    return (0);    }#ifdef BSD43_DRIVER/********************************************************************************* esmcOutput - ethernet output routine** Encapsulate a packet of type family for the local net.* Use trailer local net encapsulation if enough data in first* packet leaves a multiple of 512 bytes of data in remainder.* If destination is this address or broadcast, send packet to* loop device to kludge around the fact that 3com interfaces can't* talk to themselves.** RETURNS:  OK if successful, otherwise errno.*/LOCAL int esmcOutput     (    struct ifnet *ifp,    struct mbuf *m0,    struct sockaddr *dst     )    {    return (ether_output (ifp, m0, dst, (FUNCPTR)esmcPut,			  &esmc_softc [ifp->if_unit].es_ac));    }#endif/********************************************************************************* esmcIoctl - ioctl for interface** RETURNS: OK if successful, otherwise errno.*/LOCAL int esmcIoctl     (    FAST struct ifnet *ifp,    int cmd,    caddr_t data     )    {    FAST ESMC_SOFTC *sc = &esmc_softc[ifp->if_unit];    int status = OK;    int s = splimp();    short flags;    switch (cmd)	{	case SIOCSIFADDR:            ((struct arpcom *)ifp)->ac_ipaddr = IA_SIN (data)->sin_addr;            arpwhohas (ifp, &IA_SIN (data)->sin_addr);	    break;	case SIOCSIFFLAGS:            flags = ifp->if_flags;	    if (ifp->if_flags & IFF_UP)                ifp->if_flags = flags | (IFF_UP|IFF_RUNNING);            else                ifp->if_flags = flags & ~(IFF_UP|IFF_RUNNING);	    break;	default:	    status = EINVAL;	}    splx (s);    return (status);    }/********************************************************************************* esmcIntr - Ethernet interface interrupt** Hand off reading of packets from the interface to task level.** RETURNS: N/A*/LOCAL void esmcIntr     (    int unit     )    {    FAST ESMC_SOFTC *sc = &esmc_softc[unit];    FAST int ioaddr     = sc->ioAddr;    int timeout         = ESMC_INTR_TIMEOUT;    u_short bank;    u_short pointerSave;    u_short statusTx;    u_short statusCard;    u_short packetFail;    u_char packetSave;    u_char mask;    u_char status;

⌨️ 快捷键说明

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