📄 zl5011xlan.c
字号:
{
status = zl5011xReleaseDevice(zl5011xParams);
}
else
{
/* already have an error code, so don't overwrite it */
(void)zl5011xReleaseDevice(zl5011xParams);
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xLanQueueConfigureStructInit
Description:
Initialises structure used by zl5011xLanQueueConfigure 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 zl5011xLanQueueConfigureStructInit(zl5011xParamsS *zl5011xParams,
zl5011xLanQueueConfigureS *par)
{
zlStatusE status = ZL5011X_OK;
Uint8T queueLoop;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
/* main function code starts */
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
"zl5011xLanQueueConfigureStructInit:",
0, 0, 0, 0, 0, 0);
par->portNum = (Uint8T)ZL5011X_INVALID;
par->priorityMode = ZL5011X_WFQ_NONE;
for (queueLoop = 0; queueLoop < ZL5011X_PKQ_NUM_QUEUES; queueLoop++)
{
par->granuleThresholdDropPackets[queueLoop] = ZL5011X_TRUE;
/* arbitrarily set the default queue size to be 200 granules */
par->granuleThreshold[queueLoop] = 200;
/* arbitrarily set the weights to be equal and 32. Valid values for
the weights are in the range from 0 to 63 */
par->priorityWeighting[queueLoop] = 32;
}
par->osExclusionEnable = ZL5011X_TRUE;
}
return status;
}
/*******************************************************************************
Function:
zl5011xLanQueueConfigure
Description:
Used to configure the Lan queues for a given port. Setting granule thresholds
and queue priority.
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items. See below:
Structure inputs:
portNum which port to configure
priorityMode determine the queue priority mechanism
granuleThresholdDropPackets set to ZL5011X_TRUE to drop packets when the
queue reaches the granule threshold
granuleThreshold granule thresholds to use for the queues
priorityWeighting the weightings to apply to the queues when they are in
weighted fair queue mode
osExclusionEnable ZL5011X_TRUE to enable OS exclusion
Structure outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xLanQueueConfigure(zl5011xParamsS *zl5011xParams, zl5011xLanQueueConfigureS *par)
{
zlStatusE status = ZL5011X_OK;
Uint8T internalPortNum;
Uint8T queueLoop;
zl5011xBooleanE gotDevice = ZL5011X_FALSE;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
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;
}
}
/* main function code starts */
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
"zl5011xLanQueueConfigure:",
0, 0, 0, 0, 0, 0);
/* check that a valid port has been provided */
if (par->portNum >= zl5011xParams->devLimits.lanNumLanPorts)
{
status = ZL5011X_INVALID_PORT;
}
else
{
/* Map requested port to real internal one */
status = zl5011xPkiExternalPortToInternal(zl5011xParams, &internalPortNum, par->portNum);
}
}
/* configure the queue size and packet dropping mode */
for (queueLoop = 0; queueLoop < ZL5011X_PKQ_NUM_QUEUES; queueLoop++)
{
if (status != ZL5011X_OK)
break;
status = zl5011xPkqConfigureQueue(zl5011xParams, internalPortNum, queueLoop,
par->granuleThresholdDropPackets[queueLoop], par->granuleThreshold[queueLoop]);
}
/* set the priorities for the queues associated with the Lan port */
if (status == ZL5011X_OK)
{
status = zl5011xPkqSetQueuePriority(zl5011xParams,
internalPortNum,
par->priorityMode);
}
if (status == ZL5011X_OK)
{
/* if any of the queues are WFQ, then set the weighting */
if (par->priorityMode != ZL5011X_WFQ_NONE)
{
status = zl5011xPkqSetWeighting(zl5011xParams, internalPortNum,
par->priorityWeighting[0], par->priorityWeighting[1],
par->priorityWeighting[2], par->priorityWeighting[3]);
}
}
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:
zl5011xLanRxFilterStructInit
Description:
Initialises structure used by zl5011xLanRxFilter 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 zl5011xLanRxFilterStructInit(zl5011xParamsS *zl5011xParams,
zl5011xLanRxFilterS *par)
{
zlStatusE status = ZL5011X_OK;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
/* main function code starts */
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
"zl5011xLanRxFilterStructInit:",
0, 0, 0, 0, 0, 0);
par->cpuQueue = ZL5011X_QUEUE_0;
/* enables for the various MAC address and ethertype filters */
par->filterMulticastEnable = ZL5011X_FALSE;
par->filterBroadcastEnable = ZL5011X_FALSE;
par->filterControlEnable = ZL5011X_FALSE;
par->filterArpEnable = ZL5011X_FALSE;
par->filterRarpEnable = ZL5011X_FALSE;
par->osExclusionEnable = ZL5011X_TRUE;
}
return status;
}
/*******************************************************************************
Function:
zl5011xLanRxFilter
Description:
Used to setup very basic filters for some common packet types. The filters are
used to send packets to the host.
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items. See below:
Structure inputs:
cpuQueue which cpu queue to foward the following filter matches to
filterMulticastEnable set to ZL5011X_TRUE to direct multicast packets to the
host
filterBroadcastEnable set to ZL5011X_TRUE to direct broadcast packets to the
host
filterControlEnable set to ZL5011X_TRUE to direct control packets to the
host
filterArpEnable set to ZL5011X_TRUE to direct ARP packets to the
host
filterRarpEnable set to ZL5011X_TRUE to direct RARP packets to the
host
osExclusionEnable ZL5011X_TRUE to enable OS exclusion
Structure outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xLanRxFilter(zl5011xParamsS *zl5011xParams,
zl5011xLanRxFilterS *par)
{
zlStatusE status = ZL5011X_OK;
Uint32T loop;
zl5011xBooleanE failedInit = ZL5011X_FALSE;
zl5011xLanRxDeleteFilterMatchS deleteFilter;
Uint8T macIndex, typeIndex;
/* there are a maximum of 3 MAC mode filters and 2 ethertype filters, so
define an array of 3 filters */
zl5011xLanRxSetFilterMatchS filters[3] = {{0}};
zl5011xBooleanE gotDevice = ZL5011X_FALSE;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
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;
}
}
/* main function code starts */
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_LAN_FN_ID, "zl5011xLanRxFilter:", 0, 0, 0, 0, 0, 0);
}
for (loop = 0; loop < (sizeof(filters) / sizeof(zl5011xLanRxSetFilterMatchS)); loop++)
{
if (status != ZL5011X_OK)
{
failedInit = ZL5011X_TRUE;
break;
}
status = zl5011xLanRxSetFilterMatchStructInit(zl5011xParams, filters + loop);
filters[loop].match.ethertypeCpuQueue = par->cpuQueue;
filters[loop].match.macAddressCpuQueue = par->cpuQueue;
filters[loop].osExclusionEnable = ZL5011X_FALSE;
}
macIndex = 0;
typeIndex = 0;
if (status == ZL5011X_OK)
{
/* Initialise the structures for the mac address filters */
if (par->filterMulticastEnable == ZL5011X_TRUE)
{
filters[macIndex].match.macAddressFilterEnable = ZL5011X_TRUE;
/* The device supports a mask of up to 15 bits for MAC address ranges.
Set a multicast filter for the range 01-00-5e-00-00-00 to 01-00-5e-00-7f-ff.
This is a subrange of the full address range reserved for internet
multicast (01-00-5e-00-00-00 to 01-00-5e-7f-ff-ff). See
IANA ETHERNET MULTICAST ADDRESSES) */
filters[macIndex].match.macAddress[5] = 0x01;
filters[macIndex].match.macAddress[4] = 0x00;
filters[macIndex].match.macAddress[3] = 0x5e;
filters[macIndex].match.macAddress[2] = 0x00;
filters[macIndex].match.macAddress[1] = 0x00;
filters[macIndex].match.macAddress[0] = 0x00;
filters[macIndex].match.macAddressNumMaskBits = 15; /* Mask off 15 bits from the
right most part of the MAC address. (15 is the maximum mask size) */
macIndex++;
}
if (par->filterBroadcastEnable == ZL5011X_TRUE)
{
filters[macIndex].match.macAddressFilterEnable = ZL5011X_TRUE;
/* for broadcast packets, the mac address is all 1's */
filters[macIndex].match.macAddress[5] = 0xff;
filters[macIndex].match.macAddress[4] = 0xff;
filters[macIndex].match.macAddress[3] = 0xff;
filters[macIndex].match.macAddress[2] = 0xff;
filters[macIndex].match.macAddress[1] = 0xff;
filters[macIndex].match.macAddress[0] = 0xff;
filters[macIndex].match.macAddressNumMaskBits = 0; /* No mask bits, match explicitly */
macIndex++;
}
if (par->filterControlEnable == ZL5011X_TRUE)
{
filters[macIndex].match.macAddressFilterEnable = ZL5011X_TRUE;
/* for misc ethernet control packets, the mac address is in the range
01-80-C2-00-00-00 to 01-80-C2-00-00-FF */
filters[macIndex].match.macAddress[5] = 0x01;
filters[macIndex].match.macAddress[4] = 0x80;
filters[macIndex].match.macAddress[3] = 0xc2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -