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

📄 m8260fccend.c

📁 Embedded Planet公司的ep8260单板计算机的BSP包(VxWorks)
💻 C
📖 第 1 页 / 共 5 页
字号:
	goto errorExit;

    pDrvCtrl->phyInfo->phySpeed = MOT_FCC_10MBS;
    if (END_MIB_INIT (&pDrvCtrl->endObj, M2_ifType_ethernet_csmacd, 
		      (u_char *) &enetAddr[0], MOT_FCC_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_FCC_LOG (MOT_FCC_DBG_LOAD, ("motFccEndLoad... Done \n"), 
				    1, 2, 3, 4, 5, 6);

    return (&pDrvCtrl->endObj);

errorExit:
    motFccUnload (pDrvCtrl);
    return NULL;
}

/*******************************************************************************
*
* motFccUnload - unload a driver from the system
*
* This routine unloads the driver pointed to by <pDrvCtrl> from the system.
*
* RETURNS: OK, always.
*
* SEE ALSO: motFccLoad()
*/
LOCAL STATUS motFccUnload
    (
    DRV_CTRL	* pDrvCtrl       /* pointer to DRV_CTRL structure */
    )
    {
	FCC_PARAM_T	*pParam;

    /* get to the beginning of the parameter area */
    pParam = pDrvCtrl->fccPar;

    MOT_FCC_LOG (MOT_FCC_DBG_LOAD, ("Unloading end..."), 1, 2, 3, 4, 5, 6);

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

    pDrvCtrl->loaded = FALSE;

    /* free allocated memory if necessary */

    if ((MOT_FCC_FLAG_ISSET (MOT_FCC_OWN_BUF_MEM)) && (pDrvCtrl->pBufBase != NULL))
		free (pDrvCtrl->pBufBase);

    if ((MOT_FCC_FLAG_ISSET (MOT_FCC_OWN_BD_MEM)) && (pDrvCtrl->pBdBase != NULL))
		cacheDmaFree (pDrvCtrl->pBdBase);
	else if((MOT_FCC_USR_FLAG_ISSET(MOT_FCC_USR_DPRAM_ALOC)) && (pDrvCtrl->pBdBase != NULL))
	{
		/* If pBdBase is not equal to NULL then it was allocated from the DPRAM pool */
		sys82xxDpramFree((void*)pDrvCtrl->pBdBase);
		pDrvCtrl->pBdBase = NULL;
	}

    /* free allocated memory if necessary */

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

    END_OBJECT_UNLOAD (&pDrvCtrl->endObj);

    /* free the semaphores if necessary */

    MOT_FCC_GRA_SEM_DELETE;

    if ((char *) pDrvCtrl->phyInfo != NULL)
	cfree ((char *) pDrvCtrl->phyInfo);

	/* free allocated DPRAM memory if necessary */
	if((MOT_FCC_USR_FLAG_ISSET(MOT_FCC_USR_DPRAM_ALOC)) && (pParam->riptr != NULL))
	{
		sys82xxDpramFccFree((void*)((ULONG)pParam->riptr));
        pParam->riptr = NULL;
	}
    if((MOT_FCC_USR_FLAG_ISSET(MOT_FCC_USR_DPRAM_ALOC)) && (pParam->tiptr != NULL))
	{
	    sys82xxDpramFccFree((void*)((ULONG)pParam->tiptr));
		pParam->tiptr = NULL;
	}

    MOT_FCC_LOG (MOT_FCC_DBG_LOAD, ("motFccUnload... Done\n"), 
				    1, 2, 3, 4, 5, 6);

    return (OK);
    }

/*******************************************************************************
*
* motFccInitParse - 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 motFccInitParse
    (
    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 = (int) strtoul (tok, NULL, 16);

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

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

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

    tok = strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->bdSize = 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->phyDefMode = (UINT8) strtoul (tok, NULL, 16);

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

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

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

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

    if (!pDrvCtrl->tbdNum || pDrvCtrl->tbdNum <= 2)
	{
	MOT_FCC_FLAG_SET (MOT_FCC_INV_TBD_NUM);
	pDrvCtrl->tbdNum = MOT_FCC_TBD_DEF_NUM;
	}

    if (!pDrvCtrl->rbdNum || pDrvCtrl->rbdNum <= 2)
	{
	MOT_FCC_FLAG_SET (MOT_FCC_INV_RBD_NUM);
	pDrvCtrl->rbdNum = MOT_FCC_RBD_DEF_NUM; 
	}

    MOT_FCC_LOG (MOT_FCC_DBG_LOAD,
		 ("motFccEndParse: unit=%d immrVal=0x%x 
		 bufBase=0x%x bufSize=0x%x,
		 bdBase=0x%x bdSize=0x%x \n"),
		 pDrvCtrl->unit, 
		 (int) pDrvCtrl->immrVal,
		 (int) pDrvCtrl->pBufBase,
		 pDrvCtrl->bufSize,
		 (int) pDrvCtrl->pBdBase,
		 pDrvCtrl->bdSize);

    MOT_FCC_LOG (MOT_FCC_DBG_LOAD,
		 ("motFccEndParse: fifoTxBase=0x%x fifoRxBase=0x%x
		 tbdNum=%d rbdNum=%d flags=0x%x fccNum=%d\n"),
		 pDrvCtrl->fifoTxBase,
		 pDrvCtrl->fifoRxBase,
		 pDrvCtrl->tbdNum,
		 pDrvCtrl->rbdNum,
		 pDrvCtrl->userFlags,
		 pDrvCtrl->fccNum);

    MOT_FCC_LOG (MOT_FCC_DBG_LOAD,
                 ("motFccEndParse: phyAddr=0x%x 
                  phyDefMode=0x%x orderTbl=0x%x \n"),
                 pDrvCtrl->phyInfo->phyAddr,
                 pDrvCtrl->phyInfo->phyDefMode,
                 (int) pDrvCtrl->phyInfo->phyAnOrderTbl,
                 0, 0, 0);
    return (OK);
    }

/*******************************************************************************
* motFccInitMem - 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 motFccInitMem (DRV_CTRL *  pDrvCtrl)
{
UINT32		bdMemSize,rbdMemSize,tbdMemSize;
UINT16		clNum;		/* a buffer number holder */

/* cluster blocks configuration */
M_CL_CONFIG	mclBlkConfig = {0, 0, NULL, 0};
/* cluster blocks config table */
CL_DESC		clDescTbl [] = { {MOT_FCC_MAX_CL_LEN, 0, NULL, 0} };
/* number of different clusters sizes in pool -- only 1 */
int		clDescTblNumEnt = 1;

    /* initialize the netPool */
    if ((pDrvCtrl->endObj.pNetPool = malloc (sizeof (NET_POOL))) == NULL){
	return ERROR;
    }

    /* 
     * Establish the memory area that we will share with the device.  This
     * area may be thought of as being divided into two parts: one is the 
     * buffer descriptors (BD) and the second one is for the data buffers. 
     * Since they have different requirements as far as cache are concerned,
     * they may be addressed separately.
     * We'll deal with the BDs area first.  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 has not provided 
     * an area, then we must obtain it from the system, using the cache 
     * savvy allocation routine.
     */

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

	/* this driver can't handle write incoherent caches */
	if (!CACHE_DMA_IS_WRITE_COHERENT ()) {
	    MOT_FCC_LOG (MOT_FCC_DBG_LOAD, "motFccInitMem: shared memory not cache coherent\n",0,0,0,0,0,0);
	    return ERROR;
	}
	rbdMemSize = MOT_FCC_RBD_SZ * pDrvCtrl->rbdNum;
	tbdMemSize = MOT_FCC_TBD_SZ * pDrvCtrl->tbdNum;
	bdMemSize = rbdMemSize + tbdMemSize + MOT_FCC_BD_ALIGN;
	pDrvCtrl->pBdBase = cacheDmaMalloc(bdMemSize);
	if(pDrvCtrl->pBdBase == NULL){     /* no memory available */
	    MOT_FCC_LOG (MOT_FCC_DBG_LOAD, "motFccInitMem: could not obtain memory\n",0,0,0,0,0,0);
	    return ERROR;
	}
	pDrvCtrl->bdSize = bdMemSize;
	MOT_FCC_FLAG_SET (MOT_FCC_OWN_BD_MEM);
	pDrvCtrl->bdCacheFuncs = cacheDmaFuncs;
	break;

      default :			       /* the user provided an area */
	if(!pDrvCtrl->bdSize){
	    MOT_FCC_LOG (MOT_FCC_DBG_LOAD, "motFccInitMem: not enough memory\n",0,0,0,0,0,0);
	    return ERROR;
	}

	/* 
	 * check whether user provided a number for Rx and Tx BDs
	 * fill in the blanks if we can.
	 * check whether enough memory was provided, etc.
	 */

	if (MOT_FCC_FLAG_ISSET (MOT_FCC_INV_TBD_NUM) && MOT_FCC_FLAG_ISSET (MOT_FCC_INV_RBD_NUM)) {
	    pDrvCtrl->tbdNum = pDrvCtrl->bdSize / (MOT_FCC_TBD_SZ + MOT_FCC_RBD_SZ);
	    pDrvCtrl->rbdNum = pDrvCtrl->tbdNum;
	} else if (MOT_FCC_FLAG_ISSET (MOT_FCC_INV_TBD_NUM)) {
	    rbdMemSize = MOT_FCC_RBD_SZ * pDrvCtrl->rbdNum;
	    pDrvCtrl->tbdNum = (pDrvCtrl->bdSize - rbdMemSize) / MOT_FCC_TBD_SZ;
	} else if (MOT_FCC_FLAG_ISSET (MOT_FCC_INV_RBD_NUM)) {
	    tbdMemSize = MOT_FCC_TBD_SZ * pDrvCtrl->tbdNum;
	    pDrvCtrl->rbdNum = (pDrvCtrl->bdSize - tbdMemSize) / MOT_FCC_RBD_SZ;
	} else {
	    rbdMemSize = MOT_FCC_RBD_SZ * pDrvCtrl->rbdNum;
	    tbdMemSize = MOT_FCC_TBD_SZ * pDrvCtrl->tbdNum;
	    bdMemSize = rbdMemSize + tbdMemSize + MOT_FCC_BD_ALIGN;
	    if (pDrvCtrl->bdSize < bdMemSize) {
		MOT_FCC_LOG (MOT_FCC_DBG_LOAD, "motFccInitMem: not enough memory\n",0,0,0,0,0,0);
		return ERROR;
	    }
	}
	if ((pDrvCtrl->tbdNum < MOT_FCC_TBD_MIN) || (pDrvCtrl->rbdNum < MOT_FCC_RBD_MIN)) {
	    MOT_FCC_LOG (MOT_FCC_DBG_LOAD, "motFccInitMem: not enough BDs\n",0,0,0,0,0,0);
	    return ERROR;
	}
	MOT_FCC_FLAG_CLEAR (MOT_FCC_OWN_BD_MEM);
	pDrvCtrl->bdCacheFuncs = cacheNullFuncs;
	break;
    }

    /* zero the shared memory */
    memset (pDrvCtrl->pBdBase, 0, (int) pDrvCtrl->bdSize);

    /* align the shared memory */
    pDrvCtrl->pBdBase = (char *) ROUND_UP((UINT32)pDrvCtrl->pBdBase,MOT_FCC_BD_ALIGN);

    /* 
     * number of clusters, including loaning buffers, a min number
     * of transmit clusters for copy-mode transmit, and one transmit
     * cluster for polling operation.

⌨️ 快捷键说明

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