📄 motfcc2end.c
字号:
* If the caller indicates that this routine must allocate the shared memory* region, then this routine will use cacheDmaMalloc() to obtain* some cache-safe memory. The attributes of this memory will be checked,* and if the memory is not write coherent, this routine will abort and* return NULL.** RETURNS: an END object pointer, or NULL on error.** SEE ALSO: ifLib,* .I "MPC8260 Power QUICC II User's Manual"*/END_OBJ* motFcc2EndLoad ( char *initString ) { DRV_CTRL * pDrvCtrl = NULL; /* pointer to DRV_CTRL structure */ UCHAR enetAddr[MOT_FCC_ADDR_LEN]; /* ethernet address */ int retVal; if (initString == NULL) return NULL; if (initString[0] == 0) { bcopy ((char *)MOT_FCC_DEV_NAME, (void *)initString,MOT_FCC_DEV_NAME_LEN); return NULL; } /* allocate the device structure */ pDrvCtrl = (DRV_CTRL *) calloc (sizeof (DRV_CTRL), 1); if (pDrvCtrl == NULL) return NULL; /* get memory for the phyInfo structure */ if ((pDrvCtrl->phyInfo = calloc (sizeof (PHY_INFO), 1)) == NULL) return NULL; /* set up function pointers */ pDrvCtrl->netJobAdd = (FUNCPTR) netJobAdd; pDrvCtrl->muxTxRestart = (FUNCPTR) muxTxRestart; pDrvCtrl->muxError = (FUNCPTR) muxError; #ifdef MOT_FCC_DBG pDrvCtrlDbg = pDrvCtrl; /* get memory for the drivers stats structure */ if ((pDrvCtrl->Stats = calloc (sizeof (FCC_DRIVER_STATS), 1)) == NULL) return NULL; /* support unit test */ _func_netJobAdd = (FUNCPTR) netJobAdd; _func_txRestart = (FUNCPTR) muxTxRestart; _func_error = (FUNCPTR) muxError;#endif /* MOT_FCC_DBG */ /* Parse InitString */ if (motFccInitParse (pDrvCtrl, initString) == ERROR) goto errorExit; /* sanity check the unit number */ if (pDrvCtrl->unit < 0 ) goto errorExit; /* memory initialization */ if (motFccInitMem (pDrvCtrl) == ERROR) goto errorExit; /* get our ethernet hardware address */ SYS_FCC_ENET_ADDR_GET (enetAddr); /* init miiPhy fuctions */ if ( pDrvCtrl->motFccFuncs == NULL ) { pDrvCtrl->hbFailFunc = NULL; pDrvCtrl->intDiscFunc = NULL; pDrvCtrl->phyInitFunc = NULL; pDrvCtrl->phyDuplexFunc = NULL; pDrvCtrl->phySpeedFunc = NULL; } else { pDrvCtrl->hbFailFunc = pDrvCtrl->motFccFuncs->hbFail; pDrvCtrl->intDiscFunc = pDrvCtrl->motFccFuncs->intDisc; pDrvCtrl->phyInitFunc = pDrvCtrl->motFccFuncs->miiPhyInit; pDrvCtrl->phyDuplexFunc = pDrvCtrl->motFccFuncs->miiPhyDuplex; pDrvCtrl->phySpeedFunc = pDrvCtrl->motFccFuncs->miiPhySpeed; /* BSP call back to driver */ pDrvCtrl->motFccFuncs->miiPhyInt = (FUNCPTR) motFccPhyLSCInt; } /* init dpram functions */ if (pDrvCtrl->motFccFuncs->dpramFree == NULL) pDrvCtrl->dpramFreeFunc = (FUNCPTR) m82xxDpramFree; else pDrvCtrl->dpramFreeFunc = pDrvCtrl->motFccFuncs->dpramFree; if (pDrvCtrl->motFccFuncs->dpramFccMalloc == NULL) pDrvCtrl->dpramFccMallocFunc = (FUNCPTR) m82xxDpramFccMalloc; else pDrvCtrl->dpramFccMallocFunc = pDrvCtrl->motFccFuncs->dpramFccMalloc; if (pDrvCtrl->motFccFuncs->dpramFccFree == NULL) pDrvCtrl->dpramFccFreeFunc = (FUNCPTR) m82xxDpramFccFree; else pDrvCtrl->dpramFccFreeFunc = pDrvCtrl->motFccFuncs->dpramFccFree; /* initialize some flags */ pDrvCtrl->intrConnect = FALSE; /* Set zeroBufFlag */ if (pDrvCtrl->userFlags & MOT_FCC_USR_BUF_LBUS || pDrvCtrl->userFlags & MOT_FCC_USR_NO_ZCOPY) { pDrvCtrl->zeroBufFlag = FALSE; } else { pDrvCtrl->zeroBufFlag = TRUE; } /* store the internal ram base address */ pDrvCtrl->fccIramAddr = (UINT32) M8260_FGMR1 (pDrvCtrl->immrVal) + ((pDrvCtrl->fccNum - 1) * M8260_FCC_IRAM_GAP); pDrvCtrl->fccReg = (FCC_REG_T *)pDrvCtrl->fccIramAddr; /* store the parameter ram base address */ pDrvCtrl->fccPramAddr = (UINT32) M8260_FCC1_BASE (pDrvCtrl->immrVal) + ((pDrvCtrl->fccNum - 1) * M8260_FCC_DPRAM_GAP); pDrvCtrl->fccPar = (FCC_PARAM_T *) pDrvCtrl->fccPramAddr; pDrvCtrl->fccEthPar = &pDrvCtrl->fccPar->prot.e; /* * create the synchronization semaphore for graceful transmit * command interrupts. */ if ( (pDrvCtrl->graSem = semBCreate (SEM_Q_FIFO, SEM_EMPTY) )== NULL ) \ goto errorExit; /* * Because we create EMPTY semaphore we need to give it here * other wise the only time that it's given back is in the * motFccInt() and if we have two NI in the bootrom like SCC * and FCC the motFccStop() will be spin forever when it will * try to do semTake. */ semGive (pDrvCtrl->graSem); /* endObj initializations */ if (END_OBJ_INIT (&pDrvCtrl->endObj, (DEV_OBJ*) pDrvCtrl, MOT_FCC_DEV_NAME, pDrvCtrl->unit, &netFccFuncs, "Motorola FCC Ethernet Enhanced Network Driver") == ERROR) goto errorExit; pDrvCtrl->phyInfo->phySpeed = MOT_FCC_10MBS;#ifdef INCLUDE_RFC_2233 /* Initialize MIB-II entries (for RFC 2233 ifXTable) */ pDrvCtrl->endObj.pMib2Tbl = m2IfAlloc(M2_ifType_ethernet_csmacd, (UINT8*) enetAddr, 6, ETHERMTU, pDrvCtrl->phyInfo->phySpeed, MOT_FCC_DEV_NAME, pDrvCtrl->unit); if (pDrvCtrl->endObj.pMib2Tbl == NULL) { logMsg ("%s%d - MIB-II initializations failed\n", (int)MOT_FCC_DEV_NAME, pDrvCtrl->unit,0,0,0,0); goto errorExit; } /* * Set the RFC2233 flag bit in the END object flags field and * install the counter update routines. */ m2IfPktCountRtnInstall(pDrvCtrl->endObj.pMib2Tbl, m2If8023PacketCount); /* * Make a copy of the data in mib2Tbl struct as well. We do this * mainly for backward compatibility issues. There might be some * code that might be referencing the END pointer and might * possibly do lookups on the mib2Tbl, which will cause all sorts * of problems. */ bcopy ((char *)&pDrvCtrl->endObj.pMib2Tbl->m2Data.mibIfTbl, (char *)&pDrvCtrl->endObj.mib2Tbl, sizeof (M2_INTERFACETBL)); /* Mark the device ready */ END_OBJ_READY (&pDrvCtrl->endObj, IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST | END_MIB_2233);#else /* Old RFC 1213 mib2 interface */ 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);#endif /* INCLUDE_RFC_2233 */ /* Allocate DPRAM memory for the riptr, tiptr & pad */ pDrvCtrl->riPtr = (void *) pDrvCtrl->dpramFccMallocFunc (32,32); if (pDrvCtrl->riPtr == NULL) goto errorExit; pDrvCtrl->tiPtr = (void *) pDrvCtrl->dpramFccMallocFunc (32,32); if (pDrvCtrl->tiPtr == NULL) goto errorExit; pDrvCtrl->padPtr = (void *) pDrvCtrl->dpramFccMallocFunc (32,32); if (pDrvCtrl->padPtr == NULL) goto errorExit; /* connect the interrupt handler */ SYS_FCC_INT_CONNECT (pDrvCtrl, motFccInt, (int) pDrvCtrl, retVal); if (retVal == ERROR) goto errorExit; pDrvCtrl->state = MOT_FCC_STATE_LOADED; 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; 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -