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

📄 motfcc2end.c

📁 vxworks MPC8541 BSP
💻 C
📖 第 1 页 / 共 5 页
字号:
* 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;    FCC_ETH_PARAM_T *   pEthPar;    int                 retVal;    /* get to the beginning of the parameter area */    pParam  = pDrvCtrl->fccPar;    pEthPar = pDrvCtrl->fccEthPar;    if (pDrvCtrl == NULL)        goto errorExit;    if ((pDrvCtrl->state & MOT_FCC_STATE_LOADED) == MOT_FCC_STATE_NOT_LOADED)        goto errorExit;    /* must stop the device before unloading it */    if ((pDrvCtrl->state & MOT_FCC_STATE_RUNNING) == MOT_FCC_STATE_RUNNING)        motFccStop(pDrvCtrl);    /* disconnect the interrupt handler */    SYS_FCC_INT_DISCONNECT (pDrvCtrl, motFccInt, (int)pDrvCtrl, retVal);    if ( retVal == ERROR )        goto errorExit;    /* 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        {        /* release from the DPRAM pool */        pDrvCtrl->dpramFreeFunc ((void *) pDrvCtrl->pBdBase);        pDrvCtrl->pBdBase = NULL;        }    /* free allocated memory if necessary */    if ((pDrvCtrl->pMBlkArea) != NULL)        free (pDrvCtrl->pMBlkArea);#ifdef INCLUDE_RFC_2233    /* Free MIB-II entries */    m2IfFree(pDrvCtrl->endObj.pMib2Tbl);    pDrvCtrl->endObj.pMib2Tbl = NULL;#endif /* INCLUDE_RFC_2233 */    /* free misc resources */    if (pDrvCtrl->rBufList)        free(pDrvCtrl->rBufList);    pDrvCtrl->rBufList = NULL;    if (pDrvCtrl->tBufList)        free(pDrvCtrl->tBufList);    pDrvCtrl->tBufList = NULL;    END_OBJECT_UNLOAD (&pDrvCtrl->endObj);    /* free the semaphores if necessary */    if (pDrvCtrl->graSem != NULL)        semDelete (pDrvCtrl->graSem);    if ((char *) pDrvCtrl->phyInfo != NULL)        cfree ((char *) pDrvCtrl->phyInfo);    /* free allocated DPRAM memory if necessary */    if (pDrvCtrl->riPtr != NULL)        {        pDrvCtrl->dpramFccFreeFunc (pDrvCtrl->riPtr);        pParam->riptr = 0;        pDrvCtrl->riPtr = NULL;        }    if (pDrvCtrl->tiPtr != NULL)        {        pDrvCtrl->dpramFccFreeFunc (pDrvCtrl->tiPtr);        pParam->tiptr = 0;        pDrvCtrl->tiPtr = NULL;        }    if (pDrvCtrl->padPtr != NULL)        {        pDrvCtrl->dpramFccFreeFunc (pDrvCtrl->padPtr);        pEthPar->pad_ptr = 0;        pDrvCtrl->padPtr = NULL;        }    pDrvCtrl->state = MOT_FCC_STATE_INIT;#ifdef MOT_FCC_DBG    pDrvCtrlDbg = NULL;    free (pDrvCtrl->Stats);#endif /* MOT_FCC_DBG */    /* free driver control structure */    free (pDrvCtrl);    return (OK);    errorExit:    return ERROR;    }/********************************************************************************* 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);    /* bsp function structure */    tok = strtok_r (NULL, ":", &holder);    if (tok == NULL)        return ERROR;    pDrvCtrl->motFccFuncs = (FCC_END_FUNCS *) 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;        }    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;   /* total BD area including Alignment */    UINT32  rbdMemSize;  /* Receive BD area size */    UINT32  tbdMemSize;  /* Transmit BD area size */    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 :            /*             * The user has not provided a BD data area             * This driver can't handle write incoherent caches.             */            if ( !CACHE_DMA_IS_WRITE_COHERENT () )                return ERROR;            rbdMemSize = MOT_FCC_RBD_SZ * pDrvCtrl->rbdNum;            tbdMemSize = MOT_FCC_TBD_SZ * pDrvCtrl->tbdNum;            bdMemSize = rbdMemSize + tbdMemSize + MOT_FCC_BD_ALIGN;            /* Allocated from dma safe memory */            pDrvCtrl->pBdBase = cacheDmaMalloc(bdMemSize);            if ( pDrvCtrl->pBdBase == NULL )                return ERROR;    /* no memory available */            pDrvCtrl->bdSize = bdMemSize;            MOT_FCC_FLAG_SET (MOT_FCC_OWN_BD_MEM);            break;        default :            /* The user provided an area for the BDs  */            if ( !pDrvCtrl->bdSize )                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;                tbd

⌨️ 快捷键说明

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