1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45#include <IxEthDB.h>
46#include <IxNpeMh.h>
47#include <IxFeatureCtrl.h>
48
49#include "IxEthDB_p.h"
50#include "IxEthDBMessages_p.h"
51#include "IxEthDB_p.h"
52#include "IxEthDBLog_p.h"
53
54#ifdef IX_UNIT_TEST
55
56int dbAccessCounter = 0;
57int overflowEvent = 0;
58
59#endif
60
61
62
63
64extern HashTable dbHashtable;
65
66
67
68
69IX_ETH_DB_PUBLIC
70PortInfo ixEthDBPortInfo[IX_ETH_DB_NUMBER_OF_PORTS];
71
72IX_ETH_DB_PRIVATE
73struct
74{
75 BOOL saved;
76 IxEthDBPriorityTable priorityTable;
77 IxEthDBVlanSet vlanMembership;
78 IxEthDBVlanSet transmitTaggingInfo;
79 IxEthDBFrameFilter frameFilter;
80 IxEthDBTaggingAction taggingAction;
81 IxEthDBFirewallMode firewallMode;
82 BOOL stpBlocked;
83 BOOL srcAddressFilterEnabled;
84 UINT32 maxRxFrameSize;
85 UINT32 maxTxFrameSize;
86} ixEthDBPortState[IX_ETH_DB_NUMBER_OF_PORTS];
87
88#define IX_ETH_DB_DEFAULT_FRAME_SIZE (1518)
89
90
91
92
93
94
95
96
97
98
99
100
101IX_ETH_DB_PUBLIC
102void ixEthDBPortInit(IxEthDBPortId portID)
103{
104 PortInfo *portInfo;
105
106 if (portID >= IX_ETH_DB_NUMBER_OF_PORTS)
107 {
108 return;
109 }
110
111 portInfo = &ixEthDBPortInfo[portID];
112
113 if (ixEthDBSingleEthNpeCheck(portID) != IX_ETH_DB_SUCCESS)
114 {
115 WARNING_LOG("EthDB: Unavailable Eth %d: Cannot initialize EthDB Port.\n", (UINT32) portID);
116
117 return;
118 }
119
120 if (portInfo->initialized)
121 {
122
123 return;
124 }
125
126
127 portInfo->portID = portID;
128 SET_DEPENDENCY_MAP(portInfo->dependencyPortMap, portID);
129
130
131 portInfo->agingEnabled = FALSE;
132 portInfo->enabled = FALSE;
133 portInfo->macAddressUploaded = FALSE;
134 portInfo->maxRxFrameSize = IX_ETHDB_DEFAULT_FRAME_SIZE;
135 portInfo->maxTxFrameSize = IX_ETHDB_DEFAULT_FRAME_SIZE;
136
137
138 portInfo->updateMethod.searchTree = NULL;
139 portInfo->updateMethod.searchTreePendingWrite = FALSE;
140 portInfo->updateMethod.treeInitialized = FALSE;
141 portInfo->updateMethod.updateEnabled = FALSE;
142 portInfo->updateMethod.userControlled = FALSE;
143
144
145 memset(portInfo->bbsid, 0, sizeof (portInfo->bbsid));
146 portInfo->frameControlDurationID = 0;
147
148
149 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
150 {
151
152 portInfo->updateMethod.updateHandler = ixEthDBNPEUpdateHandler;
153 }
154
155
156 ixEthDBPortState[portID].saved = FALSE;
157
158 portInfo->initialized = TRUE;
159}
160
161
162
163
164
165
166
167
168
169
170
171
172IX_ETH_DB_PUBLIC
173IxEthDBStatus ixEthDBPortEnable(IxEthDBPortId portID)
174{
175 IxEthDBPortMap triggerPorts;
176 PortInfo *portInfo;
177
178 IX_ETH_DB_CHECK_PORT_EXISTS(portID);
179
180 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
181
182 portInfo = &ixEthDBPortInfo[portID];
183
184 if (portInfo->enabled)
185 {
186
187 return IX_ETH_DB_SUCCESS;
188 }
189
190 SET_DEPENDENCY_MAP(triggerPorts, portID);
191
192
193 portInfo->enabled = TRUE;
194
195
196 if(IX_FEATURE_CTRL_SWCONFIG_DISABLED ==
197 ixFeatureCtrlSwConfigurationCheck(IX_FEATURECTRL_ETH_LEARNING))
198 {
199 return IX_ETH_DB_SUCCESS;
200 }
201
202 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE && !portInfo->macAddressUploaded)
203 {
204 IX_ETH_DB_SUPPORT_TRACE("DB: (Support) MAC address not set on port %d, enable failed\n", portID);
205
206
207 return IX_ETH_DB_MAC_UNINITIALIZED;
208 }
209
210 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
211 {
212 IX_ETH_DB_SUPPORT_TRACE("DB: (Support) Attempting to enable the NPE callback for port %d...\n", portID);
213
214 if (!portInfo->updateMethod.userControlled
215 && ((portInfo->featureCapability & IX_ETH_DB_FILTERING) != 0))
216 {
217 portInfo->updateMethod.updateEnabled = TRUE;
218 }
219
220
221
222 if (!portInfo->updateMethod.treeInitialized)
223 {
224 IX_ETH_DB_SUPPORT_TRACE("DB: (Support) Initializing tree for port %d\n", portID);
225
226
227 ixEthDBUpdatePortLearningTrees(triggerPorts);
228
229
230 portInfo->updateMethod.treeInitialized = TRUE;
231 }
232 }
233
234 if (ixEthDBPortState[portID].saved)
235 {
236
237 if ((portInfo->featureCapability & IX_ETH_DB_FIREWALL) != 0)
238 {
239 ixEthDBFirewallModeSet(portID, ixEthDBPortState[portID].firewallMode);
240 ixEthDBFirewallInvalidAddressFilterEnable(portID, ixEthDBPortState[portID].srcAddressFilterEnabled);
241 }
242
243#if 0
244 if ((portInfo->featureCapability & IX_ETH_DB_VLAN_QOS) != 0)
245 {
246 ixEthDBAcceptableFrameTypeSet(portID, ixEthDBPortState[portID].frameFilter);
247 ixEthDBIngressVlanTaggingEnabledSet(portID, ixEthDBPortState[portID].taggingAction);
248
249 ixEthDBEgressVlanTaggingEnabledSet(portID, ixEthDBPortState[portID].transmitTaggingInfo);
250 ixEthDBPortVlanMembershipSet(portID, ixEthDBPortState[portID].vlanMembership);
251
252 ixEthDBPriorityMappingTableSet(portID, ixEthDBPortState[portID].priorityTable);
253 }
254#endif
255
256 if ((portInfo->featureCapability & IX_ETH_DB_SPANNING_TREE_PROTOCOL) != 0)
257 {
258 ixEthDBSpanningTreeBlockingStateSet(portID, ixEthDBPortState[portID].stpBlocked);
259 }
260
261 ixEthDBFilteringPortMaximumRxFrameSizeSet(portID, ixEthDBPortState[portID].maxRxFrameSize);
262 ixEthDBFilteringPortMaximumTxFrameSizeSet(portID, ixEthDBPortState[portID].maxTxFrameSize);
263
264
265 ixEthDBPortState[portID].saved = FALSE;
266 }
267
268 IX_ETH_DB_SUPPORT_TRACE("DB: (Support) Enabling succeeded for port %d\n", portID);
269
270 return IX_ETH_DB_SUCCESS;
271}
272
273
274
275
276
277
278
279
280
281
282
283
284
285IX_ETH_DB_PUBLIC
286IxEthDBStatus ixEthDBPortDisable(IxEthDBPortId portID)
287{
288 HashIterator iterator;
289 IxEthDBPortMap triggerPorts;
290 BOOL result;
291 PortInfo *portInfo;
292 IxEthDBFeature learningEnabled;
293#if 0
294 IxEthDBPriorityTable classZeroTable;
295#endif
296
297 IX_ETH_DB_CHECK_PORT_EXISTS(portID);
298
299 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
300
301 portInfo = &ixEthDBPortInfo[portID];
302
303 if (!portInfo->enabled)
304 {
305
306 return IX_ETH_DB_SUCCESS;
307 }
308
309 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
310 {
311
312 ixEthDBPortState[portID].firewallMode = portInfo->firewallMode;
313 ixEthDBPortState[portID].frameFilter = portInfo->frameFilter;
314 ixEthDBPortState[portID].taggingAction = portInfo->taggingAction;
315 ixEthDBPortState[portID].stpBlocked = portInfo->stpBlocked;
316 ixEthDBPortState[portID].srcAddressFilterEnabled = portInfo->srcAddressFilterEnabled;
317 ixEthDBPortState[portID].maxRxFrameSize = portInfo->maxRxFrameSize;
318 ixEthDBPortState[portID].maxTxFrameSize = portInfo->maxTxFrameSize;
319
320 memcpy(ixEthDBPortState[portID].vlanMembership, portInfo->vlanMembership, sizeof (IxEthDBVlanSet));
321 memcpy(ixEthDBPortState[portID].transmitTaggingInfo, portInfo->transmitTaggingInfo, sizeof (IxEthDBVlanSet));
322 memcpy(ixEthDBPortState[portID].priorityTable, portInfo->priorityTable, sizeof (IxEthDBPriorityTable));
323
324 ixEthDBPortState[portID].saved = TRUE;
325
326
327
328#if 0
329
330 if ((portInfo->featureCapability & IX_ETH_DB_VLAN_QOS) != 0)
331 {
332 ixEthDBPortVlanMembershipRangeAdd((IxEthDBPortId) portID, 0, IX_ETH_DB_802_1Q_MAX_VLAN_ID);
333 ixEthDBEgressVlanRangeTaggingEnabledSet((IxEthDBPortId) portID, 0, IX_ETH_DB_802_1Q_MAX_VLAN_ID, FALSE);
334 ixEthDBAcceptableFrameTypeSet((IxEthDBPortId) portID, IX_ETH_DB_ACCEPT_ALL_FRAMES);
335 ixEthDBIngressVlanTaggingEnabledSet((IxEthDBPortId) portID, IX_ETH_DB_PASS_THROUGH);
336
337 memset(classZeroTable, 0, sizeof (classZeroTable));
338 ixEthDBPriorityMappingTableSet((IxEthDBPortId) portID, classZeroTable);
339 }
340#endif
341
342
343 if ((portInfo->featureCapability & IX_ETH_DB_SPANNING_TREE_PROTOCOL) != 0)
344 {
345 ixEthDBSpanningTreeBlockingStateSet((IxEthDBPortId) portID, FALSE);
346 }
347
348
349 if ((portInfo->featureCapability & IX_ETH_DB_FIREWALL) != 0)
350 {
351 ixEthDBFirewallModeSet((IxEthDBPortId) portID, IX_ETH_DB_FIREWALL_BLACK_LIST);
352 ixEthDBFirewallTableDownload((IxEthDBPortId) portID);
353 ixEthDBFirewallInvalidAddressFilterEnable((IxEthDBPortId) portID, FALSE);
354 }
355
356
357 ixEthDBFilteringPortMaximumFrameSizeSet((IxEthDBPortId) portID, IX_ETH_DB_DEFAULT_FRAME_SIZE);
358
359
360 if ((portInfo->featureCapability & IX_ETH_DB_WIFI_HEADER_CONVERSION) != 0)
361 {
362 ixEthDBWiFiConversionTableDownload((IxEthDBPortId) portID);
363 }
364
365
366 learningEnabled = portInfo->featureStatus & IX_ETH_DB_LEARNING;
367 portInfo->featureStatus &= ~IX_ETH_DB_LEARNING;
368 }
369 else
370 {
371
372 learningEnabled = portInfo->featureStatus & IX_ETH_DB_LEARNING;
373 }
374
375 SET_EMPTY_DEPENDENCY_MAP(triggerPorts);
376
377 ixEthDBUpdateLock();
378
379
380 BUSY_RETRY(ixEthDBInitHashIterator(&dbHashtable, &iterator));
381
382 while (IS_ITERATOR_VALID(&iterator))
383 {
384 MacDescriptor *descriptor = (MacDescriptor *) iterator.node->data;
385
386
387 if (descriptor->portID == portID
388 && (descriptor->type == IX_ETH_DB_FILTERING_RECORD || descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD)
389 && !descriptor->recordData.filteringData.staticEntry)
390 {
391
392 BUSY_RETRY(ixEthDBRemoveEntryAtHashIterator(&dbHashtable, &iterator));
393
394
395 JOIN_PORT_TO_MAP(triggerPorts, portID);
396 }
397 else
398 {
399
400 BUSY_RETRY(ixEthDBIncrementHashIterator(&dbHashtable, &iterator));
401 }
402 }
403
404 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
405 {
406 if (portInfo->updateMethod.searchTree != NULL)
407 {
408 ixEthDBFreeMacTreeNode(portInfo->updateMethod.searchTree);
409 portInfo->updateMethod.searchTree = NULL;
410 }
411
412 ixEthDBNPEUpdateHandler(portID, IX_ETH_DB_FILTERING_RECORD);
413 }
414
415
416 portInfo->enabled = FALSE;
417
418
419 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
420 {
421 if (!portInfo->updateMethod.userControlled)
422 {
423 portInfo->updateMethod.updateEnabled = FALSE;
424 }
425
426
427 portInfo->updateMethod.treeInitialized = FALSE;
428 }
429
430 ixEthDBUpdateUnlock();
431
432
433 portInfo->featureStatus |= learningEnabled;
434
435
436 IS_EMPTY_DEPENDENCY_MAP(result, triggerPorts);
437
438 if (!result)
439 {
440 ixEthDBUpdatePortLearningTrees(triggerPorts);
441 }
442
443 return IX_ETH_DB_SUCCESS;
444}
445
446
447
448
449
450
451
452
453
454
455
456IX_ETH_DB_PRIVATE
457IxEthDBStatus ixEthDBPortFrameLengthsUpdate(IxEthDBPortId portID)
458{
459 IxNpeMhMessage message;
460 PortInfo *portInfo = &ixEthDBPortInfo[portID];
461 IX_STATUS result;
462
463 FILL_SETMAXFRAMELENGTHS_MSG(message, portID, portInfo->maxRxFrameSize, portInfo->maxTxFrameSize);
464
465 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result);
466
467 return result;
468}
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485IX_ETH_DB_PUBLIC
486IxEthDBStatus ixEthDBFilteringPortMaximumRxFrameSizeSet(IxEthDBPortId portID, UINT32 maximumRxFrameSize)
487{
488 IX_ETH_DB_CHECK_PORT_EXISTS(portID);
489
490 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
491
492 if (!ixEthDBPortInfo[portID].initialized)
493 {
494 return IX_ETH_DB_PORT_UNINITIALIZED;
495 }
496
497 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
498 {
499 if ((maximumRxFrameSize < IX_ETHDB_MIN_NPE_FRAME_SIZE) ||
500 (maximumRxFrameSize > IX_ETHDB_MAX_NPE_FRAME_SIZE))
501 {
502 return IX_ETH_DB_INVALID_ARG;
503 }
504 }
505 else
506 {
507 return IX_ETH_DB_NO_PERMISSION;
508 }
509
510
511 ixEthDBPortInfo[portID].maxRxFrameSize = maximumRxFrameSize;
512
513
514 return ixEthDBPortFrameLengthsUpdate(portID);
515}
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532IX_ETH_DB_PUBLIC
533IxEthDBStatus ixEthDBFilteringPortMaximumTxFrameSizeSet(IxEthDBPortId portID, UINT32 maximumTxFrameSize)
534{
535 IX_ETH_DB_CHECK_PORT_EXISTS(portID);
536
537 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
538
539 if (!ixEthDBPortInfo[portID].initialized)
540 {
541 return IX_ETH_DB_PORT_UNINITIALIZED;
542 }
543
544 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
545 {
546 if ((maximumTxFrameSize < IX_ETHDB_MIN_NPE_FRAME_SIZE) ||
547 (maximumTxFrameSize > IX_ETHDB_MAX_NPE_FRAME_SIZE))
548 {
549 return IX_ETH_DB_INVALID_ARG;
550 }
551 }
552 else
553 {
554 return IX_ETH_DB_NO_PERMISSION;
555 }
556
557
558 ixEthDBPortInfo[portID].maxTxFrameSize = maximumTxFrameSize;
559
560
561 return ixEthDBPortFrameLengthsUpdate(portID);
562}
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583IX_ETH_DB_PUBLIC
584IxEthDBStatus ixEthDBFilteringPortMaximumFrameSizeSet(IxEthDBPortId portID, UINT32 maximumFrameSize)
585{
586 IX_ETH_DB_CHECK_PORT_EXISTS(portID);
587
588 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
589
590 if (!ixEthDBPortInfo[portID].initialized)
591 {
592 return IX_ETH_DB_PORT_UNINITIALIZED;
593 }
594
595 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
596 {
597 if ((maximumFrameSize < IX_ETHDB_MIN_NPE_FRAME_SIZE) ||
598 (maximumFrameSize > IX_ETHDB_MAX_NPE_FRAME_SIZE))
599 {
600 return IX_ETH_DB_INVALID_ARG;
601 }
602 }
603 else
604 {
605 return IX_ETH_DB_NO_PERMISSION;
606 }
607
608
609 ixEthDBPortInfo[portID].maxRxFrameSize = maximumFrameSize;
610 ixEthDBPortInfo[portID].maxTxFrameSize = maximumFrameSize;
611
612
613 return ixEthDBPortFrameLengthsUpdate(portID);
614}
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629IX_ETH_DB_PUBLIC
630IxEthDBStatus ixEthDBPortAddressSet(IxEthDBPortId portID, IxEthDBMacAddr *macAddr)
631{
632 IxNpeMhMessage message;
633 IxOsalMutex *ackPortAddressLock;
634 IX_STATUS result;
635
636
637
638 IX_ETH_DB_CHECK_PORT_EXISTS(portID);
639
640 IX_ETH_DB_CHECK_REFERENCE(macAddr);
641
642 if (!ixEthDBPortInfo[portID].initialized)
643 {
644 return IX_ETH_DB_PORT_UNINITIALIZED;
645 }
646
647 ackPortAddressLock = &ixEthDBPortInfo[portID].npeAckLock;
648
649
650 if(IX_FEATURE_CTRL_SWCONFIG_DISABLED ==
651 ixFeatureCtrlSwConfigurationCheck(IX_FEATURECTRL_ETH_LEARNING))
652 {
653 return IX_ETH_DB_SUCCESS;
654 }
655
656 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
657
658
659 if (ixEthDBPortDefinitions[portID].type != IX_ETH_NPE)
660 {
661 return IX_ETH_DB_INVALID_PORT;
662 }
663
664
665 FILL_SETPORTADDRESS_MSG(message, portID, macAddr->macAddress);
666
667 IX_ETH_DB_SUPPORT_TRACE("DB: (Support) Sending SetPortAddress on port %d...\n", portID);
668
669
670 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result);
671
672 if (result == IX_SUCCESS)
673 {
674 ixEthDBPortInfo[portID].macAddressUploaded = TRUE;
675 }
676
677 return result;
678}
679