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

📄 ax88796end.c

📁 其中包括88796网卡驱动、mbmflash驱动、i2c接口的eeprom驱动、oki的ml9620can网卡驱动、扩展的串口驱动源代码。适用于moto的ppc8××系列在vxworks环境下。
💻 C
📖 第 1 页 / 共 5 页
字号:
/* AX88796End.c - AX88796 END network interface driver */

/* Copyright 1984-2002 Wind River Systems, Inc. */
#include "copyright_wrs.h"

/*
modification history
--------------------
01o,24jan02,rcs  added support for user setting the "Configuration Register A"
                 or "Configuration Register B" from the load end string.
01n,14jan02,dat  Removing warnings from Diab compiler
01m,05dec00,dat  merge from sustaining to tor2_0_x
01l,30nov00,pai  corrected the handling of EIOCSFLAGS ioctl (SPR #29423).
01k,30nov00,pai  IFF_UP flag set in ax88796Start routine (SPR #32034, 34433).
01j,10may00,pai  Discontinued use of splnet() (SPR #28366).  The ax88796Send()
                 routine now returns END_ERR_BLOCK instead of ERROR so that
                 upper-level protocols will clean up passed in mBlk.
01i,28jul99,jkf  cleaned up warnings, fixed multicast support. (SPR#27921)
01h,31mar99,sbs  changed atoi to strtoul for offset parameter parsing.
                 (SPR #26208)
01g,29mar99,dat  SPR 26119, documentation, usage of .bS/.bE
01f,09feb99,fle  doc : fixed a problem with end of library description
01e,27jan99,dat  removed most of the lint. (more work needed)
01d,11aug98,mem  rewrote part of the overwrite recovery handling to
		 avoid locking up the driver.
01c,20may98,mem  added additional debug tracing, removed free of
		 pMblk in ax88796PollSend().
01b,06may98,mem  integrated changes from Brian Nash.
01a,16mar98,mem	 written, based on drv/netif/if_ene.c.
*/

/*
DESCRIPTION

This module implements the AX88796 Ethernet network interface driver.

EXTERNAL INTERFACE
The only external interface is the ax88796EndLoad() routine, which expects
the <initString> parameter as input.  This parameter passes in a
colon-delimited string of the format:

<unit>:<adrs>:<vecNum>:<intLvl>:<byteAccess>:<usePromEnetAddr>:<offset>

The ax88796EndLoad() function uses strtok() to parse the string.

TARGET-SPECIFIC PARAMETERS
.IP <unit>
A convenient holdover from the former model.  This parameter is used only
in the string name for the driver.
.IP <adrs>
Tells the driver where to find the ax88796.
.IP <vecNum>
Configures the ax88796 device to generate hardware interrupts
for various events within the device. Thus, it contains
an interrupt handler routine.  The driver calls sysIntConnect() to connect
its interrupt handler to the interrupt vector generated as a result of
the ax88796 interrupt.
.IP <intLvl>
This parameter is passed to an external support routine, sysLanIntEnable(),
which is described below in "External Support Requirements." This routine
is called during as part of driver's initialization.  It handles any
board-specific operations required to allow the servicing of a ax88796
interrupt on targets that use additional interrupt controller devices to
help organize and service the various interrupt sources.  This parameter
makes it possible for this driver to avoid all board-specific knowledge of
such devices.
.IP <byteAccess>
Tells the driver the AX88796 is jumpered to operate in 8-bit mode.
Requires that SYS_IN_WORD_STRING() and SYS_OUT_WORD_STRING() be
written to properly access the device in this mode.
.IP <usePromEnetAddr>
Attempt to get the ethernet address for the device from the on-chip
(board) PROM attached to the AX88796.  Will fall back to using the
BSP-supplied ethernet address if this parameter is 0 or if unable to
read the ethernet address.
.IP <offset>
Specifies the memory alignment offset.

EXTERNAL SUPPORT REQUIREMENTS
This driver requires several external support functions, defined as macros:
.CS
    SYS_INT_CONNECT(pDrvCtrl, routine, arg)
    SYS_INT_DISCONNECT (pDrvCtrl, routine, arg)
    SYS_INT_ENABLE(pDrvCtrl)
    SYS_IN_CHAR(pDrvCtrl, reg, pData)
    SYS_OUT_CHAR(pDrvCtrl, reg, pData)
    SYS_IN_WORD_STRING(pDrvCtrl, reg, pData)
    SYS_OUT_WORD_STRING(pDrvCtrl, reg, pData)
.CE

These macros allow the driver to be customized for BSPs that use
special versions of these routines.

The macro SYS_INT_CONNECT is used to connect the interrupt handler to
the appropriate vector.  By default it is the routine intConnect().

The macro SYS_INT_DISCONNECT is used to disconnect the interrupt handler prior
to unloading the module.  By default this is a dummy routine that
returns OK.

The macro SYS_INT_ENABLE is used to enable the interrupt level for the
end device.  It is called once during initialization.  By default this is
the routine sysLanIntEnable(), defined in the module sysLib.o.

The macro SYS_ENET_ADDR_GET is used to get the ethernet address (MAC)
for the device.  The single argument to this routine is the END_DEVICE
pointer.  By default this routine copies the ethernet address stored in
the global variable ax88796EndEnetAddr into the END_DEVICE structure.

The macros SYS_IN_CHAR, SYS_OUT_CHAR, SYS_IN_WORD_STRING and
SYS_OUT_WORD_STRING are used for accessing the ax88796 device.  The
default macros map these operations onto sysInByte(), sysOutByte(),
sysInWordString() and sysOutWordString().

INCLUDES:
end.h endLib.h etherMultiLib.h

SEE ALSO: muxLib, endLib
.I "Writing and Enhanced Network Driver"

INTERNAL: We are using the DP83905 manual as our reference. It is 
AX88796 compatible.

*/

#include "vxWorks.h"
#include "endLib.h"			/* Common END structures. */
#include "etherMultiLib.h"
#include "netLib.h"
#include "cacheLib.h"
#include "lstLib.h"			/* Needed to maintain protocol list. */
#include "iv.h"
#include "stdlib.h"
#include "sysLib.h"
#include "intLib.h"
#include "taskLib.h"
#include "stdio.h"
#include "logLib.h"
#include "drv/end/AX88796End.h"		/* Common defines. */
#include "drv/multi/ppc860Siu.h"


/***** LOCAL DEFINITIONS *****/

#define AX88796_ALL_INTS    (IM_OVWE | IM_TXEE | IM_RXEE | IM_PTXE | IM_PRXE)


/*
 * AUTODIN-II, FDDI, ethernet polynomial for 32 bit CRC.
 *
 * The polynomial is expressed:
 *
 *   ( x^32 + x^26 + x^23 + x^22 + x^16 +
 *     x^12 + x^11 + x^10 + x^8  + x^7  +
 *            x^5  + x^4  + x^2  + x^1  + 1 ) = 0x04c11db7
 *
 * Where x = base 2 (binary) and x^32 is ignored for CRC.
 * (x^32, is not in 32 bit value (ends at x^31)
 */

#define CRC32_POLYNOMIAL		0x04c11db7


/* Configuration items */

#define END_SPEED		10000000

/* Naming items */
#define AX88796_DEV_NAME		"ene"
#define AX88796_DEV_NAME_LEN	4

/*
 * Default macro definitions for BSP interface.
 * These macros can be redefined in a wrapper file, to generate
 * a new module with an optimized interface.
 */

/* Macro to connect interrupt handler to vector */

#ifndef SYS_INT_CONNECT
#define SYS_INT_CONNECT(pDrvCtrl,rtn,arg,pResult) \
	{ \
	IMPORT STATUS sysIntConnect(); \
	*pResult = intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC (pDrvCtrl->ivec), \
			     rtn, (int)arg); \
	}
#endif

/* Macro to disconnect interrupt handler from vector */

#ifndef SYS_INT_DISCONNECT
#define SYS_INT_DISCONNECT(pDrvCtrl,rtn,arg,pResult) \
	{ \
	*pResult = OK; /* HELP: need a real routine */ \
	}
#endif

/* Macro to enable the appropriate interrupt level */

#ifndef SYS_INT_ENABLE
#define SYS_INT_ENABLE(pDrvCtrl) \
	{ \
	IMPORT void ax88796IntEnable(); \
	ax88796IntEnable (pDrvCtrl->ilevel); \
	}
#endif

/* Macro to get the ethernet address from the BSP */

#ifndef SYS_ENET_ADDR_GET
#define SYS_ENET_ADDR_GET(pDevice) \
	ax88796EnetAddrGet(pDevice)
#endif

/*
 * Macros to do a short (UINT16) access to the chip. Default
 * assumes a normal memory mapped device.
 * CPU_FAMILY is used to avoid conflict between x86 and non
 * x86 defintitions (proper) of these macro's.  This is
 * to avoid some compiler warnings.
 */

#if     (CPU_FAMILY == I80X86)

/* sysLib.h uses two declarations of sys<Blah>WordString */

#ifndef SYS_OUT_CHAR
#define SYS_OUT_CHAR(pDrvCtrl,addr,value) \
	sysOutByte((pDrvCtrl)->base + (int) (addr),(char) (value))
#endif

#ifndef SYS_IN_CHAR
#define SYS_IN_CHAR(pDrvCtrl,addr,pData) \
	(*(pData) = (UCHAR) sysInByte((pDrvCtrl)->base + (int) (addr)))
#endif

/* sysLib.h head setsup to declarations of sys<Blah>WordString */
#ifndef SYS_IN_WORD_STRING
#define SYS_IN_WORD_STRING(pDrvCtrl,addr,pData,len) \
	(sysInWordString ((pDrvCtrl)->base + (int) (addr), (short *)(pData), \
			  (len)))
#endif

#ifndef SYS_OUT_WORD_STRING
#define SYS_OUT_WORD_STRING(pDrvCtrl,addr,pData,len) \
	(sysOutWordString ((pDrvCtrl)->base + (int) (addr), (short *)(pData), \
			   (len)))
#endif

#else /* #if     (CPU_FAMILY == I80X86) */

#ifndef SYS_OUT_CHAR
#define SYS_OUT_CHAR(pDrvCtrl,addr,value) \
    	sysOutByte((pDrvCtrl)->base + (UINT) (addr), (value))
#endif

#ifndef SYS_IN_CHAR
#define SYS_IN_CHAR(pDrvCtrl,addr,pData) \
    	(*(pData) = (UCHAR) sysInByte((pDrvCtrl)->base + (UINT) (addr)))
#endif

#ifndef SYS_IN_WORD_STRING
#define SYS_IN_WORD_STRING(pDrvCtrl,addr,pData,len) \
    	(sysInWordString ((pDrvCtrl)->base + (UINT) (addr),  \
			  (UINT16 *)(pData), (len)))
#endif

#ifndef SYS_OUT_WORD_STRING
#define SYS_OUT_WORD_STRING(pDrvCtrl,addr,pData,len) \
    	(sysOutWordString ((pDrvCtrl)->base + (UINT) (addr), \
			   (UINT16 *) (pData), (len)))
#endif

#endif /* #if     (CPU_FAMILY == I80X86) */

/* A shortcut for getting the hardware address from the MIB II stuff. */

#define END_HADDR(pEnd)	\
		((pEnd)->mib2Tbl.ifPhysAddress.phyAddress)

#define END_HADDR_LEN(pEnd) \
		((pEnd)->mib2Tbl.ifPhysAddress.addrLength)


/* Statistics we gather from the AX88796 */

typedef struct
    {
    UINT collisions;
    UINT crcs;
    UINT aligns;
    UINT missed;
    UINT overruns;
    UINT disabled;
    UINT deferring;
    UINT underruns;
    UINT aborts;
    UINT outofwindow;
    UINT heartbeats;
    UINT badPacket;
    UINT shortPacket;
    UINT tnoerror;
    UINT rnoerror;
    UINT terror;
    UINT rerror;
    UINT overwrite;
    UINT wrapped;
    UINT interrupts;
    UINT reset;
    UINT strayint;
    UINT jabber;
    } AX88796_STAT;

/*
 * The definition of the driver control structure.  The packetBuf[]
 * array needs to be kept at least word-aligned as it gets passed to
 * SYS_OUT_WORD_STRING() and some architectures cannot handle
 * misaligned accesses.
 */

typedef struct ax88796_device
    {
    END_OBJ		endObj;		/* The class we inherit from. */
    END_ERR		lastError;	/* Last error passed to muxError */
    int			lastIntError;	/* last interrupt signalled error */
    int			unit;		/* unit number */
    int			ivec;		/* interrupt vector */
    int			ilevel;		/* interrupt level */
    int			byteAccess;	/* 8-bit access mode */
    int			usePromEnetAddr;/* enet addr from PROM */
    ULONG		base;		/* base address */
    int			offset;		/* offset for memory alignment */
    char		packetBuf [AX88796_BUFSIZ];	/* long-aligned */
    volatile long	flags;		/* Our local flags. */
    volatile UCHAR	current;	/* current-page reg at interrupt */
    volatile ULONG	imask;		/* interrupt mask */
    volatile AX88796_STAT stats;		/* AX88796 stats */
    UCHAR		enetAddr[6];	/* ethernet address */
    UCHAR		mcastFilter[8];	/* multicast filter */
    UCHAR		nextPacket;	/* where the next received packet is */
    CL_POOL_ID		clPoolId;
    int                 configRegA;     /* configuration register A */
    int                 configRegB;     /* configuration register B */
} AX88796END_DEVICE;

/* Definitions for the flags field */

#define END_PROMISCUOUS_FLAG	0x01
#define END_RECV_HANDLING_FLAG	0x02
#define END_TX_IN_PROGRESS	0x04
#define END_TX_BLOCKED		0x08
#define END_POLLING		0x10
#define END_OVERWRITE		0x20
#define END_OVERWRITE2		0x40

/***** DEBUG MACROS *****/

#undef DEBUG 

#ifdef DEBUG
#   include "stdio.h"
#   include "logLib.h"
    int endDebug = 0;
#   define ENDLOGMSG(x) \
	do { \
	    if (endDebug) \
		logMsg x; \
	   } while (0)
#else
#   define ENDLOGMSG(x)
#endif /* ENDDEBUG */

/***** LOCALS *****/

/* imports */
IMPORT void axReset(UINT32 regBase);
IMPORT STATUS ax88796EnetMacAddrGet (UCHAR *addr);
IMPORT int endMultiLstCnt (END_OBJ *);
IMPORT UINT32 vxImmrIsbGet();

/* forward static functions */

LOCAL void	ax88796Int (AX88796END_DEVICE* pDrvCtrl);
LOCAL void	ax88796HandleRcvInt (AX88796END_DEVICE* pDrvCtrl);
LOCAL void	ax88796Config (AX88796END_DEVICE* pDrvCtrl,
			      int intEnable);
LOCAL void	ax88796OverwriteRecover (AX88796END_DEVICE* pDrvCtrl,
					UCHAR cmdStatus);
LOCAL int	ax88796PacketGet (AX88796END_DEVICE* pDrvCtrl, char *pData);
LOCAL void	ax88796AddrFilterSet (AX88796END_DEVICE* pDrvCtrl);
LOCAL UINT32 	ax88796CrcWork (UINT8 inChar, UINT32 inCrc);
LOCAL void	ax88796EnetAddrGet (AX88796END_DEVICE* pDrvCtrl);
LOCAL UCHAR	ax88796GetCurr (AX88796END_DEVICE* pDrvCtrl);
LOCAL void	ax88796DataIn (AX88796END_DEVICE* pDrvCtrl, int eneAddress,
			      int len, char* pData);
LOCAL void	ax88796DataOut (AX88796END_DEVICE* pDrvCtrl, char* pData,
			       int len, int eneAddress);
LOCAL STATUS	ax88796Parse (AX88796END_DEVICE* pDrvCtrl, char* initString);
LOCAL STATUS	ax88796MemInit (AX88796END_DEVICE* pDrvCtrl);
LOCAL STATUS	ax88796PollStart (AX88796END_DEVICE* pDrvCtrl);
LOCAL STATUS	ax88796PollStop (AX88796END_DEVICE* pDrvCtrl);

LOCAL void	delay (int n);
LOCAL STATUS	ax88796OverWiteRcvInt (AX88796END_DEVICE* pDrvCtrl);


/* END Specific interfaces. */

/* This is the only externally visible interface. */

END_OBJ * 	ax88796EndLoad (char* initString, void *pBSP);

LOCAL STATUS	ax88796Start (void* pCookie);
LOCAL STATUS	ax88796Stop (void* pCookie);
LOCAL STATUS	ax88796Unload (void *pCookie);
LOCAL int	ax88796Ioctl (void *pCookie, int cmd, caddr_t data);
LOCAL STATUS	ax88796Send (void *pCookie, M_BLK_ID pBuf);
LOCAL STATUS	ax88796MCastAdd (void *pCookie, char* pAddress);
LOCAL STATUS	ax88796MCastDel (void *pCookie, char* pAddress);
LOCAL STATUS	ax88796MCastGet (void *pCookie, MULTI_TABLE* pTable);
LOCAL STATUS	ax88796PollSend (void *pCookie, M_BLK_ID pBuf);
LOCAL STATUS	ax88796PollRecv (void *pCookie, M_BLK_ID pBuf);

/*
 * Declare our function table.  This is static across all driver
 * instances.
 */
LOCAL NET_FUNCS ax88796FuncTable =
    {
    (FUNCPTR) ax88796Start,	/* Function to start the device. */
    (FUNCPTR) ax88796Stop,	/* Function to stop the device. */
    (FUNCPTR) ax88796Unload,	/* Unloading function for the driver. */
    (FUNCPTR) ax88796Ioctl,	/* Ioctl function for the driver. */
    (FUNCPTR) ax88796Send,	/* Send function for the driver. */
    (FUNCPTR) ax88796MCastAdd,	/* Multicast address add function for the */
				/* driver. */
    (FUNCPTR) ax88796MCastDel,	/* Multicast address delete function for */
				/* the driver. */
    (FUNCPTR) ax88796MCastGet,	/* Multicast table retrieve function for */
				/* the driver. */
    (FUNCPTR) ax88796PollSend,	/* Polling send function for the driver. */
    (FUNCPTR) ax88796PollRecv,	/* Polling receive function for the driver. */
    endEtherAddressForm, /* put address info into a NET_BUFFER */
    (FUNCPTR) endEtherPacketDataGet, /* get pointer to data in NET_BUFFER */
    (FUNCPTR) endEtherPacketAddrGet  /* Get packet addresses. */
    };

/******************************************************************************
*

⌨️ 快捷键说明

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