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

📄 dec21x40end.c

📁 Tornado 2.0.2 source code!vxworks的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
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->offset = 0;    if (dec21x40InitParse (pDrvCtrl, initStr) == ERROR)        {        DRV_LOG  (DRV_DEBUG_LOAD, "%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_LOAD, "%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_LOAD, "dec21x40InitMem failed",0,0,0,0,0,0);        goto error;        }    if (dec21x40EnetAddrGet (pDrvCtrl, eAdrs) == ERROR)        {        DRV_LOG  (DRV_DEBUG_LOAD, "%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]);    if (END_MIB_INIT (&pDrvCtrl->endObj, M2_ifType_ethernet_csmacd,                      (UINT8*) eAdrs, 6,                       ETHERMTU, DEC_SPEED_DEF) == ERROR)        {        DRV_LOG  (DRV_DEBUG_LOAD, "%s%d - MIB-II initializations failed\n",                  (int)DRV_NAME, pDrvCtrl->unit,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;        default :            DRV_FLAGS_SET (DEC_21040);            break;        }    /* Mark the device ready with default flags */    END_OBJ_READY (&pDrvCtrl->endObj,                   IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST);    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);    return (OK);    }/********************************************************************************* dec21x40InitParse - parse parameter values from initString** The initialization string is modified by muxLib.o to include the unit number* as the first parameter.** Parse the input string.  Fill in values in the driver control structure.** The initialization string format is:* "<device addr>:<PCI addr>:<ivec>:<ilevel>:<mem base>:<mem size>:	\*  <user flags>:<phyAddr>:<pPhyTbl>:<phyFlags>:<offset>"** .bS* device addr	base address of hardware device registers* PCI addr	main memory address over the PCI bus* ivec		interrupt vector number* ilevel	interrupt level* mem base	base address of a DMA-able, cache free,pre-allocated  memory* mem size	size of the pre-allocated memory* user flags	User flags control the run-time characteristics of the chip* phyAddr	MII PHY address (optional)* pPhyTbl	address of auto-negotiation table (optional)* phyFlags	PHY configuration flags (optional)* offset        Memory offset for alignment (optional)** The last four arguments are optional. If the PHY address is to be specified* then phyAddr, pPhyTbl, and phyFlags should all be specified together.** RETURNS: OK or ERROR for invalid arguments.*/LOCAL STATUS dec21x40InitParse    (    DRV_CTRL	*pDrvCtrl,    char 	*initString    )    {    char *	tok;		/* an initString token */    char *	holder=NULL;	/* points to initString fragment beyond tok */        DRV_LOG (DRV_DEBUG_LOAD, "InitParse: Initstr=%s\n",             (int) initString, 0, 0, 0, 0, 0);    tok = endTok_r(initString, ":", &holder);    if (tok == NULL)        return ERROR;    pDrvCtrl->unit = atoi(tok);    tok=endTok_r(NULL, ":", &holder);    if (tok == NULL)        return ERROR;    pDrvCtrl->devAdrs = strtoul (tok, NULL, 16);        tok=endTok_r(NULL, ":", &holder);    if (tok == NULL)        return ERROR;    pDrvCtrl->pciMemBase = strtoul (tok, NULL, 16);    tok=endTok_r(NULL, ":", &holder);    if (tok == NULL)        return ERROR;    pDrvCtrl->ivec = strtoul (tok, NULL, 16);    tok=endTok_r(NULL, ":", &holder);    if (tok == NULL)        return ERROR;    pDrvCtrl->ilevel = strtoul (tok, NULL, 16);        tok = endTok_r(NULL, ":", &holder);    if (tok == NULL)        return ERROR;    if (atoi(tok) < 0)        pDrvCtrl->numRds = NUM_RDS_DEF;    else        pDrvCtrl->numRds = atoi(tok);        tok = endTok_r(NULL, ":", &holder);    if (tok == NULL)        return ERROR;    if (atoi(tok) < 0)        pDrvCtrl->numTds = NUM_TDS_DEF;    else        pDrvCtrl->numTds = atoi(tok);    tok=endTok_r(NULL, ":", &holder);    if (tok == NULL)        return ERROR;    pDrvCtrl->memBase = (char *) strtoul (tok, NULL, 16);    tok=endTok_r(NULL, ":", &holder);    if (tok == NULL)        return ERROR;    pDrvCtrl->memSize = strtoul (tok, NULL, 16);    tok=endTok_r(NULL, ":", &holder);    if (tok == NULL)        return (ERROR);    pDrvCtrl->usrFlags = strtoul(tok, NULL, 16);     /* start of optional parameters */    /* set MII defaults */    pDrvCtrl->pMiiPhyTbl = NULL;    pDrvCtrl->phyAddr = (UINT8) 0xFF;    pDrvCtrl->miiPhyFlags = (DEC_USR_MII_10MB | DEC_USR_MII_HD |			    DEC_USR_MII_100MB | DEC_USR_MII_FD |			    DEC_USR_MII_BUS_MON);    tok = endTok_r (NULL, ":", &holder);    if (tok != NULL)	{	pDrvCtrl->phyAddr = (UINT8) strtoul (tok, NULL, 16);	}    tok = endTok_r (NULL, ":", &holder);    if (tok != NULL)	{	pDrvCtrl->pMiiPhyTbl = (MII_AN_ORDER_TBL *) strtoul (tok, NULL, 16);	}    tok = endTok_r (NULL, ":", &holder);    if (tok != NULL)	{	pDrvCtrl->miiPhyFlags = (UINT32) strtoul (tok, NULL, 16);	}     tok = endTok_r (NULL, ":", &holder);    if (tok != NULL)	pDrvCtrl->offset = atoi (tok);    /* print debug info */    DRV_LOG (DRV_DEBUG_LOAD,            "EndLoad: unit=%d devAdrs=0x%x ivec=0x%x ilevel=0x%x\n",            pDrvCtrl->unit, pDrvCtrl->devAdrs, pDrvCtrl->ivec,	    pDrvCtrl->ilevel, 0, 0);    DRV_LOG (DRV_DEBUG_LOAD,            "         membase=0x%x memSize=0x%x\n",            (int)pDrvCtrl->memBase, pDrvCtrl->memSize, 0,0,0,0);        DRV_LOG (DRV_DEBUG_LOAD,             "        pciMemBase=0x%x flags=0x%x usrFlags=0x%x offset=%d\n",             (int)pDrvCtrl->pciMemBase, pDrvCtrl->flags, pDrvCtrl->usrFlags,             pDrvCtrl->offset, 0, 0);    DRV_LOG (DRV_DEBUG_LOAD,	     "        phyAddr=0x%x pMiiPhyTbl=0x%x miiPhyFlags=0x%x\n",	     (int) pDrvCtrl->phyAddr, (int) pDrvCtrl->pMiiPhyTbl,	     (int) pDrvCtrl->miiPhyFlags,	     0,0,0);    return OK;    }/********************************************************************************

⌨️ 快捷键说明

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