⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcm1250macend.c

📁 操作系统vxworks平台下end设备的驱动程序,支持多种芯片,支持多种cpu
💻 C
📖 第 1 页 / 共 5 页
字号:
** RETURNS: An END object pointer or NULL on error.*/END_OBJ * bcm1250MacEndLoad    (    char *  initString            /* String to be parsed by the driver. */    )    {    STATUS      rtv;    DRV_CTRL *  pDrvCtrl;   /* driver control structure */    char        enetAddr[6];    DRV_LOG (DRV_DEBUG_LOAD, "Loading bcm1250MacEnd...\n", 1, 2, 3, 4, 5, 6);    /* Check for an allocated string. */    if (initString == (char *)NULL)        {        DRV_LOG (DRV_DEBUG_LOAD, "bcm1250MacEndLoad: NULL initStr\n",                 1, 2, 3, 4, 5, 6);        return ((END_OBJ *)NULL);        }    /* If a null string, then copy the device's name to the string. */    if (initString[0] == '\0')        {        bcopy ((char *)SB_DEV_NAME, initString, SB_DEV_NAME_LEN);        DRV_LOG (DRV_DEBUG_LOAD, "bcm1250MacEndLoad: initString[0]==NUL\n",                 1, 2, 3, 4, 5, 6);        return ((END_OBJ *)NULL);        }    /* Allocate the device structure */    pDrvCtrl = (DRV_CTRL *)calloc (sizeof (DRV_CTRL), 1);    if (pDrvCtrl == (DRV_CTRL *)NULL)        {        DRV_LOG (DRV_DEBUG_LOAD,                 "bcm1250MacEndLoad: alloc for pDrvCtrl failed.\n",                 1, 2, 3, 4, 5, 6);        return ((END_OBJ *)NULL);        }    /* Parse the init string, filling in the device structure */    if (bcm1250MacInitParse (pDrvCtrl, initString) == ERROR)        {        DRV_LOG (DRV_DEBUG_LOAD, "bcm1250MacEndLoad: init parse failed\n",                 1, 2, 3, 4, 5, 6);        goto errorExit;        }    /* Initialize register addresses. */    pDrvCtrl->regMacEnable = R_MAC_ENABLE;    pDrvCtrl->regMacCfg    = R_MAC_CFG;    pDrvCtrl->regFifoCfg   = R_MAC_THRSH_CFG;    pDrvCtrl->regFrameCfg  = R_MAC_FRAMECFG;    pDrvCtrl->regRxFilter  = R_MAC_ADFILTER_CFG;    pDrvCtrl->regIsr       = R_MAC_STATUS;    pDrvCtrl->regImr       = R_MAC_INT_MASK;    pDrvCtrl->regMdio      = R_MAC_MDIO;    /* Ask the BSP to provide the ethernet address. */    sysBcm1250MacEnetAddrGet (pDrvCtrl->unit, &enetAddr[0]);    DRV_LOG (DRV_DEBUG_LOAD,             "Loading bcm1250MacEnd: mac addr = %x:%x:%x:%x:%x:%x\n",             enetAddr[0], enetAddr[1], enetAddr[2], enetAddr[3], enetAddr[4],             enetAddr[5]);    /* initialize the END_OBJ. */    rtv = END_OBJ_INIT (&pDrvCtrl->endObj,                         (DEV_OBJ *)pDrvCtrl,                         SB_DEV_NAME,                        pDrvCtrl->unit,                         &bcm1250MacFuncTable,                         "BCM1250 END Driver.");    if (rtv == ERROR)        goto errorExit;    /* Reset the ethernet MAC. */    ETH_MAC_REG_WRITE (pDrvCtrl->regMacEnable, M_MAC_PORT_RESET);    ETH_MAC_REG_WRITE (pDrvCtrl->regMacEnable, 0);    /* Perform memory allocation/initialization for ethernet DMA receive structure. */    DRV_LOG (DRV_DEBUG_LOAD, "rxDMA ch#0 init\n", 1, 2, 3, 4, 5, 6);    rtv = bcm1250MacDmaInit (&pDrvCtrl->rxDma, pDrvCtrl->regDmaBase, 0);    if (rtv == ERROR)        goto errorExit;    /* Perform memory allocation/initialization for ethernet DMA transmit structure. */    DRV_LOG (DRV_DEBUG_LOAD, "txDMA ch#0 init\n", 1, 2, 3, 4, 5, 6);    rtv = bcm1250MacDmaInit (&pDrvCtrl->txDma, pDrvCtrl->regDmaBase, 1);    if (rtv == ERROR)        goto errorExit;    /*      * Perform memory allocation/initialization for the netBufLib-managed      * memory pool.     */     if (bcm1250MacMemInit (pDrvCtrl) == ERROR)        goto errorExit;    /* Allocate a cluster buffer for polled mode transmit. */    pTxPollBuf = NET_BUF_ALLOC ();    /* Find the address of the physical interface chip. */    bcm1250MacEthMiiFindPhy (pDrvCtrl);    /* Determine the speed and configuration of the physical interface. */    bcm1250MacEthMiiPoll (pDrvCtrl);    /* Initialize the MIB-II structure */    rtv = END_MIB_INIT (&pDrvCtrl->endObj,                         M2_ifType_ethernet_csmacd,                        (UINT8 *)&enetAddr[0],                         6,                         ETHERMTU,                        BCM1250_MAC_SPEED_DEF);    if (rtv == ERROR)        {        DRV_LOG (DRV_DEBUG_LOAD,                 "bcm1250MacEndLoad: MIB init failed\n",                 1, 2, 3, 4, 5, 6);        goto errorExit;        }    /* set the flags to indicate readiness */    END_OBJ_READY (&pDrvCtrl->endObj,                   IFF_UP | IFF_RUNNING | IFF_NOTRAILERS |                    IFF_BROADCAST | IFF_MULTICAST);    DRV_LOG (DRV_DEBUG_LOAD, "Done loading ...", 1, 2, 3, 4, 5, 6);    return (&pDrvCtrl->endObj);errorExit:    free ((char *)pDrvCtrl);    return ((END_OBJ *)NULL);    }/********************************************************************************* bcm1250MacInitParse - Parse the initialization string** Parse the input string.  This routine is called from bcm1250MacEndLoad()* which initializes some values in the driver control structure with the* values passed in the intialization string.** The initialization string format is:* "<unit>:<hwunit>:<vecnum>:<flags>:<numRds0>:<numTds0>"** .IP <unit>* Device unit number, 0 - 2.* .IP <hwunit>* Not used, but must be present to parse properly.* .IP <vecnum>* Interrupt vector number.* .IP <flags>* Device specific flags, for future use.* .IP <numRds0>* Number of receive DMA buffer descriptors for channel 0.* .IP <numTds0>* Number of transmit DMA buffer descriptors for channel 0.** RETURNS: OK, or ERROR if any arguments are invalid.*/LOCAL STATUS bcm1250MacInitParse    (    DRV_CTRL *  pDrvCtrl,   /* driver control structure */    char *      initString    )    {    char *          tok;    /* an initString token */    char *          holder = (char *)NULL;  /* points beyond tok */    ETH_MAC_DMA *   pRxDma0 = &pDrvCtrl->rxDma;    ETH_MAC_DMA *   pTxDma0 = &pDrvCtrl->txDma;    DRV_LOG (DRV_DEBUG_LOAD, "InitParse: Initstr=%s\n",             (int)initString, 2, 3, 4, 5, 6);    /* Process the device unit number. */    tok = strtok_r (initString, ":", &holder);    if (tok == (char *)NULL)        return ERROR;    pDrvCtrl->unit = atoi (tok);    /* Validate the device unit number, and set the interrupt source. */    switch (pDrvCtrl->unit)        {        case 0:            pDrvCtrl->intSource = K_INT_MAC_0;            break;        case 1:            pDrvCtrl->intSource = K_INT_MAC_1;            break;        case 2:            pDrvCtrl->intSource = K_INT_MAC_2;            break;        default:            return ERROR;        }    /* Discard the hwunit, which is not used. */    tok = strtok_r ((char *)NULL, ":", &holder);    if (tok == (char *)NULL)        return ERROR;    /* Set the base address for the ethernet registers for this device. */    pDrvCtrl->regMacBase = PHYS_TO_K1 (A_MAC_CHANNEL_BASE (pDrvCtrl->unit));    pDrvCtrl->regDmaBase = pDrvCtrl->regMacBase;    /* Process the interrupt vector number. */    tok = strtok_r ((char *)NULL, ":", &holder);    if (tok == (char *)NULL)        return ERROR;    pDrvCtrl->iVecNum = strtoul (tok, (char **)NULL, 10);    /* Process the Device specific flags. */    tok = strtok_r ((char *)NULL, ":", &holder);    if (tok == (char *)NULL)        return (ERROR);    pDrvCtrl->flags = strtoul (tok, (char **)NULL, 16);    /* Process the number of receive DMA buffer descriptors for channel 0. */    tok = strtok_r ((char *)NULL, ":", &holder);    if (tok == (char *)NULL)        return ERROR;    if (atoi (tok) < 0)        pRxDma0->maxDescr = NUM_RDS_DEF;    else        pRxDma0->maxDescr = atoi (tok);    /* Process the number of transmit DMA buffer descriptors for channel 0. */    tok = strtok_r ((char *)NULL, ":", &holder);    if (tok == (char *)NULL)        return ERROR;    if (atoi (tok) < 0)        pTxDma0->maxDescr = NUM_TDS_DEF;    else        pTxDma0->maxDescr = atoi (tok);    DRV_LOG (DRV_DEBUG_LOAD,             "EndLoad: flags=0x%x dmaBase=0x%x macBase=0x%x iVecNum=0x%x intSource=0x%x ",             pDrvCtrl->flags, pDrvCtrl->regDmaBase, pDrvCtrl->regMacBase,             pDrvCtrl->iVecNum, pDrvCtrl->intSource, 6);    DRV_LOG (DRV_DEBUG_LOAD,             "EndLoad: numRd0 %d numTd0 %d unit %d\n",             pRxDma0->maxDescr, pTxDma0->maxDescr, pDrvCtrl->unit, 4, 5, 6);    return OK;    }/********************************************************************************* bcm1250MacMemInit - initialize memory.** Allocates and initializes the mBlk/clBlk/cluster memory pool.** RETURNS: OK or ERROR.*/LOCAL STATUS bcm1250MacMemInit    (    DRV_CTRL *  pDrvCtrl    /* driver control structure */    )    {    STATUS          rtv;            /* function return value */    M_CL_CONFIG     mClBlkConfig;   /* mBlk/clBlk configuration table */    CL_DESC         clDesc;         /* cluster descriptor table */    DRV_LOG (DRV_DEBUG_LOAD, "sbe%d - bcm1250MacMemInit() start.\n",             pDrvCtrl->unit, 2, 3, 4, 5, 6);    /*     * Clear the mBlk/clBlk configuration table,      * and the cluster descriptor table.     */    bzero ((char *)&mClBlkConfig, sizeof (mClBlkConfig));    bzero ((char *)&clDesc, sizeof (clDesc));    /* Calculate the number of clusters. */    clDesc.clNum = pDrvCtrl->rxDma.maxDescr +                   pDrvCtrl->txDma.maxDescr +                   (RXDSCR_LOAN_NUM * 2) + 2;    /* Set the size of the clusters. */    clDesc.clSize = ROUND_UP ((MAX_FRAME_SIZE + CACHELINESIZE),                              CACHELINESIZE);    /* Calculate the memory size for the clusters. */    clDesc.memSize = (clDesc.clNum * (clDesc.clSize + sizeof (long))) +                     CACHELINESIZE;    /* Allocate memory for the clusters from cache safe memory. */    pDrvCtrl->bufBase = (char *)memalign (CACHELINESIZE, clDesc.memSize);    if (pDrvCtrl->bufBase == (char *)NULL)        {        DRV_LOG (DRV_DEBUG_LOAD,                 "sbe%d - pDrvCtrl->bufBase alloc failed for size 0x%8x\n",                 pDrvCtrl->unit, clDesc.memSize, 3, 4, 5, 6);        return (ERROR);        }    /* Set the base address of the cluster memory. */    clDesc.memArea = (char *)pDrvCtrl->bufBase;    /*      * Purposely misalign the base address of the cluster memory by      * (CACHELINESIZE - sizeof (long)), and adjust the size of the      * clusters, so that the guts of the buffers are cache aligned.     */    clDesc.memArea += (CACHELINESIZE - sizeof (long));    clDesc.clSize -= sizeof (long);    DRV_LOG (DRV_DEBUG_LOAD,             "sbe%d - InitMem NetBufLib Cluster memArea 0x%08x\n",             pDrvCtrl->unit, (UINT32)clDesc.memArea, 3, 4, 5, 6);    /* Set twice as many mBlk's as clusters. */    mClBlkConfig.mBlkNum = clDesc.clNum * 2;    /* Set the number of clusters. */    mClBlkConfig.clBlkNum = clDesc.clNum;    /* Calculate the memory size needed. */    mClBlkConfig.memSize = (mClBlkConfig.mBlkNum * (M_BLK_SZ + sizeof (long))) +                           (mClBlkConfig.clBlkNum * CL_BLK_SZ);    /* Allocated the required memory */    mClBlkConfig.memArea = (char *)memalign (sizeof (long),                                             mClBlkConfig.memSize);    if (mClBlkConfig.memArea == (char *)NULL)        {        DRV_LOG (DRV_DEBUG_LOAD,                 "sbe%d - mClBlkConfig.memArea alloc failed for size 0x%8x\n",                 pDrvCtrl->unit, mClBlkConfig.memSize, 3, 4, 5, 6);        return (ERROR);        }    pDrvCtrl->mClBlkBase = mClBlkConfig.memArea;    /* Allocate the network pool. */    pDrvCtrl->endObj.pNetPool = (NET_POOL_ID)malloc (sizeof (NET_POOL));    if (pDrvCtrl->endObj.pNetPool == (NET_POOL_ID)NULL)        {        DRV_LOG (DRV_DEBUG_LOAD,                 "sbe%d - pNetPool alloc failed for size 0x%8x\n",                 pDrvCtrl->unit, sizeof (NET_POOL), 3, 4, 5, 6);        return (ERROR);        }    /* Initialize the netBufLib-managed memory pool */    rtv = netPoolInit (pDrvCtrl->endObj.pNetPool, &mClBlkConfig, &clDesc, 1,                       (POOL_FUNC *)NULL);    if (rtv == ERROR)        {        DRV_LOG (DRV_DEBUG_LOAD, "netPoolInit() failed.\n",                1, 2, 3, 4, 5, 6);        return (ERROR);        }    /* Get the cluster pool ID for the clusters. */    pDrvCtrl->clPoolId = netClPoolIdGet (pDrvCtrl->endObj.pNetPool,                                         MAX_FRAME_SIZE, FALSE);    if (pDrvCtrl->clPoolId == (CL_POOL_ID)NULL)        {        DRV_LOG (DRV_DEBUG_LOAD, "netClPoolIdGet() returned NULL pool ID.\n",                1, 2, 3, 4, 5, 6);        return (ERROR);        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -