📄 motfcc2end.c
字号:
/* Base Address of BDs */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->pBdBase = (char *) strtoul (tok, NULL, 16); /* Size of BDs */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->bdSize = strtoul (tok, NULL, 16); /* Memory Pool Base Address */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->pBufBase = (char *) strtoul (tok, NULL, 16); /* Memory Pool Size */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->bufSize = strtoul (tok, NULL, 16); /* TX FIFO Base Address */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->fifoTxBase = (UINT32) strtoul (tok, NULL, 16); /* RX FIFO Base Address */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->fifoRxBase = (UINT32) strtoul (tok, NULL, 16); /* Number of TX Buffer Descriptors */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->tbdNum = (UINT16) strtoul (tok, NULL, 16); /* Number of RX Buffer Descriptors */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->rbdNum = (UINT16) strtoul (tok, NULL, 16); /* Address of the PHY */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->phyInfo->phyAddr = (UINT8) strtoul (tok, NULL, 16); /* PHY Default Operating Mode */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->phyInfo->phyDefMode = (UINT8) strtoul (tok, NULL, 16); /* Auto-Negotiation Table */ tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->phyInfo->phyAnOrderTbl = (MII_AN_ORDER_TBL *) strtoul (tok, NULL, 16); /* User Flags */ 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); /* passing maxRxFrames is optional. The default is rbdNum * 2 */ pDrvCtrl->maxRxFrames = 0; /* mark to use default */ tok = strtok_r (NULL, ":", &holder); if ((tok != NULL) && (tok != (char *)-1)) pDrvCtrl->maxRxFrames = strtoul (tok, NULL, 16); /* else default to a reasonable value eg 16 but do it when number of * RBDs are known in InitMem */ if (pDrvCtrl->tbdNum < MOT_FCC_TBD_MIN) { MOT_FCC_FLAG_SET (MOT_FCC_INV_TBD_NUM); pDrvCtrl->tbdNum = MOT_FCC_TBD_DEF_NUM; } if (pDrvCtrl->rbdNum < MOT_FCC_RBD_MIN) { 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 */ /* 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 () ) { free(pDrvCtrl->endObj.pNetPool); pDrvCtrl->endObj.pNetPool = NULL; 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->pRawBdBase = cacheDmaMalloc(bdMemSize); if ( pDrvCtrl->pRawBdBase == NULL ) { free(pDrvCtrl->endObj.pNetPool); pDrvCtrl->endObj.pNetPool = NULL; return ERROR; /* no memory available */ } pDrvCtrl->pBdBase = pDrvCtrl->pRawBdBase; 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 ) { free(pDrvCtrl->endObj.pNetPool); pDrvCtrl->endObj.pNetPool = NULL; 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 = (UINT16) (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 = (UINT16)((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 = (UINT16) ((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; } if (pDrvCtrl->maxRxFrames < 1) pDrvCtrl->maxRxFrames = pDrvCtrl->rbdNum >> 1; /* Divide by 2 */ /* 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: twice number of RBDs including a min number of * transmit clusters and one transmit cluster for polling operation. * TODO: The ratio of clusters to RBDs should probably be made configurable. */ clNum = (2 * pDrvCtrl->rbdNum) + MOT_FCC_TX_POLL_NUM + MOT_FCC_TX_CL_NUM; /* * 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 cacheable data block. */ pDrvCtrl->initType = END_NET_POOL_CREATE; MOT_FCC_FLAG_SET (MOT_FCC_OWN_BUF_MEM); /* cache functions descriptor for data buffers */ pDrvCtrl->bufCacheFuncs = cacheUserFuncs; break; default : /* * The user provides the area for buffers. This must be from a * non cacheable area. */ pDrvCtrl->initType = END_NET_POOL_INIT; MOT_FCC_FLAG_CLEAR (MOT_FCC_OWN_BUF_MEM); pDrvCtrl->bufCacheFuncs = cacheNullFuncs; break; } if (pDrvCtrl->initType == END_NET_POOL_INIT) { /* M_BLK/CL_BLK configuration */ M_CL_CONFIG mclBlkConfig = {0, 0, NULL, 0}; /* cluster configuration table */ CL_DESC clDescTbl [] = { {MOT_FCC_MAX_CL_LEN, 0, NULL, 0}}; /* number of different clusters sizes in pool -- only 1 */ int clDescTblNumEnt = 1; /* pool of clusters */ clDescTbl[0].clNum = clNum; clDescTbl[0].clSize = MOT_FCC_MAX_CL_LEN; /* Set memArea to the buffer base */ clDescTbl[0].memArea = pDrvCtrl->pBufBase; /* * There's a cluster overhead and an alignment issue. The * most stringent alignment requirement is from linkBufLib. * The CL_SIZE() macro rounds up to a multiple of NETBUF_ALIGN (64). * The extra NETBUF_ALIGN is required by linkBufLib to guarantee * alignment. */ clDescTbl[0].memSize = clNum * CL_SIZE (MOT_FCC_MAX_CL_LEN) + NETBUF_ALIGN; /* * check the user provided enough memory with reference * to the given number of receive/transmit frames, if any. */ if ( pDrvCtrl->bufSize < clDescTbl[0].memSize ) return ERROR; /* zero the shared memory */ memset (pDrvCtrl->pBufBase, 0, (int) pDrvCtrl->bufSize); /* pool of mblks */ mclBlkConfig.mBlkNum = clNum; /* pool of cluster blocks */ mclBlkConfig.clBlkNum = clNum; /* memory requirements from linkBufPool.c. (See linkMblkCarve().) */ mclBlkConfig.memSize = ROUND_UP ((sizeof (M_LINK) + sizeof (NET_POOL_ID)), NETBUF_ALIGN) * clNum + NETBUF_ALIGN; /* linkBufPool takes care of the alignment */ mclBlkConfig.memArea = (char *) malloc (mclBlkConfig.memSize); if (mclBlkConfig.memArea == NULL) { return ERROR; } /* store the pointer to the mBlock area */ pDrvCtrl->pMBlkArea = mclBlkConfig.memArea; pDrvCtrl->mBlkSize = mclBlkConfig.memSize; /* init the mem pool */ if ( netPoolInit (pDrvCtrl->endObj.pNetPool, &mclBlkConfig, &clDescTbl[0], clDescTblNumEnt, _pLinkPoolFuncTbl)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -