📄 motfccend.c
字号:
/********************************************************************************* 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 */ ) { 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); /* 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); if ((char *) pDrvCtrl != NULL) cfree ((char *) pDrvCtrl); 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); 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, pDrvCtrl->pBufBase, pDrvCtrl->bufSize, 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, 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 /* pointer to DRV_CTRL structure */ ) { UINT32 bdSize; /* temporary size holder */ UINT16 clNum; /* a buffer number holder */ M_CL_CONFIG mclBlkConfig = {0, 0, NULL, 0}; /* cluster blocks configuration */ CL_DESC clDescTbl [] = { {MOT_FCC_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_FCC_BD_MEM (pDrvCtrl) + MOT_FCC_BD_ALIGN); /* * Establish the memory area that we will share with the device. This * area may be thought of as being devided 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"), 1, 2, 3, 4, 5, 6); return (ERROR); } pDrvCtrl->pBdBase = cacheDmaMalloc (bdSize); if (pDrvCtrl->pBdBase == NULL) /* no memory available */ { MOT_FCC_LOG (MOT_FCC_DBG_LOAD, ("motFccInitMem: could not obtain memory\n"), 1, 2, 3, 4, 5, 6); return (ERROR); } pDrvCtrl->bdSize = bdSize; MOT_FCC_FLAG_SET (MOT_FCC_OWN_BD_MEM); pDrvCtrl->bdCacheFuncs = cacheDmaFuncs; break; default : /* the user provided an area */ if (pDrvCtrl->bdSize == 0) { MOT_FCC_LOG (MOT_FCC_DBG_LOAD, ("motFccInitMem: not enough memory\n"), 1, 2, 3, 4, 5, 6); return (ERROR); } /* * check the user provided enough memory with reference * to the given number of receive/transmit frames, if any. */ if (MOT_FCC_FLAG_ISSET (MOT_FCC_INV_TBD_NUM) && MOT_FCC_FLAG_ISSET (MOT_FCC_INV_RBD_NUM)) { pDrvCtrl->tbdNum = (MOT_FCC_BD_MEM_SZ (pDrvCtrl) / (MOT_FCC_TBD_SZ + MOT_FCC_RBD_SZ)); pDrvCtrl->rbdNum = pDrvCtrl->tbdNum; } else if (MOT_FCC_FLAG_ISSET (MOT_FCC_INV_TBD_NUM)) { pDrvCtrl->tbdNum = ((MOT_FCC_BD_MEM_SZ (pDrvCtrl) - MOT_FCC_RBD_MEM (pDrvCtrl)) / MOT_FCC_TBD_SZ); } else if (MOT_FCC_FLAG_ISSET (MOT_FCC_INV_RBD_NUM)) { pDrvCtrl->rbdNum = ((MOT_FCC_BD_MEM_SZ (pDrvCtrl) - MOT_FCC_TBD_MEM (pDrvCtrl)) / MOT_FCC_RBD_SZ); } else { if (MOT_FCC_BD_MEM_SZ (pDrvCtrl) < bdSize) { MOT_FCC_LOG (MOT_FCC_DBG_LOAD, ("motFccInitMem: not enough memory\n"), 1, 2, 3, 4, 5, 6); 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"), 1, 2, 3, 4, 5, 6); 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 *) (((UINT32) (pDrvCtrl->pBdBase) + MOT_FCC_BD_ALIGN - 1) & ~(MOT_FCC_BD_ALIGN - 1)); /* * number of clusters, including loaning buffers, a min number * of transmit clusters for copy-mode transmit, and one transmit * cluster for polling operation. */ clNum = 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 - 1); /* * 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, but 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 : /* we must obtain it */ clDescTbl[0].memArea = (char *) (memalign (CL_ALIGNMENT, clDescTbl[0].memSize)); if (clDescTbl[0].memArea == NULL) { MOT_FCC_LOG (MOT_FCC_DBG_LOAD, ("motFccInitMem: could not
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -