📄 txc_envoy_drv_mgmt_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_lmgmt_real.c
Description: The layer management functions are function that support
the driver but do not affect the device. The layer management will not
affect traffic (except for device reset).
--------------------------------------------------------------------------
Revision History
--------------------------------------------------------------------------
Rev Date Author Description
----- ------- ------------ -----------------
0.5.0 6/03/04 F. Giannella Initial release (beta)
*--------------------------------------------------------------------------*/
/****************************************************************************
** Include Files **
****************************************************************************/
#include "txc_envoy_api.h"
/* none of this runs if virtual */
#ifndef TXC_ENVOY_VIRTUAL_DEVICE_MODE
#include "txc_envoy_drv_mgmt_real.h"
#include "txc_envoy_mac_support.h"
#include "txc_envoy_database.h"
#include "txc_hw_platform.h"
#include "txc_envoy_mem_map.h"
#include "txc_os_sem.h"
#include <string.h>
/****************************************************************************
** Static Functions **
****************************************************************************/
static TXC_U16BIT ENVOY_DeviceHardResetReal (TXC_U16BIT handle);
/* static TXC_U16BIT ENVOY_DeviceInitReal (TXC_U16BIT handle); */
/****************************************************************************
** Static/Global Variables **
****************************************************************************/
/****************************************************************************
** Data Structures **
****************************************************************************/
/****************************************************************************
** Code **
****************************************************************************/
/*--------------------------------------------------------------------------*
FUNCTION: ENVOY_DeviceResetReal
DESCRIPTION: This function actually processess the TXC_ENVOY_DeviceReset
INPUTS: same as TXC_ENVOY_DeviceReset
RETURNS: TXC_NO_ERR or an appropriate specific error code
CAVEATS: None.
REVISION HISTORY:
Rev Date Author Description
----- ------- ------------ -----------------
0.5.0 6/03/04 F. Giannella Initial release (beta)
*--------------------------------------------------------------------------*/
TXC_U16BIT ENVOY_DeviceResetReal (TXC_U16BIT handle, ENVOY_DEV_RESET_STRUCT * deviceResetTypePtr)
{
TXC_U16BIT error;
/* switch on the reset type */
error = TXC_NO_ERR;
switch (deviceResetTypePtr->resetType)
{
case ENVOY_DEV_RESET_WITHOUT_INIT:
error = ENVOY_DeviceHardResetReal(handle);
break;
case ENVOY_DEV_RESET_WITH_INIT:
error = ENVOY_DeviceHardResetReal(handle);
/*if (error == TXC_NO_ERR)
{
error = ENVOY_DeviceInitReal(handle);
}*/
break;
default:
error = TXC_INVALID_PARM_ERR; /* should never occur */
break;
} /* end of switch */
/* send back the error */
return error;
}
static TXC_U16BIT ENVOY_DeviceHardResetReal (TXC_U16BIT handle)
{
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_SEM_ID semId;
ENVOY_HOST_RESET_STRUCT *hostResetPtr;
ENVOY_MAC_CONFIG_STRUCT *macCfgPtr;
TXC_U16BIT portIdx;
TXC_U16BIT endPort;
TXC_U16BIT startPort;
TXC_U16BIT deviceType;
/* grab the semaphore now, instead of each batch access, as this function
does require multiple-batched accesses */
semId = ENVOY_DbGetSemId ();
if (semId != TXC_NULL)
{ error = TXC_SemWait (semId, TXC_OS_SEM_WAIT_FOREVER);
if ( error != TXC_NO_ERR)
return TXC_OS_RESOURCE_ERR;
}
batchData.semId = TXC_NULL; /* handle mutual exclusion here, not in the batch process */
/* Reset The Global Registers */
memset (®Data[0], 0, sizeof(regData) );
/* first, fill the batch platfrom header */
batchData.regDataPtr = ®Data[0];
batchData.regCount = 2; /* number of reset registers*/
batchData.writeVerifyFlag = TXC_FALSE;
regData[0].mask = 0xFFFFFFFF; /* register 0x0010 */
regData[0].data = 0xFFFFFFFF; /* register 0x0010 */
regData[1].mask = 0x1F; /* register 0x0014 */
regData[1].data = 0x1F; /* register 0x0014 */
/* determine the base address of the device */
baseAddr = (TXC_REG_32 *) ENVOY_DbGetDeviceAddr (handle);
hostResetPtr = (ENVOY_HOST_RESET_STRUCT *) (baseAddr + ENVOY_HOST_RESET_OFFSET);
regData[0].addr = (TXC_REG_32 *) &(hostResetPtr->resetEthernetPortReg);
regData[1].addr = (TXC_REG_32 *) &(hostResetPtr->resetModuleReg);
error = TXC_BatchReg32BitWrite (&batchData);
/* reset all MAC ports */
/* First, get the device type. */
deviceType = ENVOY_DbGetDeviceType (handle);
if ((deviceType != ENVOY_CE2) && (deviceType != ENVOY_CE4) )
{
return TXC_DEVICE_RESET_ERR;
}
if (deviceType == ENVOY_CE2)
{
startPort = 0;
endPort = ENVOY_CE2_MAX_MAC_PORTS;
}
else /* that is, deviceType == ENVOY_CE4 */
{
startPort = 0;
endPort = ENVOY_CE4_MAX_MAC_PORTS;
}
/* 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; )
{
macCfgPtr = (ENVOY_MAC_CONFIG_STRUCT *) (baseAddr + macCfgOffset[portIdx]);
regData[0].addr = (TXC_REG_32 *) &(macCfgPtr->cfg1Reg); /* perform a SOFT RESET in the MAC */
regData[0].mask = 0x800F0000;
regData[0].data = 0x800F0000;
/* 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[0].data = 0;
error = TXC_BatchReg32BitWrite (&batchData);
if (error != TXC_NO_ERR)
{
break;
}
portIdx = portIdx + 1;
}
/* release the semaphore */
if (semId != TXC_NULL)
TXC_SemPost (semId);
/* return the error code */
return error;
}
/*--------------------------------------------------------------------------*
FUNCTION: ENVOY_DeviceVersionReal
DESCRIPTION: This function actually processess the TXC_ENVOY_DeviceVersion
INPUTS: same as TXC_ENVOY_DeviceVersion
RETURNS: TXC_NO_ERR or an appropriate specific error code
CAVEATS: None.
REVISION HISTORY:
Rev Date Author Description
----- ------- ------------ -----------------
0.5.0 6/03/04 F. Giannella Initial release (beta)
*--------------------------------------------------------------------------*/
TXC_U16BIT ENVOY_DeviceVersionReal (TXC_U16BIT handle, ENVOY_DEVICE_VERSION_STRUCT * deviceVersionDataPtr)
{
TXC_U16BIT error;
TXC_BATCH_REG_ACCESS_32BIT_STRUCT batchData;
TXC_REG_ACCESS_32BIT_STRUCT regData[2];
TXC_REG_32 * baseAddr;
ENVOY_ID_REGISTER_STRUCT * structPtr;
/* first, fill the batch platfrom header, NOTE no semaphore is needed
because it read-only. This function requires 1 register to be read */
batchData.regDataPtr = ®Data[0];
batchData.regCount = 1;
batchData.writeVerifyFlag = TXC_FALSE;
batchData.semId = TXC_FALSE;
memset (& regData[0], 0, 2 *sizeof (TXC_REG_ACCESS_32BIT_STRUCT) );
/*offset into the proper block */
baseAddr = (TXC_REG_32 *) ENVOY_DbGetDeviceAddr (handle);
structPtr = (ENVOY_ID_REGISTER_STRUCT *) baseAddr;
/* determine the specific addresses */
regData[0].addr = (TXC_REG_32 *) &(structPtr->deviceId);
/* fill in masks */
regData[0].mask = (TXC_REG_32) 0xFFFFFFFF;
/* call the batch read */
error = TXC_BatchReg32BitRead (&batchData);
deviceVersionDataPtr->manufId = (TXC_U16BIT) ((regData[0].data >> 1) & 0x003FF);
deviceVersionDataPtr->partNumber = (TXC_U16BIT) ((regData[0].data >> 12)& 0x0FFFF);
deviceVersionDataPtr->version = (TXC_U16BIT) (regData[0].data >> 28);
return error;
}
/* TXC_ENVOY_VIRTUAL_DEVICE_MODE */
#endif
/****************************************************************************
** End of Module **
****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -