?? zl5011xpktpassthru.c
字號:
/*******************************************************************************
*
* File name: zl5011xPktPassthru.c
*
* Version: 2
*
* Author: APL
*
* Date created: 18/02/2005
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description:
*
* This file contains the high level functions to assist with setting up
* data passthrough from one packet port to another.
* Either an individual flow can be set up or a group of flows
* consisting of two mirrored bi-directional flows and a third flow to allow
* broadcast traffic.
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 18/02/2005 APL First version
* 2 07/03/2005 APL Improved parameter error checking
*
*******************************************************************************/
/***************** INCLUDE FILES *****************************/
#include "zl5011xApi.h"
#include "zl5011xLan.h"
#include "zl5011xLanLanLink.h"
#include "zl5011xPacket.h"
#include "zl5011xPktPassthru.h"
/***************** DEFINES ***************************************************/
/***************** EXTERNAL GLOBAL VARIABLES ********************************/
/***************** STATIC GLOBAL VARIABLES ********************************/
/***************** EXPORTED FUNCTION DEFINTIONS ***************************/
/******************************************************************************
Function:
zl5011xCreatePktToPktPassthruStructInit
Description:
Initialises structure used by functions zl5011xCreatePktToPktPassthru
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items.
See main function
Returns:
zlStatusE
Remarks:
******************************************************************************/
zlStatusE zl5011xCreatePktToPktPassthruStructInit(zl5011xParamsS *zl5011xParams,
zl5011xPktToPktPassthruS * par)
{
zlStatusE status = ZL5011X_OK;
Sint32T i;
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,"zl5011xCreatePktToPktPassthruStructInit:",0, 0, 0, 0, 0, 0);
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
par->upLinkPort = 0; /* Use port 0, queue 0 for uplink by default */
par->upLinkQueueNum = 0;
par->downLinkPort = 1; /* Use port 1, queue 0 for downlink by default */
par->downLinkQueueNum = 0;
par->protocolMatchNum = (Uint32T)ZL5011X_INVALID; /* Choose protocol match automatically */
for (i=0; i<ZL5011X_NUM_PKT_PKT_FLOWS; i++)
{
par->context[i] = (Uint32T)ZL5011X_INVALID_CONTEXT; /* Choose context automatically */
par->classifyMatchNum[i] = (Uint32T)ZL5011X_INVALID; /* Choose classify match number automatically */
}
par->osExclusionEnable = ZL5011X_TRUE; /* Default to using OS exclusion when accessing the
device from this function */
}
return(status);
}
/*******************************************************************************
Function:
zl5011xCreatePktToPktPassthru
Description:
Creates two Packet-to-Packet flows which together provide data passthrough
capability.
+-----------+ +------------+
| Host | | ZLxxxxx |
| | | |
| Mac1 |<------------>| Mac2 Mac1 |<-----------> To network
| | (downlink) | | (uplink)
| | | |
+-----------+ +------------+
The flows created in the ZL5011X_ device are as follows:
1. A flow handling host to network packets which have ethernet source
MAC address = Mac1. These are forwarded to the uplink port
2. A flow handling packets which do not match flow 1 (or any other application
defined flow). These are forwarded to the downlink port.
Flow 2, by its very nature supports both unicast and multicast packets but will
also forward any other packets to the host. A future enhancement would be possible
to separate flow 2 into a unicast flow and a multicast flow so that stray
packets will then not be forwarded.
Packets are transmitted unchanged on the appropriate Packet output port in each
case.
It is required that the network port on the ZL5011X_ device is programmed with the
same MAC address as the host ethernet port.
Structure inputs:
upLinkPort The port number of the device used for the uplink
Default = port 0
upLinkQueueNum The output queue to use on the uplink transmit port
Range 0-3. In the default priority mode, queue 3 has
the highest priority.
Default = 0.
downLinkPort The port number of the device used for the downlink
Default = port 1
downLinkQueueNum The output queue to use on the uplink transmit port
Range 0-3. In the default priority mode, queue 3 has
the highest priority.
Default = 0.
protocolMatchNumber can be set to specify which protocol match to use if the
protocol is not already defined, in which case the current
number is returned. If a number is not specified then
the highest available match number will be used.
Range = 0-3
Default = automatically choose protocol match
context[2] Can optionally be set to specify which contexts to use.
Otherwise they will automatically be selected by finding
the highest available unused context numbers.
Range = 0-maximum number of contexts (device dependent)
Default = choose contexts automatically
classifyMatchNumber[2] can be set to specify which classification match to use
for each flow. If a number is not specified then one will
automatically be chosen.
Range = 0-271
Default = automatically choose classification match
osExclusionEnable ZL5011X_TRUE to enable OS exclusion in this function
Default = ZL5011X_TRUE
Structure outputs:
protocolMatchNumber returns the protocol match number used.
classifyMatchNumber[3] returns the classification match numbers used for these contexts
context[3] returns the context numbers used for this group of
pass through flows
Returns:
status Any valid error code
Remarks:
*******************************************************************************/
zlStatusE zl5011xCreatePktToPktPassthru(zl5011xParamsS *zl5011xParams, zl5011xPktToPktPassthruS *par)
{
zlStatusE status = ZL5011X_OK;
zl5011xBooleanE gotDevice = ZL5011X_FALSE;
Sint32T i;
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,"zl5011xCreatePktToPktPassthru:",0, 0, 0, 0, 0, 0);
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
/* check that both uplink and downlink ports are valid and different */
if (par->upLinkPort >= zl5011xParams->devLimits.lanNumLanPorts)
{
status = ZL5011X_INVALID_PORT;
}
else if (par->downLinkPort >= zl5011xParams->devLimits.lanNumLanPorts)
{
status = ZL5011X_INVALID_PORT;
}
else if (par->downLinkPort == par->upLinkPort)
{
status = ZL5011X_INVALID_PORT_CONFIG;
}
else if (par->upLinkQueueNum >= ZL5011X_PKQ_NUM_QUEUES)
{
status = ZL5011X_INVALID_PORT_CONFIG;
}
else if (par->downLinkQueueNum >= ZL5011X_PKQ_NUM_QUEUES)
{
status = ZL5011X_INVALID_PORT_CONFIG;
}
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;
}
}
if (status == ZL5011X_OK)
{
/* Find the highest available protocol match number (=lowest priority)
if none specified directly */
if (par->protocolMatchNum == (Uint32T)ZL5011X_INVALID)
{
Sint32T loop;
for (loop = ZL5011X_PKC_NUM_PROTOCOL_ENTRIES-1; loop >= 0; loop--)
{
if (zl5011xParams->packetIf.packetRx.pkcProtocol[loop].protocolReserved == ZL5011X_FALSE)
{
/* Found an unused protocol match */
par->protocolMatchNum = loop;
break;
}
}
if (loop < 0)
{ /* No spare protocol match could be found */
status = ZL5011X_NO_AVAIL_PROTOCOL_MATCH;
}
}
}
/* Find empty contexts if any are not specified directly */
{
Uint32T startSearch;
/* Start searching at the highest available context */
startSearch = zl5011xParams->devLimits.numContexts-1;
for (i = 0; (status == ZL5011X_OK) && (i < ZL5011X_NUM_PKT_PKT_FLOWS); i++)
{
if (par->context[i] == (Uint32T)ZL5011X_INVALID_CONTEXT)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -