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

📄 dec21x40end.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 5 页
字号:
	MEM_TO_PCI_PHYS (DEC_CACHE_VIRT_TO_PHYS (vAdrs))#define DEC_PCI_TO_VIRT(pciAdrs)                                        \	DEC_CACHE_PHYS_TO_VIRT (PCI_TO_MEM_PHYS (pciAdrs))/* * CSR access macros * * To optimize CSR accesses, redefine DEC_CSR_READ and * DEC_CSR_WRITE macros in a wrapper file. */#ifndef DEC_CSR_READ#define DEC_CSR_READ(csr)                                               \	dec21x40CsrRead(pDrvCtrl->devAdrs, (csr))#endif /* DEC_CSR_READ */#ifndef DEC_CSR_WRITE#define DEC_CSR_WRITE(csr,val)                                          \	dec21x40CsrWrite(pDrvCtrl->devAdrs, (csr), (val))#endif /* DEC_CSR_WRITE */#define DEC_CSR_UPDATE(csr,val)                                         \	DEC_CSR_WRITE((csr), DEC_CSR_READ(csr) | (val))    #define DEC_CSR_RESET(csr,val)                                          \	DEC_CSR_WRITE((csr), DEC_CSR_READ(csr) & ~(val))    #define DEC_SROM_CMD_WRITE(adrs,delay)                                  \	{                                                               \        DEC_CSR_WRITE(CSR9, CSR9_21140_SR | CSR9_21140_WR | (adrs));    \        NSDELAY (delay);                                                \        }#define DEC_SROM_CMD_READ()                                             \	((DEC_CSR_READ(CSR9) & 0x8) >> 3)/* MII read/write access macros */   #define CSR9_MII_WR 0x00000000#define DEC_MII_BIT_READ(pBData)                                              \        {                                                                     \        DEC_CSR_WRITE (CSR9, CSR9_21140_MII | CSR9_21140_RD);                 \        NSDELAY (100);                                                        \        DEC_CSR_WRITE (CSR9, CSR9_21140_MII | CSR9_21140_RD | CSR9_21140_MDC);\        NSDELAY (100);                                                        \        *(pBData) |= CSR9_MII_DBIT_RD (DEC_CSR_READ (CSR9));                  \        }#define DEC_MII_BIT_WRITE(data)                                      \        {                                                            \        DEC_CSR_WRITE (CSR9, CSR9_MII_DBIT_WR(data) |                \                      CSR9_MII_WR | CSR9_21140_WR);                  \        NSDELAY (100);                                               \        DEC_CSR_WRITE (CSR9, CSR9_MII_DBIT_WR(data) |                \                      CSR9_MII_WR | CSR9_21140_WR | CSR9_21140_MDC); \        NSDELAY (100);                                               \        }#define DEC_MII_RTRISTATE           \        {                           \        int retVal;                 \        DEC_MII_BIT_READ (&retVal); \        }#define DEC_MII_WTRISTATE           \        {                           \        DEC_MII_BIT_WRITE(0x1);     \        DEC_MII_BIT_WRITE(0x0);     \        }#define DEC_MII_WRITE(data, bitCount)                \        {                                            \        int i=(bitCount);                            \                                                     \        while (i--)                                  \            DEC_MII_BIT_WRITE (((data) >> i) & 0x1); \        }#define DEC_MII_READ(pData, bitCount) \        {                             \        int i=(bitCount);             \                                      \        while (i--)                   \            {                         \            *(pData) <<= 1;           \            DEC_MII_BIT_READ (pData); \            }                         \        }/* * Default macro definitions for BSP interface. * These macros can be redefined in a wrapper file, to generate * a new module with an optimized interface. */#ifndef SYS_INT_CONNECT#define SYS_INT_CONNECT(pDrvCtrl,rtn,arg,pResult)                       \    {                                                                   \    int vector = pDrvCtrl->ivec;                                        \    IMPORT STATUS sysIntConnect();                                      \    if (!pDrvCtrl->intrConnect)                                         \        {                                                               \        pDrvCtrl->intrConnect = TRUE;                                   \        *pResult = intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC (vector),    \                                (rtn), (int)(arg));                     \        }                                                               \    }#endif /*SYS_INT_CONNECT*/ #ifndef SYS_INT_DISCONNECT#define SYS_INT_DISCONNECT(pDrvCtrl,rtn,arg,pResult)                    \    {                                                                   \    /* set pDrvCtrl->intrConnect to FALSE if appropriate */             \    *pResult = OK;							\    }#endif /*SYS_INT_DISCONNECT*/#ifndef SYS_INT_ENABLE#define SYS_INT_ENABLE(pDrvCtrl)                                        \    {                                                                   \    IMPORT void sysLanIntEnable();                                      \    sysLanIntEnable (pDrvCtrl->ilevel);                                 \    }#endif /*SYS_INT_ENABLE*/#ifndef SYS_INT_DISABLE#define SYS_INT_DISABLE(pDrvCtrl)                                       \    {                                                                   \    IMPORT void sysLanIntDisable();                                     \    sysLanIntDisable (pDrvCtrl->ilevel);                                \    }#endif /*SYS_INT_DISABLE*/#define	END_MIB_SPEED_SET(pEndObj, speed)                               \	((pEndObj)->mib2Tbl.ifSpeed=speed)#define NET_BUF_ALLOC()                                                 \    netClusterGet (pDrvCtrl->endObj.pNetPool, pDrvCtrl->clPoolId)#define NET_BUF_FREE(pBuf)                                              \    netClFree (pDrvCtrl->endObj.pNetPool, pBuf)#define	NET_MBLK_ALLOC()                                                \    mBlkGet (pDrvCtrl->endObj.pNetPool, M_DONTWAIT, MT_DATA)#define NET_MBLK_FREE(pMblk)                                            \    netMblkFree (pDrvCtrl->endObj.pNetPool, (M_BLK_ID)pMblk)#define	NET_CL_BLK_ALLOC()                                              \    clBlkGet (pDrvCtrl->endObj.pNetPool, M_DONTWAIT)#define NET_CL_BLK_FREE(pClblk)                                         \    clBlkFree (pDrvCtrl->endObj.pNetPool, (CL_BLK_ID)pClBlk)            #define NET_MBLK_BUF_FREE(pMblk)                                        \    netMblkClFree ((M_BLK_ID)pMblk)#define NET_MBLK_CHAIN_FREE(pMblk)                                      \    {                                                                   \    M_BLK *pNext;                                                       \                                                                        \    pNext=pMblk;                                                        \    while (pNext)                                                       \        pNext=NET_MBLK_BUF_FREE (pNext);                                \    }    #define NET_MBLK_CL_JOIN(pMblk, pClBlk)                              	\    netMblkClJoin ((pMblk), (pClBlk))#define NET_CL_BLK_JOIN(pClBlk, pBuf, len)                             	\    netClBlkJoin ((pClBlk), (pBuf), (len), NULL, 0, 0, 0)        #define	DRV_CTRL	DEC21X40_DRV_CTRL#ifdef DRV_DEBUGDRV_CTRL	*pDrvCtrlDbg;#endif/* structure sizes */#define DRV_CTRL_SIZ		sizeof(DRV_CTRL)#define RD_SIZ			sizeof(DEC_RD)#define TD_SIZ			sizeof(DEC_TD)/* locals *//* Default network buffer configuration */NET_POOL dec21x40NetPool; /* forward declarations */LOCAL STATUS	dec21x40InitParse (DRV_CTRL *pDrvCtrl, char *InitString);LOCAL STATUS	dec21x40InitMem (DRV_CTRL *pDrvCtrl);LOCAL STATUS	dec21x40IASetup (DRV_CTRL *pDrvCtrl);LOCAL void 	dec21x40ModeSet (DRV_CTRL *pDrvCtrl);LOCAL int	dec21x40HashIndex (char *eAddr);LOCAL void 	dec21x40Int (DRV_CTRL *pDrvCtrl);LOCAL STATUS 	dec21x40Recv (DRV_CTRL *pDrvCtrl, DEC_RD *rmd);LOCAL STATUS 	dec21x40ChipReset (DRV_CTRL *pDrvCtrl);LOCAL void	dec21040AuiTpInit (DRV_CTRL *pDrvCtrl);LOCAL void 	dec21x40CsrWrite (ULONG devAdrs, int reg, ULONG value);LOCAL ULONG 	dec21x40CsrRead (ULONG devAdrs, int reg);LOCAL STATUS 	dec21x40EnetAddrGet (DRV_CTRL *pDrvCtrl, char *enetAdrs);LOCAL STATUS 	dec21040EnetAddrGet (DRV_CTRL *pDrvCtrl, char *enetAdrs);LOCAL STATUS 	dec21140EnetAddrGet (DRV_CTRL *pDrvCtrl, char *enetAdrs);LOCAL void	dec21x40Restart (DRV_CTRL *pDrvCtrl);LOCAL DEC_TD *	dec21x40TxDGet (DRV_CTRL *pDrvCtrl);LOCAL DEC_RD *	dec21x40RxDGet (DRV_CTRL *pDrvCtrl);LOCAL void 	dec21x40TxRingClean (DRV_CTRL *pDrvCtrl);LOCAL void 	dec21x40RxIntHandle (DRV_CTRL *pDrvCtrl);LOCAL STATUS 	dec21140MediaSelect (DRV_CTRL *pDrvCtrl, UINT *pCsr6Val);LOCAL STATUS 	dec21143MediaSelect (DRV_CTRL *pDrvCtrl, UINT *pCsr6Val);UINT dec21x40PhyLinkPoll (DRV_CTRL *pDrvCtrl, UINT linkTry);LOCAL STATUS dec21x40MiiRead ( DRV_CTRL *pDrvCtrl, UINT8 phyAdrs, UINT8 phyReg,	UINT16 *pRetVal);LOCAL STATUS dec21x40MiiWrite (DRV_CTRL *pDrvCtrl, UINT8 phyAdrs, UINT8 phyReg,    USHORT data);/* externals */IMPORT STATUS	sysDec21x40EnetAddrGet (int unit, char *enetAdrs);/* globals */USHORT		dec21140SromWordRead (DRV_CTRL *pDrvCtrl, UCHAR lineCnt);FUNCPTR		_func_dec21x40MediaSelect = (FUNCPTR) NULL;#ifdef DRV_DEBUG#include "netShow.h"IMPORT void netPoolShow (NET_POOL_ID);void decCsrShow (void);void decShow (void);#endif /* DRV_DEBUG *//* END Specific interfaces. */END_OBJ *	dec21x40EndLoad (char *initString);LOCAL STATUS	dec21x40Unload (DRV_CTRL *pDrvCtrl);LOCAL STATUS	dec21x40Start (DRV_CTRL *pDrvCtrl);LOCAL STATUS	dec21x40Stop (DRV_CTRL *pDrvCtrl);LOCAL int	dec21x40Ioctl (DRV_CTRL *pDrvCtrl, int cmd, caddr_t data);LOCAL STATUS	dec21x40Send (DRV_CTRL *pDrvCtrl, M_BLK *pMblk);LOCAL STATUS	dec21x40MCastAddrAdd (DRV_CTRL *pDrvCtrl, char* pAddress);LOCAL STATUS	dec21x40MCastAddrDel (DRV_CTRL *pDrvCtrl, char* pAddress);LOCAL STATUS	dec21x40MCastAddrGet (DRV_CTRL *pDrvCtrl,                                       MULTI_TABLE *pTable);LOCAL STATUS	dec21x40PollSend (DRV_CTRL *pDrvCtrl, M_BLK *pMblk);LOCAL STATUS	dec21x40PollReceive (DRV_CTRL *pDrvCtrl, M_BLK *pMblk);LOCAL STATUS	dec21x40PollStart (DRV_CTRL *pDrvCtrl);LOCAL STATUS	dec21x40PollStop (DRV_CTRL *pDrvCtrl);/*  * Define the device function table.  This is static across all driver * instances. */LOCAL NET_FUNCS netFuncs =     {    (FUNCPTR)dec21x40Start,	/* start func. */                     (FUNCPTR)dec21x40Stop,	/* stop func. */    (FUNCPTR)dec21x40Unload,	/* unload func. */                    (FUNCPTR)dec21x40Ioctl,	/* ioctl func. */                     (FUNCPTR)dec21x40Send,	/* send func. */                      (FUNCPTR)dec21x40MCastAddrAdd,/* multicast add func. */             (FUNCPTR)dec21x40MCastAddrDel,/* multicast delete func. */          (FUNCPTR)dec21x40MCastAddrGet,/* multicast get fun. */              (FUNCPTR)dec21x40PollSend,	/* polling send func. */              (FUNCPTR)dec21x40PollReceive, /* polling receive func. */           endEtherAddressForm,	/* put address info into a NET_BUFFER */    endEtherPacketDataGet,	/* get pointer to data in NET_BUFFER */    endEtherPacketAddrGet	/* Get packet addresses. */    };				/********************************************************************************* dec21x40EndLoad - initialize the driver and device** This routine initializes the driver and the device to an operational state.* All of the device-specific parameters are passed in the <initStr>.* If this routine is called with an empty but allocated string, it puts the * name of this device (that is, "dc") into the <initStr> and returns 0.* If the string is allocated but not empty, this routine tries to load* the device.** RETURNS: An END object pointer or NULL on error.*/END_OBJ* dec21x40EndLoad    (    char* initStr		/* String to be parse by the driver. */    )    {    DRV_CTRL	*pDrvCtrl;    char	eAdrs[EADDR_LEN];            /* ethernet address */    if (initStr == NULL)        return (NULL);        if (initStr[0] == NULL)        {        bcopy((char *)DRV_NAME, initStr, DRV_NAME_LEN);        return (0);        }    /* Allocate a control structure for this device */    pDrvCtrl = calloc (sizeof(DRV_CTRL), 1);    if (pDrvCtrl == NULL)        {        printf ("%s - Failed to allocate control structure\n",                DRV_NAME );         return (NULL);        }#ifdef DRV_DEBUG    pDrvCtrlDbg = pDrvCtrl;#endif    pDrvCtrl->flags = NULL;    pDrvCtrl->intrConnect = FALSE;    pDrvCtrl->mediaCount = 0xff;    /* Parse InitString */    if (dec21x40InitParse (pDrvCtrl, initStr) == ERROR)        {        printf ("%s - Failed to parse initialization parameters\n",                DRV_NAME);        return (NULL);        }    /* endObject Initializations */    if (END_OBJ_INIT (&pDrvCtrl->endObj, (DEV_OBJ*)pDrvCtrl, DRV_NAME,                      pDrvCtrl->unit, &netFuncs,                      "dec21x40 Enhanced Network Driver") == ERROR)        {        printf ("%s%d - Failed to initialize END object\n",                DRV_NAME, pDrvCtrl->unit);        return (NULL);        }    /* memory Initializations */    if (dec21x40InitMem (pDrvCtrl) == ERROR)        goto error;    /* get Ethernet Address */    if (dec21x40EnetAddrGet (pDrvCtrl, eAdrs) == ERROR)        {        printf ("%s%d - Failed to read ethernet address\n",                DRV_NAME, pDrvCtrl->unit);        goto error;        }    DRV_LOG (DRV_DEBUG_LOAD,             "ENET: %x:%x:%x:%x:%x:%x\n",             eAdrs[0], eAdrs[1], eAdrs[2], eAdrs[3], eAdrs[4], eAdrs[5]);        /* Initialize MIB-II entries */    if (END_MIB_INIT (&pDrvCtrl->endObj, M2_ifType_ethernet_csmacd,                      (UINT8*) eAdrs, 6,                       ETHERMTU, DEC_SPEED_DEF) == ERROR)        {        printf ("%s%d - MIB-II initializations failed\n",                DRV_NAME, pDrvCtrl->unit);        goto error;        }    /* Mark the device ready with default flags */    END_OBJ_READY (&pDrvCtrl->endObj,                   IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST);    /* Successful return */    return (&pDrvCtrl->endObj);    /***** Handle error cases *****/    error:	{        dec21x40Unload (pDrvCtrl);        return (NULL);        }    }/********************************************************************************* dec21x40Unload - unload a driver from the system** This routine deallocates lists, and free allocated memory.** RETURNS: OK, always.*/LOCAL STATUS dec21x40Unload    (    DRV_CTRL *pDrvCtrl    )    {    DRV_LOG (DRV_DEBUG_LOAD, "EndUnload\n", 0, 0, 0, 0, 0, 0);    /* deallocate lists */    END_OBJ_UNLOAD (&pDrvCtrl->endObj);    /* deallocate allocated shared memory */    if (DRV_FLAGS_ISSET (DEC_MEMOWN)  && pDrvCtrl->memBase)        cacheDmaFree (pDrvCtrl->memBase);

⌨️ 快捷键说明

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