?? zl5011xpkq.c
字號(hào):
/*******************************************************************************
*
* File name: zl5011xPkq.c
*
* Version: 23
*
* Author: LCW
*
* Date created: 16/04/2002
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description:
* This file contains all the functions that will initialise and control
* the PKQ block.
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 16/04/2002 LCW Creation.
* 2 17/04/2002 LCW Minor mods.
* 3 09/05/2002 LCW Minor mods.
* 4 14/05/2002 LCW Minor mods.
* 5 16/05/2002 LCW Minor mods.
* 6 16/05/2002 LCW Minor mods.
* 7 05/06/2002 MRC Update
* 8 05/06/2002 MRC Fixed a few ZL5011X_TRACE statements
* 9 19/05/2002 MRC Uses defines from addrmap for number of entries
* in the context table
* 10 26/06/2002 LCW Update
* 11 28/06/2002 LCW Code review actions
* 12 26/07/2002 MRC Changed queue weighting. Sum of weights no longer
* has to add to add to 64.
* 13 22/10/2002 MRC zl5011xPkqSetMpidConnection now records port and
* queue settings in the device structure
* 14 31/10/2002 MRC Added variants + minor fixes
* 15 29/01/2003 MRC Added check for the total granule threshold param
* 16 22/05/2003 MRC Changed size of arrays for Lan Tx port / queue
* 17 09/06/2003 DJA Performed pre-audit actions
* 18 23/06/2004 APL Corrected an array index into internal current
* state structure and removed duplicate write.
* Validated port parameter for zl5011xPkqConfigureQueue
* 19 29/07/2004 MRC Fixed some compiler warnings
* 20 17/09/2004 MRC Added check for the queue granule threshold
* 21 17/09/2004 MRC Changed default for queue granule threshold
* 22 27/09/2004 MRC Added function to return port / queue for an mpid
* 23 21/07/2005 MRC Reduced default number of granules for discard port
*
*******************************************************************************/
/***************** INCLUDE FILES ******************************************/
#include "zl5011x.h"
#include "zl5011xPkqMap.h"
#include "zl5011xPkq.h"
#include "zl5011xUtilLib.h"
#include "zl5011xRdWr.h"
/*******************************************************************************
Function:
zl5011xPkqInit
Description:
Called at initialisation time. Enables packet dropping when the total granule
usage threshold is exceeded. Initialises the MPID connection table.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkqInit(zl5011xParamsS *zl5011xParams)
{
zlStatusE status = ZL5011X_OK;
Uint32T i,tempGranules;
Uint8T portNumber;
Uint8T queueNumber;
ZL5011X_TRACE(ZL5011X_PKQ_FN_ID, "zl5011xPkqInit:", 0, 0, 0, 0, 0, 0);
/* initialise the PKQ mode and total threshold limit for the queues */
status = zl5011xPkqSetTotalThresholdMode(zl5011xParams,
ZL5011X_PKQ_DEFAULT_PACKET_DROP_MODE);
if (status == ZL5011X_OK)
{
status = zl5011xPkqSetTotalGranuleThreshold(zl5011xParams,
ZL5011X_PKQ_DEFAULT_TOTAL_GRAN_THLD);
}
/* Set granule threshold for all queues */
for (portNumber = 0; portNumber < ZL5011X_PKQ_NUMBER_OF_PORTS; portNumber++)
{
if (portNumber == zl5011xParams->devLimits.lanDiscardPort)
{
tempGranules = ZL5011X_PKQ_DEFAULT_DISCARD_GRAN_THLD;
}
else
{
tempGranules = ZL5011X_PKQ_DEFAULT_QUEUE_GRAN_THLD;
}
for (queueNumber = 0; queueNumber < ZL5011X_PKQ_QUEUES_PER_PORT; queueNumber++)
{
if (status != ZL5011X_OK)
{
break;
}
status = zl5011xPkqSetGranuleThreshold(zl5011xParams, portNumber,
queueNumber, tempGranules);
}
}
/* Enable packet dropping mode for all queues */
for (portNumber = 0; portNumber < ZL5011X_PKQ_NUMBER_OF_PORTS; portNumber++)
{
for (queueNumber = 0; queueNumber < ZL5011X_PKQ_QUEUES_PER_PORT; queueNumber++)
{
if (status != ZL5011X_OK)
{
break;
}
status = zl5011xPkqSetThresholdMode(zl5011xParams, portNumber,
queueNumber, ZL5011X_PKQ_DEFAULT_PACKET_DROP_MODE);
}
}
/* initialise the queues to be strict priority */
for (portNumber = 0; portNumber < ZL5011X_PKQ_NUMBER_OF_PORTS; portNumber++)
{
if (status != ZL5011X_OK)
{
break;
}
status = zl5011xPkqSetQueuePriority(zl5011xParams, portNumber, ZL5011X_WFQ_NONE);
}
/* setup the context table. The first entries are for MPID associated
data flows, and the next 16 are for host flows (where there is one for
each port and queue combination) */
for (i = 0; i < ZL5011X_PKT_TX_NUM_CONTEXT_HEADERS; i++)
{
if (status != ZL5011X_OK)
{
break;
}
/* initialise data flows to use a default Lan port and queue */
status = zl5011xPkqSetMpidConnection(zl5011xParams, i,
ZL5011X_PKQ_DEFAULT_PORT, ZL5011X_PKQ_DEFAULT_QUEUE);
}
/* Add further MPIDs for use by host Tx */
for (i = 0; i < ZL5011X_PKT_TX_NUM_HOST_HEADERS; i++)
{
if (status != ZL5011X_OK)
{
break;
}
queueNumber = (Uint8T)(i % ZL5011X_PKQ_QUEUES_PER_PORT);
portNumber = (Uint8T)((i / ZL5011X_PKQ_QUEUES_PER_PORT) % ZL5011X_PKQ_NUMBER_OF_PORTS);
status = zl5011xPkqSetMpidConnection(zl5011xParams,
ZL5011X_PKT_TX_NUM_CONTEXT_HEADERS + i,
portNumber, queueNumber);
}
return (status);
}
/*******************************************************************************
Function:
zl5011xPkqSetQueuePriority
Description:
Implements a quality of service feature by setting the queue priority for a
particular port. A queue will be allocated strict priority or weighted fair
queueing status.
When queues are in strict priority mode the highest priority queue is emptied
first.
For WFQ, each queue has its own weight to determine the amount of bandwidth
that will be allocated for its queue.
Inputs:
zl5011xParams Pointer to the structure for this device instance
portNumber LAN port number
priorityMode Priority mode of port can take the following values:
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkqSetQueuePriority(zl5011xParamsS *zl5011xParams,
Uint8T portNumber,
zl5011xPacketQueuePriorityModeE priorityMode)
{
zlStatusE status = ZL5011X_OK;
Uint32T queueWeighting = 0, mask = 0;
ZL5011X_TRACE(ZL5011X_PKQ_FN_ID, "zl5011xPkqSetQueuePriority: Port %ld,Prioity Mode %ld",
portNumber, priorityMode, 0, 0, 0, 0);
/* Check priority mode is valid */
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_WFQ(priorityMode);
}
if (status == ZL5011X_OK)
{
queueWeighting = priorityMode << (portNumber * ZL5011X_PKQ_NUMBER_OF_WFQ_BITS);
mask = ZL5011X_2BIT_MASK << (portNumber * ZL5011X_PKQ_NUMBER_OF_WFQ_BITS);
status = zl5011xReadModWrite(zl5011xParams, ZL5011X_PKQ_LMR, queueWeighting,
mask);
/* Record port priority mode in device structure */
zl5011xParams -> pkq.priorityMode[portNumber] = priorityMode;
}
return (status);
}
/*******************************************************************************
Function:
zl5011xPkqSetWeighting
Description:
Sets weighting for queue
Inputs:
zl5011xParams Pointer to the structure for this device instance
portNumber LAN port number
queue0Weighting Weighting of queue 0
queue1Weighting Weighting of queue 1
queue2Weighting Weighting of queue 2
queue3Weighting Weighting of queue 3
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkqSetWeighting(zl5011xParamsS *zl5011xParams,
Uint8T portNumber,
Uint32T queue0Weighting,
Uint32T queue1Weighting,
Uint32T queue2Weighting,
Uint32T queue3Weighting)
{
zlStatusE status = ZL5011X_OK;
Uint32T gpBuffer = 0, i, registerAddress;
Uint32T queueWeights[ZL5011X_PKQ_NUM_QUEUES];
ZL5011X_TRACE(ZL5011X_PKQ_FN_ID,
"zl5011xPkqSetWeighting: Port %ld, Q0 %ld, Q1 %ld, Q2 %ld, Q3 %ld",
portNumber, queue0Weighting, queue1Weighting, queue2Weighting,
queue3Weighting, 0);
queueWeights[0] = queue0Weighting;
queueWeights[1] = queue1Weighting;
queueWeights[2] = queue2Weighting;
queueWeights[3] = queue3Weighting;
/* Mask out unused bits */
for (i = 0; i < ZL5011X_PKQ_NUM_QUEUES; i++)
{
if (status != ZL5011X_OK)
{
break;
}
if (queueWeights[i] > ZL5011X_PKQ_MAX_QUEUE_WEIGHTING)
{
status = ZL5011X_PARAMETER_INVALID;
}
}
if (status == ZL5011X_OK)
{
for (i = 0; i < ZL5011X_PKQ_QUEUES_PER_PORT; i++)
{
gpBuffer |= queueWeights[i] << (ZL5011X_PKQ_WFQ_SHIFT * i);
}
registerAddress = ZL5011X_PKQ_WTA + (portNumber * sizeof(Uint32T));
status = zl5011xWrite(zl5011xParams, registerAddress, gpBuffer);
/* Record queue weights in device structure */
if (status == ZL5011X_OK)
{
for (i = 0; i < ZL5011X_PKQ_QUEUES_PER_PORT; i++)
{
zl5011xParams -> pkq.queueWeight[portNumber][i] = queueWeights[i];
}
}
}
return (status);
}
/*******************************************************************************
Function:
zl5011xPkqConfigureQueue
Description:
Sets threshold mode and size of thresholds.
Inputs:
zl5011xParams Pointer to the structure for this device instance
portNumber LAN port number
queueNumber Queue number
thresholdMode Enables/disables the dropping of packets once granule
threshold has been reached.
granuleThreshold Granule threshold in queue
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPkqConfigureQueue(zl5011xParamsS *zl5011xParams,
Uint8T portNumber,
Uint8T queueNumber,
zl5011xBooleanE thresholdMode,
Uint32T granuleThreshold)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PKQ_FN_ID, "zl5011xPkqConfigureQueue: Port %ld, Queue %ld, Threshold Mode %ld, Granule Threshold %ld",
portNumber, queueNumber, thresholdMode, granuleThreshold, 0, 0);
if (status == ZL5011X_OK)
{
/* check queue number is in range */
if (queueNumber >= ZL5011X_PKQ_NUM_QUEUES)
{
status= ZL5011X_PARAMETER_INVALID;
}
}
if (status == ZL5011X_OK)
{
/* check port number is in range */
if (portNumber >= ZL5011X_MAX_NUM_LAN_PORTS)
{
status= ZL5011X_PARAMETER_INVALID;
}
}
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_BOOLEAN(thresholdMode);
}
if (status == ZL5011X_OK)
{
/* Set granule threshold */
status = zl5011xPkqSetGranuleThreshold(zl5011xParams, portNumber,
queueNumber, granuleThreshold);
if (status == ZL5011X_OK)
{
/* Set threshold mode */
status = zl5011xPkqSetThresholdMode(zl5011xParams, portNumber,
queueNumber, thresholdMode);
}
}
return (status);
}
/*******************************************************************************
Function:
zl5011xPkqSetGranuleThreshold
Description:
Sets granule threshold for a queue.
Inputs:
zl5011xParams Pointer to the structure for this device instance
portNumber LAN port number
queueNumber Queue number
granuleThreshold Granule threshold of a particular queue
Outputs:
None
Returns:
zlStatusE
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -