?? zl5011xpkcclassify.c
字號:
/*******************************************************************************
*
* File name: zl5011xPkcClassify.c
*
* Version: 17
*
* Author: MRC
*
* Date created: 09/05/2002
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description:
*
* This file contains all the functions that will control the classifier
* part of the Pkc block. The classifier is used to determine the context of a
* data flow and to match control packets for the host. When a match is made,
* the match is checked to ensure that it is valid. The routing information etc.
* is set to determine the destination for the packet.
*
* The various stages in the PKC are as follows:
*
* pre-processor matches ethertype / MAC addresses for directing to the host.
* pre-classifier matches the protocol type and extracts bytes from the header
* for use in the classification stage
* classifier matches the bytes extracted by the pre-classifier, to
* determine the context number for data transactions. Is also
* used to direct control packets related to a data path to the
* host.
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 09/05/2002 MRC Creation
* 2 13/05/2002 MRC Update
* 3 15/05/2002 MRC Used the flow type to determine RTP stats bit
* in the classifier, rather than an i/p field
* 4 21/05/2002 MRC PKC Rams have to be written in reverse order.
* 5 13/06/2002 MRC Uses the match define for both the mask and
* the match function
* 6 21/06/2002 MRC Revamped the entry allocation fns
* 7 12/07/2002 MRC Rationalised the 2 enums for CPU queues
* 8 22/07/2002 MRC pkt length for host packets is now the Rx length
* 9 31/10/2002 MRC Added variants + minor fixes
* 10 07/11/2002 MRC Added control for SetContextMatch fn to use the
* raw Rx packet length
* 11 06/01/2003 MRC Modified function zl5011xPkcProtocolConfigure
* 12 30/04/2003 JFE Made change to take account of pkc pre-classify bug
* in errata 2.56
* 13 29/07/2003 APL Enable RTP stats for PKT_PE_PKT flow
* 14 23/07/2004 MRC Fixed some compiler warnings
* 15 26/08/2004 MRC Reset PW interrupt when changing a match
* 16 21/01/2005 MRC Added extra flow type
* 17 21/07/2005 MRC Added function to check if an entry is used
*
*******************************************************************************/
/***************** INCLUDE FILES *****************************/
#include "zl5011x.h"
#include "zl5011xPkc.h"
#include "zl5011xPkcMap.h"
#include "zl5011xUtilLib.h"
/***************** EXPORTED GLOBAL VARIABLES *****************************/
/***************** STATIC GLOBAL VARIABLES *****************************/
/*******************************************************************************
Function:
zl5011xPkcClassifyConfigure
Description:
This function controls the behaviour for packets that are not matched in
the classifier, or fail to verify following a successful match.
They can be discarded or forwarded to the host using a specified queue.
Inputs:
zl5011xParams Pointer to the structure for this device instance
discard ZL5011X_TRUE to discard non-matching packets,
ZL5011X_FALSE to forward to the host
queueNum queue number to use for packets forwarded to host
verifyDiscard ZL5011X_TRUE to discard packets failing verification,
ZL5011X_FALSE to forward to the host
verifyQueueNum queue number to use for packets failing verification that
are to be forwarded to host
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkcClassifyConfigure(zl5011xParamsS *zl5011xParams,
zl5011xBooleanE discard, zl5011xQueueE queueNum,
zl5011xBooleanE verifyDiscard, zl5011xQueueE verifyQueueNum)
{
zlStatusE status = ZL5011X_OK;
Uint32T bits = 0;
ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
"zl5011xPkcClassifyConfigure: drop %d, queue %d, verify: drop %d, queue %d",
discard, queueNum, verifyDiscard, verifyQueueNum, 0, 0);
status = ZL5011X_CHECK_BOOLEAN(discard);
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_BOOLEAN(verifyDiscard);
}
if (status == ZL5011X_OK)
{
if (discard == ZL5011X_FALSE)
{
status = ZL5011X_CHECK_QUEUE_NUMBER(queueNum);
/* if the packets are being directed to the CPU, then set the
queue ID and leave the discard bit */
if (status == ZL5011X_OK)
{
bits = queueNum << ZL5011X_PKC_CLASSIFY_NO_MATCH_QUEUE_BITS;
}
}
else
{
/* if discarding the packets, then set the bit to enable this */
bits = ZL5011X_1BIT_MASK << ZL5011X_PKC_CLASSIFY_NO_MATCH_DROP_BIT;
}
}
if (status == ZL5011X_OK)
{
status = zl5011xWrite(zl5011xParams, ZL5011X_PKC_CLASSIFY_NO_MATCH, bits);
}
if (status == ZL5011X_OK)
{
if (verifyDiscard == ZL5011X_FALSE)
{
status = ZL5011X_CHECK_QUEUE_NUMBER(verifyQueueNum);
/* if the packets are being directed to the CPU, then set the
queue ID and leave the discard bit */
if (status == ZL5011X_OK)
{
bits = verifyQueueNum << ZL5011X_PKC_VERIFY_NO_MATCH_QUEUE_BITS;
}
}
else
{
/* if discarding the packets, then set the bit to enable this */
bits = ZL5011X_1BIT_MASK << ZL5011X_PKC_VERIFY_NO_MATCH_DROP_BIT;
}
}
if (status == ZL5011X_OK)
{
status = zl5011xWrite(zl5011xParams, ZL5011X_PKC_VERIFY_NO_MATCH, bits);
}
if (status == ZL5011X_OK)
{
/* store the discard and queue settings in the device structure */
zl5011xParams->packetIf.packetRx.pkcClassifyDiscard = discard;
zl5011xParams->packetIf.packetRx.pkcClassifyCpuQueue = queueNum;
zl5011xParams->packetIf.packetRx.pkcVerifyDiscard = verifyDiscard;
zl5011xParams->packetIf.packetRx.pkcVerifyCpuQueue = verifyQueueNum;
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPkcClassifyCheckFreeEntry
Description:
This function is provided to allow the application to check whether a PKC
classifier match is in use without actually reserving it for use.
Inputs:
zl5011xParams Pointer to the structure for this device instance
matchNum the classifier match number to check
Outputs:
entryFree ZL5011X_TRUE if the entry is unused
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkcClassifyCheckFreeEntry(zl5011xParamsS *zl5011xParams,
Uint32T matchNum, zl5011xBooleanE *entryFree)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
"zl5011xPkcClassifyCheckFreeEntry: match %d",
matchNum, 0, 0, 0, 0, 0);
*entryFree = ZL5011X_FALSE;
/* check that a valid match number was specified */
if (matchNum >= ZL5011X_PKC_NUM_CLASSIFY_ENTRIES)
{
status = ZL5011X_PARAMETER_INVALID;
}
else
{
/* check whether the match is in use */
if (zl5011xParams->packetIf.packetRx.pkcClassify[matchNum].classifyReserved == ZL5011X_FALSE)
{
*entryFree = ZL5011X_TRUE;
}
}
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
"zl5011xPkcClassifyCheckFreeEntry: match %d, avail %d",
matchNum, *entryFree, 0, 0, 0, 0);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPkcClassifyGetFreeEntry
Description:
This function can reserve an entry in the classifier if a valid match
number is provided, or will allocate one if possible.
Inputs:
zl5011xParams Pointer to the structure for this device instance
matchNum the number of a free entry or ZL5011X_INVALID to allocate a
match number
Outputs:
matchNum the number of a free entry if at input it was ZL5011X_INVALID
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkcClassifyGetFreeEntry(zl5011xParamsS *zl5011xParams,
Uint32T *matchNum)
{
Uint32T loop;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
"zl5011xPkcClassifyGetFreeEntry: match in %d",
*matchNum, 0, 0, 0, 0, 0);
/* if the match number was set to a special value of invalid,
then one will be automatically found */
if (*matchNum == (Uint32T)ZL5011X_INVALID)
{
for (loop = 0; loop < ZL5011X_PKC_NUM_CLASSIFY_ENTRIES; loop++)
{
if (zl5011xParams->packetIf.packetRx.pkcClassify[loop].classifyReserved == ZL5011X_FALSE)
break;
}
if (loop >= ZL5011X_PKC_NUM_CLASSIFY_ENTRIES)
{
/* no free matches in the classifier, so return error */
status = ZL5011X_NO_AVAIL_CLASSIFY_MATCH;
}
else
{
*matchNum = loop;
}
}
else
{
/* if the number was specified, but was not valid, then throw an error */
if (*matchNum >= ZL5011X_PKC_NUM_CLASSIFY_ENTRIES)
{
status = ZL5011X_PARAMETER_INVALID;
}
else
{
/* check that the match is not already in use */
if (zl5011xParams->packetIf.packetRx.pkcClassify[*matchNum].classifyReserved == ZL5011X_TRUE)
{
status = ZL5011X_CLASSIFY_MATCH_IN_USE;
}
}
}
/* reserve the match if there has not been an error */
if (status == ZL5011X_OK)
{
zl5011xParams->packetIf.packetRx.pkcClassify[*matchNum].classifyReserved = ZL5011X_TRUE;
zl5011xParams->packetIf.packetRx.pkcClassify[*matchNum].classifyContext = (Uint32T)ZL5011X_INVALID_CONTEXT;
ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
"zl5011xPkcClassifyGetFreeEntry: match out %d",
*matchNum, 0, 0, 0, 0, 0);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPkcClassifyEnableEntry
Description:
Enables a classifier entry. The entry should be configured before it is
enabled.
Inputs:
zl5011xParams Pointer to the structure for this device instance
matchNum the number of the entry to enable
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkcClassifyEnableEntry(zl5011xParamsS *zl5011xParams,
Uint32T matchNum)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -