📄 motfcc2end.c
字号:
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; tbdMemSize = MOT_FCC_TBD_SZ * pDrvCtrl->tbdNum; bdMemSize = rbdMemSize + tbdMemSize + MOT_FCC_BD_ALIGN; if ( pDrvCtrl->bdSize < bdMemSize ) return ERROR; } if ((pDrvCtrl->tbdNum < MOT_FCC_TBD_MIN) || (pDrvCtrl->rbdNum < MOT_FCC_RBD_MIN)) return ERROR; MOT_FCC_FLAG_CLEAR (MOT_FCC_OWN_BD_MEM); 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. */ clNum = (2 * pDrvCtrl->rbdNum) + MOT_FCC_BD_LOAN_NUM + MOT_FCC_TX_POLL_NUM + MOT_FCC_TX_CL_NUM; /* pool of mblks */ if ( mclBlkConfig.mBlkNum == 0 ) { mclBlkConfig.mBlkNum = clNum * 2; } /* pool of clusters, including loaning buffers */ if ( clDescTbl[0].clNum == 0 ) { clDescTbl[0].clNum = clNum; clDescTbl[0].clSize = MOT_FCC_MAX_CL_LEN; } /* there's a cluster overhead and an alignment issue */ clDescTbl[0].memSize = clDescTbl[0].clNum * (clDescTbl[0].clSize + CL_OVERHEAD) + CL_ALIGNMENT; /* * Now we'll deal with the data buffers. 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. This means we will not be * using the cache savvy allocation routine, since we will flushing or * invalidate the data cache itself as appropriate. This speeds up * driver operation, as the network stack will be able to process data * in a cacheable area. */ switch ( (int) pDrvCtrl->pBufBase ) { case NONE : /* * The user has not provided data area for the clusters. * Allocate from cachable data block. */ clDescTbl[0].memArea = (char *) memalign(CL_ALIGNMENT, clDescTbl[0].memSize); if ( clDescTbl[0].memArea == NULL ) return ERROR; /* store t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -