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

📄 bcm1250macend.c

📁 操作系统vxworks平台下end设备的驱动程序,支持多种芯片,支持多种cpu
💻 C
📖 第 1 页 / 共 5 页
字号:
/* bcm1250MacEnd.c - END style BCM1250 MAC Ethernet driver *//* Copyright 2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/* * Copyright 2000,2001 * Broadcom Corporation. All rights reserved. * * This software is furnished under license to Wind River Systems, Inc. * and may be used only in accordance with the terms and conditions of * this license.  No title or ownership is transferred hereby. *//* * This file has been developed or significantly modified by the * MIPS Center of Excellence Dedicated Engineering Staff. * This notice is as per the MIPS Center of Excellence Master Partner * Agreement, do not remove this notice without checking first with * WR/Platforms MIPS Center of Excellence engineering management. *//*modification history--------------------01i,30jan03,m_h  IPv6 Support01h,26jun02,pgh  Fix SPR 79037, polled mode.01g,21jun02,agf  change comment block to match coding standard01f,19mar02,pgh  Apply code review fixes.01e,14mar02,pgh  Made the code compliant with the coding standard.                 Eliminated unused code.                 Added comments.                 Restructured areas of the code.01d,06mar02,pgh  Fixes SPR 73552 and SPR 74000.01c,05mar02,pgh  Fixes SPR73549, SPR73550, and SPR73644.01b,07dec01,agf  apply coding standard fix-ups01a,15nov01,agf  written.*//*DESCRIPTIONThis module implements the Broadcom BCM1250 on-chip ethernet MACs.The BCM1250 ethernet DMA has two channels, but this module only supports channel 0.  The dual DMA channel feature is intended for packet classification and quality of service applications.EXTERNAL INTERFACEThe only external interface is the bcm1250MacEndLoad() routine, which has the<initString> as its only parameter.  The initString parameter must be a colon-delimited string in the following format:<unit>:<hwunit>:<vecnum>:<flags>:<numRds0>:<numTds0>TARGET-SPECIFIC PARAMETERS.IP <unit>This parameter defines which ethernet interface is being loaded..IP <hwunit>This parameter is no longer used, but must be present so the string can be parsed properly.  Its value should be zero..IP <vecnum>This parameter specifies the interrupt vector number.  This driver configures the MAC device to generate hardware interrupts for various events within the device; thus it contains an interrupt handler routine.  The driver calls bcm1250IntConnect() to connect its interrupt handler to this interrupt vector..IP <flags>Device specific flags, for future use.  Its value should be zero..IP <numRds0>This parameter specifies the number of receive DMA buffer descriptors for DMAchannel 0..IP <numTds0>This parameter specifies the number of transmit DMA buffer descriptors for DMAchannel 0.SYSTEM RESOURCE USAGEWhen implemented, this driver requires the following system resources:    - one mutual exclusion semaphore    - one interrupt vector    - 68 bytes in the initialized data section (data)    - 0 bytes in the uninitialized data section (BSS)    The driver allocates clusters of size 1520 bytes for receive frames and    and transmit frames.INCLUDES:endLib.h etherMultiLib.h bcm1250MacEnd.hSEE ALSO: muxLib, endLib, netBufLib.I "Writing and Enhanced Network Driver"*/#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "logLib.h"#include "semLib.h"#include "intLib.h"#include "netLib.h"#include "netBufLib.h"#include "memLib.h"#include "etherLib.h"#include "etherMultiLib.h"#include "endLib.h"#include "lstLib.h"#ifdef WR_IPV6#include "adv_net.h"#endif /*WR_IPV6*/#include "drv/multi/bcm1250Lib.h"#include "drv/end/bcm1250MacEnd.h"#define DRV_DEBUG#ifdef  DRV_DEBUG#define DRV_DEBUG_OFF           0x0000#define DRV_DEBUG_RX            0x0001#define DRV_DEBUG_TX            0x0002#define DRV_DEBUG_INT           0x0004#define DRV_DEBUG_POLL          (DRV_DEBUG_POLL_RX | DRV_DEBUG_POLL_TX)#define DRV_DEBUG_POLL_RX       0x0008#define DRV_DEBUG_POLL_TX       0x0010#define DRV_DEBUG_LOAD          0x0020#define DRV_DEBUG_IOCTL         0x0040#define DRV_DEBUG_RXD           0x0100#define DRV_DEBUG_TXD           0x0200#define DRV_DEBUG_POLL_REDIR   0x10000#define DRV_DEBUG_LOG_NVRAM    0x20000#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)                        \        if (bcm1250MacDebug & FLG)                                             \            (void)logMsg (X0, X1, X2, X3, X4, X5, X6);#else /*DRV_DEBUG*/#define DRV_LOG(DBG_SW, X0, X1, X2, X3, X4, X5, X6)#endif /*DRV_DEBUG*//* DRV_CTRL flags access macros */#define DRV_FLAGS_SET(setBits) \        (pDrvCtrl->flags |= (setBits))#define DRV_FLAGS_ISSET(setBits) \        (pDrvCtrl->flags & (setBits))#define DRV_FLAGS_CLR(clrBits) \        (pDrvCtrl->flags &= ~(clrBits))#define DRV_FLAGS_GET() \        (pDrvCtrl->flags)#define END_FLAGS_ISSET(pEnd, setBits) \        ((pEnd)->flags & (setBits))#define END_HADDR(pEnd) \        ((pEnd)->mib2Tbl.ifPhysAddress.phyAddress)#define END_HADDR_LEN(pEnd) \        ((pEnd)->mib2Tbl.ifPhysAddress.addrLength)#define KVTOPHYS(x) ((UINT32)(x) & 0x7FFFFFFF)#define PHYSTOV(x)  ((UINT32)(x) | 0x80000000)#ifndef ETH_MAC_REG_READ#define ETH_MAC_REG_READ(reg)  \    MIPS3_LD (pDrvCtrl->regMacBase + reg)#endif /* ETH_MAC_REG_READ */#ifndef ETH_MAC_REG_WRITE#define ETH_MAC_REG_WRITE(reg, val)  \    MIPS3_SD ((pDrvCtrl->regMacBase + reg), (val))#endif /* ETH_MAC_REG_WRITE */#ifndef ETH_DMA_REG_READ#define ETH_DMA_REG_READ(reg)   MIPS3_LD (reg)#endif /* ETH_DMA_REG_READ */#ifndef ETH_DMA_REG_WRITE#define ETH_DMA_REG_WRITE(reg, val)     MIPS3_SD ((reg), (val))#endif /* ETH_DMA_REG_WRITE */#define NET_BUF_ALLOC() \    netClusterGet (pDrvCtrl->endObj.pNetPool, pDrvCtrl->clPoolId)#define NET_BUF_FREE(pBuf) \    netClFree (pDrvCtrl->endObj.pNetPool, (unsigned char *)(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) \    (void)netMblkClFree ((M_BLK_ID)pMblk)#define NET_MBLK_CL_JOIN(pMblk, pClBlk) \    (void)netMblkClJoin ((pMblk), (pClBlk))#define NET_CL_BLK_JOIN(pClBlk, pBuf, len) \    (void)netClBlkJoin ((pClBlk), (pBuf), (len), (FUNCPTR)NULL, 0, 0, 0)/* PHY/MII */#define MII_COMMAND_START       0x01#define MII_COMMAND_READ        0x02#define MII_COMMAND_WRITE       0x01#define MII_COMMAND_ACK         0x02/* Basic Mode Control Register bit definitions */#define BMCR_RESET     0x8000#define BMCR_LOOPBACK  0x4000#define BMCR_SPEED0    0x2000#define BMCR_ANENABLE  0x1000#define BMCR_POWERDOWN 0x0800#define BMCR_ISOLATE   0x0400#define BMCR_RESTARTAN 0x0200#define BMCR_DUPLEX    0x0100#define BMCR_COLTEST   0x0080#define BMCR_SPEED1    0x0040#define BMCR_SPEED1000 (BMCR_SPEED1 | BMCR_SPEED0)#define BMCR_SPEED100  (BMCR_SPEED0)#define BMCR_SPEED10    0/* Basic Mode Status Register bit definitions */#define BMSR_100BT4     0x8000#define BMSR_100BT_FDX  0x4000#define BMSR_100BT_HDX  0x2000#define BMSR_10BT_FDX   0x1000#define BMSR_10BT_HDX   0x0800#define BMSR_100BT2_FDX 0x0400#define BMSR_100BT2_HDX 0x0200#define BMSR_1000BT_XSR 0x0100#define BMSR_PRESUP     0x0040#define BMSR_ANCOMPLT   0x0020#define BMSR_REMFAULT   0x0010#define BMSR_AUTONEG    0x0008#define BMSR_LINKSTAT   0x0004#define BMSR_JABDETECT  0x0002#define BMSR_EXTCAPAB   0x0001/* 1K Status Register bit definitions */#define K1STSR_MSMCFLT  0x8000#define K1STSR_MSCFGRES 0x4000#define K1STSR_LRSTAT   0x2000#define K1STSR_RRSTAT   0x1000#define K1STSR_LP1KFD   0x0800#define K1STSR_LP1KHD   0x0400#define K1STSR_LPASMDIR 0x0200/* AutoNegotiation Link Partner Abilities Register bit definitions */#define ANLPAR_NP       0x8000#define ANLPAR_ACK      0x4000#define ANLPAR_RF       0x2000#define ANLPAR_ASYPAUSE 0x0800#define ANLPAR_PAUSE    0x0400#define ANLPAR_T4       0x0200#define ANLPAR_TXFD     0x0100#define ANLPAR_TXHD     0x0080#define ANLPAR_10FD     0x0040#define ANLPAR_10HD     0x0020#define ANLPAR_PSB      0x0001  /* 802.3 */#define PHYIDR1         0x2000#define PHYIDR2         0x5C60/* Physical interface chip register index definitions */#define MII_BMCR    0x00    /* Basic mode control register (rw) */#define MII_BMSR    0x01    /* Basic mode status register (ro) */#define MII_K1STSR  0x0A    /* 1K Status Register (ro) */#define MII_ANLPAR  0x05    /* AutoNegotiation Link Partner Abilities (rw) */#define M_MAC_MDIO_DIR_OUTPUT   0               /* for clarity *//* externs */IMPORT void sysBcm1250MacEnetAddrGet (int, char *);IMPORT STATUS bcm1250IntConnect (int, int, VOIDFUNCPTR, int);IMPORT STATUS bcm1250IntDisconnect (int);IMPORT STATUS bcm1250IntEnable (int);IMPORT STATUS bcm1250IntDisable (int);/* locals */#ifdef  DRV_DEBUG/*LOCAL int bcm1250MacDebug = DRV_DEBUG_LOAD | DRV_DEBUG_INT | DRV_DEBUG_TX |                            DRV_DEBUG_RX | DRV_DEBUG_POLL;*/LOCAL int bcm1250MacDebug = DRV_DEBUG_OFF;#endif /*DRV_DEBUG*/char *  pTxPollBuf;     /* Points to polled mode transmit cluster *//* forward declarations */void bcm1250MacRxDmaShow (int);    /* for debug */void bcm1250MacTxDmaShow (int);    /* for debug */void bcm1250MacShow (int);         /* for debug */void bcm1250MacPhyShow (int);      /* for debug */LOCAL UINT64 bcm1250MacAddr2Reg (unsigned char *);LOCAL STATUS bcm1250MacMemInit (DRV_CTRL *);LOCAL STATUS bcm1250MacDmaInit (ETH_MAC_DMA *, MAC_REG, int);LOCAL STATUS bcm1250MacPktCopyTransmit (DRV_CTRL *, M_BLK *);LOCAL STATUS bcm1250MacPktTransmit (DRV_CTRL *, M_BLK *, int);LOCAL void bcm1250MacTxHandle (DRV_CTRL *);LOCAL void bcm1250MacRxHandle (DRV_CTRL *);LOCAL STATUS bcm1250MacInitParse (DRV_CTRL *, char *);LOCAL void bcm1250MacInt (DRV_CTRL *);LOCAL void bcm1250MacRxFilterSet (DRV_CTRL *);LOCAL void  bcm1250MacMblkWalk (M_BLK *, int *, BOOL *);LOCAL unsigned bcm1250MacEthHash (unsigned char *);LOCAL void bcm1250MacEthMiiPoll (DRV_CTRL *);LOCAL void bcm1250MacEthMiiFindPhy (DRV_CTRL *);LOCAL void bcm1250MacEthMiiSync (DRV_CTRL *);LOCAL void bcm1250MacEthMiiSendData (DRV_CTRL *, unsigned int, int);LOCAL int bcm1250MacEthMiiRead (DRV_CTRL *, int, int);LOCAL STATUS bcm1250MacHashRegAdd (DRV_CTRL *, char *);LOCAL STATUS bcm1250MacHashRegSet (DRV_CTRL *);LOCAL STATUS bcm1250MacSetConfig (DRV_CTRL *, MAC_SPEED, MAC_DUPLEX, MAC_FC);/* This is the only externally visible interface. */END_OBJ * bcm1250MacEndLoad (char * initString);/* END Specific interfaces. */LOCAL STATUS bcm1250MacStart (DRV_CTRL *);LOCAL STATUS bcm1250MacStop (DRV_CTRL *);LOCAL STATUS bcm1250MacUnload (DRV_CTRL *);LOCAL int bcm1250MacIoctl (DRV_CTRL *, int, caddr_t);LOCAL STATUS bcm1250MacSend (DRV_CTRL *, M_BLK_ID);LOCAL STATUS bcm1250MacMCastAdd (DRV_CTRL *, char *);LOCAL STATUS bcm1250MacMCastDel (DRV_CTRL *, char *);LOCAL STATUS bcm1250MacMCastGet (DRV_CTRL *, MULTI_TABLE *);LOCAL STATUS bcm1250MacPollSend (DRV_CTRL *, M_BLK_ID);LOCAL STATUS bcm1250MacPollRcv (DRV_CTRL *, M_BLK_ID);LOCAL void bcm1250MacPollStart (DRV_CTRL *);LOCAL void bcm1250MacPollStop (DRV_CTRL *);/* * Define the device function table.  This is static across all driver * instances. */LOCAL NET_FUNCS bcm1250MacFuncTable =    {    (FUNCPTR)bcm1250MacStart,       /* Function to start the device. */    (FUNCPTR)bcm1250MacStop,        /* Function to stop the device. */    (FUNCPTR)bcm1250MacUnload,      /* Unloading function for the driver. */    (FUNCPTR)bcm1250MacIoctl,       /* Ioctl function for the driver. */    (FUNCPTR)bcm1250MacSend,        /* Send function for the driver. */    (FUNCPTR)bcm1250MacMCastAdd,    /* Multicast add function for the */    (FUNCPTR)bcm1250MacMCastDel,    /* Multicast delete function for */    (FUNCPTR)bcm1250MacMCastGet,    /* Multicast retrieve function for */    (FUNCPTR)bcm1250MacPollSend,    /* Polling send function */    (FUNCPTR)bcm1250MacPollRcv,     /* Polling receive function */    endEtherAddressForm,            /* put address info into a NET_BUFFER */    (FUNCPTR)endEtherPacketDataGet, /* get pointer to data in NET_BUFFER */    (FUNCPTR)endEtherPacketAddrGet  /* Get packet addresses. */    };/********************************************************************************* bcm1250MacEndLoad - initialize the driver and device** This routine initializes the driver and the device to the operational state.* All of the device specific parameters are passed in <initString>, which* expects a string of the following format:** The initialization string format is:* "<unit>:<hwunit>:<vecnum>:<flags>:<numRds0>:<numTds0>:<numRds1>:<numTds1>"** The hwunit field is not used, but must be present to parse properly.** This routine can be called in two modes.  If it is called with an empty but* allocated string, it places the name of this device (that is, "sbe0", "sbe1",* or "sbe2") into the <initString> and returns NULL.** If the string is allocated and not empty, the routine attempts to load* the driver using the values specified in the string.

⌨️ 快捷键说明

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