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

📄 if_eitp.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* if_eitp.c - Intel 82596 Ethernet network interface driver for the TP41V *//* Copyright 1989-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------03f,03jul97,spm  added ARP request to SIOCSIFADDR ioctl handler03e,07apr97,spm  code cleanup, corrected statistics, and upgraded to BSD 4.403d,11aug93,jmm  Changed ioctl.h and socket.h to sys/ioctl.h and sys/socket.h03c,24mar93,jdi  documentation cleanup for 5.1.03b,30nov92,rfs  Branched off custom version for TP41.                 Removed calls to sys596Init(), sys596IntAck().                 Replaced calls to sys596IntDisable() with intLock().                 Replaced calls to sys596IntEnable() with intUnlock().                 Removed dummy function eiChipReset().03a,05oct92,rfs  Added documentation.02z,02oct92,rfs  Made multiple attach calls per unit return OK, not ERROR.02y,01oct92,rfs  Added 16 byte page alignment for SCP.02x,28sep92,rfs  Modified the eiAction() routine to clear all events.  This                 makes the diagnostics pass, for some undocumented reason.02w,09sep92,gae  documentation tweaks.02v,11aug92,rfs  Slight change to memory carving.  Also fixed receive bug                 that was due to device manual incorrectly describing bit 7                 of config byte 10 and added error checks to RFDs.  Changed                 the device startup routine.02u,26aug92,kdl  moved internal notes to file header (were just #ifdef'd out).02t,19aug92,smb  changed systime.h to sys/times.h02s,31jul92,dave Changed to new cacheLib.02r,28jul92,rfs  Adapted to latest cache coherency model.                 Renamed driver control structure and moved it to bss.                 Combined the init() routine with the attach() routine and                 made attach() reject multiple invocations.  Rewrote the                 ioctl() routine to do the right stuff.  Reworked the action                 command routine and the primary command routine.  Other misc.02q,16jul92,rfs  Moved driver specific items from header file to here,                 where they belong.02p,16jul92,rfs  Moved internal comments to end of file, where they belong.02o,03jul92,jwt  converted cacheClearEntry() calls to cacheClear() for 5.1.02n,26jun92,rrr  make eiBusSnoop global again (needed by bsps)02m,25jun92,rfs  backed out last mod; the manual is incorrect about the                 state of the bit that configures CRC inclusion02l,25jun92,rfs  bug fix, changed a receive config parm that selects whether                 the CRC is included in the buffer02k,23jun92,ajm  made eiChipReset global for tp41 BSP02j,08jun92,ajm  modified so eiattach is only external function                 got rid of MEM_ROUND_UP macro now pulled in with vxWorks.h                 got rid of many ansi complaints02i,26may92,rrr  the tree shuffle                 -changed includes to have absolute path from h/02h,22feb92,wmd  added conditional compiles for 040, ansi fixes.02g,07jan92,shl  made driver cache safe. added eiBusSnoop(). eliminated some                 ANSI warnings.02f,12nov91,wmd  Added fix, courtesy of jrb-Intel, which added a watchdog to                 timeout any stalls due to hardware lockup and resets the                 82596.02e,25oct91,rfs  Changed eiChipReset() to not depend on valid *es, and                 made it global for TP41 usage. Also eliminated ANSI                 warnings.02d,04oct91,rrr  passed through the ansification filter                 -changed functions to ansi style                 -changed includes to have absolute path from h/                 -changed VOID to void                 -changed copyright notice02c,15sep91,rfs  Bug fix. Eliminated lock condition when output queue full                 and out of TFDs. Added major comment to eiTxStartup. Also,                 major changes to eiChipReset() to make more robust. All                 instances of intLock()/intUnlock() changed to                 sys596IntDisable()/sys596IntEnable respectively. Statistic                 counters now being used, which required moderate changes to                 the transmit side design. More comments added.02b,21aug91,rfs  changed method of obtaining Ethernet address.02a,22jul91,jcf  completely rewritten to utilize simplified mode,            rfs  added big endian support, reworked buffer loaning.01h,01may91,elh  fixed ethernet addressing problem, upgraded to 5.0,                 added buffer loanouts, fixed ifAddrSet bug by disabling                 interrupts in eiHardReset.01g,28apr91,del  added #define of ETHER_HEADER_SIZE as workaround for                 gnu960 pading of struct ether_header.01f,05jan91,gae  added global eiSCPSysConfig for board specific SCP parameters.                 moved CDELAY here from if_ei.h and renamed eichkcca.01e,03jan91,gae  more cleanup and merged with Intel's fixes.                 Ethernet address (eiEnetAddr) is set in sysHwInit.                 cleaned up error printing & no carrier message always printed.                 changed printf's to printErr's (logMsg if at int level).                 made most routines local -- not available outside this module.01d,31dec90,gae  removed 68K stuff.01c,14dec90,elh  more cleanup.01b,12dec90,elh  fixed buffer problems, cleaned up, added etherhooks.01a,06feb90,djk  written*//*This module implements the Intel 82596 Ethernet network interface driver.This driver is a custom version of the generic `ei' driver, to support theTadpole TP41V.   Use the information from manual page for if_ei, except forthe following differences:.iP "" 4The name of the attach routine is eitpattach().  The arguments are the same..iPThe following external support routines are not required:  sys596Init(),sys596IntEnable(), sys596IntDisable(), and sys596IntAck().SEE ALSO: if_ei, ifLib,.I "Intel 82596 User's Manual"*/#include "vxWorks.h"#include "wdLib.h"#include "iv.h"#include "vme.h"#include "net/mbuf.h"#include "net/protosw.h"#include "sys/socket.h"#include "sys/ioctl.h"#include "errno.h"#include "memLib.h"#include "intLib.h"#include "net/if.h"#include "net/route.h"#include "cacheLib.h"#include "logLib.h"#include "netLib.h"#include "stdio.h"#include "stdlib.h"#include "sysLib.h"#ifdef  INET#include "netinet/in.h"#include "netinet/in_systm.h"#include "netinet/in_var.h"#include "netinet/ip.h"#include "netinet/if_ether.h"#endif  /* INET */#include "etherLib.h"#include "net/systm.h"#include "sys/times.h"#include "drv/netif/if_ei.h"#include "net/if_subr.h"/***** LOCAL DEFINITIONS *****/#undef EI_DEBUG                             /* Compiles debug output */#define MAX_UNITS       4                   /* maximum units to support */#define DEF_NUM_TFDS    32                  /* default number of TFDs */#define DEF_NUM_RFDS    32                  /* default number of RFDs */#define MAX_RFDS_LOANED 8                   /* max RFDs that can be loaned *//* 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;typedef struct ether_header ETH_HDR;/* The definition of our linked list management structure */typedef struct ei_list                       /* EI_LIST - 82596 queue head */    {    volatile EI_NODE *  head;       /* header of list */    volatile EI_NODE *  tail;       /* tail of list */    } EI_LIST;/* The definition of the driver control structure */typedef struct drv_ctrl    {    IDR                 idr;        /* interface data record */    BOOL                attached;   /* indicates attach() called */    char                *memBase;   /* 82596 memory pool base */    SCP                 *pScp;      /* SCP ptr */    ISCP                *pIscp;     /* ISCP ptr */    SCB                 *pScb;      /* SCB ptr */    CFD                 *pCfd;      /* synchronous command frame */    RFD                 *rfdPool;   /* RFD pool */    TFD                 *tfdPool;   /* TFD pool */    RFD                 *pFreeRfd;  /* first empty RFD in rxQueue */    volatile EI_LIST    rxQueue;    /* receive queue */    volatile EI_LIST    txQueue;    /* to be sent queue */    volatile EI_LIST    tfdQueue;   /* free transmit frame descriptors */    volatile EI_LIST    cblQueue;   /* actual chip transmit queue */    volatile EI_LIST    cleanQueue; /* queue of TFDs to cleanup */    volatile BOOL       rcvHandling;/* flag, indicates netTask active */    volatile BOOL       txCleaning; /* flag, indicates netTask active */    volatile BOOL       txIdle;     /* flag, indicates idle transmitter */    int                 nTFDs;      /* how many TFDs to create */    int                 nRFDs;      /* how many RFDs to create */    int                 nLoanRfds;  /* number of loanable RFDs left */    UINT8               sysbus;     /* SCP sysbus value */    int                 ivec;       /* interrupt vector */    CACHE_FUNCS         cacheFuncs; /* cache descriptor */    WDOG_ID             wid;        /* watchdog timer for transmit */    long                transLocks; /* count for transmit lockup failures */    } DRV_CTRL;#define DRV_CTRL_SIZ  sizeof(DRV_CTRL)/***** GLOBALS *****//* Function declarations not in any header files */IMPORT STATUS sysEnetAddrGet (int unit, char addr[]);IMPORT void   sys596Port (int unit, int cmd, UINT32 addr);IMPORT void   sys596ChanAtn (int unit);/***** LOCALS *****//* The array of driver control structs */LOCAL DRV_CTRL drvCtrl [MAX_UNITS];/* forward function declarations */static void eiReset (int unit);static int eiIoctl (IDR *pIDR, int cmd, caddr_t data);#ifdef BSD43_DRIVERstatic int eiOutput (IDR *pIDR, MBUF *pMbuf, SOCK *pDestAddr);static void eiTxStartup (int unit);#elsestatic void eiTxStartup (DRV_CTRL *pDrvCtrl);#endifstatic void eiInt (DRV_CTRL *pDrvCtrl);static void eiTxCleanQ (DRV_CTRL *pDrvCtrl);static void eiHandleRecvInt (DRV_CTRL *pDrvCtrl);static STATUS eiReceive (DRV_CTRL *pDrvCtrl, RFD *pRfd);static void eiLoanFree (DRV_CTRL *pDrvCtrl, RFD *pRfd);static STATUS eiDiag (int unit);static void eiConfig (int unit);static void eiIASetup (int unit);static void eiRxStartup (DRV_CTRL *pDrvCtrl);static void eiAction (int unit, UINT16 action);static STATUS eiCommand (DRV_CTRL *pDrvCtrl, UINT16 cmd);static void eiTxQPut (DRV_CTRL *pDrvCtrl, TFD *pTfd);static void eiTxQFlush (DRV_CTRL *pDrvCtrl);static void eiRxQPut (DRV_CTRL *pDrvCtrl, RFD *pRfd);static RFD *eiRxQGet (DRV_CTRL *pDrvCtrl);static BOOL eiRxQFull (DRV_CTRL *pDrvCtrl);static void eiQInit (EI_LIST *pHead);static EI_NODE *eiQGet (EI_LIST *pQueue);static void eiQPut (int unit, EI_LIST *pQueue, EI_NODE *pNode);static STATUS eiDeviceStart (int unit);static void eiWatchDog(int unit);/********************************************************************************* eitpattach - publish the `ei' network interface for the TP41V and initialize the driver and device** The routine publishes the `ei' 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.** The 82596 shares a region of memory with the driver.  The caller of this* routine can specify the address of this memory region, or can specify that* the driver must obtain this memory region from the system resources.** The <sysbus> parameter accepts values as described in the Intel manual* for the 82596.  A default number of transmit/receive frames of 32 can be* selected by passing zero in the parameters <nTfds> and <nRfds>.* In other cases, the number of frames selected should be greater than two.** The <memBase> parameter is used to inform the driver about the shared* memory region.  If this parameter is set to the constant "NONE", then* eitpattach() will attempt to allocate the shared memory from the system.* Any other value for this parameter is interpreted as the address of the* shared memory region to be used.** If the caller provides the shared memory region, then the driver assumes* that this region does not require cache coherency operations, nor does it* require conversions between virtual and physical addresses.** If the caller indicates that this routine must allocate the shared memory* region, then this routine will use the routine cacheDmaMalloc() to obtain* some  non-cacheable memory.  The attributes of this memory will be checked,* and if the memory is not both read and write coherent, this routine will* abort and return ERROR.** RETURNS: OK or ERROR.** SEE ALSO: if_ei, ifLib,* .I "Intel 82596 User's Manual"*/STATUS eitpattach    (    int         unit,              /* unit number */    int         ivec,              /* interrupt vector number */    UINT8       sysbus,            /* sysbus field of SCP */    char *      memBase,           /* address of memory pool or NONE */    int         nTfds,             /* no. of transmit frames (0 = default) */    int         nRfds              /* no. of receive frames (0 = default) */    )    {    DRV_CTRL    *pDrvCtrl;    UINT        size;                           /* temporary size holder */    UINT        sizeScp;    UINT        sizeIscp;    UINT        sizeScb;    UINT        sizeCfd;	int			intLevel;    static char *errMsg1 = "\neiattach: could not obtain memory\n";    static char *errMsg2 = "\neiattach: shared memory not cache coherent\n";    sizeScp  = MEM_ROUND_UP (sizeof (SCP));    sizeIscp = MEM_ROUND_UP (sizeof (ISCP));    sizeScb  = MEM_ROUND_UP (sizeof (SCB));    sizeCfd  = MEM_ROUND_UP (sizeof (CFD));    /* 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);    /* Determine number of Tx and Rx descriptors to use */    pDrvCtrl->nTFDs = nTfds ? nTfds : DEF_NUM_TFDS;    pDrvCtrl->nRFDs = nRfds ? nRfds : DEF_NUM_RFDS;    /* Publish the interface record */#ifdef BSD43_DRIVER    ether_attach ( (IFNET *)&pDrvCtrl->idr, unit, "eitp", (FUNCPTR)NULL,                   (FUNCPTR) eiIoctl, (FUNCPTR) eiOutput, (FUNCPTR) eiReset);#else    ether_attach    (                    &pDrvCtrl->idr.ac_if,                    unit,                    "eitp",                    (FUNCPTR) NULL,                    (FUNCPTR) eiIoctl,                    (FUNCPTR) ether_output,                    (FUNCPTR) eiReset                    );    pDrvCtrl->idr.ac_if.if_start = (FUNCPTR)eiTxStartup;#endif    /* calculate the total size of 82596 memory pool */    size =            16 +                                /* allow for alignment */            sizeScp +            sizeIscp +            sizeScb +            sizeCfd +                           /* synch'ed command frame */            (sizeof (RFD) * pDrvCtrl->nRFDs) +  /* pool of receive frames */            (sizeof (TFD) * pDrvCtrl->nTFDs);   /* pool of transmit frames */    /* Establish the memory area that we will share with the device.  If     * the caller has provided an area, then we assume it is non-cacheable     * and will not require the use of the special cache routines.     * If the caller did not provide an area, then we must obtain it from     * the system, using the cache savvy allocation routine.     */    switch ((int) memBase)        {        case NONE :                            /* we must obtain it */            /* this driver can't handle incoherent caches */            if (!CACHE_DMA_IS_WRITE_COHERENT () ||                !CACHE_DMA_IS_READ_COHERENT ())                {                printf (errMsg2);                goto error;                }            pDrvCtrl->memBase = cacheDmaMalloc (size);            if (pDrvCtrl->memBase == NULL)    /* no memory available */                {                printf (errMsg1);                goto error;                }            pDrvCtrl->cacheFuncs = cacheDmaFuncs;            break;        default :                               /* the user provided an area */            pDrvCtrl->memBase = memBase;        /* use the provided address */            pDrvCtrl->cacheFuncs = cacheNullFuncs;            break;        }

⌨️ 快捷键说明

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