2 * @file IxEthDBFeatures.c
4 * @brief Implementation of the EthDB feature control API
7 * IXP400 SW Release version 2.0
9 * -- Copyright Notice --
12 * Copyright 2001-2005, Intel Corporation.
13 * All rights reserved.
16 * SPDX-License-Identifier: BSD-3-Clause
18 * -- End of Copyright Notice --
22 #include "IxEthDBQoS.h"
23 #include "IxEthDB_p.h"
26 * @brief scans the capabilities of the loaded NPE images
28 * This function MUST be called by the ixEthDBInit() function.
29 * No EthDB features (including learning and filtering) are enabled
30 * before this function is called.
37 void ixEthDBFeatureCapabilityScan(void)
39 IxNpeDlImageId imageId, npeAImageId;
40 IxEthDBPortId portIndex;
42 IxEthDBPriorityTable defaultPriorityTable;
45 UINT32 queueStructureIndex;
46 UINT32 trafficClassDefinitionIndex;
48 /* read version of NPE A - required to set the AQM queues for B and C */
49 npeAImageId.functionalityId = 0;
50 ixNpeDlLoadedImageGet(IX_NPEDL_NPEID_NPEA, &npeAImageId);
52 for (portIndex = 0 ; portIndex < IX_ETH_DB_NUMBER_OF_PORTS ; portIndex++)
56 portInfo = &ixEthDBPortInfo[portIndex];
58 /* check and bypass if NPE B or C is fused out */
59 if (ixEthDBSingleEthNpeCheck(portIndex) != IX_ETH_DB_SUCCESS) continue;
61 /* all ports are capable of LEARNING by default */
62 portInfo->featureCapability |= IX_ETH_DB_LEARNING;
63 portInfo->featureStatus |= IX_ETH_DB_LEARNING;
65 if (ixEthDBPortDefinitions[portIndex].type == IX_ETH_NPE)
68 if (ixNpeDlLoadedImageGet(IX_ETH_DB_PORT_ID_TO_NPE(portIndex), &imageId) != IX_SUCCESS)
70 WARNING_LOG("DB: (FeatureScan) NpeDl did not provide the image ID for NPE port %d\n", portIndex);
74 /* initialize and empty NPE response mutex */
75 ixOsalMutexInit(&portInfo->npeAckLock);
76 ixOsalMutexLock(&portInfo->npeAckLock, IX_OSAL_WAIT_FOREVER);
78 /* check NPE response to GetStatus */
79 msg.data[0] = IX_ETHNPE_NPE_GETSTATUS << 24;
81 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portIndex), msg, result);
82 if (result != IX_SUCCESS)
84 WARNING_LOG("DB: (FeatureScan) warning, could not send message to the NPE\n");
89 if (imageId.functionalityId == 0x00
90 || imageId.functionalityId == 0x03
91 || imageId.functionalityId == 0x04
92 || imageId.functionalityId == 0x80)
94 portInfo->featureCapability |= IX_ETH_DB_FILTERING;
95 portInfo->featureCapability |= IX_ETH_DB_FIREWALL;
96 portInfo->featureCapability |= IX_ETH_DB_SPANNING_TREE_PROTOCOL;
98 else if (imageId.functionalityId == 0x01
99 || imageId.functionalityId == 0x81)
101 portInfo->featureCapability |= IX_ETH_DB_FILTERING;
102 portInfo->featureCapability |= IX_ETH_DB_FIREWALL;
103 portInfo->featureCapability |= IX_ETH_DB_SPANNING_TREE_PROTOCOL;
104 portInfo->featureCapability |= IX_ETH_DB_VLAN_QOS;
106 else if (imageId.functionalityId == 0x02
107 || imageId.functionalityId == 0x82)
109 portInfo->featureCapability |= IX_ETH_DB_WIFI_HEADER_CONVERSION;
110 portInfo->featureCapability |= IX_ETH_DB_FIREWALL;
111 portInfo->featureCapability |= IX_ETH_DB_SPANNING_TREE_PROTOCOL;
112 portInfo->featureCapability |= IX_ETH_DB_VLAN_QOS;
115 /* reset AQM queues */
116 memset(portInfo->ixEthDBTrafficClassAQMAssignments, 0, sizeof (portInfo->ixEthDBTrafficClassAQMAssignments));
118 /* ensure there's at least one traffic class record in the definition table, otherwise we have no default case, hence no queues */
119 IX_ENSURE(sizeof (ixEthDBTrafficClassDefinitions) != 0, "DB: no traffic class definitions found, check IxEthDBQoS.h");
121 /* find the traffic class definition index compatible with the current NPE A functionality ID */
122 for (trafficClassDefinitionIndex = 0 ;
123 trafficClassDefinitionIndex < ARRAY_SIZE(ixEthDBTrafficClassDefinitions);
124 trafficClassDefinitionIndex++)
126 if (ixEthDBTrafficClassDefinitions[trafficClassDefinitionIndex][IX_ETH_DB_NPE_A_FUNCTIONALITY_ID_INDEX] == npeAImageId.functionalityId)
133 /* select the default case if we went over the array boundary */
134 if (trafficClassDefinitionIndex == ARRAY_SIZE(ixEthDBTrafficClassDefinitions))
136 trafficClassDefinitionIndex = 0; /* the first record is the default case */
139 /* select queue assignment structure based on the traffic class configuration index */
140 queueStructureIndex = ixEthDBTrafficClassDefinitions[trafficClassDefinitionIndex][IX_ETH_DB_QUEUE_ASSIGNMENT_INDEX];
142 /* only traffic class 0 is active at initialization time */
143 portInfo->ixEthDBTrafficClassCount = 1;
145 /* enable port, VLAN and Firewall feature bits to initialize QoS/VLAN/Firewall configuration */
146 portInfo->featureStatus |= IX_ETH_DB_VLAN_QOS;
147 portInfo->featureStatus |= IX_ETH_DB_FIREWALL;
148 portInfo->enabled = true;
150 #define CONFIG_WITH_VLAN /* test-only: VLAN support not included to save space!!! */
151 #ifdef CONFIG_WITH_VLAN /* test-only: VLAN support not included to save space!!! */
152 /* set VLAN initial configuration (permissive) */
153 if ((portInfo->featureCapability & IX_ETH_DB_VLAN_QOS) != 0) /* QoS-enabled image */
156 portInfo->ixEthDBTrafficClassAvailable = ixEthDBTrafficClassDefinitions[trafficClassDefinitionIndex][IX_ETH_DB_TRAFFIC_CLASS_COUNT_INDEX];
159 for (queueIndex = 0 ; queueIndex < IX_IEEE802_1Q_QOS_PRIORITY_COUNT ; queueIndex++)
161 portInfo->ixEthDBTrafficClassAQMAssignments[queueIndex] = ixEthDBQueueAssignments[queueStructureIndex][queueIndex];
164 /* set default PVID (0) and default traffic class 0 */
165 ixEthDBPortVlanTagSet(portIndex, 0);
167 /* enable reception of all frames */
168 ixEthDBAcceptableFrameTypeSet(portIndex, IX_ETH_DB_ACCEPT_ALL_FRAMES);
170 /* clear full VLAN membership */
171 ixEthDBPortVlanMembershipRangeRemove(portIndex, 0, IX_ETH_DB_802_1Q_MAX_VLAN_ID);
173 /* clear TTI table - no VLAN tagged frames will be transmitted */
174 ixEthDBEgressVlanRangeTaggingEnabledSet(portIndex, 0, 4094, false);
176 /* set membership on 0, otherwise no Tx or Rx is working */
177 ixEthDBPortVlanMembershipAdd(portIndex, 0);
179 else /* QoS not available in this image */
180 #endif /* test-only */
182 /* initialize traffic class availability (only class 0 is available) */
183 portInfo->ixEthDBTrafficClassAvailable = 1;
185 /* point all AQM queues to traffic class 0 */
186 for (queueIndex = 0 ; queueIndex < IX_IEEE802_1Q_QOS_PRIORITY_COUNT ; queueIndex++)
188 portInfo->ixEthDBTrafficClassAQMAssignments[queueIndex] =
189 ixEthDBQueueAssignments[queueStructureIndex][0];
193 #ifdef CONFIG_WITH_VLAN /* test-only: VLAN support not included to save space!!! */
194 /* download priority mapping table and Rx queue configuration */
195 memset (defaultPriorityTable, 0, sizeof (defaultPriorityTable));
196 ixEthDBPriorityMappingTableSet(portIndex, defaultPriorityTable);
199 /* by default we turn off invalid source MAC address filtering */
200 ixEthDBFirewallInvalidAddressFilterEnable(portIndex, false);
202 /* disable port, VLAN, Firewall feature bits */
203 portInfo->featureStatus &= ~IX_ETH_DB_VLAN_QOS;
204 portInfo->featureStatus &= ~IX_ETH_DB_FIREWALL;
205 portInfo->enabled = false;
207 /* enable filtering by default if present */
208 if ((portInfo->featureCapability & IX_ETH_DB_FILTERING) != 0)
210 portInfo->featureStatus |= IX_ETH_DB_FILTERING;
218 * @brief returns the capability of a port
220 * @param portID ID of the port
221 * @param featureSet location to store the port capability in
223 * This function will save the capability set of the given port
224 * into the given location. Capabilities are bit-ORed, each representing
225 * a bit of the feature set.
227 * Note that this function is documented in the main component
228 * public header file, IxEthDB.h.
230 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
231 * or IX_ETH_DB_INVALID_PORT if the given port is invalid
234 IxEthDBStatus ixEthDBFeatureCapabilityGet(IxEthDBPortId portID, IxEthDBFeature *featureSet)
236 IX_ETH_DB_CHECK_PORT_INITIALIZED(portID);
238 IX_ETH_DB_CHECK_REFERENCE(featureSet);
240 *featureSet = ixEthDBPortInfo[portID].featureCapability;
242 return IX_ETH_DB_SUCCESS;
246 * @brief enables or disables a port capability
248 * @param portID ID of the port
249 * @param feature feature to enable or disable
250 * @param enabled true to enable the selected feature or false to disable it
252 * Note that this function is documented in the main component
253 * header file, IxEthDB.h.
255 * @return IX_ETH_DB_SUCCESS if the operation completed
256 * successfully or an appropriate error message otherwise
259 IxEthDBStatus ixEthDBFeatureEnable(IxEthDBPortId portID, IxEthDBFeature feature, BOOL enable)
262 IxEthDBPriorityTable defaultPriorityTable;
263 IxEthDBVlanSet vlanSet;
264 IxEthDBStatus status = IX_ETH_DB_SUCCESS;
267 IX_ETH_DB_CHECK_PORT_INITIALIZED(portID);
269 portInfo = &ixEthDBPortInfo[portID];
270 portEnabled = portInfo->enabled;
272 /* check that only one feature is selected */
273 if (!ixEthDBCheckSingleBitValue(feature))
275 return IX_ETH_DB_FEATURE_UNAVAILABLE;
278 /* port capable of this feature? */
279 if ((portInfo->featureCapability & feature) == 0)
281 return IX_ETH_DB_FEATURE_UNAVAILABLE;
284 /* mutual exclusion between learning and WiFi header conversion */
285 if (enable && ((feature | portInfo->featureStatus) & (IX_ETH_DB_FILTERING | IX_ETH_DB_WIFI_HEADER_CONVERSION))
286 == (IX_ETH_DB_FILTERING | IX_ETH_DB_WIFI_HEADER_CONVERSION))
288 return IX_ETH_DB_NO_PERMISSION;
291 /* learning must be enabled before filtering */
292 if (enable && (feature == IX_ETH_DB_FILTERING) && ((portInfo->featureStatus & IX_ETH_DB_LEARNING) == 0))
294 return IX_ETH_DB_NO_PERMISSION;
297 /* filtering must be disabled before learning */
298 if (!enable && (feature == IX_ETH_DB_LEARNING) && ((portInfo->featureStatus & IX_ETH_DB_FILTERING) != 0))
300 return IX_ETH_DB_NO_PERMISSION;
303 /* redundant enabling or disabling */
304 if ((!enable && ((portInfo->featureStatus & feature) == 0))
305 || (enable && ((portInfo->featureStatus & feature) != 0)))
308 return IX_ETH_DB_SUCCESS;
311 /* force port enabled */
312 portInfo->enabled = true;
316 /* turn on enable bit */
317 portInfo->featureStatus |= feature;
319 #ifdef CONFIG_WITH_VLAN /* test-only: VLAN support not included to save space!!! */
320 /* if this is VLAN/QoS set the default priority table */
321 if (feature == IX_ETH_DB_VLAN_QOS)
323 /* turn on VLAN/QoS (most permissive mode):
324 - set default 802.1Q priority mapping table, in accordance to the
325 availability of traffic classes
326 - set the acceptable frame filter to accept all
327 - set the Ingress tagging mode to pass-through
328 - set full VLAN membership list
330 - set the default 802.1Q tag to 0 (VLAN ID 0, Pri 0, CFI 0)
331 - enable TPID port extraction
334 portInfo->ixEthDBTrafficClassCount = portInfo->ixEthDBTrafficClassAvailable;
336 /* set default 802.1Q priority mapping table - note that C indexing starts from 0, so we substract 1 here */
337 memcpy (defaultPriorityTable,
338 (const void *) ixEthIEEE802_1QUserPriorityToTrafficClassMapping[portInfo->ixEthDBTrafficClassCount - 1],
339 sizeof (defaultPriorityTable));
341 /* update priority mapping and AQM queue assignments */
342 status = ixEthDBPriorityMappingTableSet(portID, defaultPriorityTable);
344 if (status == IX_ETH_DB_SUCCESS)
346 status = ixEthDBAcceptableFrameTypeSet(portID, IX_ETH_DB_ACCEPT_ALL_FRAMES);
349 if (status == IX_ETH_DB_SUCCESS)
351 status = ixEthDBIngressVlanTaggingEnabledSet(portID, IX_ETH_DB_PASS_THROUGH);
354 /* set membership and TTI tables */
355 memset (vlanSet, 0xFF, sizeof (vlanSet));
357 if (status == IX_ETH_DB_SUCCESS)
359 /* use the internal function to bypass PVID check */
360 status = ixEthDBPortVlanTableSet(portID, portInfo->vlanMembership, vlanSet);
363 if (status == IX_ETH_DB_SUCCESS)
365 /* use the internal function to bypass PVID check */
366 status = ixEthDBPortVlanTableSet(portID, portInfo->transmitTaggingInfo, vlanSet);
370 if (status == IX_ETH_DB_SUCCESS)
372 status = ixEthDBPortVlanTagSet(portID, 0);
375 /* enable TPID port extraction */
376 if (status == IX_ETH_DB_SUCCESS)
378 status = ixEthDBVlanPortExtractionEnable(portID, true);
381 else if (feature == IX_ETH_DB_FIREWALL)
384 /* firewall starts in black-list mode unless otherwise configured before *
385 * note that invalid source MAC address filtering is disabled by default */
386 if (portInfo->firewallMode != IX_ETH_DB_FIREWALL_BLACK_LIST
387 && portInfo->firewallMode != IX_ETH_DB_FIREWALL_WHITE_LIST)
389 status = ixEthDBFirewallModeSet(portID, IX_ETH_DB_FIREWALL_BLACK_LIST);
391 if (status == IX_ETH_DB_SUCCESS)
393 status = ixEthDBFirewallInvalidAddressFilterEnable(portID, false);
398 if (status != IX_ETH_DB_SUCCESS)
400 /* checks failed, disable */
401 portInfo->featureStatus &= ~feature;
406 /* turn off features */
407 if (feature == IX_ETH_DB_FIREWALL)
409 /* turning off the firewall is equivalent to:
410 - set to black-list mode
411 - clear all the entries and download the new table
412 - turn off the invalid source address checking
415 status = ixEthDBDatabaseClear(portID, IX_ETH_DB_FIREWALL_RECORD);
417 if (status == IX_ETH_DB_SUCCESS)
419 status = ixEthDBFirewallModeSet(portID, IX_ETH_DB_FIREWALL_BLACK_LIST);
422 if (status == IX_ETH_DB_SUCCESS)
424 status = ixEthDBFirewallInvalidAddressFilterEnable(portID, false);
427 if (status == IX_ETH_DB_SUCCESS)
429 status = ixEthDBFirewallTableDownload(portID);
432 else if (feature == IX_ETH_DB_WIFI_HEADER_CONVERSION)
434 /* turn off header conversion */
435 status = ixEthDBDatabaseClear(portID, IX_ETH_DB_WIFI_RECORD);
437 if (status == IX_ETH_DB_SUCCESS)
439 status = ixEthDBWiFiConversionTableDownload(portID);
442 #ifdef CONFIG_WITH_VLAN /* test-only: VLAN support not included to save space!!! */
443 else if (feature == IX_ETH_DB_VLAN_QOS)
445 /* turn off VLAN/QoS:
446 - set a priority mapping table with one traffic class
447 - set the acceptable frame filter to accept all
448 - set the Ingress tagging mode to pass-through
449 - clear the VLAN membership list
450 - clear the TTI table
451 - set the default 802.1Q tag to 0 (VLAN ID 0, Pri 0, CFI 0)
452 - disable TPID port extraction
455 /* initialize all => traffic class 0 priority mapping table */
456 memset (defaultPriorityTable, 0, sizeof (defaultPriorityTable));
457 portInfo->ixEthDBTrafficClassCount = 1;
458 status = ixEthDBPriorityMappingTableSet(portID, defaultPriorityTable);
460 if (status == IX_ETH_DB_SUCCESS)
462 status = ixEthDBAcceptableFrameTypeSet(portID, IX_ETH_DB_ACCEPT_ALL_FRAMES);
465 if (status == IX_ETH_DB_SUCCESS)
467 status = ixEthDBIngressVlanTaggingEnabledSet(portID, IX_ETH_DB_PASS_THROUGH);
470 /* clear membership and TTI tables */
471 memset (vlanSet, 0, sizeof (vlanSet));
473 if (status == IX_ETH_DB_SUCCESS)
475 /* use the internal function to bypass PVID check */
476 status = ixEthDBPortVlanTableSet(portID, portInfo->vlanMembership, vlanSet);
479 if (status == IX_ETH_DB_SUCCESS)
481 /* use the internal function to bypass PVID check */
482 status = ixEthDBPortVlanTableSet(portID, portInfo->transmitTaggingInfo, vlanSet);
486 if (status == IX_ETH_DB_SUCCESS)
488 status = ixEthDBPortVlanTagSet(portID, 0);
491 /* disable TPID port extraction */
492 if (status == IX_ETH_DB_SUCCESS)
494 status = ixEthDBVlanPortExtractionEnable(portID, false);
499 if (status == IX_ETH_DB_SUCCESS)
501 /* checks passed, disable */
502 portInfo->featureStatus &= ~feature;
506 /* restore port enabled state */
507 portInfo->enabled = portEnabled;
513 * @brief returns the status of a feature
515 * @param portID port ID
516 * @param present location to store a boolean value indicating
517 * if the feature is present (true) or not (false)
518 * @param enabled location to store a booleam value indicating
519 * if the feature is present (true) or not (false)
521 * Note that this function is documented in the main component
522 * header file, IxEthDB.h.
524 * @return IX_ETH_DB_SUCCESS if the operation completed
525 * successfully or an appropriate error message otherwise
528 IxEthDBStatus ixEthDBFeatureStatusGet(IxEthDBPortId portID, IxEthDBFeature feature, BOOL *present, BOOL *enabled)
532 IX_ETH_DB_CHECK_PORT(portID);
534 IX_ETH_DB_CHECK_REFERENCE(present);
536 IX_ETH_DB_CHECK_REFERENCE(enabled);
538 portInfo = &ixEthDBPortInfo[portID];
540 *present = (portInfo->featureCapability & feature) != 0;
541 *enabled = (portInfo->featureStatus & feature) != 0;
543 return IX_ETH_DB_SUCCESS;
547 * @brief returns the value of an EthDB property
549 * @param portID ID of the port
550 * @param feature feature owning the property
551 * @param property ID of the property
552 * @param type location to store the property type into
553 * @param value location to store the property value into
555 * Note that this function is documented in the main component
556 * header file, IxEthDB.h.
558 * @return IX_ETH_DB_SUCCESS if the operation completed
559 * successfully or an appropriate error message otherwise
562 IxEthDBStatus ixEthDBFeaturePropertyGet(IxEthDBPortId portID, IxEthDBFeature feature, IxEthDBProperty property, IxEthDBPropertyType *type, void *value)
564 IX_ETH_DB_CHECK_PORT_EXISTS(portID);
566 IX_ETH_DB_CHECK_REFERENCE(type);
568 IX_ETH_DB_CHECK_REFERENCE(value);
570 if (feature == IX_ETH_DB_VLAN_QOS)
572 if (property == IX_ETH_DB_QOS_TRAFFIC_CLASS_COUNT_PROPERTY)
574 * (UINT32 *) value = ixEthDBPortInfo[portID].ixEthDBTrafficClassCount;
575 *type = IX_ETH_DB_INTEGER_PROPERTY;
577 return IX_ETH_DB_SUCCESS;
579 else if (property >= IX_ETH_DB_QOS_TRAFFIC_CLASS_0_RX_QUEUE_PROPERTY
580 && property <= IX_ETH_DB_QOS_TRAFFIC_CLASS_7_RX_QUEUE_PROPERTY)
582 UINT32 classDelta = property - IX_ETH_DB_QOS_TRAFFIC_CLASS_0_RX_QUEUE_PROPERTY;
584 if (classDelta >= ixEthDBPortInfo[portID].ixEthDBTrafficClassCount)
586 return IX_ETH_DB_FAIL;
589 * (UINT32 *) value = ixEthDBPortInfo[portID].ixEthDBTrafficClassAQMAssignments[classDelta];
590 *type = IX_ETH_DB_INTEGER_PROPERTY;
592 return IX_ETH_DB_SUCCESS;
596 return IX_ETH_DB_INVALID_ARG;
600 * @brief sets the value of an EthDB property
602 * @param portID ID of the port
603 * @param feature feature owning the property
604 * @param property ID of the property
605 * @param value location containing the property value
607 * This function implements a private property intended
608 * only for EthAcc usage. Upon setting the IX_ETH_DB_QOS_QUEUE_CONFIGURATION_COMPLETE
609 * property (the value is ignored), the availability of traffic classes is
610 * frozen to whatever traffic class structure is currently in use.
611 * This means that if VLAN_QOS has been enabled before EthAcc
612 * initialization then all the defined traffic classes will be available;
613 * otherwise only one traffic class (0) will be available.
615 * Note that this function is documented in the main component
616 * header file, IxEthDB.h as not accepting any parameters. The
617 * current implementation is only intended for the private use of EthAcc.
619 * Also note that once this function is called the effect is irreversible,
620 * unless EthDB is complete unloaded and re-initialized.
622 * @return IX_ETH_DB_INVALID_ARG (no read-write properties are
623 * supported in this release)
626 IxEthDBStatus ixEthDBFeaturePropertySet(IxEthDBPortId portID, IxEthDBFeature feature, IxEthDBProperty property, void *value)
628 IX_ETH_DB_CHECK_PORT_EXISTS(portID);
630 if ((feature == IX_ETH_DB_VLAN_QOS) && (property == IX_ETH_DB_QOS_QUEUE_CONFIGURATION_COMPLETE))
632 ixEthDBPortInfo[portID].ixEthDBTrafficClassAvailable = ixEthDBPortInfo[portID].ixEthDBTrafficClassCount;
634 return IX_ETH_DB_SUCCESS;
637 return IX_ETH_DB_INVALID_ARG;