📄 fei82557end.c
字号:
if (pDrvCtrl == NULL) return (NULL); /* Parse InitString */ if (fei82557InitParse (pDrvCtrl, initString) == ERROR) goto errorExit; /* sanity check the unit number */ if (pDrvCtrl->unit < 0 ) goto errorExit; /* * initialize the default parameter for the Physical medium * layer control user has his chance to override in the BSP, * just be CAREFUL */ pDrvCtrl->board.phyAddr = 1; pDrvCtrl->board.phySpeed = PHY_AUTO_SPEED; pDrvCtrl->board.phyDpx = PHY_AUTO_DPX; pDrvCtrl->board.others = 0; pDrvCtrl->board.tcbTxThresh = FEI_TCB_TX_THRESH;#ifdef INCLUDE_PCI /* callout to perform adapter init */ if (sys557Init (pDrvCtrl->unit, &pDrvCtrl->board) == ERROR) goto errorExit;#endif /* get CSR address from the FEI_BOARD_INFO structure */ if ((pDrvCtrl->pCSR = (CSR_ID) pDrvCtrl->board.baseAddr) == NULL) goto errorExit; /* probe for memory-mapped CSR */ CACHE_PIPE_FLUSH(); CSR_WORD_RD (CSR_STAT_OFFSET, scbStatus); if (vxMemProbe ((char *) &scbStatus, VX_READ, 2, &bucket[0]) != OK) { DRV_LOG (DRV_DEBUG_LOAD, (": need MMU mapping for address 0x%x\n"), (UINT32) pDrvCtrl->pCSR, 2, 3, 4, 5, 6); goto errorExit; } /* memory initialization */ if (fei82557InitMem (pDrvCtrl) == ERROR) goto errorExit; I82557_INT_DISABLE(SCB_C_M); /* initialize the Physical medium layer */ if (fei82557PhyInit (pDrvCtrl) != OK) { DRV_PRINT (DRV_DEBUG_LOAD, ("LINK FAILS, Check line connection\n")); } speed = ((((int) pDrvCtrl->board.phySpeed) == PHY_100MBS) ? FEI_100MBS : FEI_10MBS); if (fei82557ClkRate == 0) fei82557ClkRate = sysClkRateGet (); /* * reset the chip: this should be replaced by a true * adapter reset routine, once the init code is here. */ if (fei82557Reset (pDrvCtrl) != OK) goto errorExit; /* CU and RU should be idle following fei82557Reset() */ if (fei82557SCBCommand (pDrvCtrl, SCB_C_CULDBASE, TRUE, 0x0) == ERROR) goto errorExit; if (fei82557SCBCommand (pDrvCtrl, SCB_C_RULDBASE, TRUE, 0x0) == ERROR) goto errorExit; pDrvCtrl->attached = TRUE; /* get our ethernet hardware address */ bcopy ((char *)&pDrvCtrl->board.enetAddr, (char *)&enetAddr[0], FEI_ADDR_LEN); DRV_LOG (DRV_DEBUG_LOAD, ("fei82557Load...\n ADRR: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x \n "), enetAddr[0], enetAddr[1], enetAddr[2], enetAddr[3], enetAddr[4], enetAddr[5]); /* endObj initializations */ if (END_OBJ_INIT (&pDrvCtrl->endObj, (DEV_OBJ*) pDrvCtrl, DEV_NAME, pDrvCtrl->unit, &netFuncs, "Intel 82557 Ethernet Enhanced Network Driver") == ERROR) goto errorExit;#ifdef INCLUDE_RFC_1213 /* Old RFC 1213 mib2 interface */ if (END_MIB_INIT (&pDrvCtrl->endObj, M2_ifType_ethernet_csmacd, (u_char *) &enetAddr[0], FEI_ADDR_LEN, ETHERMTU, speed) == ERROR) goto errorExit; /* Mark the device ready */ END_OBJ_READY (&pDrvCtrl->endObj, IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST);#else /* New RFC 2233 mib2 interface */ /* Initialize MIB-II entries (for RFC 2233 ifXTable) */ pDrvCtrl->endObj.pMib2Tbl = m2IfAlloc(M2_ifType_ethernet_csmacd, (UINT8*) enetAddr, 6, ETHERMTU, speed, DEV_NAME, pDrvCtrl->unit); if (pDrvCtrl->endObj.pMib2Tbl == NULL) { printf ("%s%d - MIB-II initializations failed\n", DEV_NAME, pDrvCtrl->unit); 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);#endif /* INCLUDE_RFC_1213 */ DRV_LOG (DRV_DEBUG_LOAD, ("fei82557Load... Done \n"), 1, 2, 3, 4, 5, 6); return (&pDrvCtrl->endObj);errorExit: DRV_LOG (DRV_DEBUG_LOAD, "fei82557Load failed\n", 0,0,0,0,0,0); fei82557Unload (pDrvCtrl); free ((char *) pDrvCtrl); return NULL; }/********************************************************************************* fei82557Unload - unload a driver from the system** RETURNS: N/A*/LOCAL STATUS fei82557Unload ( DRV_CTRL *pDrvCtrl /* pointer to DRV_CTRL structure */ ) { DRV_LOG (DRV_DEBUG_LOAD, ("Unloading end..."), 1, 2, 3, 4, 5, 6);#ifndef INCLUDE_RFC_1213 /* New RFC 2233 mib2 interface */ /* Free MIB-II entries */ m2IfFree(pDrvCtrl->endObj.pMib2Tbl); pDrvCtrl->endObj.pMib2Tbl = NULL;#endif /* INCLUDE_RFC_1213 */ pDrvCtrl->attached = FALSE; /* free lists */ END_OBJECT_UNLOAD (&pDrvCtrl->endObj); /* free allocated memory if necessary */ if ((FEI_FLAG_ISSET (FEI_OWN_MEM)) && (pDrvCtrl->pMemBase != NULL)) cacheDmaFree (pDrvCtrl->pMemBase); /* free allocated memory if necessary */ cfree (pDrvCtrl->pMemArea); DRV_LOG (DRV_DEBUG_LOAD, ("fei82557Unload... Done\n"), 1, 2, 3, 4, 5, 6); return (OK); }/********************************************************************************* fei82557InitParse - parse parameter values from initString** RETURNS: OK or ERROR*/LOCAL STATUS fei82557InitParse ( 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 = atoi (tok); tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->pMemBase = (char *) strtoul (tok, NULL, 16); tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->memSize = strtoul (tok, NULL, 16); tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->nCFDs = strtoul (tok, NULL, 16); tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->nRFDs = strtoul (tok, NULL, 16); tok = strtok_r (NULL, ":", &holder); if (tok == NULL) return ERROR; pDrvCtrl->flags = atoi (tok); /* offset value is optional, default is zero */ pDrvCtrl->offset = 0; tok = strtok_r (NULL, ":", &holder); if (tok != NULL) pDrvCtrl->offset = atoi (tok); /* device ID is optional, default is zero */ pDrvCtrl->deviceId = 0; tok = strtok_r (NULL, ":", &holder); if (tok != NULL) pDrvCtrl->deviceId = atoi (tok); if (!pDrvCtrl->nCFDs || pDrvCtrl->nCFDs <= 2) { FEI_FLAG_SET (FEI_INV_NCFD); pDrvCtrl->nCFDs = DEF_NUM_CFDS; } if (!pDrvCtrl->nRFDs || pDrvCtrl->nRFDs <= 2) { FEI_FLAG_SET (FEI_INV_NRFD); pDrvCtrl->nRFDs = DEF_NUM_RFDS; } DRV_LOG (DRV_DEBUG_LOAD, "fei82557EndLoad: unit=%d pMemBase=0x%x memSize=0x%x\n", pDrvCtrl->unit, (int) pDrvCtrl->pMemBase, (int) pDrvCtrl->memSize, 0,0,0); DRV_LOG (DRV_DEBUG_LOAD, "fei82557EndLoad: nCFDs=%d nRFDs=%d flags=%d offset=%d\n", pDrvCtrl->nCFDs, pDrvCtrl->nRFDs, pDrvCtrl->flags, pDrvCtrl->offset, 0, 0); return (OK); }/********************************************************************************* fei82557InitMem - initialize memory** RETURNS: OK or ERROR*/LOCAL STATUS fei82557InitMem ( DRV_CTRL * pDrvCtrl /* pointer to DRV_CTRL structure */ ) { volatile CFD_ID pCFD; /* pointer to CFDs */ volatile RFD_ID pRFD; /* pointer to RFDs */ UINT32 size; /* temporary size holder */ int ix; /* a counter */ int nRFDLoan; /* number of loaning RFDs */ BOOL firstCFD = TRUE;/* is this the first CFD? */ BOOL firstRFD = TRUE;/* is this the first RFD? */ M_CL_CONFIG fei82557MclBlkConfig = { /* * mBlkNum clBlkNum memArea memSize * ----------- ---- ------- ------- */ 0, 0, NULL, 0 }; CL_DESC fei82557ClDescTbl [] = { /* * clusterSize num memArea memSize * ----------- ---- ------- ------- */ {RFD_SIZE, 0, NULL, 0} }; int fei82557ClDescTblNumEnt = (NELEMENTS (fei82557ClDescTbl)); /* initialize the netPool */ if ((pDrvCtrl->endObj.pNetPool = malloc (sizeof (NET_POOL))) == NULL) return (ERROR); /* it looks sensible */ nRFDLoan = (pDrvCtrl->nRFDs * FEI_RFD_LOAN_MULTIPLIER); /* * the final 4 is to allow for alignment */ size = (((pDrvCtrl->nRFDs) * (CL_RFD_SIZE)) + (nRFDLoan * (CL_RFD_SIZE)) + ((pDrvCtrl->nCFDs) * (CFD_SIZE + sizeof(long))) + 4); printf("size=%d\n", size); /* * Establish the memory area that we will share with the device. 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 did not provide an area, then we must obtain it from * the system, using the cache savvy allocation routine. */ switch ((int) pDrvCtrl->pMemBase) { case NONE : /* we must obtain it */ /* this driver can't handle write incoherent caches */ if (!CACHE_DMA_IS_WRITE_COHERENT ()) { DRV_LOG (DRV_DEBUG_LOAD, ("fei82557EndLoad: shared memory not cache coherent\n"), 1, 2, 3, 4, 5, 6); return (ERROR); } pDrvCtrl->pMemBase = cacheDmaMalloc(size); if (pDrvCtrl->pMemBase == NULL) /* no memory available */ { DRV_LOG (DRV_DEBUG_LOAD, ("fei82557EndLoad: could not obtain memory\n"), 1, 2, 3, 4, 5, 6); return (ERROR); } pDrvCtrl->memSize = size; FEI_FLAG_SET (FEI_OWN_MEM); pDrvCtrl->cacheFuncs = cacheDmaFuncs; break; default : /* the user provided an area */ if (pDrvCtrl->memSize == 0) { DRV_LOG (DRV_DEBUG_LOAD, ("fei82557EndLoad: 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 (FEI_FLAG_ISSET (FEI_INV_NCFD) && FEI_FLAG_ISSET (FEI_INV_NRFD)) { pDrvCtrl->nCFDs = pDrvCtrl->nRFDs = (FEI_SAFE_MEM (pDrvCtrl) / ((2 * CL_RFD_SIZE) + CFD_SIZE)); } else if (FEI_FLAG_ISSET (FEI_INV_NCFD))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -