📄 txc_envoy_mac_real.c
字号:
/*--------------------------------------------------------------------------
******* ****
* ***** ** * * * * * * ***** **** * *
* * * * * ** * * * * * * * * * *
* * * * * * * * **** * * * * * ******
* ***** ****** * * * * * ** * * * * * *
* * * * * * ** * * ** ** * * * * * *
* * * * * * * **** * * * * **** * *
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_mac_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_mac_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 GetMacPortRange(TXC_U16BIT handle, TXC_U16BIT port,
TXC_U16BIT * start, TXC_U16BIT * end, TXC_U16BIT * inc);
/****************************************************************************
** Code **
****************************************************************************/
/* ======================================================================== */
/* MAC FUNCTIONS */
/*--------------------------------------------------------------------------*
FUNCTION: ENVOY_MacResetReal
DESCRIPTION: This function actually processess the ENVOY_MacReset
INPUTS: Same as ENVOY_MacReset
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_MacResetReal(TXC_U16BIT handle, TXC_U16BIT port,
TXC_IfMAC_RESET_STRUCT *macResetPtr )
{
ENVOY_MAC_CONFIG_STRUCT *macCfgPtr;
ENVOY_HOST_RESET_STRUCT *hostIfacePtr;
TXC_U16BIT error = TXC_NO_ERR;
TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
TXC_REG_ACCESS_32BIT_STRUCT regData;
TXC_REG_32 *baseAddr, tmpdata;
TXC_REG_32 *portAddr;
TXC_REG_32 *hostAddr;
TXC_U16BIT portIdx;
TXC_U16BIT endPort;
TXC_U16BIT startPort;
TXC_U16BIT portInc;
/* Set the mask and data for default MAC SOFT RESET */
regData.mask = ENVOY_MAC_FULL_RESET_CMD;
tmpdata = ENVOY_MAC_FULL_RESET_CMD;
/* determine if one MAC port is being reset 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 = ®Data;
batchData.writeVerifyFlag = TXC_FALSE;
/* No semaphore needed since it is atomic write */
batchData.semId = TXC_FALSE;
batchData.regCount = 1;
/* loop thru all ports setting, then clearing the appropriate reset bit */
for (portIdx = startPort; portIdx < endPort; )
{
portAddr = baseAddr + macCfgOffset[portIdx];
macCfgPtr = (ENVOY_MAC_CONFIG_STRUCT *) portAddr;
hostAddr = baseAddr + ENVOY_HOST_RESET_OFFSET;
/* mgmtPortPtr = (ENVOY_MGMT_PORT_STRUCT *) mgmtAddr; */
hostIfacePtr = (ENVOY_HOST_RESET_STRUCT *) hostAddr;
/*if (macResetPtr->resetMode == ENVOY_MAC_FULL_RESET) */
if (macResetPtr->resetMode == TXC_IfMAC_SOFT_RESET)
{
regData.addr = (TXC_REG_32 *) &(macCfgPtr->cfg1Reg); /* perform a SOFT RESET in the MAC */
}
if (macResetPtr->resetMode == TXC_IfMAC_HARD_RESET)
{
regData.addr = (TXC_REG_32 *) &(hostIfacePtr->resetEthernetPortReg); /* reset miimgmt*/
regData.mask = 1 << portIdx;
tmpdata = regData.mask;
}
regData.data = tmpdata; /* command */
/* call the batch write to set the bit */
error = TXC_BatchReg32BitWrite (&batchData);
if (error != TXC_NO_ERR)
{
break;
}
/* call the batch write to clear the bit */
regData.data = 0;
error = TXC_BatchReg32BitWrite (&batchData);
if (error != TXC_NO_ERR)
{
break;
}
portIdx = portIdx + portInc;
}
return error;
}
/*--------------------------------------------------------------------------*
FUNCTION: ENVOY_SetMacIfaceReal
DESCRIPTION: This function actually processess the ENVOY_SetMacIface
INPUTS: Same as ENVOY_SetMacIface
RETURNS: TXC_NO_ERR or an appropriate specific error code listed in
appendix.
CAVEATS: The hardware default on the interface comes up in GPSI mode,
which is not recommended for use.
REVISION HISTORY:
Rev Date Author Description
----- ------- ------------ -----------------
0.5.0 6/03/04 F. Giannella Initial release (beta)
*--------------------------------------------------------------------------*/
TXC_U16BIT ENVOY_SetMacIfaceReal(TXC_U16BIT handle, TXC_U16BIT port,
TXC_IfMAC_CONFIG_STRUCT *macIfaceDataPtr)
{
TXC_U16BIT error = TXC_NO_ERR;
TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
TXC_REG_ACCESS_32BIT_STRUCT regData[8];
TXC_REG_32 *baseAddr;
TXC_REG_32 *portAddr;
TXC_U16BIT portIdx;
TXC_U16BIT endPort;
TXC_U16BIT startPort;
TXC_U16BIT portInc;
ENVOY_MAC_CONFIG_STRUCT *macCfgPtr;
/* First, fill the batch platform header. This function requires 4
registers to be written */
/* This function requires 5 registers to be written */
batchData.regDataPtr = ®Data[0];
batchData.writeVerifyFlag = TXC_WRITE_VERIFY_FLAG;
batchData.semId = ENVOY_DbGetSemId();
batchData.regCount = 5;
memset ( (char *)regData, 0, sizeof(regData) );
/* 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);
/* Setup the data and masks for Mac Address */
regData[0].data = ((macIfaceDataPtr->stationAddr[0] << 8) | (macIfaceDataPtr->stationAddr[1])) << 16;
regData[0].data |= ((macIfaceDataPtr->stationAddr[2] << 8) | (macIfaceDataPtr->stationAddr[3]));
regData[1].data = ((macIfaceDataPtr->stationAddr[4] << 8) | (macIfaceDataPtr->stationAddr[5])) << 16;
regData[0].mask = 0xFFFFFFFF;
regData[1].mask = 0xFFFF0000;
regData[2].data = ((TXC_U16BIT)(macIfaceDataPtr->preambleLen) & 0xF) << 12;
regData[2].data |=(TXC_U16BIT)(macIfaceDataPtr->ingressFrameLenCheckEnable) << 4;
regData[2].data |=(TXC_U16BIT)(macIfaceDataPtr->hugeFrameEnable) << 5;
regData[2].data |=(TXC_U16BIT)(macIfaceDataPtr->fullDuplexEnable);
regData[2].data |= ((TXC_U16BIT)(macIfaceDataPtr->egressPadAndCrcAppendMode) & 0x3) << 1;
regData[2].mask = 0x0000F037;
regData[3].data = (TXC_U16BIT)(macIfaceDataPtr->b2bIPG) & 0x3F;
regData[3].data |= ((TXC_U16BIT)(macIfaceDataPtr->minIFG) & 0xFF) << 8;
regData[3].mask = 0x0000FF3F;
regData[4].data = (TXC_U16BIT)(macIfaceDataPtr->maxFrameLen) & 0xFFFF;
regData[4].mask = 0x0000FFFF;
/* loop thru all ports setting up the MAC interface parameters */
for (portIdx = startPort; portIdx < endPort; )
{
portAddr = baseAddr + macCfgOffset[portIdx];
macCfgPtr = (ENVOY_MAC_CONFIG_STRUCT *) portAddr;
/* Setup the addresses to write the MAC interface config */
regData[0].addr = (TXC_REG_32 *) &(macCfgPtr->stationAddr1Reg);
regData[1].addr = (TXC_REG_32 *) &(macCfgPtr->stationAddr2Reg);
regData[2].addr = (TXC_REG_32 *) &(macCfgPtr->cfg2Reg);
regData[3].addr = (TXC_REG_32 *) &(macCfgPtr->ipgIfgReg);
regData[4].addr = (TXC_REG_32 *) &(macCfgPtr->maxFrmLenReg);
error = TXC_BatchReg32BitWrite (&batchData);
if (error != TXC_NO_ERR)
return(error);
portIdx = portIdx + portInc;
}
return error;
}
/*--------------------------------------------------------------------------*
FUNCTION: ENVOY_GetMacIfaceReal
DESCRIPTION: This function actually processess the ENVOY_MacIfaceGet
INPUTS: Same as ENVOY_MacIfaceGet
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_GetMacIfaceReal(TXC_U16BIT handle, TXC_U16BIT port,
TXC_IfMAC_CONFIG_STRUCT *macIfaceDataPtr)
{
TXC_U16BIT error;
TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
TXC_REG_ACCESS_32BIT_STRUCT regData[6];
TXC_REG_32 *baseAddr;
ENVOY_MAC_CONFIG_STRUCT *macCfgPtr;
/* First, fill the batch platform header. This function requires 5
registers to be read */
memset (®Data[0], 0, (4 * sizeof(TXC_REG_ACCESS_32BIT_STRUCT) ) );
batchData.regDataPtr = ®Data[0];
batchData.writeVerifyFlag = TXC_WRITE_VERIFY_FLAG;
batchData.semId = ENVOY_DbGetSemId();
batchData.regCount = 5;
/* determine the base address of the device */
baseAddr = (TXC_REG_32 *) ENVOY_DbGetDeviceAddr (handle);
macCfgPtr = (ENVOY_MAC_CONFIG_STRUCT *) (baseAddr+macCfgOffset[port] );
/* Setup the addresses and masks to read for MAC interface */
regData[0].addr = (TXC_REG_32 *) &(macCfgPtr->stationAddr1Reg);
regData[1].addr = (TXC_REG_32 *) &(macCfgPtr->stationAddr2Reg);
regData[2].addr = (TXC_REG_32 *) &(macCfgPtr->cfg2Reg);
regData[3].addr = (TXC_REG_32 *) &(macCfgPtr->ipgIfgReg);
regData[4].addr = (TXC_REG_32 *) &(macCfgPtr->maxFrmLenReg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -