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

📄 txc_envoy_fifo_real.c

📁 TranSwitch Envoy CE2 & Envoy CE4 设备驱动及编程指南
💻 C
📖 第 1 页 / 共 3 页
字号:
/*--------------------------------------------------------------------------

  *******                           ****
     *     *****     **    *    *  *       *    *   *  *****   ****   *    *
     *     *    *   *  *   **   *  *       *    *   *    *    *    *  *    *
     *     *    *  *    *  * *  *   ****   *    *   *    *    *       ******
     *     *****   ******  *  * *       *  * ** *   *    *    *       *    *
     *     *   *   *    *  *   **  *    *  **  **   *    *    *    *  *    *
     *     *    *  *    *  *    *   ****   *    *   *    *     ****   *    *

                        Proprietary and Confidential 

    This program is made available only to customers and prospective customers 
of TranSwitch Corporation under license and may be used only with TranSwitch 
semi-conductor products.

                      Copyright(c) 2004 TranSwitch Inc.

 --------------------------------------------------------------------------

             *******  **      **  **        **   ********   **      **
             *******  ***     **  **        **  **********  **      **
             **       ** *    **  **        **  **      **   **    **
             *****    **  *   **   **      **   **      **     *  *
             *****    **   *  **    **    **    **      **      **
             **       **    * **     **  **     **      **      **
             *******  **     ***      ****      **********      **
             *******  **      **       **        ********       **

 --------------------------------------------------------------------------
                           TranSwitch Envoy-CE2/CE4
                                Device Driver
 --------------------------------------------------------------------------

   Workfile:  txc_envoy_pkt_ctrl_real.c

   Description:  The ethernet MAC port function allows the user to configure 
   and retrieve status of each MAC.

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


/****************************************************************************
 **                             Include Files                              **
 ****************************************************************************/

#include "txc_envoy_api.h"

/* do nothing if this driver is in virtual mode */
#ifndef TXC_ENVOY_VIRTUAL_DEVICE_MODE

#include "txc_envoy_fifo_support.h"
#include "txc_envoy_database.h"
#include "txc_hw_platform.h"
#include "txc_envoy_mem_map.h"
#include <string.h>

/****************************************************************************
 **                            Static Functions                            **
 ****************************************************************************/


/****************************************************************************
 **                        Static/Global Variables                         **
 ****************************************************************************/
static void GetFifoPortRange(TXC_U16BIT handle, TXC_U16BIT port, 
                    TXC_U16BIT * start, TXC_U16BIT * end, TXC_U16BIT * inc);
static void GetFifoPortBlockRange(TXC_U16BIT handle, TXC_U16BIT portBlockID, 
                    TXC_U16BIT * start, TXC_U16BIT * end, TXC_U16BIT * inc);


/*--------------------------------------------------------------------------*
   FUNCTION:  GetFifoPortRange

   DESCRIPTION: This local function determines the range of ports to process
                based on device type. For Envoy-CE2, only ports 0 and 8 can 
                be programmed for GMII. For Envoy-CE4 only ports 0, 8, 16 and 
                24 can be programmed for GMII.  FG - to do : tighten the range.

   INPUTS:  handle, port

   RETURNS:  start port, end port and increment.

   CAVEATS:  None.

   REVISION HISTORY:

    Rev       Date          Author               Description
   -----    -------      ------------         -----------------
   0.5.0    6/03/04      F. Giannella         Initial release (beta)
 *--------------------------------------------------------------------------*/
static void GetFifoPortRange(TXC_U16BIT handle, TXC_U16BIT port,
            TXC_U16BIT * start, TXC_U16BIT * end, TXC_U16BIT * inc)
{
    TXC_U16BIT deviceType;

    /* First, get the device type. */
    deviceType = ENVOY_DbGetDeviceType (handle);
    if ((deviceType != ENVOY_CE2) && (deviceType != ENVOY_CE4) )
       return;

    /* determine if one MAC port is being accessed */
    if (port == ENVOY_MAC_ALL_PORTS)
    {
        if (deviceType == ENVOY_CE2)
        {
            *start = 0;
            *end = ENVOY_CE2_MAX_MAC_PORTS;
            *inc = 1;
        }
        else  /* that is, deviceType == ENVOY_CE4 */ 
        {
            *start = 0;
            *end = ENVOY_CE4_MAX_MAC_PORTS;
            *inc = 1;
        }
    }
    else
    {
        *start = port;
        *end = port + 1;
        *inc = 1;
    }
}

/*--------------------------------------------------------------------------*
   FUNCTION:  GetFifoPortRange

   DESCRIPTION: This local function determines the range of ports to process
                based on device type. For Envoy-CE2, only ports 0 and 8 can 
                be programmed for GMII. For Envoy-CE4 only ports 0, 8, 16 and 
                24 can be programmed for GMII.  FG - to do : tighten the range.

   INPUTS:  handle, port

   RETURNS:  start port, end port and increment.

   CAVEATS:  None.

   REVISION HISTORY:

    Rev       Date          Author               Description
   -----    -------      ------------         -----------------
   0.5.0    6/03/04      F. Giannella         Initial release (beta)
 *--------------------------------------------------------------------------*/
static void GetFifoPortBlockRange(TXC_U16BIT handle, TXC_U16BIT portBlockID,
            TXC_U16BIT * start, TXC_U16BIT * end, TXC_U16BIT * inc)
{
    TXC_U16BIT deviceType;

    /* First, get the device type. */
    deviceType = ENVOY_DbGetDeviceType (handle);
    if ((deviceType != ENVOY_CE2) && (deviceType != ENVOY_CE4) )
       return;

    /* determine if one MAC port is being accessed */
    if (portBlockID == ENVOY_MAC_ALL_PORTS)
    {
        if (deviceType == ENVOY_CE2)
        {
            *start = 0;
            *end = ENVOY_CE2_MAX_MAC_PORT_BLOCKS;
            *inc = 1;
        }
        else  /* that is, deviceType == ENVOY_CE4 */ 
        {
            *start = 0;
            *end = ENVOY_CE4_MAX_MAC_PORT_BLOCKS;
            *inc = 1;
        }
    }
    else
    {
        *start = portBlockID;
        *end = portBlockID + 1;
        *inc = 1;
    }
}



/****************************************************************************
 **                                  Code                                  **
 ****************************************************************************/



/* ======================================================================== */

/*                              FIFO FUNCTIONS                              */

/************************************************************************************/
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/************************************************************************************
                                                                             
   FUNCTION:  ENVOY_SetIngressFlowCtrlWmarkReal                                           
                                                                             
   DESCRIPTION: This function actually processess the TXC_ENVOY_IngressFlowCtrlWmarkSet
                API function.
                                                                             
   INPUTS:  Same as TXC_ENVOY_IngressFlowCtrlWmarkSet                            
                                                                             
   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_SetIngressFlowCtrlWmarkReal (TXC_U16BIT handle, TXC_U16BIT portBlockID,
                      ENVOY_IFIFO_FLOW_CTRL_WMARK_STRUCT *ingressFlowCtrlWmarkDataPtr)
{
    TXC_U16BIT error = TXC_NO_ERR;
    TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
    TXC_REG_ACCESS_32BIT_STRUCT regData[3];
    TXC_REG_32 *baseAddr;
    TXC_REG_32 *cmacIdAddr;
    TXC_U16BIT portIdx;
    TXC_U16BIT endPort;
    TXC_U16BIT startPort;
    TXC_U16BIT portInc;
    ENVOY_IFIFO_CMAC_FC_THRSHLD_STRUCT *ififoFcThrshldRegPtr;
    ENVOY_IFIFO_CMAC_PF_TIMER_STRUCT *ififoPfTimerRegPtr;

    /* First, fill the batch platform header. This function requires 3
       registers to be written */
    /* This function requires 5 registers to be written */
    memset (&regData[0], 0, (3 * sizeof(TXC_REG_ACCESS_32BIT_STRUCT) ) );
    batchData.regDataPtr = &regData[0];
    batchData.writeVerifyFlag = TXC_WRITE_VERIFY_FLAG;
    batchData.semId = ENVOY_DbGetSemId();
    batchData.regCount = 3;


    /* determine if one MAC port is being configured or all ports */
    GetFifoPortBlockRange(handle, portBlockID, &startPort, &endPort, &portInc);
        
    /* determine the base address of the device */
    baseAddr = (TXC_REG_32 *) ENVOY_DbGetDeviceAddr (handle);

    /* Setup the data and masks for Mac Address */
    regData[0].data = ingressFlowCtrlWmarkDataPtr->ingressFlowControlHiWmark;
    regData[1].data = ingressFlowCtrlWmarkDataPtr->ingressFlowControlLoWmark;
    regData[2].data = ingressFlowCtrlWmarkDataPtr->ingressPauseFrameRegenerationTimer;

    regData[0].mask = 0x1FFF;
    regData[1].mask = 0x1FFF;
    regData[2].mask = 0xFFFF;


    ififoPfTimerRegPtr = (ENVOY_IFIFO_CMAC_PF_TIMER_STRUCT *) (baseAddr + ENVOY_IFIFO_PAUSE_TIMER_OFFSET);

    /* loop thru all ports setting up the MAC interface parameters */
    for (portIdx = startPort; portIdx < endPort; )
    {
        /* Setup the addresses to write the MAC interface config */
        cmacIdAddr = baseAddr + iFifoCmacFcOffset[portIdx];
        ififoFcThrshldRegPtr = (ENVOY_IFIFO_CMAC_FC_THRSHLD_STRUCT *) cmacIdAddr;
        regData[0].addr = (TXC_REG_32 *) &(ififoFcThrshldRegPtr->iFifoCmacFcHiThrshldReg);
        regData[1].addr = (TXC_REG_32 *) &(ififoFcThrshldRegPtr->iFifoCmacFcLoThrshldReg);

        regData[2].addr = (TXC_REG_32 *) &(ififoPfTimerRegPtr->iFifoCmacPfTimerReg[portIdx]);

        error = TXC_BatchReg32BitWrite (&batchData); 
        if (error != TXC_NO_ERR)
            return(error);

        portIdx = portIdx + portInc;
    }
    return error;
}


/************************************************************************************/
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/************************************************************************************

   FUNCTION:  ENVOY_GetIngressFlowCtrlWmarkReal

   DESCRIPTION: This function actually processess the TXC_ENVOY_IngressFlowCtrlWmarkGet
                API function.

   INPUTS:  Same as TXC_ENVOY_IngressFlowCtrlWmarkGet

   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_GetIngressFlowCtrlWmarkReal (TXC_U16BIT handle, TXC_U16BIT portBlockID,
                      ENVOY_IFIFO_FLOW_CTRL_WMARK_STRUCT *ingressFlowCtrlWmarkDataPtr)
{
    TXC_U16BIT error;
    TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
    TXC_REG_ACCESS_32BIT_STRUCT regData[3];
    TXC_REG_32 *baseAddr;
    ENVOY_IFIFO_CMAC_FC_THRSHLD_STRUCT *ififoFcThrshldRegPtr;
    ENVOY_IFIFO_CMAC_PF_TIMER_STRUCT *ififoPfTimerRegPtr;

    /* First, fill the batch platform header. This function requires 5
       registers to be read */
    memset (&regData[0], 0, (3 * sizeof(TXC_REG_ACCESS_32BIT_STRUCT) ) );
    batchData.regDataPtr = &regData[0];
    batchData.writeVerifyFlag = TXC_WRITE_VERIFY_FLAG;
    batchData.semId = ENVOY_DbGetSemId();
    batchData.regCount = 3;

    /* determine the base address of the device */
    baseAddr = (TXC_REG_32 *) ENVOY_DbGetDeviceAddr (handle);
    ififoFcThrshldRegPtr = (ENVOY_IFIFO_CMAC_FC_THRSHLD_STRUCT *) (baseAddr + iFifoCmacFcOffset[portBlockID]);

    /* Setup the addresses and masks to read */
    regData[0].addr = (TXC_REG_32 *) &(ififoFcThrshldRegPtr->iFifoCmacFcHiThrshldReg);
    regData[1].addr = (TXC_REG_32 *) &(ififoFcThrshldRegPtr->iFifoCmacFcLoThrshldReg);

    ififoPfTimerRegPtr = (ENVOY_IFIFO_CMAC_PF_TIMER_STRUCT *) (baseAddr + ENVOY_IFIFO_PAUSE_TIMER_OFFSET);
    regData[2].addr = (TXC_REG_32 *) &(ififoPfTimerRegPtr->iFifoCmacPfTimerReg[portBlockID]);

    /* Masks */
    regData[0].mask = 0x1FFF;
    regData[1].mask = 0x1FFF;
    regData[2].mask = 0xFFFF;

    /* Read the registers and return the data */    
    error = TXC_BatchReg32BitRead (&batchData);
    if (error == TXC_NO_ERR)
    {
        /* Copy the MAC Address */
        ingressFlowCtrlWmarkDataPtr->ingressFlowControlHiWmark = regData[0].data;
        ingressFlowCtrlWmarkDataPtr->ingressFlowControlLoWmark = regData[1].data;
        ingressFlowCtrlWmarkDataPtr->ingressPauseFrameRegenerationTimer = regData[2].data;
    }
    return error;
}


/************************************************************************************/
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/************************************************************************************
                                                                             
   FUNCTION:  ENVOY_SetIngressFifoTransferModeReal                                           
                                                                             
   DESCRIPTION: This function actually processess the TXC_ENVOY_IfifoTransferModeSet
                API function.
                                                                             
   INPUTS:  Same as TXC_ENVOY_IfifoTransferModeSet                            
                                                                             
   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_SetIngressFifoTransferModeReal (TXC_U16BIT handle, 
           ENVOY_IFIFO_TRANSFER_MODE_STRUCT *ingressFifoTransferModeDataPtr)
{
    TXC_U16BIT error = TXC_NO_ERR;
    TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
    TXC_REG_ACCESS_32BIT_STRUCT regData[1];
    TXC_REG_32 *baseAddr;
    ENVOY_IFIFO_MODE_STRUCT *ififoModeRegPtr;

⌨️ 快捷键说明

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