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

📄 motfecend.c

📁 其中包括88796网卡驱动、mbmflash驱动、i2c接口的eeprom驱动、oki的ml9620can网卡驱动、扩展的串口驱动源代码。适用于moto的ppc8××系列在vxworks环境下。
💻 C
📖 第 1 页 / 共 5 页
字号:
    pDrvCtrl = (DRV_CTRL *) calloc (sizeof (DRV_CTRL), 1);
    if (pDrvCtrl == NULL)
	return (NULL);

    pDrvCtrl->phyInfo = (PHY_INFO *) calloc (sizeof (PHY_INFO), 1);
    if (pDrvCtrl->phyInfo == NULL)
	{
	free ((char *)pDrvCtrl);
	return (NULL);
	}

#ifdef MOT_FEC_DBG
    pDrvCtrlDbg = pDrvCtrl;
#endif /* MOT_FEC_DBG */

    /* Parse InitString */

    if (motFecInitParse (pDrvCtrl, initString) == ERROR)
	goto errorExit;	

    pDrvCtrl->ilevel = (int) IVEC_TO_ILEVEL (pDrvCtrl->ivec);

    /* sanity check the unit number */

    if (pDrvCtrl->unit < 0 )
	goto errorExit;

    /* memory initialization */

    if (motFecInitMem (pDrvCtrl) == ERROR)
	goto errorExit;

    /* get our ethernet hardware address */

    SYS_FEC_ENET_ADDR_GET (enetAddr);

    MOT_FEC_LOG (MOT_FEC_DBG_LOAD, ("motFecEndLoad: enetAddr= \n\
				    0x%x 0x%x 0x%x 0x%x 0x%x 0x%x \n "),
				    enetAddr[0],
				    enetAddr[1],
				    enetAddr[2],
				    enetAddr[3],
				    enetAddr[4],
				    enetAddr[5]);

    /* initialize some flags */

    pDrvCtrl->loaded = TRUE;
    pDrvCtrl->intrConnect = FALSE;

    /*
     * create the synchronization semaphores for mii intr handling
     * and for graceful transmit command interrupts.
     */
    if (miiSem == (SEM_ID)NULL)
      MOT_FEC_MII_SEM_CREATE;

    MOT_FEC_GRA_SEM_CREATE;

    /* endObj initializations */

    if (END_OBJ_INIT (&pDrvCtrl->endObj, (DEV_OBJ*) pDrvCtrl,
		      MOT_FEC_DEV_NAME, pDrvCtrl->unit, &netFuncs,
		      "Motorola FEC Ethernet Enhanced Network Driver")
	== ERROR)
	goto errorExit;

    pDrvCtrl->phyInfo->phySpeed = MOT_FEC_10MBS;
    if (END_MIB_INIT (&pDrvCtrl->endObj, M2_ifType_ethernet_csmacd,
		      (u_char *) &enetAddr[0], MOT_FEC_ADDR_LEN,
		      ETHERMTU, pDrvCtrl->phyInfo->phySpeed) == ERROR)
	goto errorExit;

    /* Mark the device ready */

    END_OBJ_READY (&pDrvCtrl->endObj,
                   IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST);

    MOT_FEC_LOG (MOT_FEC_DBG_LOAD, ("motFecEndLoad... Done \n"),
				    1, 2, 3, 4, 5, 6);

    /*
     * determine the revision number of the processor, and set pinMux
     * bit accordingly
     */

    if (motRevNumGet () >= REV_D_3)
        pinMux = MOT_FEC_ETH_PINMUX;
    else
        pinMux = 0;

        pinMux = MOT_FEC_ETH_PINMUX;

    return (&pDrvCtrl->endObj);

errorExit:
    motFecUnload (pDrvCtrl);
    free ((char *) pDrvCtrl);
    return NULL;
    }

/*******************************************************************************
*
* motFecUnload - unload a driver from the system
*
* This routine unloads the driver pointed to by <pDrvCtrl> from the system.
*
* RETURNS: OK, always.
*
* SEE ALSO: motFecLoad()
*/

LOCAL STATUS motFecUnload
    (
    DRV_CTRL	*pDrvCtrl       /* pointer to DRV_CTRL structure */
    )
    {
    int		ix = 0;		/* a counter */

    MOT_FEC_LOG (MOT_FEC_DBG_LOAD, ("Unloading end..."), 1, 2, 3, 4, 5, 6);

    if (pDrvCtrl == NULL)
	return (ERROR);

    pDrvCtrl->loaded = FALSE;

    /* free lists */

    for (ix = 0; ix < pDrvCtrl->tbdNum; ix++)
	{
	cfree ((char *) pDrvCtrl->pTbdList [ix]);
	}

    END_OBJECT_UNLOAD (&pDrvCtrl->endObj);

    /* free allocated memory if necessary */

    if ((MOT_FEC_FLAG_ISSET (MOT_FEC_OWN_MEM)) &&
	(pDrvCtrl->pBufBase != NULL))
	cacheDmaFree (pDrvCtrl->pBufBase);

    /* free allocated memory if necessary */

    if ((pDrvCtrl->pMBlkArea) != NULL)
	free (pDrvCtrl->pMBlkArea);

    /* free the semaphores if necessary */

    MOT_FEC_MII_SEM_DELETE;
    MOT_FEC_GRA_SEM_DELETE;

    free (pDrvCtrl->phyInfo);

    MOT_FEC_LOG (MOT_FEC_DBG_LOAD, ("motFecUnload... Done\n"),
				    1, 2, 3, 4, 5, 6);

    return (OK);
    }

/*******************************************************************************
*
* motFecInitParse - parse parameter values from initString
*
* This routine parses parameter values from initString and stores them in
* the related fiels of the driver control structure.
*
* RETURNS: OK or ERROR
*/

LOCAL STATUS motFecInitParse
    (
    DRV_CTRL *	pDrvCtrl,      		/* pointer to DRV_CTRL structure */
    char *	initString		/* parameter string */
    )
    {
    char *  tok;		/* an initString token */
    char *  holder = NULL;	/* points to initString fragment beyond tok */

    tok = strtok_r (initString, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->unit = atoi (tok);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->motCpmAddr = (UINT32) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->ivec = (int) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->fecNum = (int) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->pBufBase = (char *) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->bufSize = strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->fifoTxBase = (UINT32) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->fifoRxBase = (UINT32) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->tbdNum = (UINT16) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->rbdNum = (UINT16) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->phyInfo->phyAddr = (UINT8) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->phyInfo->isoPhyAddr = (UINT8) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
        return ERROR;
    pDrvCtrl->phyInfo->phyDefMode = (UINT8) strtoul (tok, NULL, 16);

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->userFlags = strtoul (tok, NULL, 16);

    /* start of optional parameters */

    tok = strtok_r (NULL, ":", &holder);
    if (tok != NULL)
	pDrvCtrl->clockSpeed = atoi (tok);

    if (!pDrvCtrl->tbdNum || pDrvCtrl->tbdNum <= 2)
	{
	MOT_FEC_FLAG_SET (MOT_FEC_INV_TBD_NUM);
	pDrvCtrl->tbdNum = MOT_FEC_TBD_DEF_NUM;
	}

    if (!pDrvCtrl->rbdNum || pDrvCtrl->rbdNum <= 2)
	{
	MOT_FEC_FLAG_SET (MOT_FEC_INV_RBD_NUM);
	pDrvCtrl->rbdNum = MOT_FEC_RBD_DEF_NUM;
	}

    MOT_FEC_LOG (MOT_FEC_DBG_LOAD,
		 ("motFecEndParse: unit=%d motCpmAddr=0x%x ivec=0x%x\n\
		 fecNum=0x%x bufBase=0x%x bufSize=0x%x \n"),
		 pDrvCtrl->unit,
		 (int) pDrvCtrl->motCpmAddr,
		 (int) pDrvCtrl->ivec,
		 (int) pDrvCtrl->fecNum,
		 (int) pDrvCtrl->pBufBase,
		 pDrvCtrl->bufSize);

    MOT_FEC_LOG (MOT_FEC_DBG_LOAD,
		 ("motFecEndParse: fifoTxBase=0x%x fifoRxBase=0x%x\n\
		 tbdNum=%d rbdNum=%d flags=0x%x\n"),
		 pDrvCtrl->fifoTxBase,
		 pDrvCtrl->fifoRxBase,
		 pDrvCtrl->tbdNum,
		 pDrvCtrl->rbdNum,
		 pDrvCtrl->userFlags,
		 0);

    MOT_FEC_LOG (MOT_FEC_DBG_LOAD,
                 ("motFecEndParse: phyAddr=0x%x isoPhyAddr=0x%x\n\
                  phyDefMode=0x%x \n"),
                 pDrvCtrl->phyInfo->phyAddr,
                 pDrvCtrl->phyInfo->isoPhyAddr,
                 pDrvCtrl->phyInfo->phyDefMode,
                 0, 0, 0);
    return (OK);
    }

/*******************************************************************************
*
* motFecInitMem - initialize memory
*
* This routine initializes all the memory needed by the driver whose control
* structure is passed in <pDrvCtrl>.
*
* RETURNS: OK or ERROR
*/

LOCAL STATUS motFecInitMem
    (
    DRV_CTRL *  pDrvCtrl       		/* pointer to DRV_CTRL structure */
    )
    {
    UINT32		bdSize;	   	/* temporary size holder */
    UINT32		clSize;	   	/* temporary size holder */
    UINT16		clNum;		/* a buffer number holder */
    M_CL_CONFIG	 	mclBlkConfig = {0, 0, NULL, 0};
					/* cluster blocks configuration */
    CL_DESC	 	clDescTbl [] = { {MOT_FEC_MAX_CL_LEN, 0, NULL, 0} };
					/* cluster blocks config table */
    int clDescTblNumEnt = (NELEMENTS (clDescTbl));
					/* number of different clusters */

    /* initialize the netPool */

    if ((pDrvCtrl->endObj.pNetPool = malloc (sizeof (NET_POOL))) == NULL)
	return (ERROR);

    /*
     * we include here room for both TBDs and RBDs,
     * and the alignment factor.
     */

    bdSize = (MOT_FEC_BD_MEM (pDrvCtrl) + MOT_FEC_BD_ALIGN);

    /*
     * Establish the memory area that we will share with the device.  If
     * the caller has provided an area, then we assume it is non-cacheable
     * and will not require the use of the special cache routines.
     * If the caller did provide an area, then we must obtain it from
     * the system, using the cache savvy allocation routine.
     */

    switch ((int) pDrvCtrl->pBufBase)
	{
	case NONE :			     /* we must obtain it */

	    /* this driver can't handle write incoherent caches */

	    if (!CACHE_DMA_IS_WRITE_COHERENT ())
		{
		MOT_FEC_LOG (MOT_FEC_DBG_LOAD, ("motFecInitMem: shared \n\
					        memory not cache coherent\n"),
					        1, 2, 3, 4, 5, 6);
		return (ERROR);
		}

	    pDrvCtrl->pBufBase = cacheDmaMalloc (bdSize);

	    if (pDrvCtrl->pBufBase == NULL)      /* no memory available */
		{
		MOT_FEC_LOG (MOT_FEC_DBG_LOAD, ("motFecInitMem: could not \n\
					        obtain memory\n"),
					        1, 2, 3, 4, 5, 6);
		return (ERROR);
		}

            pDrvCtrl->pBufBase = (char *) (((UINT32) (pDrvCtrl->pBufBase) +
                                  MOT_FEC_BD_ALIGN - 1) &
                                  ~(MOT_FEC_BD_ALIGN -1));

	    pDrvCtrl->bufSize = bdSize;

	    MOT_FEC_FLAG_SET (MOT_FEC_OWN_MEM);

	    pDrvCtrl->bdCacheFuncs = cacheDmaFuncs;

⌨️ 快捷键说明

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