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

📄 if_eihk.c

📁 Tornado 2.0.2 source code!vxworks的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* if_eihk.c - Intel 82596 Ethernet network interface driver for hkv3500 *//* Copyright 1989-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------04e,15jul97,spm  added ARP request to SIOCSIFADDR ioctl handler04f,30apr97,map  doc update.04e,29apr97,map  Modified receive to use RBDs, and buf loaning [SPR# 3511]04d,04mar97,dat  fixed watchdog to use netJobAdd, SPR 777104d,07apr97,spm  code cleanup, corrected statistics, and upgraded to BSD 4.404c,13aug96,dat  fixed wdog timer restart. SPR 695804b,12nov94,tmk  removed some IMPORTed function decs and included unixLib.h04a,03nov93,caf  derived hkv3500-specific driver from version 03g of if_ei.c.		 changed eiattach() to eihkattach(); changed MAX_RFDS_LOANED		 from 8 to 0; added second parm to sys596Init(); connected		 interrupt to sysSpareInt1() instead of eiInt(); made eiInt()		 global.03g,14oct93,wmd  Added initialization of pointer pDrvCtrl in eiWatchDog(),		 SPR #2567.03f,30sep93,wmd  Added changes to include timeout check of the receiver 		 as done in the 5.0.6 release. Recreated eiInit() to allow		 resetting the 596 if it locks up.03e,11aug93,jmm  Changed ioctl.h and socket.h to sys/ioctl.h and sys/socket.h03d,19feb93,jdi  documentation cleanup.03c,15jan93,wmd  added setting of errno to S_ioslib_INVALID_ETHERNET_ADDRESS.03b,11dec92,rfs  Removed dummy eiChipReset(), no longer needed for TP41.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 a hkv3500 specfic Intel 82596 Ethernet networkinterface driver.This driver is derived from the generic if_ei ethernet driver to supporthkv3500 target board. The receive buffer scheme has been modified from asimplified memory structure to a flexible memory structure so that receivebuffers can be word-aligned, and thus support buffer loaning on a MIPS CPUarchitecture.The driver requires several target-specific parameters, and some externalsupport routines which are detailed below.This driver can run with the device configured in either big-endian orlittle-endian modes.  Error recovery code has been added to deal with some ofthe known errata in the A0 version of the device.  This driver supports up tofour 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.The only user-callable routine is eihkattach(), which publishes the `ei'interface and initializes the driver and device.TARGET-SPECIFIC PARAMETERS.iP "the <sysbus> value"This parameter is passed to the driver by eihkattach().The Intel 82596 requires this parameter during initialization.  Thisparameter tells the device about the system bus, hence the name "sysbus."To determine the correct value for a target, refer to the document.I "Intel 32-bit Local Area Network (LAN) Component User's Manual.".iP "interrupt vector"This parameter is passed to the driver by eihkattach().The Intel 82596 generates hardware interrupts for various events withinthe device; thus it contains an interrupt handler routine.This driver calls intConnect() to connect its interrupt handler to the interrupt vector generated as a result of the 82596 interrupt..iP "shared memory address"This parameter is passed to the driver by eihkattach().The Intel 82596 device is a DMA type device and typically sharesaccess to some region of memory with the CPU.  This driver is designedfor systems that directly share memory between the CPU and the 82596.This parameter can be used to specify an explicit memory region for useby the 82596.  This should be done on targets that restrict the 82596to a particular memory region.  The constant NONE can be used to indicatethat there are no memory limitations, in which case, the driver attempts to allocate the shared memory from the system space..iP "number of Receive and Transmit Frame Descriptors"These parameters are passed to the driver by eihkattach().The Intel 82596 accesses frame descriptors in memory for each frametransmitted or received.  The number of frame descriptors at run-time can be configured using these parameters..iP "Ethernet address"This parameter is obtained by a call to an external support routine.During initialization, the driver needs to know the Ethernet address forthe Intel 82596 device.  The driver calls the external support routine,sysEnetAddrGet(), to obtain the Ethernet address.  For a description ofsysEnetAddrGet(), see "External Support Requirements" below..LPEXTERNAL SUPPORT REQUIREMENTSThis driver requires seven external support functions:.iP "STATUS sysEnetAddrGet (int unit, char *pCopy)" "" 9 -1This routine provides the six-byte Ethernet addressused by <unit>.  It must copy the six-byte addressto the space provided by <pCopy>.  This routine returns OK, or ERROR if it fails.  The driver calls this routine, once per unit, using eihkattach()..iP "STATUS sys596Init (int unit, SCB *pScb)"This routine performs any target-specific initializationrequired before the 82596 is initialized.  Typically, it is empty.  This routine must return OK, or ERROR if it fails.The driver calls this routine, once per unit, using eihkattach()..iP "void sys596Port (int unit, int cmd, UINT32 addr)"This routine provides access to the special portfunction of the 82596.  It delivers the command andaddress arguments to the port of the specified unit.The driver calls this routine primarily duringinitialization, but may also call it during errorrecovery procedures..iP "void sys596ChanAtn (int unit)"This routine provides the channel attention signal tothe 82596, for the specified <unit>.  The driver callsthis routine frequently throughout all phases ofoperation..iP "void sys596IntEnable (int unit), void sys596IntDisable (int unit)"These routines enable or disable the interrupt fromthe 82596 for the specified <unit>.  Typically, thisinvolves interrupt controller hardware, eitherinternal or external to the CPU.  Since the 82596itself has no mechanism for controlling its interruptactivity, these routines are vital to the correctoperation of the driver.  The driver calls theseroutines throughout normal operation to protectcertain critical sections of code from interrupthandler intervention..iP "void sys596IntAck (int unit)"This routine must perform any required interrupt acknowledgment or clearing.  Typically, this involves an operation to some interruptcontrol hardware.  Note that the INT signal from the 82596behaves in an "edge-triggered" mode; therefore, this routine typically clears a latch within the control circuitry.The driver calls this routine from the interrupt handler..LPSYSTEM RESOURCE USAGEWhen implemented, this driver requires the following system resources:    - one mutual exclusion semaphore    - one interrupt vector    - one watchdog timer.    - 8 bytes in the initialized data section (data)    - 912 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 driver uses cacheDmaMalloc() to allocate memory to share with the 82596.  The fixed-size pieces in this area total 160 bytes.  The variable-size pieces in this area are affected by the configuration parameters specified in the eihkattach() call.  The size of one RFD (Receive FrameDescriptor) is 1536 bytes.  The size of one TFD (Transmit Frame Descriptor) is 1534 bytes.  For more information about RFDs and TFDs, see the .I "Intel 82596 User's Manual."The 82596 can be operated only if this shared memory region is non-cacheableor if the hardware implements bus snooping.  The driver cannot maintaincache coherency for the device because fields within the commandstructures are asynchronously modified by both the driver and the device,and these fields may share the same cache line.TUNING HINTSThe only adjustable parameters are the number of TFDs and RFDs that will becreated at run-time.  These parameters are given to the driver when eihkattach()is called.  There is one TFD and one RFD associated with each transmittedframe and each received frame respectively.  For memory-limited applications,decreasing the number of TFDs and RFDs may be desirable.  Increasing the numberof TFDs will provide no performance benefit after a certain point.Increasing the number of RFDs will provide more buffering before packets aredropped.  This can be useful if there are tasks running at a higher prioritythan the net task.SEE ALSO: ifLib,.I "Intel 82596 User's Manual,".I "Intel 32-bit Local Area Network (LAN) Component 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/unixLib.h"#include "net/route.h"#include "iosLib.h"#include "errnoLib.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_eihk.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 */    int                 wdInterval; /* ticks between eiWatchDog runs */    long		recvLocks;  /* count for receive lockup failures */    long                transLocks; /* count for transmit lockup failures */    volatile char	wdTxTimeout;/* watchdog runs with transmit hung */    volatile char	wdRxTimeout;/* watchdog runs with receive hung */    } DRV_CTRL;

⌨️ 快捷键说明

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