📄 dec21x40end.c
字号:
#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) \ do { \ M_BLK *pNext; \ \ pNext=pMblk; \ while (pNext) \ pNext=NET_MBLK_BUF_FREE (pNext); \ } while (0) #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/* 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 */int dec21x40Loops = DEC_LOOPS_PER_NS; /* spin loops per nsec */FUNCPTR dec21x40IntConnectRtn = intConnect;/* constant data to set PHY control register */LOCAL const UINT dcForcePhyModes[] = { MII_CR_100 | MII_CR_FDX, /* 100FD */ MII_CR_100, /* 100HD */ MII_CR_FDX, /* 10FD */ 0, /* 10HD */ -1 } ;/* 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 (DRV_CTRL *pDrvCtrl, int reg, ULONG value);LOCAL ULONG dec21x40CsrRead (DRV_CTRL *pDrvCtrl, 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 STATUS dec21x40MediaChange (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);LOCAL STATUS dec21145DecodeExt7InfoBlock ( DRV_CTRL *pDrvCtrl, UCHAR * pInfoBlock);LOCAL STATUS dec21145MediaSelect (DRV_CTRL *pDrvCtrl, UINT *pCsr6Val);LOCAL STATUS dec21x40PhyPreInit (DRV_CTRL *pDrvCtrl, UCHAR * pInfoBlock);LOCAL STATUS dec21x40MiiInit (DRV_CTRL *pDrvCtrl, UINT *pCsr6Val, UCHAR * pInfoBlock);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;VOIDFUNCPTR _func_dec2114xIntAck = (VOIDFUNCPTR) NULL;#ifdef DRV_DEBUG#include "netShow.h"IMPORT void netPoolShow (NET_POOL_ID);void decCsrShow (int inst);void decShow (int inst);#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. */ }; /******************************************************************************** endTok_r - get a token string (modified version)** This modified version can be used with optional parameters. If the* parameter is not specified, this version returns NULL. It does not* signify the end of the original string, but that the parameter is null.** .CS** /@ required parameters @/** string = endTok_r (initString, ":", &pLast);* if (string == NULL)* return ERROR;* reqParam1 = strtoul (string);** string = endTok_r (NULL, ":", &pLast);* if (string == NULL)* return ERROR;* reqParam2 = strtoul (string);** /@ optional parameters @/** string = endTok_r (NULL, ":", &pLast);* if (string != NULL)* optParam1 = strtoul (string);** string = endTok_r (NULL, ":", &pLast);* if (string != NULL)* optParam2 = strtoul (string);* .CE*/ char * endTok_r ( char * string, /* string to break into tokens */ const char * separators, /* the separators */ char ** ppLast /* pointer to serve as string index */ ) { if ((string == NULL) && ((string = *ppLast) == NULL)) return (NULL); if ((*ppLast = strpbrk (string, separators)) != NULL) *(*ppLast)++ = EOS; /* Return NULL, if string is empty */ if (*string == EOS) return NULL; return (string); }/***************************************************************************** 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) { DRV_LOG (DRV_DEBUG_LOAD, "dec21x40EndLoad: NULL initStr\r\n", 0,0,0,0,0,0); return (NULL); } if (initStr[0] == '\0') { 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) { DRV_LOG (DRV_DEBUG_LOAD,"%s - Failed to allocate control structure\n", (int)DRV_NAME, 0,0,0,0,0 ); return (NULL); } pDrvCtrl->flags = 0; pDrvCtrl->intrConnect = FALSE; pDrvCtrl->mediaCount = 0xff; pDrvCtrl->homePNAPhyValuesFound = FALSE; pDrvCtrl->offset = 0; if (dec21x40InitParse (pDrvCtrl, initStr) == ERROR) { DRV_LOG (DRV_DEBUG_INIT, "%s - Failed to parse initialization" "parameters\n", (int)DRV_NAME,0,0,0,0,0); return (NULL); } if (END_OBJ_INIT (&pDrvCtrl->endObj, (DEV_OBJ*)pDrvCtrl, DRV_NAME, pDrvCtrl->unit, &netFuncs, "dec21x40 Enhanced Network Driver") == ERROR) { DRV_LOG (DRV_DEBUG_INIT, "%s%d - Failed to initialize END object\n", (int)DRV_NAME, pDrvCtrl->unit, 0,0,0,0); return (NULL); } if (dec21x40InitMem (pDrvCtrl) == ERROR) { DRV_LOG (DRV_DEBUG_INIT, "dec21x40InitMem failed",0,0,0,0,0,0); goto error; } /* decode non-register user flags */ if (pDrvCtrl->usrFlags & DEC_USR_XEA) DRV_FLAGS_SET (DEC_BSP_EADRS); switch (pDrvCtrl->usrFlags & DEC_USR_VER_MSK) { case DEC_USR_21143 : DRV_FLAGS_SET (DEC_21143); break; case DEC_USR_21140 : DRV_FLAGS_SET (DEC_21140); break; case DEC_USR_21145 : DRV_FLAGS_SET (DEC_21145); break; default : DRV_FLAGS_SET (DEC_21040); break; } if (dec21x40EnetAddrGet (pDrvCtrl, eAdrs) == ERROR) { DRV_LOG (DRV_DEBUG_INIT, "%s%d - Failed to read ethernet address\n", (int)DRV_NAME, pDrvCtrl->unit,0,0,0,0); 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]);#ifdef INCLUDE_RFC_1213 /* Old RFC 1213 mib2 interface */ /* Initialize MIB-II entries */ if (END_MIB_INIT (&pDrvCtrl->endObj, M2_ifType_ethernet_csmacd, (UINT8*) eAdrs, 6, ETHERMTU, DEC_SPEED_DEF) == ERROR) { DRV_LOG (DRV_DEBUG_INIT, "%s%d - MIB-II initializations failed\n", (int)DRV_NAME, pDrvCtrl->unit,0,0,0,0); goto error; } /* Mark the device ready with default flags */ END_OBJ_READY (&pDrvCtrl->endObj, IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST); #else /* New RFC 2233 mib2 interface */ /* Initialize MIB-II entries (for RFC 2233 ifXTable) */ pDrvCtrl->endObj.pMib2Tbl = m2IfAlloc(M2_ifType_ethernet_csmacd, (UINT8*) eAdrs, 6, ETHERMTU, DEC_SPEED_DEF, DRV_NAME, pDrvCtrl->unit); if (pDrvCtrl->endObj.pMib2Tbl == NULL) { printf ("%s%d - MIB-II initializations failed\n", DRV_NAME, pDrvCtrl->unit); goto error; } /* * Set the RFC2233 flag bit in the END object flags field and * install the counter update routines. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -