?? zl5011xlanlanlink.c
字號(hào):
/*******************************************************************************
*
* File name: zl5011xLanLanLink.c
*
* Version: 7
*
* Author: APL
*
* Date created: 26/07/2004
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description:
* Supports Lan To Lan links between one ethernet port and another
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 26/07/2004 APL New file
* 2 14/09/2004 APL Minor tidying following review
* 3 27/09/2004 APL Corrected a trace message
* 4 27/09/2004 APL Need to set Wan Rx flow type when context created
* 5 04/10/2004 APL Updated comments
* 6 11/04/2005 APL Updated comment
* 7 21/07/2005 MRC Corrected context state check
*
*******************************************************************************/
/***************** INCLUDE FILES ******************************************/
#include "zl5011xLanLanLink.h"
#include "zl5011xApi.h"
#include "zl5011xLan.h"
/***************** COMPILE CONTROLS *****************************************/
/***************** # DEFINES **********************************************/
/***************** MACROS and ENUMERATIONS ********************************/
/***************** DATA STRUCTURES ****************************************/
/***************** STATIC FUNCTION DECLARATIONS ***************************/
/***************** STATIC GLOBAL VARIABLES ********************************/
/***************** STATIC GLOBAL ACCESSORS ******************************/
/***************** STATIC FUNCTION DEFINITIONS ****************************/
/***************** EXPORTED GLOBAL VARIABLES ******************************/
/***************** EXPORTED FUNCTION DEFINTIONS ***************************/
/*******************************************************************************
Function:
zl5011xLanLanContextCreateStructInit
Description:
Initialises structure used by zl5011xLanLanContextCreate function.
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items.
See main function
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xLanLanContextCreateStructInit(zl5011xParamsS *zl5011xParams, zl5011xContextCreateS *par)
{
zlStatusE status = ZL5011X_OK;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_TDM_FN_ID,
"zl5011xLanLanContextCreateStructInit:",
0, 0, 0, 0, 0, 0);
/* Ensure all structure members are initialised */
memset(par, 0, sizeof(zl5011xContextCreateS));
par->context = ZL5011X_INVALID_CONTEXT;
par->flow = ZL5011X_FLOW_PKT_PE_PKT;
par->osExclusionEnable = ZL5011X_TRUE;
/* All other parameters in the zl5011xContextCreateS structure are unused */
}
return status;
}
/*******************************************************************************
Function:
zl5011xLanLanContextCreate
Description:
Create a context for a particular data flow within the device.
Inputs:
contextNumber The context number to create
osExclusionEnable Whether to use mutex locking to access the device structure
flow Routing through the device corresponding to this context.
Normally this will be one of:
ZL5011X_FLOW_PKT_PKT if no additional header is to be added
to the packet OR if only layer 2/3 header
will be added.
ZL5011X_FLOW_PKT_PE_PKT (default) if layer 4/5 header must also be
modified.
Note: the choice of default here is almost certainly wrong because
most applications will want to set this to ZL5011X_FLOW_PKT_PKT.
However, the default value here cannot be changed in order to maintain
backward compatibility.
Lan-to-Lan contexts may also be used to create CPU-to-LAN flows
so the following values are also permitted.
ZL5011X_FLOW_CPU_PKT
ZL5011X_FLOW_CPU_PE_PKT
In some applications this flow value can be overridden later
by a specific call to zl5011xLanRxSetContextMatch.
All other members of the zl5011xContextCreateS structure are unused.
Outputs:
None
Returns:
status Any valid error code
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xLanLanContextCreate(zl5011xParamsS *zl5011xParams,
zl5011xContextCreateS *par)
{
zlStatusE status = ZL5011X_OK;
zl5011xBooleanE gotDevice = ZL5011X_FALSE;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
/* Check device is running and therefore initialised OK */
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
/* Check the flow parameter */
if (status == ZL5011X_OK)
{
switch (par->flow)
{
case ZL5011X_FLOW_PKT_PE_PKT:
case ZL5011X_FLOW_PKT_PKT:
case ZL5011X_FLOW_CPU_PKT:
case ZL5011X_FLOW_CPU_PE_PKT:
/* These are permitted values */
break;
default:
status = ZL5011X_PARAMETER_INVALID;
break;
}
}
/* Obtain exclusive access to the device if required */
if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
{
/* get access to the device */
status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);
if (status == ZL5011X_OK)
{
gotDevice = ZL5011X_TRUE;
}
}
/* Check Lan context is valid */
if (status == ZL5011X_OK)
{
status = zl5011xLanLanContextCheck(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_NUMBER);
}
/* main function code starts */
if (status == ZL5011X_OK)
{
ZL5011X_TRACE_CONTEXT(ZL5011X_LAN_FN_ID, par->context,
"zl5011xLanLanContextCreate: ctxt %3d, flow %3d",
par->context, par->flow, 0, 0, 0, 0);
}
/* If this context was previously used for either a Wan (TDM) Rx or Tx context then check that
the context delete has completed */
if (status == ZL5011X_OK)
{
/* Check to see whether a previous Wan Rx context teardown has now completed. */
if (zl5011xParams->wanIf.plaCurrent.context[par->context].state == ZL5011X_STATE_TEARING_DOWN)
{
status = zl5011xPlaCheckContextTeardown(zl5011xParams, par->context);
/* if the teardown has completed, then reset the error code and
continue */
if (status == ZL5011X_CONTEXT_TEARDOWN_COMPLETE)
{
status = ZL5011X_OK;
}
}
}
if (status == ZL5011X_OK)
{
/* Check to see whether a previous Wan Tx context teardown has now completed. */
if (zl5011xParams->wanIf.tfmCurrent.context[par->context].state == ZL5011X_STATE_TEARING_DOWN)
{
status = zl5011xTfmCheckContextTeardown(zl5011xParams, par->context);
/* if the teardown has completed, then reset the error code and
continue */
if (status == ZL5011X_CONTEXT_TEARDOWN_COMPLETE)
{
status = ZL5011X_OK;
}
}
}
/* Any context can be used either as a Lan-to-Lan context or as a Wan (TDM) context but not both.
Therefore the context state for all contexts is stored in the Wan (TDM) part of the device structure.*/
if (status == ZL5011X_OK)
{
/* check that the context is not currently in use */
if ((zl5011xParams->wanIf.plaCurrent.context[par->context].state != ZL5011X_STATE_NOT_IN_USE) ||
(zl5011xParams->wanIf.tfmCurrent.context[par->context].state != ZL5011X_STATE_NOT_IN_USE))
{
status = ZL5011X_CONTEXT_IN_USE;
}
}
if (status == ZL5011X_OK)
{
/* Set both the wan Tx and Rx state parameters for this context to ensure it cannot
be reused */
zl5011xParams->wanIf.plaCurrent.context[par->context].state = ZL5011X_STATE_INIT;
zl5011xParams->wanIf.tfmCurrent.context[par->context].state = ZL5011X_STATE_INIT;
zl5011xParams->wanIf.wanTxFlow[par->context] = par->flow; /* Used by zl5011xLanRxSetContextMatch */
zl5011xParams->wanIf.wanRxFlow[par->context] = par->flow; /* Used by zl5011xSetPacketTx */
/* Set the flag to indicate this is a Lan-to-Lan context */
zl5011xParams->packetIf.lanLanContext[par->context] = ZL5011X_TRUE;
/* Clear the flag that indicates there is a pending classifier rule */
zl5011xParams->packetIf.classifierEnablePending[par->context] = ZL5011X_FALSE;
}
/* Release the device */
if (gotDevice == ZL5011X_TRUE)
{
if (status == ZL5011X_OK)
{
status = zl5011xReleaseDevice(zl5011xParams);
}
else
{
/* already have an error code, so don't overwrite it */
(void)zl5011xReleaseDevice(zl5011xParams);
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xLanLanContextUpdateStructInit
Description:
Initialises structure used by zl5011xUpdateLanLanContext function.
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items.
See main function
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xLanLanContextUpdateStructInit(zl5011xParamsS *zl5011xParams,
zl5011xContextS *par)
{
zlStatusE status = ZL5011X_OK;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -