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

📄 if_sn.c

📁 Tornado 2.0.2 source code!vxworks的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* if_sn.c - National Semiconductor DP83932B SONIC Ethernet network driver *//* Copyright 1984-1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/* Copyright 1991 Ironics Inc. *//*modification history--------------------01w,16mar99,elg  add unsupported features in documentation (SPR 9145).01v,15jul97,map  added code to pullup highly fragmented mbufs [SPR# 20843]01u,15jul97,spm  added ARP request to SIOCSIFADDR ioctl handler01t,07apr97,spm  code cleanup, corrected statistics, and upgraded to BSD 4.401s,23apr96,wkm  allow extra space for Sonic buffer overrun, zero sequence cnto1r,16jan96,kkk  increase number of TX desc and TX frags.o1q,13feb95,jdi  doc cleanup.o1p,18oct93,cd   fixed virtual/physical address confusion, added extra		 debug options, corrected comments.           +caf  made new snClkEnable() and snClkDisable() routines NOMANUAL.01q,11aug93,jmm  Changed ioctl.h and socket.h to sys/ioctl.h and sys/socket.h01p,19feb93,jdi  documentation cleanup.01o,06feb93,rfs  Fixed SPR #1990.01n,05feb93,rfs  Fixed SPR #1984.01m,13oct92,rfs  Added documentation.01l,02oct92,rfs  Made multiple attach calls per unit return OK.                 Adapted to new convention for driver control structure.01k,09sep92,gae  documentation tweaks.01j,30jul92,dnw  Changed to new cacheLib.                 Removed cache flushes (except of mbufs) since this driver                 requires write coherent dma caches.01i,16jul92,rfs  Consolidated init() into attach().01h,15jul92,rfs  Enabled input hook mechanism.01g,14jul92,rfs  Sync'ed up to cache library changes.  Required rewriting of                 method used to obtain shared memory and aligining it to                 meet the requirements of the device.01f,29jun92,jwt  added RFS changes to support copy-back caches.    18jun92,jwt  prototyped 5.1 cache library with SPARC targets.    13apr92,rfs  Needed to subtract FCS from len of Rx packets.    17mar92,rfs  Verified cache scheme. Dealt with Tx FIFO underrun.    10mar92,rfs  Reworked cache coherency scheme and misc sanitizing.    20feb92,rfs  Receive side was hogging the spl semaphore.  It is now                 given up, and only taken when needed.01e,26may92,rrr  the tree shuffle                 -changed includes to have absolute path from h/01d,30jan92,rfs  unANSIized for 5.0.x support.                 Eliminated many routines and re-ordered routines into                 logical sections.01c,05nov91,rfs  WRSized, genericized, sanitized, revitalized, ANSIized01b,29jul91,kjl  clean up in anticipation of beta release01a,25mar91,kjl  adapted from WRS if_ln.c 01s,20sep90,dab*//*DESCRIPTIONThis module implements the National Semiconductor DP83932 SONIC Ethernet network interface driver.This driver is designed to be moderately generic, operating unmodifiedacross the range of architectures and targets supported by VxWorks.  To achieve this, the driver must be given several target-specificparameters, and some external support routines must be provided.  Theseparameters, and the mechanisms used to communicate them to the driver, aredetailed below.  If any of the assumptions stated below are not true foryour particular hardware, this driver will probably not function correctlywith it.  This driver supports up to four individual units per CPU.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.There is one user-callable routine, snattach();for details, see the manual entry for this routine.TARGET-SPECIFIC PARAMETERS.iP "device I/O address"This parameter is passed to the driver by snattach().It specifies the base address of the device's I/O registerset..iP "interrupt vector"This parameter is passed to the driver by snattach().It specifies the interrupt vector to be used by the driverto service an interrupt from the SONIC device.  The driver will connectthe interrupt handler to this vector by calling intConnect()..iP "Ethernet address"This parameter is obtained by calling an external support routine.It specifies the unique, six-byte address assigned to the VxWorks targeton the Ethernet..LPEXTERNAL SUPPORT REQUIREMENTSThis driver requires five external support functions:.iP "void sysEnetInit (int unit)" "" 9 -1This routine performs any target-specificoperations that must be executed before the SONICdevice is initialized.  The driver calls this routine, once per unit, from snattach()..iP "STATUS sysEnetAddrGet (int unit, char *pCopy)"This routine provides the six-byte Ethernet address used by <unit>.  Itmust copy the six-byte address to the space provided by <pCopy>.  Thisroutine returns OK, or ERROR if it fails.  The driver calls this routine, once per unit, from snattach()..iP "void sysEnetIntEnable (int unit), void sysEnetIntDisable (int unit)"These routines enable or disable the interrupt fromthe SONIC device for the specified <unit>.  Typically,this involves interrupt controller hardware,either internal or external to the CPU.  The driver calls these routines only during initialization, from snattach()..iP "void sysEnetIntAck (int unit)"This routine performs any interrupt acknowledgement orclearing that may be required.  This typicallyinvolves an operation to some interrupt controlhardware.  The driver calls this routine from theinterrupt handler..LPDEVICE CONFIGURATIONTwo global variables, `snDcr' and `snDcr2', are used to set the SONICdevice configuration registers.  By default, the device is programmed in32-bit mode with zero wait states.  If these values are not suitable,the `snDcr' and `snDcr2' variables should be modified before callingsnattach().  See the SONIC manual to change these parameters.SYSTEM RESOURCE USAGEWhen implemented, this driver requires the following system resources:        - one interrupt vector    - 0 bytes in the initialized data section (data)    - 696 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.This driver uses cacheDmaMalloc() to allocate the memory to be shared with theSONIC device.  The size requested is 117,188 bytes.The SONIC device can only be operated if the shared memory region iswrite-coherent with the data cache.  The driver cannot maintain cachecoherency for the device for data that is written by the driverbecause fields within the shared structures are asynchronously modified bythe driver and the device, and these fields may share the same cacheline.NOTE 1The previous transmit descriptor does not exist until the transmitterhas been asked to send at least one packet.  Unfortunately the testfor this condition must be done every time a new descriptor is to be added,even though the condition is only true the first time.  However, itis a valuable test, since we should not use the fragment count fieldas an index if it is 0.NOTE 2There are some things unsupported in this version:    a) buffer loaning on receive    b) output hooks    c) trailer protocol    d) promiscuous modeAlso, the receive setup needs work so that the number of RRA descriptorsis not fixed at four.  It would be a nice addition to allow all thesizes of the shared memory structures to be specified by the runtimefunctions that call our init routines.SEE ALSO: ifLib*//*INTERNALThis driver contains the conditional compilation switch SN_DEBUG.If defined, the debug output routines are included.  Output is furtherselectable at run-time via the snDebug global variable.See also the NOTES section at the end of this file.*/#include "vxWorks.h"#include "sys/types.h"#include "taskLib.h"#include "iv.h"#include "memLib.h"#include "sys/ioctl.h"#include "etherLib.h"#include "net/mbuf.h"#include "net/protosw.h"#include "sys/socket.h"#include "errno.h"#include "net/if.h"#include "net/route.h"#include "netinet/in.h"#include "netinet/in_systm.h"#include "netinet/in_var.h"#include "netinet/ip.h"#include "netinet/if_ether.h"#include "net/if_subr.h"#include "cacheLib.h"#include "stdio.h"#include "intLib.h"#include "logLib.h"#include "netLib.h"/* Tunables needed by device header file */#define NUM_RRA_DESC  (4)             /* number of RRA descriptors */#define NUM_RX_DESC   (512)           /* number of Rx descriptors */#define NUM_TX_DESC   (64)            /* num of Tx desc, must be power of 2 */#define MAX_TX_FRAGS  (64)            /* max transmit frags to support */#include "drv/netif/if_sn.h"          /* device description *//* CONDITIONAL SWITCHES *//* LOCAL DEFINITIONS */#define MAX_UNITS   4                   /* max number of units to support */#define RX_BUF_SIZE (0x2000)            /* size of one receive buffer */                                        /* total size of receive buffer area */#define RX_BUF_EXTRA (0x200)		/* Extra space needed to accomodate */					/* Sonic buffer overrun in Rev. C */					/* parts - found by Algorithmics  */#define RBA_SIZE    ((RX_BUF_SIZE + RX_BUF_EXTRA) * NUM_RRA_DESC)/* 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;/* Driver control structure.  One per unit supported. */typedef struct drv_ctrl    {    IDR sn_ac;                          /* Ethernet common part */    SONIC *pDev;                        /* ptr to the device registers */    BOOL attached;                      /* indicates unit is attached */    char *pMem;                         /* ptr to allocated chunk */    char *pShMem;                       /* ptr to area shared with device */    unsigned long shMemSize;            /* size of the shared area */    unsigned long RSA;                  /* Start of Resource Area */    unsigned long REA;                  /* End of Resource Area */    unsigned long RBA1;                 /* Start of Receive Buffer Area */    unsigned long RBA2;                 /* Start of Receive Buffer Area */    unsigned long RBA3;                 /* Start of Receive Buffer Area */    unsigned long RBA4;                 /* Start of Receive Buffer Area */    unsigned long RDA;                  /* Start of Receive Desc Area */    unsigned long CDA;                  /* Start of CAM Desc Area */    TX_DESC *pTDA;                      /* Start of Transmit Desc Area */    TX_DESC *pTXDFree;                  /* ptr to next free TXD */    TX_DESC *pTXDReclaim;               /* ptr to next reclaimable TXD */    RX_DESC *pRXDNext;                  /* Next Receive descriptor */    RX_DESC *pRXDLast;                  /* Last one in link */    int TxErrs;                         /* transmitter errors */    FUNCPTR timerIntHandler;    int	 ticks;    unsigned int imr;    } DRV_CTRL;#define DRV_CTRL_SIZ    sizeof(DRV_CTRL)/* shorthand for some struct members */#define sn_if       sn_ac.ac_if             /* network-visible interface */#define sn_enaddr   sn_ac.ac_enaddr         /* hardware Ethernet address *//* GLOBALS */unsigned long snDcr = WAIT0 | DW_32;unsigned long snDcr2 = 0;#define SN_DEBUG#ifdef SN_DEBUGint snDebug;#define SN_DEBUG_INIT      (snDebug & 0x01)#define SN_DEBUG_TX        (snDebug & 0x02)#define SN_DEBUG_RX        (snDebug & 0x04)#define SN_DEBUG_EVENT     (snDebug & 0x08)#define SN_DEBUG_VERBOSE   (snDebug & 0x10)#define SN_DEBUG_TRACE     (snDebug & 0x20)#endif/* External function prototypes not defined in any header files. * Some of these are the functions required of the BSP modules. */IMPORT STATUS sysEnetAddrGet ();IMPORT STATUS sysEnetInit ();IMPORT STATUS sysEnetIntEnable ();IMPORT STATUS sysEnetIntDisable ();IMPORT STATUS sysEnetIntAck ();extern int    splnet ();extern int    splimp ();extern void   splx (int x);/* LOCALS *//* an array of driver control struct ptrs, one per unit */LOCAL DRV_CTRL  drvCtrl [MAX_UNITS];LOCAL void      snIntr ();LOCAL void      snTxReclaim ();LOCAL void      snEventHandler ();LOCAL BOOL      snRxPktReady ();LOCAL STATUS    snRxPktProcess ();#ifdef BSD43_DRIVERLOCAL int       snOutput ();#endifLOCAL int       snIoctl ();LOCAL void      snReset ();#ifdef BSD43_DRIVERLOCAL void      snStartOutput ();#elseLOCAL void 	snStartOutput (DRV_CTRL *);#endif    /* BSD43_DRIVER */LOCAL void      snChipReset ();LOCAL void      snChipInit ();LOCAL void      snCamInit ();/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * SECTION: Special routines; attach, ioctl, etc. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*//********************************************************************************* snattach - publish the `sn' network interface and initialize the driver and device** This routine publishes the `sn' 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 snattach    (    int    unit,       /* unit number */    char * pDevRegs,   /* addr of device's regs */    int    ivec        /* vector number */    )    {    u_long   temp;    DRV_CTRL *pDrvCtrl;#ifdef SN_DEBUG    if (SN_DEBUG_INIT)        logMsg ("snattach: unit=%d, addr=0x%x, vector=0x%x\n",                unit, (int)pDevRegs, ivec, 0, 0, 0);#endif /* SN_DEBUG */    /* 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 driver existance */#ifdef BSD43_DRIVER    ether_attach (&pDrvCtrl->sn_if, unit, "sn", (FUNCPTR) NULL,                   (FUNCPTR) snIoctl, (FUNCPTR) snOutput, (FUNCPTR) snReset);#else    ether_attach (                  &pDrvCtrl->sn_if,                 unit,                 "sn",                 (FUNCPTR) NULL,                 (FUNCPTR) snIoctl,                 (FUNCPTR) ether_output,  /* generic output for Ethernet */                 (FUNCPTR) snReset                 );    pDrvCtrl->sn_if.if_start = (FUNCPTR) snStartOutput;#endif    pDrvCtrl->pDev = (SONIC *) pDevRegs;             /* save the device ptr */    /* get an Ethernet addr in a board specific manner */    if (sysEnetAddrGet (unit, pDrvCtrl->sn_enaddr) == ERROR)        return (ERROR);    {   /***** Establish shared memory region *****/    /* The driver and the device share areas of memory.  Each area has a     * specific use.  The device imposes a nasty restriction, in that     * an area's bounds must lie in the same 64k page.  The entire amount of     * shared memory that is needed is much less than 64k.  Therefore, we     * will group all the individual areas into one area, and attempt to     * ensure that this total area lies in a single 64k page.     *     * We must also consider data cache coherency of this shared memory.     * We therefore use the special system functions that allow us to     * obtain cache-safe memory, or at least allow us to maintain the     * coherency of this memory ourselves.     *     * The first step is to calculate the size of this shared region.     */    pDrvCtrl->shMemSize =                    CAM_SIZE +      /* the area used for Ethernet addrs */                    RRA_SIZE +      /* the area that describes Rx buffers */                    RDA_SIZE +      /* the area that holds Rx descriptors */                    TDA_SIZE +      /* the area that holds Tx descriptors */                    RBA_SIZE;       /* the area that holds all Rx buffers */

⌨️ 快捷键说明

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