blob: e7c67ae520d16ab3ea2367b784caf2b845fdb5d5 [file] [log] [blame]
Wolfgang Denk4646d2a2006-05-30 15:56:48 +02001/**
2 * @file IxEthDB_p.h
3 *
4 * @brief Private MAC learning API
5 *
6 * @par
7 * IXP400 SW Release version 2.0
8 *
9 * -- Copyright Notice --
10 *
11 * @par
12 * Copyright 2001-2005, Intel Corporation.
13 * All rights reserved.
14 *
15 * @par
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the Intel Corporation nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * @par
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @par
42 * -- End of Copyright Notice --
43 */
44
45#ifndef IxEthDB_p_H
46#define IxEthDB_p_H
47
48#include <IxTypes.h>
49#include <IxOsal.h>
50#include <IxEthDB.h>
51#include <IxNpeMh.h>
52#include <IxEthDBPortDefs.h>
53
54#include "IxEthDBMessages_p.h"
55#include "IxEthDBLog_p.h"
56
57#if (CPU==SIMSPARCSOLARIS)
58
59/* when running unit tests intLock() won't protect the event queue so we lock it manually */
60#define TEST_FIXTURE_LOCK_EVENT_QUEUE { ixOsalMutexLock(&eventQueueLock, IX_OSAL_WAIT_FOREVER); }
61#define TEST_FIXTURE_UNLOCK_EVENT_QUEUE { ixOsalMutexUnlock(&eventQueueLock); }
62
63#else
64
65#define TEST_FIXTURE_LOCK_EVENT_QUEUE /* nothing */
66#define TEST_FIXTURE_UNLOCK_EVENT_QUEUE /* nothing */
67
68#endif /* #if(CPU==SIMSPARCSOLARIS) */
69
70#ifndef IX_UNIT_TEST
71
72#define TEST_FIXTURE_INCREMENT_DB_CORE_ACCESS_COUNTER /* nothing */
73#define TEST_FIXTURE_MARK_OVERFLOW_EVENT /* nothing */
74
75#else
76
77extern int dbAccessCounter;
78extern int overflowEvent;
79
80#define TEST_FIXTURE_INCREMENT_DB_CORE_ACCESS_COUNTER { dbAccessCounter++; }
81#define TEST_FIXTURE_MARK_OVERFLOW_EVENT { overflowEvent = 1; }
82
83#endif
84
85/* code readability markers */
86#define __mempool__ /* memory pool marker */
87#define __lock__ /* hash write locking marker */
88#define __smartpointer__ /* smart pointer marker - warning: use only clone() when duplicating! */
89#define __alignment__ /* marker for data used only as alignment zones */
90
91/* constants */
92#define IX_ETH_DB_NPE_TIMEOUT (100) /* NPE response timeout, in ms */
93
94/**
95 * number of hash table buckets
96 * it should be at least 8x the predicted number of entries for performance
97 * each bucket needs 8 bytes
98 */
99#define NUM_BUCKETS (8192)
100
101/**
102 * number of hash table buckets to preload when incrementing bucket iterator
103 * = two cache lines
104 */
105#define IX_ETHDB_CACHE_LINE_AHEAD (2)
106
107#define IX_ETHDB_BUCKETPTR_AHEAD ((IX_ETHDB_CACHE_LINE_AHEAD * IX_OSAL_CACHE_LINE_SIZE)/sizeof(void *))
108
109#define IX_ETHDB_BUCKET_INDEX_MASK (((IX_OSAL_CACHE_LINE_SIZE)/sizeof(void *)) - 1)
110
111/* locks */
112#define MAX_LOCKS (20) /**< maximum number of locks used simultaneously, do not tamper with */
113
114/* learning tree constants */
115#define INITIAL_ELT_SIZE (8) /**< initial byte size of tree (empty unused root size) */
116#define MAX_ELT_SIZE (512) /**< maximum number of entries (includes unused root) */
117#define MAX_GW_SIZE (32) /**< maximum number of gateway entries (including unused root) */
118#define MAX_FW_SIZE (32) /**< maximum number of firewall entries (including unused root) */
119#define ELT_ENTRY_SIZE (8) /**< entry size, in bytes */
120#define ELT_ROOT_OFFSET (ELT_ENTRY_SIZE) /**< tree root offset, in bytes - node preceeding root is unused */
121#define FULL_ELT_BYTE_SIZE (MAX_ELT_SIZE * ELT_ENTRY_SIZE) /**< full size of tree, in bytes, including unused root */
122#define FULL_GW_BYTE_SIZE (MAX_GW_SIZE * ELT_ENTRY_SIZE) /**< full size of gateway list, in bytes, including unused root */
123#define FULL_FW_BYTE_SIZE (MAX_FW_SIZE * ELT_ENTRY_SIZE) /**< full size of firewall table, in bytes, including unused root */
124
125/* maximum size of the VLAN table:
126 * 4096 bits (one per VLAN)
127 * 8 bits in one byte
128 * interleaved VLAN membership and VLAN TTI (*2) */
129#define FULL_VLAN_BYTE_SIZE (4096 / 8 * 2)
130
131/* upper 9 bits used as set index, lower 3 bits as byte index */
132#define VLAN_SET_OFFSET(vlanID) ((vlanID) >> 3)
133#define VLAN_SET_MASK(vlanID) (0x7 - ((vlanID) & 0x7))
134
135/* Update zone definitions */
136#define NPE_TREE_MEM_SIZE (4096) /* ((511 entries + 1 unused root) * 8 bytes/entry) */
137
138/* check the above value, we rely on 4k */
139#if NPE_TREE_MEM_SIZE != 4096
140 #error NPE_TREE_MEM_SIZE is not defined to 4096 bytes!
141#endif
142
143/* Size Filtering limits (Jumbo frame filtering) */
144#define IX_ETHDB_MAX_FRAME_SIZE 65535 /* other ports than NPE ports */
145#define IX_ETHDB_MIN_FRAME_SIZE 1 /* other ports than NPE ports */
146#define IX_ETHDB_MAX_NPE_FRAME_SIZE 16320 /* NPE ports firmware limit */
147#define IX_ETHDB_MIN_NPE_FRAME_SIZE 1 /* NPE ports firmware limit */
148#define IX_ETHDB_DEFAULT_FRAME_SIZE 1522
149
150/* memory management pool sizes */
151
152/*
153 * Note:
154 *
155 * NODE_POOL_SIZE controls the maximum number of elements in the database at any one time.
156 * It should be large enough to cover all the search trees of all the ports simultaneously.
157 *
158 * MAC_POOL_SIZE should be higher than NODE_POOL_SIZE by at least the total number of MAC addresses
159 * possible to be held at any time in all the ports.
160 *
161 * TREE_POOL_SIZE should follow the same guideline as for MAC_POOL_SIZE.
162 *
163 * The database structure described here (2000/4000/4000) is enough for two NPEs holding at most 511
164 * entries each plus one PCI NIC holding at most 900 entries.
165 */
166
167#define NODE_POOL_SIZE (2000) /**< number of HashNode objects - also master number of elements in the database; each entry has 16 bytes */
168#define MAC_POOL_SIZE (4000) /**< number of MacDescriptor objects; each entry has 28 bytes */
169#define TREE_POOL_SIZE (4000) /**< number of MacTreeNode objects; each entry has 16 bytes */
170
171/* retry policies */
172#define BUSY_RETRY_ENABLED (TRUE) /**< if set to TRUE the API will retry automatically calls returning BUSY */
173#define FOREVER_RETRY (TRUE) /**< if set to TRUE the API will retry forever BUSY calls */
174#define MAX_RETRIES (400) /**< upper retry limit - used only when FOREVER_RETRY is FALSE */
175#define BUSY_RETRY_YIELD (5) /**< ticks to yield for every failed retry */
176
177/* event management */
178#define EVENT_QUEUE_SIZE (500) /**< size of the sink collecting events from the Message Handler FIFO */
179#define EVENT_PROCESSING_LIMIT (100) /**< batch processing control size (how many events are extracted from the queue at once) */
180
181/* MAC descriptors */
182#define STATIC_ENTRY (TRUE)
183#define DYNAMIC_ENTRY (FALSE)
184
185/* age reset on next maintenance - incrementing by 1 will reset to 0 */
186#define AGE_RESET (0xFFFFFFFF)
187
188/* dependency maps */
189#define EMPTY_DEPENDENCY_MAP (0)
190
191/* trees */
192#define RIGHT (1)
193#define LEFT (-1)
194
195/* macros */
196#define MIN(a, b) ((a) < (b) ? (a) : (b))
197
198#define IX_ETH_DB_CHECK_PORT_EXISTS(portID) \
199{ \
200 if ((portID) >= IX_ETH_DB_NUMBER_OF_PORTS) \
201 { \
202 return IX_ETH_DB_INVALID_PORT; \
203 } \
204}
205
206#define IX_ETH_DB_CHECK_PORT_INITIALIZED(portID) \
207{ \
208 if ((portID) >= IX_ETH_DB_NUMBER_OF_PORTS) \
209 { \
210 return IX_ETH_DB_INVALID_PORT; \
211 } \
212 else \
213 { \
214 if (!ixEthDBPortInfo[portID].initialized) \
215 { \
216 return IX_ETH_DB_PORT_UNINITIALIZED; \
217 } \
218 } \
219}
220
221/* single NPE check */
222#define IX_ETH_DB_CHECK_SINGLE_NPE(portID) \
223 if (ixEthDBSingleEthNpeCheck(portID) != IX_ETH_DB_SUCCESS) \
224 { \
225 WARNING_LOG("EthDB: port ID %d is unavailable\n",(UINT32) portID); \
226 \
227 return IX_ETH_DB_INVALID_PORT; \
228 }
229
230/* feature check */
231#define IX_ETH_DB_CHECK_FEATURE(portID, feature) \
232 if ((ixEthDBPortInfo[portID].featureStatus & feature) == 0) \
233 { \
234 return IX_ETH_DB_FEATURE_UNAVAILABLE; \
235 }
236
237/* busy retrying */
238#define BUSY_RETRY(functionCall) \
239 { \
240 UINT32 retries = 0; \
241 IxEthDBStatus br_result; \
242 \
243 while ((br_result = functionCall) == IX_ETH_DB_BUSY \
244 && BUSY_RETRY_ENABLED && (FOREVER_RETRY || ++retries < MAX_RETRIES)) { ixOsalSleep(BUSY_RETRY_YIELD); }; \
245 \
246 if ((!FOREVER_RETRY && retries == MAX_RETRIES) || (br_result == IX_ETH_DB_FAIL)) \
247 {\
248 ERROR_LOG("Ethernet Learning Database Error: BUSY_RETRY failed at %s:%d\n", __FILE__, __LINE__); \
249 }\
250 }
251
252#define BUSY_RETRY_WITH_RESULT(functionCall, brwr_result) \
253 { \
254 UINT32 retries = 0; \
255 \
256 while ((brwr_result = functionCall) == IX_ETH_DB_BUSY \
257 && BUSY_RETRY_ENABLED && (FOREVER_RETRY || ++retries < MAX_RETRIES)) { ixOsalSleep(BUSY_RETRY_YIELD); }; \
258 \
259 if ((!FOREVER_RETRY && retries == MAX_RETRIES) || (brwr_result == IX_ETH_DB_FAIL)) \
260 {\
261 ERROR_LOG("Ethernet Learning Database Error: BUSY_RETRY_WITH_RESULT failed at %s:%d\n", __FILE__, __LINE__); \
262 }\
263 }
264
265/* iterators */
266#define IS_ITERATOR_VALID(iteratorPtr) ((iteratorPtr)->node != NULL)
267
268/* dependency port maps */
269
270/* Warning: if port indexing starts from 1 replace (portID) with (portID - 1) in DEPENDENCY_MAP (and make sure IX_ETH_DB_NUMBER_OF_PORTS is big enough) */
271
272/* gives an empty dependency map */
273#define SET_EMPTY_DEPENDENCY_MAP(map) { int i = 0; for (; i < 32 ; i++) map[i] = 0; }
274
275#define IS_EMPTY_DEPENDENCY_MAP(result, map) { int i = 0 ; result = TRUE; for (; i < 32 ; i++) if (map[i] != 0) { result = FALSE; break; }}
276
277/**
278 * gives a map consisting only of 'portID'
279 */
280#define SET_DEPENDENCY_MAP(map, portID) {SET_EMPTY_DEPENDENCY_MAP(map); map[portID >> 3] = 1 << (portID & 0x7);}
281
282/**
283 * gives a map resulting from joining map1 and map2
284 */
285#define JOIN_MAPS(map, map1, map2) { int i = 0; for (; i < 32 ; i++) map[i] = map1[i] | map2[i]; }
286
287/**
288 * gives the map resulting from joining portID and map
289 */
290#define JOIN_PORT_TO_MAP(map, portID) { map[portID >> 3] |= 1 << (portID & 0x7); }
291
292/**
293 * gives the map resulting from excluding portID from map
294 */
295#define EXCLUDE_PORT_FROM_MAP(map, portID) { map[portID >> 3] &= ~(1 << (portID & 0x7); }
296
297/**
298 * returns TRUE if map1 is a subset of map2 and FALSE otherwise
299 */
300#define IS_MAP_SUBSET(result, map1, map2) { int i = 0; result = TRUE; for (; i < 32 ; i++) if ((map1[i] | map2[i]) != map2[i]) result = FALSE; }
301
302/**
303 * returns TRUE is portID is part of map and FALSE otherwise
304 */
305#define IS_PORT_INCLUDED(portID, map) ((map[portID >> 3] & (1 << (portID & 0x7))) != 0)
306
307/**
308 * returns the difference between map1 and map2 (ports included in map1 and not included in map2)
309 */
310#define DIFF_MAPS(map, map1, map2) { int i = 0; for (; i < 32 ; i++) map[i] = map1[i] ^ (map1[i] & map2[i]); }
311
312/**
313 * returns TRUE if the maps collide (have at least one port in common) and FALSE otherwise
314 */
315#define MAPS_COLLIDE(result, map1, map2) { int i = 0; result = FALSE; for (; i < 32 ; i++) if ((map1[i] & map2[i]) != 0) result = TRUE; }
316
317/* size (number of ports) of a dependency map */
318#define GET_MAP_SIZE(map, size) { int i = 0, b = 0; size = 0; for (; i < 32 ; i++) { char y = map[i]; for (; b < 8 && (y >>= 1); b++) size += (y & 1); }}
319
320/* copy map2 into map1 */
321#define COPY_DEPENDENCY_MAP(map1, map2) { memcpy (map1, map2, sizeof (map1)); }
322
323/* definition of a port map size/port number which cannot be reached (we support at most 32 ports) */
324#define MAX_PORT_SIZE (0xFF)
325#define MAX_PORT_NUMBER (0xFF)
326
327#define IX_ETH_DB_CHECK_REFERENCE(ptr) { if ((ptr) == NULL) { return IX_ETH_DB_INVALID_ARG; } }
328#define IX_ETH_DB_CHECK_MAP(portID, map) { if (!IS_PORT_INCLUDED(portID, map)) { return IX_ETH_DB_INVALID_ARG; } }
329
330/* event queue macros */
331#define EVENT_QUEUE_WRAP(offset) ((offset) >= EVENT_QUEUE_SIZE ? (offset) - EVENT_QUEUE_SIZE : (offset))
332
333#define CAN_ENQUEUE(eventQueuePtr) ((eventQueuePtr)->length < EVENT_QUEUE_SIZE)
334
335#define QUEUE_HEAD(eventQueuePtr) (&(eventQueuePtr)->queue[EVENT_QUEUE_WRAP((eventQueuePtr)->base + (eventQueuePtr)->length)])
336
337#define QUEUE_TAIL(eventQueuePtr) (&(eventQueuePtr)->queue[(eventQueuePtr)->base])
338
339#define PUSH_UPDATE_QUEUE(eventQueuePtr) { (eventQueuePtr)->length++; }
340
341#define SHIFT_UPDATE_QUEUE(eventQueuePtr) \
342 { \
343 (eventQueuePtr)->base = EVENT_QUEUE_WRAP((eventQueuePtr)->base + 1); \
344 (eventQueuePtr)->length--; \
345 }
346
347#define RESET_QUEUE(eventQueuePtr) \
348 { \
349 (eventQueuePtr)->base = 0; \
350 (eventQueuePtr)->length = 0; \
351 }
352
353/* node stack macros - used to browse a tree without using a recursive function */
354#define NODE_STACK_INIT(stack) { (stack)->nodeCount = 0; }
355#define NODE_STACK_PUSH(stack, node, offset) { (stack)->nodes[(stack)->nodeCount] = (node); (stack)->offsets[(stack)->nodeCount++] = (offset); }
356#define NODE_STACK_POP(stack, node, offset) { (node) = (stack)->nodes[--(stack)->nodeCount]; offset = (stack)->offsets[(stack)->nodeCount]; }
357#define NODE_STACK_NONEMPTY(stack) ((stack)->nodeCount != 0)
358
359#ifndef IX_NDEBUG
360#define IX_ETH_DB_NPE_MSG_HISTORY_DEPTH (100)
361#define LOG_NPE_MSG(msg) \
362 do { \
363 UINT32 npeMsgHistoryIndex = (npeMsgHistoryLen++) % IX_ETH_DB_NPE_MSG_HISTORY_DEPTH; \
364 npeMsgHistory[npeMsgHistoryIndex][0] = msg.data[0]; \
365 npeMsgHistory[npeMsgHistoryIndex][1] = msg.data[1]; \
366 } while (0);
367#else
368#define LOG_NPE_MSG() /* nothing */
369#endif
370
371/* ----------- Data -------------- */
372
373/* typedefs */
374
375typedef UINT32 (*HashFunction)(void *entity);
376typedef BOOL (*MatchFunction)(void *reference, void *entry);
377typedef void (*FreeFunction)(void *entry);
378
379/**
380 * basic component of a hash table
381 */
382typedef struct HashNode_t
383{
384 void *data; /**< specific data */
385 struct HashNode_t *next; /**< used for bucket chaining */
386
387 __mempool__ struct HashNode_t *nextFree; /**< memory pool management */
388
389 __lock__ IxOsalFastMutex lock; /**< node lock */
390} HashNode;
391
392/**
393 * @brief hash table iterator definition
394 *
395 * an iterator is an object which can be used
396 * to browse a hash table
397 */
398typedef struct
399{
400 UINT32 bucketIndex; /**< index of the currently iterated bucket */
401 HashNode *previousNode; /**< reference to the previously iterated node within the current bucket */
402 HashNode *node; /**< reference to the currently iterated node */
403} HashIterator;
404
405/**
406 * definition of a MAC descriptor (a database record)
407 */
408
409typedef enum
410{
411 IX_ETH_DB_WIFI_AP_TO_STA = 0x0,
412 IX_ETH_DB_WIFI_AP_TO_AP = 0x1
413} IxEthDBWiFiRecordType;
414
415typedef union
416{
417 struct
418 {
419 UINT32 age;
420 BOOL staticEntry; /**< TRUE if this address is static (doesn't age) */
421 } filteringData;
422
423 struct
424 {
425 UINT32 age;
426 BOOL staticEntry;
427 UINT32 ieee802_1qTag;
428 } filteringVlanData;
429
430 struct
431 {
432 IxEthDBWiFiRecordType type; /**< AP_TO_AP (0x1) or AP_TO_STA (0x0) */
433 UINT32 gwAddressIndex; /**< used only when linearizing the entries for NPE usage */
434 UINT8 gwMacAddress[IX_IEEE803_MAC_ADDRESS_SIZE];
435
436 __alignment__ UINT8 reserved2[2];
437 } wifiData;
438} IxEthDBRecordData;
439
440typedef struct MacDescriptor_t
441{
442 UINT8 macAddress[IX_IEEE803_MAC_ADDRESS_SIZE];
443
444 __alignment__ UINT8 reserved1[2];
445
446 UINT32 portID;
447 IxEthDBRecordType type;
448 IxEthDBRecordData recordData;
449
450 /* used for internal operations, such as NPE linearization */
451 void *internal;
452
453 /* custom user data */
454 void *user;
455
456 __mempool__ struct MacDescriptor_t *nextFree; /**< memory pool management */
457 __smartpointer__ UINT32 refCount; /**< smart pointer reference counter */
458} MacDescriptor;
459
460/**
461 * hash table definition
462 */
463typedef struct
464{
465 HashNode *hashBuckets[NUM_BUCKETS];
466 UINT32 numBuckets;
467
468 __lock__ IxOsalFastMutex bucketLocks[NUM_BUCKETS];
469
470 HashFunction entryHashFunction;
471 MatchFunction *matchFunctions;
472 FreeFunction freeFunction;
473} HashTable;
474
475typedef enum
476{
477 IX_ETH_DB_MAC_KEY = 1,
478 IX_ETH_DB_MAC_PORT_KEY = 2,
479 IX_ETH_DB_MAC_VLAN_KEY = 3,
480 IX_ETH_DB_MAX_KEY_INDEX = 3
481} IxEthDBSearchKeyType;
482
483typedef struct MacTreeNode_t
484{
485 __smartpointer__ MacDescriptor *descriptor;
486 struct MacTreeNode_t *left, *right;
487
488 __mempool__ struct MacTreeNode_t *nextFree;
489} MacTreeNode;
490
491typedef IxEthDBStatus (*IxEthDBPortUpdateHandler)(IxEthDBPortId portID, IxEthDBRecordType type);
492
493typedef void (*IxEthDBNoteWriteFn)(void *address, MacTreeNode *node);
494
495typedef struct
496{
497 BOOL updateEnabled; /**< TRUE if updates are enabled for port */
498 BOOL userControlled; /**< TRUE if the user has manually used ixEthDBPortUpdateEnableSet */
499 BOOL treeInitialized; /**< TRUE if the NPE has received an initial tree */
500 IxEthDBPortUpdateHandler updateHandler; /**< port update handler routine */
501 void *npeUpdateZone; /**< port update memory zone */
502 void *npeGwUpdateZone; /**< port update memory zone for gateways */
503 void *vlanUpdateZone; /**< port update memory zone for VLAN tables */
504 MacTreeNode *searchTree; /**< internal search tree, in MacTreeNode representation */
505 BOOL searchTreePendingWrite; /**< TRUE if searchTree holds a tree pending write to the port */
506} PortUpdateMethod;
507
508typedef struct
509{
510 IxEthDBPortId portID; /**< port ID */
511 BOOL enabled; /**< TRUE if the port is enabled */
512 BOOL agingEnabled; /**< TRUE if aging on this port is enabled */
513 BOOL initialized;
514 IxEthDBPortMap dependencyPortMap; /**< dependency port map for this port */
515 PortUpdateMethod updateMethod; /**< update method structure */
516 BOOL macAddressUploaded; /**< TRUE if the MAC address was uploaded into the port */
517 UINT32 maxRxFrameSize; /**< maximum Rx frame size for this port */
518 UINT32 maxTxFrameSize; /**< maximum Rx frame size for this port */
519
520 UINT8 bbsid[6];
521 __alignment__ UINT8 reserved[2];
522 UINT32 frameControlDurationID; /**< Frame Control - Duration/ID WiFi control */
523
524 IxEthDBVlanTag vlanTag; /**< default VLAN tag for port */
525 IxEthDBPriorityTable priorityTable; /**< QoS <=> internal priority mapping */
526 IxEthDBVlanSet vlanMembership;
527 IxEthDBVlanSet transmitTaggingInfo;
528 IxEthDBFrameFilter frameFilter;
529 IxEthDBTaggingAction taggingAction;
530
531 UINT32 npeFrameFilter;
532 UINT32 npeTaggingAction;
533
534 IxEthDBFirewallMode firewallMode;
535 BOOL srcAddressFilterEnabled;
536
537 BOOL stpBlocked;
538
539 IxEthDBFeature featureCapability;
540 IxEthDBFeature featureStatus;
541
542 UINT32 ixEthDBTrafficClassAQMAssignments[IX_IEEE802_1Q_QOS_PRIORITY_COUNT];
543
544 UINT32 ixEthDBTrafficClassCount;
545
546 UINT32 ixEthDBTrafficClassAvailable;
547
548
549
550 __lock__ IxOsalMutex npeAckLock;
551} PortInfo;
552
553/* list of port information structures indexed on port Ids */
554extern IX_ETH_DB_PUBLIC PortInfo ixEthDBPortInfo[IX_ETH_DB_NUMBER_OF_PORTS];
555
556typedef enum
557{
558 IX_ETH_DB_ADD_FILTERING_RECORD = 0xFF0001,
559 IX_ETH_DB_REMOVE_FILTERING_RECORD = 0xFF0002
560} PortEventType;
561
562typedef struct
563{
564 UINT32 eventType;
565 IxEthDBPortId portID;
566 IxEthDBMacAddr macAddr;
567 BOOL staticEntry;
568} PortEvent;
569
570typedef struct
571{
572 PortEvent queue[EVENT_QUEUE_SIZE];
573 UINT32 base;
574 UINT32 length;
575} PortEventQueue;
576
577typedef struct
578{
579 IxEthDBPortId portID; /**< originating port */
580 MacDescriptor *macDescriptors[MAX_ELT_SIZE]; /**< addresses to be synced into db */
581 UINT32 addressCount; /**< number of addresses */
582} TreeSyncInfo;
583
584typedef struct
585{
586 MacTreeNode *nodes[MAX_ELT_SIZE];
587 UINT32 offsets[MAX_ELT_SIZE];
588 UINT32 nodeCount;
589} MacTreeNodeStack;
590
591/* Prototypes */
592
593/* ----------- Memory management -------------- */
594
595IX_ETH_DB_PUBLIC void ixEthDBInitMemoryPools(void);
596
597IX_ETH_DB_PUBLIC HashNode* ixEthDBAllocHashNode(void);
598IX_ETH_DB_PUBLIC void ixEthDBFreeHashNode(HashNode *);
599
600IX_ETH_DB_PUBLIC __smartpointer__ MacDescriptor* ixEthDBAllocMacDescriptor(void);
601IX_ETH_DB_PUBLIC __smartpointer__ MacDescriptor* ixEthDBCloneMacDescriptor(MacDescriptor *macDescriptor);
602IX_ETH_DB_PUBLIC __smartpointer__ void ixEthDBFreeMacDescriptor(MacDescriptor *);
603
604IX_ETH_DB_PUBLIC __smartpointer__ MacTreeNode* ixEthDBAllocMacTreeNode(void);
605IX_ETH_DB_PUBLIC __smartpointer__ MacTreeNode* ixEthDBCloneMacTreeNode(MacTreeNode *);
606IX_ETH_DB_PUBLIC __smartpointer__ void ixEthDBFreeMacTreeNode(MacTreeNode *);
607
608IX_ETH_DB_PUBLIC void ixEthDBPoolFreeMacTreeNode(MacTreeNode *);
609IX_ETH_DB_PUBLIC UINT32 ixEthDBSearchTreeUsageGet(MacTreeNode *tree);
610IX_ETH_DB_PUBLIC int ixEthDBShowMemoryStatus(void);
611
612/* Hash Table */
613IX_ETH_DB_PUBLIC void ixEthDBInitHash(HashTable *hashTable, UINT32 numBuckets, HashFunction entryHashFunction, MatchFunction *matchFunctions, FreeFunction freeFunction);
614
615IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBAddHashEntry(HashTable *hashTable, void *entry);
616IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBRemoveHashEntry(HashTable *hashTable, int keyType, void *reference);
617IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBSearchHashEntry(HashTable *hashTable, int keyType, void *reference, HashNode **searchResult);
618IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPeekHashEntry(HashTable *hashTable, int keyType, void *reference);
619IX_ETH_DB_PUBLIC void ixEthDBReleaseHashNode(HashNode *node);
620
621IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBInitHashIterator(HashTable *hashTable, HashIterator *iterator);
622IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBIncrementHashIterator(HashTable *hashTable, HashIterator *iterator);
623IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBRemoveEntryAtHashIterator(HashTable *hashTable, HashIterator *iterator);
624IX_ETH_DB_PUBLIC void ixEthDBReleaseHashIterator(HashIterator *iterator);
625
626/* API Support */
627IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortAddressSet(IxEthDBPortId portID, IxEthDBMacAddr *macAddr);
628IX_ETH_DB_PUBLIC void ixEthDBMaximumFrameSizeAckCallback(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
629
630/* DB Core functions */
631IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBInit(void);
632IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBAdd(MacDescriptor *newRecordTemplate, IxEthDBPortMap updateTrigger);
633IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBRemove(MacDescriptor *templateRecord, IxEthDBPortMap updateTrigger);
634IX_ETH_DB_PUBLIC HashNode* ixEthDBSearch(IxEthDBMacAddr *macAddress, IxEthDBRecordType typeFilter);
635IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPeek(IxEthDBMacAddr *macAddress, IxEthDBRecordType typeFilter);
636
637/* Learning support */
638IX_ETH_DB_PUBLIC UINT32 ixEthDBAddressCompare(UINT8 *mac1, UINT8 *mac2);
639IX_ETH_DB_PUBLIC BOOL ixEthDBAddressMatch(void *reference, void *entry);
640IX_ETH_DB_PUBLIC UINT32 ixEthDBEntryXORHash(void *macDescriptor);
641IX_ETH_DB_PUBLIC UINT32 ixEthDBKeyXORHash(void *macAddress);
642
643/* Port updates */
644IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBNPEUpdateHandler(IxEthDBPortId portID, IxEthDBRecordType type);
645IX_ETH_DB_PUBLIC void ixEthDBUpdatePortLearningTrees(IxEthDBPortMap triggerPorts);
646IX_ETH_DB_PUBLIC void ixEthDBNPEAccessRequest(IxEthDBPortId portID);
647IX_ETH_DB_PUBLIC void ixEthDBUpdateLock(void);
648IX_ETH_DB_PUBLIC void ixEthDBUpdateUnlock(void);
649IX_ETH_DB_PUBLIC MacTreeNode* ixEthDBQuery(MacTreeNode *searchTree, IxEthDBPortMap query, IxEthDBRecordType recordFilter, UINT32 maximumEntries);
650IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBFirewallUpdate(IxEthDBPortId portID, void *address, UINT32 epDelta);
651
652/* Init/unload */
653IX_ETH_DB_PUBLIC void ixEthDBPortSetAckCallback(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
654IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBEventProcessorInit(void);
655IX_ETH_DB_PUBLIC void ixEthDBPortInit(IxEthDBPortId portID);
656IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortEnable(IxEthDBPortId portID);
657IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortDisable(IxEthDBPortId portID);
658IX_ETH_DB_PUBLIC void ixEthDBNPEUpdateAreasInit(void);
659IX_ETH_DB_PUBLIC UINT32 ixEthDBMatchMethodsRegister(MatchFunction *matchFunctions);
660IX_ETH_DB_PUBLIC UINT32 ixEthDBRecordSerializeMethodsRegister(void);
661IX_ETH_DB_PUBLIC UINT32 ixEthDBUpdateTypeRegister(BOOL *typeArray);
662IX_ETH_DB_PUBLIC void ixEthDBNPEUpdateAreasUnload(void);
663IX_ETH_DB_PUBLIC void ixEthDBFeatureCapabilityScan(void);
664IX_ETH_DB_PUBLIC UINT32 ixEthDBKeyTypeRegister(UINT32 *keyType);
665
666/* Event processing */
667IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBDefaultEventCallbackEnable(IxEthDBPortId portID, BOOL enable);
668IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBTriggerAddPortUpdate(IxEthDBMacAddr *macAddr, IxEthDBPortId portID, BOOL staticEntry);
669IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBTriggerRemovePortUpdate(IxEthDBMacAddr *macAddr, IxEthDBPortId portID);
670IX_ETH_DB_PUBLIC void ixEthDBNPEEventCallback(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
671
672/* NPE adaptor */
673IX_ETH_DB_PUBLIC void ixEthDBGetMacDatabaseCbk(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
674IX_ETH_DB_PUBLIC void ixEthDBNpeMsgAck(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
675IX_ETH_DB_PUBLIC void ixEthDBNPESyncScan(IxEthDBPortId portID, void *eltBaseAddress, UINT32 eltSize);
676IX_ETH_DB_PUBLIC void ixEthDBNPETreeWrite(IxEthDBRecordType type, UINT32 totalSize, void *baseAddress, MacTreeNode *tree, UINT32 *blocks, UINT32 *startIndex);
677IX_ETH_DB_PUBLIC void ixEthDBNPEGatewayNodeWrite(void *address, MacTreeNode *node);
678
679/* Other public API functions */
680IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBStartLearningFunction(void);
681IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBStopLearningFunction(void);
682IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortUpdateEnableSet(IxEthDBPortId portID, BOOL enableUpdate);
683
684/* Maximum Tx/Rx public functions */
685IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBFilteringPortMaximumRxFrameSizeSet(IxEthDBPortId portID, UINT32 maximumRxFrameSize);
686IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBFilteringPortMaximumTxFrameSizeSet(IxEthDBPortId portID, UINT32 maximumTxFrameSize);
687
688/* VLAN-related */
689IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortVlanTableSet(IxEthDBPortId portID, IxEthDBVlanSet portVlanTable, IxEthDBVlanSet vlanSet);
690
691/* Record search */
692IX_ETH_DB_PUBLIC BOOL ixEthDBAddressRecordMatch(void *untypedReference, void *untypedEntry);
693IX_ETH_DB_PUBLIC BOOL ixEthDBVlanRecordMatch(void *untypedReference, void *untypedEntry);
694IX_ETH_DB_PUBLIC BOOL ixEthDBPortRecordMatch(void *untypedReference, void *untypedEntry);
695IX_ETH_DB_PUBLIC BOOL ixEthDBNullMatch(void *reference, void *entry);
696IX_ETH_DB_PUBLIC HashNode* ixEthDBPortSearch(IxEthDBMacAddr *macAddress, IxEthDBPortId portID, IxEthDBRecordType typeFilter);
697IX_ETH_DB_PUBLIC HashNode* ixEthDBVlanSearch(IxEthDBMacAddr *macAddress, IxEthDBVlanId vlanID, IxEthDBRecordType typeFilter);
698
699/* Utilities */
700IX_ETH_DB_PUBLIC const char* mac2string(const unsigned char *mac);
701IX_ETH_DB_PUBLIC void showHashInfo(void);
702IX_ETH_DB_PUBLIC int ixEthDBAnalyzeHash(void);
703IX_ETH_DB_PUBLIC const char* errorString(IxEthDBStatus error);
704IX_ETH_DB_PUBLIC int numHashElements(void);
705IX_ETH_DB_PUBLIC void zapHashtable(void);
706IX_ETH_DB_PUBLIC BOOL ixEthDBCheckSingleBitValue(UINT32 value);
707
708/* Single Eth NPE Check */
709IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBSingleEthNpeCheck(IxEthDBPortId portId);
710
711#endif /* IxEthDB_p_H */
712