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

📄 txc_envoy_mac_real.c

📁 TranSwitch Envoy CE2 & Envoy CE4 设备驱动及编程指南
💻 C
📖 第 1 页 / 共 5 页
字号:
            }
            else
            {
                error = TXC_INVALID_FLOW_CTRL_MODE;
            }
            break;

        default: /* 0x30000 */
            error = TXC_INVALID_FLOW_CTRL_MODE;
            break;
    }
    return(error);
}




/*------------------------------------------------------------*

   FUNCTION:    ENVOY_SetMacEgressFlowCtrlReal

   DESCRIPTION: This function actually processess the TXC_ENVOY_MacEgressFlowCtrlSet

   INPUTS:  Same as TXC_ENVOY_MacEgressFlowCtrlSet

   RETURNS:  TXC_NO_ERR or an appropriate specific error code listed in appendix.

   REVISION HISTORY:

    Rev       Date          Author               Description
   -----    -------      ------------         -----------------
   0.5.0    6/03/04      F. Giannella         Initial release (beta)
 *--------------------------------------------------------------------------*/

TXC_U16BIT
ENVOY_SetMacEgressFlowCtrlReal
(
TXC_U16BIT handle,
TXC_U16BIT port,
TXC_IfMAC_EGRESS_FLOW_CTRL_MODE_STRUCT *macEgressFlowCtrlModeDataPtr
)
{   TXC_U16BIT error = TXC_NO_ERR;
    TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
    TXC_REG_ACCESS_32BIT_STRUCT regData[2];
    TXC_REG_32 *baseAddr;
    TXC_REG_32 *portAddr;
    TXC_U16BIT portIdx;
    TXC_U16BIT endPort;
    TXC_U16BIT startPort;
    TXC_U16BIT portInc;
    TXC_U32BIT tmpData;
    ENVOY_MAC_CONFIG_STRUCT * macCfgPtr;
    
    /* determine if one MAC port is being configured or all ports */
    GetMacPortRange(handle, port, &startPort, &endPort, &portInc); 

    /* determine the base address of the device */
    baseAddr = (TXC_REG_32 *) ENVOY_DbGetDeviceAddr (handle);

    batchData.regDataPtr = regData;
    batchData.writeVerifyFlag = TXC_FALSE;
    batchData.semId = ENVOY_DbGetSemId();

    memset(regData, 0, sizeof(regData)); /* init to all zero */

    batchData.regCount = 1; 

    /* configure Reg. 4080 CFPT and CFEP */
    tmpData = macEgressFlowCtrlModeDataPtr->egressFlowCtrlEnable;
    regData[0].data = tmpData << 5;
    regData[0].mask = 0x20; /* isolate bit 5 of register 4000 */

    /* loop thru all ports setting */
    for (portIdx = startPort; portIdx < endPort; )
    {
        portAddr = baseAddr + macCfgOffset[portIdx];
        macCfgPtr = (ENVOY_MAC_CONFIG_STRUCT *) portAddr;
        regData[0].addr = (TXC_REG_32 *)&(macCfgPtr->cfg1Reg);  /* reg 4000 */

        /* call the batch write to set the bit */
        error = TXC_BatchReg32BitWrite (&batchData);
        if (error != TXC_NO_ERR)
        {
            break;
        }
        portIdx = portIdx + portInc;
    }
    return error;
}




/*--------------------------------------------------------------------------*

   FUNCTION:    ENVOY_GetMacEgressFlowCtrlReal

   DESCRIPTION: This function actually processess the TXC_ENVOY_MacIngressFlowCtrlGet

   INPUTS:  Same as TXC_ENVOY_MacEgressFlowCtrlGet

   RETURNS:  TXC_NO_ERR or an appropriate specific error code listed in appendix.

   REVISION HISTORY:

    Rev       Date          Author               Description
   -----    -------      ------------         -----------------
   0.5.0    6/03/04      F. Giannella         Initial release (beta)
 *--------------------------------------------------------------------------*/

TXC_U16BIT 
ENVOY_GetMacEgressFlowCtrlReal
(
TXC_U16BIT handle,
TXC_U16BIT port,
TXC_IfMAC_EGRESS_FLOW_CTRL_MODE_STRUCT *macEgressFlowCtrlModeDataPtr
)
{
    ENVOY_MAC_CONFIG_STRUCT * macCfgPtr;
    TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
    TXC_REG_ACCESS_32BIT_STRUCT       regData[2];
    TXC_REG_32 *baseAddr;
    TXC_REG_32 *portAddr;
    TXC_U32BIT tmpData;
    TXC_U16BIT portIdx;
    TXC_U16BIT error = TXC_NO_ERR;
    
    /* set up batch request structure header */
    batchData.regDataPtr = regData;
    batchData.writeVerifyFlag = TXC_FALSE;
    batchData.semId = TXC_FALSE;
    batchData.regCount = 1;
    
    memset(regData, 0, sizeof(regData)); /* init to all zero */

    portIdx = port;

    /* determine the base address of the device */
    baseAddr = (TXC_REG_32 *) ENVOY_DbGetDeviceAddr (handle);

    portAddr = baseAddr + macCfgOffset[portIdx];
    macCfgPtr = (ENVOY_MAC_CONFIG_STRUCT *) portAddr;
    regData[0].addr = (TXC_REG_32 *)&(macCfgPtr->cfg1Reg);  /* reg 4000 */
    regData[0].mask = 0x20;

    error = TXC_BatchReg32BitRead (&batchData); /* read all registers */
    if (error != TXC_NO_ERR)
        return(error);

    /* format the return structure */
    memset((char *)macEgressFlowCtrlModeDataPtr, 0, sizeof(TXC_IfMAC_EGRESS_FLOW_CTRL_MODE_STRUCT));

    /* Reg 4000 */
    tmpData= regData[0].data;
    macEgressFlowCtrlModeDataPtr->egressFlowCtrlEnable = (tmpData >> 5);

    return(error);
}



/*--------------------------------------------------------------------------*

   FUNCTION:  ENVOY_RtrvMacStatusReal

   DESCRIPTION: This function actually processess the ENVOY_RtrvMacStatus

   INPUTS:  Same as ENVOY_RtrvMacStatus

   RETURNS:  TXC_NO_ERR or an appropriate specific error code listed in appendix.

   CAVEATS:  All bit-mapped status indicators affected by this driver are latched
   and cleared on read. If the condition persists, the status is re-latched on the
   next device clock.

   REVISION HISTORY:

    Rev       Date          Author               Description
   -----    -------      ------------         -----------------
   0.5.0    6/03/04      F. Giannella         Initial release (beta)
 *--------------------------------------------------------------------------*/

TXC_U16BIT
ENVOY_RtrvMacStatusReal(
TXC_U16BIT handle,
TXC_U16BIT port,
TXC_U32BIT *macStatusDataPtr)
{
    TXC_U16BIT error;
    TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
    TXC_REG_ACCESS_32BIT_STRUCT regData;
    TXC_REG_32 * baseAddr;
    ENVOY_MAC_CONFIG_STRUCT * macCfgPtr;
    
    /* first fill the batch request info. No semaphore needed for read only regs */
    batchData.regDataPtr = &regData;
    batchData.regCount = 1;
    batchData.writeVerifyFlag = TXC_WRITE_VERIFY_FLAG;
    batchData.semId = TXC_FALSE;
    memset (&regData, 0, sizeof(TXC_REG_ACCESS_32BIT_STRUCT));

    /* determine the base address of the device */
    baseAddr = (TXC_REG_32 *) ENVOY_DbGetDeviceAddr (handle);
    
    /* Determine register address based on device base, port and register */
    baseAddr += macCfgOffset[port];
    macCfgPtr = (ENVOY_MAC_CONFIG_STRUCT *) baseAddr;
    regData.addr = (TXC_REG_32 *) &(macCfgPtr->ifaceStatusReg);
    regData.mask = ENVOY_MAC_STATUS_MASK;
    error = TXC_BatchReg32BitRead (&batchData);
    
    /* If no error, return the data read */
    if (error == TXC_NO_ERR)
    {
        *macStatusDataPtr = (regData.data >> 4);  /* right justification */
    }
    return error;
}




/*--------------------------------------------------------------------------*

   FUNCTION:  ENVOY_SetMacLoopbackReal

   DESCRIPTION: This function actually processess the ENVOY_SetMacDiag

   INPUTS:  Same as TXC_IfMAC_MacLoopbackSet

   RETURNS:  TXC_NO_ERR or an appropriate specific error code listed in appendix.

   CAVEATS:  None.
 
   REVISION HISTORY:

    Rev       Date          Author               Description
   -----    -------      ------------         -----------------
   0.5.0    6/03/04      F. Giannella         Initial release (beta)
 *--------------------------------------------------------------------------*/

TXC_U16BIT ENVOY_SetMacLoopbackReal (TXC_U16BIT handle, TXC_U16BIT port, 
                          TXC_IfMAC_LOOPBACK_STRUCT *macLoopbackDataPtr)
{

    TXC_U16BIT error = TXC_NO_ERR;
    TXC_BATCH_REG_ACCESS_32BIT_STRUCT macBatchData;
    TXC_REG_ACCESS_32BIT_STRUCT macRegData[4];
    TXC_REG_32 * macBaseAddr;
    TXC_REG_32 * macPortAddr;
    TXC_U16BIT portIdx;
    TXC_U16BIT endPort;
    TXC_U16BIT startPort;
    TXC_U16BIT portInc;
    ENVOY_MAC_CONFIG_STRUCT * macCfgPtr;
    ENVOY_IFIFO_LOOPBACK_STRUCT * iFifoCfgPtr;


    /* First, fill the batch platform header. This function requires 1
       register to be written */
    macBatchData.regDataPtr = &macRegData[0];
    macBatchData.writeVerifyFlag = TXC_WRITE_VERIFY_FLAG;
    macBatchData.semId = ENVOY_DbGetSemId();
    memset (& macRegData[0], 0, (3* sizeof(TXC_REG_ACCESS_32BIT_STRUCT)));


    /* reg[0] = 4000, bit 8 */
    /* reg[1] = 2784, bit 0 */
    /* reg[2] = 2788, bit 0 (only if egress-to-ingress loopback is enabled) */

    /* Setup the mask to set the loopback mode */
    macRegData[0].mask = 0x100;  /* reg 4000, bit 8 */
    macRegData[1].mask = 0x1;
    macRegData[2].mask = 0x1;

    /* Determine the bit data based on the loopback type requested */
    switch ( macLoopbackDataPtr->macLpbkMode)
    {
        case TXC_IfMAC_LPBK_NONE:
                /* Turn off all loopbacks */
                macBatchData.regCount = 2;
                macRegData[0].data = 0;
                macRegData[1].data = 0;
                break;

        case TXC_IfMAC_EGR_TO_INGR_LPBK:               
                macBatchData.regCount = 2;
                macRegData[0].data = macRegData[0].mask;
                macRegData[1].data = 0;
                break;

        case TXC_IfMAC_INGR_TO_EGR_TRANSPARENT_LPBK:               
                macBatchData.regCount = 3;
                macRegData[0].data = 0;
                macRegData[1].data = macRegData[1].mask;
                macRegData[2].data = 0;
                break;

        case TXC_IfMAC_INGR_TO_EGR_NON_TRANSPARENT_LPBK:
                macBatchData.regCount = 3;
                macRegData[0].data = 0;
                macRegData[1].data = macRegData[1].mask;
                macRegData[2].data = macRegData[2].mask;
                break;

        default:
                error = TXC_INVALID_PARM_ERR;
                break;
    }


    /* determine the base address of the device */
    macBaseAddr = (TXC_REG_32 *) ENVOY_DbGetDeviceAddr (handle);

    
    /* determine if one MAC port or all ports */
    GetMacPortRange(handle, port, &startPort, &endPort, &portInc);
                
    /* loop thru all ports writing the loopback bit */
    for (portIdx = startPort; portIdx < endPort;)
    {

        macPortAddr = macBaseAddr + macCfgOffset[portIdx];
        macCfgPtr = (ENVOY_MAC_CONFIG_STRUCT *) macPortAddr;

        iFifoCfgPtr = (ENVOY_IFIFO_LOOPBACK_STRUCT *) (macBaseAddr + ENVOY_IFIFO_LOOPBACK_OFFSET); 

        /* Setup the addresses to write the MAC interface config */
        macRegData[0].addr = (TXC_REG_32 *) &(macCfgPtr->cfg1Reg);
        macRegData[1].addr = (TXC_REG_32 *) &(iFifoCfgPtr->iFifoLbkEnableReg);
        macRegData[2].addr = (TXC_REG_32 *) &(iFifoCfgPtr->iFifoNonTransparentLbkEnableReg);

        error = TXC_BatchReg32BitWrite (&macBatchData); 
        if (error != TXC_NO_ERR)
            break;

        portIdx = portIdx + portInc;

⌨️ 快捷键说明

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