IxEthDB_p.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /**
  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. * SPDX-License-Identifier: BSD-3-Clause
  17. * @par
  18. * -- End of Copyright Notice --
  19. */
  20. #ifndef IxEthDB_p_H
  21. #define IxEthDB_p_H
  22. #include <IxTypes.h>
  23. #include <IxOsal.h>
  24. #include <IxEthDB.h>
  25. #include <IxNpeMh.h>
  26. #include <IxEthDBPortDefs.h>
  27. #include "IxEthDBMessages_p.h"
  28. #include "IxEthDBLog_p.h"
  29. #if (CPU==SIMSPARCSOLARIS)
  30. /* when running unit tests intLock() won't protect the event queue so we lock it manually */
  31. #define TEST_FIXTURE_LOCK_EVENT_QUEUE { ixOsalMutexLock(&eventQueueLock, IX_OSAL_WAIT_FOREVER); }
  32. #define TEST_FIXTURE_UNLOCK_EVENT_QUEUE { ixOsalMutexUnlock(&eventQueueLock); }
  33. #else
  34. #define TEST_FIXTURE_LOCK_EVENT_QUEUE /* nothing */
  35. #define TEST_FIXTURE_UNLOCK_EVENT_QUEUE /* nothing */
  36. #endif /* #if(CPU==SIMSPARCSOLARIS) */
  37. #ifndef IX_UNIT_TEST
  38. #define TEST_FIXTURE_INCREMENT_DB_CORE_ACCESS_COUNTER /* nothing */
  39. #define TEST_FIXTURE_MARK_OVERFLOW_EVENT /* nothing */
  40. #else
  41. extern int dbAccessCounter;
  42. extern int overflowEvent;
  43. #define TEST_FIXTURE_INCREMENT_DB_CORE_ACCESS_COUNTER { dbAccessCounter++; }
  44. #define TEST_FIXTURE_MARK_OVERFLOW_EVENT { overflowEvent = 1; }
  45. #endif
  46. /* code readability markers */
  47. #define __mempool__ /* memory pool marker */
  48. #define __lock__ /* hash write locking marker */
  49. #define __smartpointer__ /* smart pointer marker - warning: use only clone() when duplicating! */
  50. #define __alignment__ /* marker for data used only as alignment zones */
  51. /* constants */
  52. #define IX_ETH_DB_NPE_TIMEOUT (100) /* NPE response timeout, in ms */
  53. /**
  54. * number of hash table buckets
  55. * it should be at least 8x the predicted number of entries for performance
  56. * each bucket needs 8 bytes
  57. */
  58. #define NUM_BUCKETS (8192)
  59. /**
  60. * number of hash table buckets to preload when incrementing bucket iterator
  61. * = two cache lines
  62. */
  63. #define IX_ETHDB_CACHE_LINE_AHEAD (2)
  64. #define IX_ETHDB_BUCKETPTR_AHEAD ((IX_ETHDB_CACHE_LINE_AHEAD * IX_OSAL_CACHE_LINE_SIZE)/sizeof(void *))
  65. #define IX_ETHDB_BUCKET_INDEX_MASK (((IX_OSAL_CACHE_LINE_SIZE)/sizeof(void *)) - 1)
  66. /* locks */
  67. #define MAX_LOCKS (20) /**< maximum number of locks used simultaneously, do not tamper with */
  68. /* learning tree constants */
  69. #define INITIAL_ELT_SIZE (8) /**< initial byte size of tree (empty unused root size) */
  70. #define MAX_ELT_SIZE (512) /**< maximum number of entries (includes unused root) */
  71. #define MAX_GW_SIZE (32) /**< maximum number of gateway entries (including unused root) */
  72. #define MAX_FW_SIZE (32) /**< maximum number of firewall entries (including unused root) */
  73. #define ELT_ENTRY_SIZE (8) /**< entry size, in bytes */
  74. #define ELT_ROOT_OFFSET (ELT_ENTRY_SIZE) /**< tree root offset, in bytes - node preceeding root is unused */
  75. #define FULL_ELT_BYTE_SIZE (MAX_ELT_SIZE * ELT_ENTRY_SIZE) /**< full size of tree, in bytes, including unused root */
  76. #define FULL_GW_BYTE_SIZE (MAX_GW_SIZE * ELT_ENTRY_SIZE) /**< full size of gateway list, in bytes, including unused root */
  77. #define FULL_FW_BYTE_SIZE (MAX_FW_SIZE * ELT_ENTRY_SIZE) /**< full size of firewall table, in bytes, including unused root */
  78. /* maximum size of the VLAN table:
  79. * 4096 bits (one per VLAN)
  80. * 8 bits in one byte
  81. * interleaved VLAN membership and VLAN TTI (*2) */
  82. #define FULL_VLAN_BYTE_SIZE (4096 / 8 * 2)
  83. /* upper 9 bits used as set index, lower 3 bits as byte index */
  84. #define VLAN_SET_OFFSET(vlanID) ((vlanID) >> 3)
  85. #define VLAN_SET_MASK(vlanID) (0x7 - ((vlanID) & 0x7))
  86. /* Update zone definitions */
  87. #define NPE_TREE_MEM_SIZE (4096) /* ((511 entries + 1 unused root) * 8 bytes/entry) */
  88. /* check the above value, we rely on 4k */
  89. #if NPE_TREE_MEM_SIZE != 4096
  90. #error NPE_TREE_MEM_SIZE is not defined to 4096 bytes!
  91. #endif
  92. /* Size Filtering limits (Jumbo frame filtering) */
  93. #define IX_ETHDB_MAX_FRAME_SIZE 65535 /* other ports than NPE ports */
  94. #define IX_ETHDB_MIN_FRAME_SIZE 1 /* other ports than NPE ports */
  95. #define IX_ETHDB_MAX_NPE_FRAME_SIZE 16320 /* NPE ports firmware limit */
  96. #define IX_ETHDB_MIN_NPE_FRAME_SIZE 1 /* NPE ports firmware limit */
  97. #define IX_ETHDB_DEFAULT_FRAME_SIZE 1522
  98. /* memory management pool sizes */
  99. /*
  100. * Note:
  101. *
  102. * NODE_POOL_SIZE controls the maximum number of elements in the database at any one time.
  103. * It should be large enough to cover all the search trees of all the ports simultaneously.
  104. *
  105. * MAC_POOL_SIZE should be higher than NODE_POOL_SIZE by at least the total number of MAC addresses
  106. * possible to be held at any time in all the ports.
  107. *
  108. * TREE_POOL_SIZE should follow the same guideline as for MAC_POOL_SIZE.
  109. *
  110. * The database structure described here (2000/4000/4000) is enough for two NPEs holding at most 511
  111. * entries each plus one PCI NIC holding at most 900 entries.
  112. */
  113. #define NODE_POOL_SIZE (2000) /**< number of HashNode objects - also master number of elements in the database; each entry has 16 bytes */
  114. #define MAC_POOL_SIZE (4000) /**< number of MacDescriptor objects; each entry has 28 bytes */
  115. #define TREE_POOL_SIZE (4000) /**< number of MacTreeNode objects; each entry has 16 bytes */
  116. /* retry policies */
  117. #define BUSY_RETRY_ENABLED (true) /**< if set to true the API will retry automatically calls returning BUSY */
  118. #define FOREVER_RETRY (true) /**< if set to true the API will retry forever BUSY calls */
  119. #define MAX_RETRIES (400) /**< upper retry limit - used only when FOREVER_RETRY is false */
  120. #define BUSY_RETRY_YIELD (5) /**< ticks to yield for every failed retry */
  121. /* event management */
  122. #define EVENT_QUEUE_SIZE (500) /**< size of the sink collecting events from the Message Handler FIFO */
  123. #define EVENT_PROCESSING_LIMIT (100) /**< batch processing control size (how many events are extracted from the queue at once) */
  124. /* MAC descriptors */
  125. #define STATIC_ENTRY (true)
  126. #define DYNAMIC_ENTRY (false)
  127. /* age reset on next maintenance - incrementing by 1 will reset to 0 */
  128. #define AGE_RESET (0xFFFFFFFF)
  129. /* dependency maps */
  130. #define EMPTY_DEPENDENCY_MAP (0)
  131. /* trees */
  132. #define RIGHT (1)
  133. #define LEFT (-1)
  134. /* macros */
  135. #define IX_ETH_DB_CHECK_PORT_EXISTS(portID) \
  136. { \
  137. if ((portID) >= IX_ETH_DB_NUMBER_OF_PORTS) \
  138. { \
  139. return IX_ETH_DB_INVALID_PORT; \
  140. } \
  141. }
  142. #define IX_ETH_DB_CHECK_PORT_INITIALIZED(portID) \
  143. { \
  144. if ((portID) >= IX_ETH_DB_NUMBER_OF_PORTS) \
  145. { \
  146. return IX_ETH_DB_INVALID_PORT; \
  147. } \
  148. else \
  149. { \
  150. if (!ixEthDBPortInfo[portID].initialized) \
  151. { \
  152. return IX_ETH_DB_PORT_UNINITIALIZED; \
  153. } \
  154. } \
  155. }
  156. /* single NPE check */
  157. #define IX_ETH_DB_CHECK_SINGLE_NPE(portID) \
  158. if (ixEthDBSingleEthNpeCheck(portID) != IX_ETH_DB_SUCCESS) \
  159. { \
  160. WARNING_LOG("EthDB: port ID %d is unavailable\n",(UINT32) portID); \
  161. \
  162. return IX_ETH_DB_INVALID_PORT; \
  163. }
  164. /* feature check */
  165. #define IX_ETH_DB_CHECK_FEATURE(portID, feature) \
  166. if ((ixEthDBPortInfo[portID].featureStatus & feature) == 0) \
  167. { \
  168. return IX_ETH_DB_FEATURE_UNAVAILABLE; \
  169. }
  170. /* busy retrying */
  171. #define BUSY_RETRY(functionCall) \
  172. { \
  173. UINT32 retries = 0; \
  174. IxEthDBStatus br_result; \
  175. \
  176. while ((br_result = functionCall) == IX_ETH_DB_BUSY \
  177. && BUSY_RETRY_ENABLED && (FOREVER_RETRY || ++retries < MAX_RETRIES)) { ixOsalSleep(BUSY_RETRY_YIELD); }; \
  178. \
  179. if ((!FOREVER_RETRY && retries == MAX_RETRIES) || (br_result == IX_ETH_DB_FAIL)) \
  180. {\
  181. ERROR_LOG("Ethernet Learning Database Error: BUSY_RETRY failed at %s:%d\n", __FILE__, __LINE__); \
  182. }\
  183. }
  184. #define BUSY_RETRY_WITH_RESULT(functionCall, brwr_result) \
  185. { \
  186. UINT32 retries = 0; \
  187. \
  188. while ((brwr_result = functionCall) == IX_ETH_DB_BUSY \
  189. && BUSY_RETRY_ENABLED && (FOREVER_RETRY || ++retries < MAX_RETRIES)) { ixOsalSleep(BUSY_RETRY_YIELD); }; \
  190. \
  191. if ((!FOREVER_RETRY && retries == MAX_RETRIES) || (brwr_result == IX_ETH_DB_FAIL)) \
  192. {\
  193. ERROR_LOG("Ethernet Learning Database Error: BUSY_RETRY_WITH_RESULT failed at %s:%d\n", __FILE__, __LINE__); \
  194. }\
  195. }
  196. /* iterators */
  197. #define IS_ITERATOR_VALID(iteratorPtr) ((iteratorPtr)->node != NULL)
  198. /* dependency port maps */
  199. /* 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) */
  200. /* gives an empty dependency map */
  201. #define SET_EMPTY_DEPENDENCY_MAP(map) { int i = 0; for (; i < 32 ; i++) map[i] = 0; }
  202. #define IS_EMPTY_DEPENDENCY_MAP(result, map) { int i = 0 ; result = true; for (; i < 32 ; i++) if (map[i] != 0) { result = false; break; }}
  203. /**
  204. * gives a map consisting only of 'portID'
  205. */
  206. #define SET_DEPENDENCY_MAP(map, portID) {SET_EMPTY_DEPENDENCY_MAP(map); map[portID >> 3] = 1 << (portID & 0x7);}
  207. /**
  208. * gives a map resulting from joining map1 and map2
  209. */
  210. #define JOIN_MAPS(map, map1, map2) { int i = 0; for (; i < 32 ; i++) map[i] = map1[i] | map2[i]; }
  211. /**
  212. * gives the map resulting from joining portID and map
  213. */
  214. #define JOIN_PORT_TO_MAP(map, portID) { map[portID >> 3] |= 1 << (portID & 0x7); }
  215. /**
  216. * gives the map resulting from excluding portID from map
  217. */
  218. #define EXCLUDE_PORT_FROM_MAP(map, portID) { map[portID >> 3] &= ~(1 << (portID & 0x7); }
  219. /**
  220. * returns true if map1 is a subset of map2 and false otherwise
  221. */
  222. #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; }
  223. /**
  224. * returns true is portID is part of map and false otherwise
  225. */
  226. #define IS_PORT_INCLUDED(portID, map) ((map[portID >> 3] & (1 << (portID & 0x7))) != 0)
  227. /**
  228. * returns the difference between map1 and map2 (ports included in map1 and not included in map2)
  229. */
  230. #define DIFF_MAPS(map, map1, map2) { int i = 0; for (; i < 32 ; i++) map[i] = map1[i] ^ (map1[i] & map2[i]); }
  231. /**
  232. * returns true if the maps collide (have at least one port in common) and false otherwise
  233. */
  234. #define MAPS_COLLIDE(result, map1, map2) { int i = 0; result = false; for (; i < 32 ; i++) if ((map1[i] & map2[i]) != 0) result = true; }
  235. /* size (number of ports) of a dependency map */
  236. #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); }}
  237. /* copy map2 into map1 */
  238. #define COPY_DEPENDENCY_MAP(map1, map2) { memcpy (map1, map2, sizeof (map1)); }
  239. /* definition of a port map size/port number which cannot be reached (we support at most 32 ports) */
  240. #define MAX_PORT_SIZE (0xFF)
  241. #define MAX_PORT_NUMBER (0xFF)
  242. #define IX_ETH_DB_CHECK_REFERENCE(ptr) { if ((ptr) == NULL) { return IX_ETH_DB_INVALID_ARG; } }
  243. #define IX_ETH_DB_CHECK_MAP(portID, map) { if (!IS_PORT_INCLUDED(portID, map)) { return IX_ETH_DB_INVALID_ARG; } }
  244. /* event queue macros */
  245. #define EVENT_QUEUE_WRAP(offset) ((offset) >= EVENT_QUEUE_SIZE ? (offset) - EVENT_QUEUE_SIZE : (offset))
  246. #define CAN_ENQUEUE(eventQueuePtr) ((eventQueuePtr)->length < EVENT_QUEUE_SIZE)
  247. #define QUEUE_HEAD(eventQueuePtr) (&(eventQueuePtr)->queue[EVENT_QUEUE_WRAP((eventQueuePtr)->base + (eventQueuePtr)->length)])
  248. #define QUEUE_TAIL(eventQueuePtr) (&(eventQueuePtr)->queue[(eventQueuePtr)->base])
  249. #define PUSH_UPDATE_QUEUE(eventQueuePtr) { (eventQueuePtr)->length++; }
  250. #define SHIFT_UPDATE_QUEUE(eventQueuePtr) \
  251. { \
  252. (eventQueuePtr)->base = EVENT_QUEUE_WRAP((eventQueuePtr)->base + 1); \
  253. (eventQueuePtr)->length--; \
  254. }
  255. #define RESET_QUEUE(eventQueuePtr) \
  256. { \
  257. (eventQueuePtr)->base = 0; \
  258. (eventQueuePtr)->length = 0; \
  259. }
  260. /* node stack macros - used to browse a tree without using a recursive function */
  261. #define NODE_STACK_INIT(stack) { (stack)->nodeCount = 0; }
  262. #define NODE_STACK_PUSH(stack, node, offset) { (stack)->nodes[(stack)->nodeCount] = (node); (stack)->offsets[(stack)->nodeCount++] = (offset); }
  263. #define NODE_STACK_POP(stack, node, offset) { (node) = (stack)->nodes[--(stack)->nodeCount]; offset = (stack)->offsets[(stack)->nodeCount]; }
  264. #define NODE_STACK_NONEMPTY(stack) ((stack)->nodeCount != 0)
  265. #ifndef IX_NDEBUG
  266. #define IX_ETH_DB_NPE_MSG_HISTORY_DEPTH (100)
  267. #define LOG_NPE_MSG(msg) \
  268. do { \
  269. UINT32 npeMsgHistoryIndex = (npeMsgHistoryLen++) % IX_ETH_DB_NPE_MSG_HISTORY_DEPTH; \
  270. npeMsgHistory[npeMsgHistoryIndex][0] = msg.data[0]; \
  271. npeMsgHistory[npeMsgHistoryIndex][1] = msg.data[1]; \
  272. } while (0);
  273. #else
  274. #define LOG_NPE_MSG() /* nothing */
  275. #endif
  276. /* ----------- Data -------------- */
  277. /* typedefs */
  278. typedef UINT32 (*HashFunction)(void *entity);
  279. typedef BOOL (*MatchFunction)(void *reference, void *entry);
  280. typedef void (*FreeFunction)(void *entry);
  281. /**
  282. * basic component of a hash table
  283. */
  284. typedef struct HashNode_t
  285. {
  286. void *data; /**< specific data */
  287. struct HashNode_t *next; /**< used for bucket chaining */
  288. __mempool__ struct HashNode_t *nextFree; /**< memory pool management */
  289. __lock__ IxOsalFastMutex lock; /**< node lock */
  290. } HashNode;
  291. /**
  292. * @brief hash table iterator definition
  293. *
  294. * an iterator is an object which can be used
  295. * to browse a hash table
  296. */
  297. typedef struct
  298. {
  299. UINT32 bucketIndex; /**< index of the currently iterated bucket */
  300. HashNode *previousNode; /**< reference to the previously iterated node within the current bucket */
  301. HashNode *node; /**< reference to the currently iterated node */
  302. } HashIterator;
  303. /**
  304. * definition of a MAC descriptor (a database record)
  305. */
  306. typedef enum
  307. {
  308. IX_ETH_DB_WIFI_AP_TO_STA = 0x0,
  309. IX_ETH_DB_WIFI_AP_TO_AP = 0x1
  310. } IxEthDBWiFiRecordType;
  311. typedef union
  312. {
  313. struct
  314. {
  315. UINT32 age;
  316. BOOL staticEntry; /**< true if this address is static (doesn't age) */
  317. } filteringData;
  318. struct
  319. {
  320. UINT32 age;
  321. BOOL staticEntry;
  322. UINT32 ieee802_1qTag;
  323. } filteringVlanData;
  324. struct
  325. {
  326. IxEthDBWiFiRecordType type; /**< AP_TO_AP (0x1) or AP_TO_STA (0x0) */
  327. UINT32 gwAddressIndex; /**< used only when linearizing the entries for NPE usage */
  328. UINT8 gwMacAddress[IX_IEEE803_MAC_ADDRESS_SIZE];
  329. __alignment__ UINT8 reserved2[2];
  330. } wifiData;
  331. } IxEthDBRecordData;
  332. typedef struct MacDescriptor_t
  333. {
  334. UINT8 macAddress[IX_IEEE803_MAC_ADDRESS_SIZE];
  335. __alignment__ UINT8 reserved1[2];
  336. UINT32 portID;
  337. IxEthDBRecordType type;
  338. IxEthDBRecordData recordData;
  339. /* used for internal operations, such as NPE linearization */
  340. void *internal;
  341. /* custom user data */
  342. void *user;
  343. __mempool__ struct MacDescriptor_t *nextFree; /**< memory pool management */
  344. __smartpointer__ UINT32 refCount; /**< smart pointer reference counter */
  345. } MacDescriptor;
  346. /**
  347. * hash table definition
  348. */
  349. typedef struct
  350. {
  351. HashNode *hashBuckets[NUM_BUCKETS];
  352. UINT32 numBuckets;
  353. __lock__ IxOsalFastMutex bucketLocks[NUM_BUCKETS];
  354. HashFunction entryHashFunction;
  355. MatchFunction *matchFunctions;
  356. FreeFunction freeFunction;
  357. } HashTable;
  358. typedef enum
  359. {
  360. IX_ETH_DB_MAC_KEY = 1,
  361. IX_ETH_DB_MAC_PORT_KEY = 2,
  362. IX_ETH_DB_MAC_VLAN_KEY = 3,
  363. IX_ETH_DB_MAX_KEY_INDEX = 3
  364. } IxEthDBSearchKeyType;
  365. typedef struct MacTreeNode_t
  366. {
  367. __smartpointer__ MacDescriptor *descriptor;
  368. struct MacTreeNode_t *left, *right;
  369. __mempool__ struct MacTreeNode_t *nextFree;
  370. } MacTreeNode;
  371. typedef IxEthDBStatus (*IxEthDBPortUpdateHandler)(IxEthDBPortId portID, IxEthDBRecordType type);
  372. typedef void (*IxEthDBNoteWriteFn)(void *address, MacTreeNode *node);
  373. typedef struct
  374. {
  375. BOOL updateEnabled; /**< true if updates are enabled for port */
  376. BOOL userControlled; /**< true if the user has manually used ixEthDBPortUpdateEnableSet */
  377. BOOL treeInitialized; /**< true if the NPE has received an initial tree */
  378. IxEthDBPortUpdateHandler updateHandler; /**< port update handler routine */
  379. void *npeUpdateZone; /**< port update memory zone */
  380. void *npeGwUpdateZone; /**< port update memory zone for gateways */
  381. void *vlanUpdateZone; /**< port update memory zone for VLAN tables */
  382. MacTreeNode *searchTree; /**< internal search tree, in MacTreeNode representation */
  383. BOOL searchTreePendingWrite; /**< true if searchTree holds a tree pending write to the port */
  384. } PortUpdateMethod;
  385. typedef struct
  386. {
  387. IxEthDBPortId portID; /**< port ID */
  388. BOOL enabled; /**< true if the port is enabled */
  389. BOOL agingEnabled; /**< true if aging on this port is enabled */
  390. BOOL initialized;
  391. IxEthDBPortMap dependencyPortMap; /**< dependency port map for this port */
  392. PortUpdateMethod updateMethod; /**< update method structure */
  393. BOOL macAddressUploaded; /**< true if the MAC address was uploaded into the port */
  394. UINT32 maxRxFrameSize; /**< maximum Rx frame size for this port */
  395. UINT32 maxTxFrameSize; /**< maximum Rx frame size for this port */
  396. UINT8 bbsid[6];
  397. __alignment__ UINT8 reserved[2];
  398. UINT32 frameControlDurationID; /**< Frame Control - Duration/ID WiFi control */
  399. IxEthDBVlanTag vlanTag; /**< default VLAN tag for port */
  400. IxEthDBPriorityTable priorityTable; /**< QoS <=> internal priority mapping */
  401. IxEthDBVlanSet vlanMembership;
  402. IxEthDBVlanSet transmitTaggingInfo;
  403. IxEthDBFrameFilter frameFilter;
  404. IxEthDBTaggingAction taggingAction;
  405. UINT32 npeFrameFilter;
  406. UINT32 npeTaggingAction;
  407. IxEthDBFirewallMode firewallMode;
  408. BOOL srcAddressFilterEnabled;
  409. BOOL stpBlocked;
  410. IxEthDBFeature featureCapability;
  411. IxEthDBFeature featureStatus;
  412. UINT32 ixEthDBTrafficClassAQMAssignments[IX_IEEE802_1Q_QOS_PRIORITY_COUNT];
  413. UINT32 ixEthDBTrafficClassCount;
  414. UINT32 ixEthDBTrafficClassAvailable;
  415. __lock__ IxOsalMutex npeAckLock;
  416. } PortInfo;
  417. /* list of port information structures indexed on port Ids */
  418. extern IX_ETH_DB_PUBLIC PortInfo ixEthDBPortInfo[IX_ETH_DB_NUMBER_OF_PORTS];
  419. typedef enum
  420. {
  421. IX_ETH_DB_ADD_FILTERING_RECORD = 0xFF0001,
  422. IX_ETH_DB_REMOVE_FILTERING_RECORD = 0xFF0002
  423. } PortEventType;
  424. typedef struct
  425. {
  426. UINT32 eventType;
  427. IxEthDBPortId portID;
  428. IxEthDBMacAddr macAddr;
  429. BOOL staticEntry;
  430. } PortEvent;
  431. typedef struct
  432. {
  433. PortEvent queue[EVENT_QUEUE_SIZE];
  434. UINT32 base;
  435. UINT32 length;
  436. } PortEventQueue;
  437. typedef struct
  438. {
  439. IxEthDBPortId portID; /**< originating port */
  440. MacDescriptor *macDescriptors[MAX_ELT_SIZE]; /**< addresses to be synced into db */
  441. UINT32 addressCount; /**< number of addresses */
  442. } TreeSyncInfo;
  443. typedef struct
  444. {
  445. MacTreeNode *nodes[MAX_ELT_SIZE];
  446. UINT32 offsets[MAX_ELT_SIZE];
  447. UINT32 nodeCount;
  448. } MacTreeNodeStack;
  449. /* Prototypes */
  450. /* ----------- Memory management -------------- */
  451. IX_ETH_DB_PUBLIC void ixEthDBInitMemoryPools(void);
  452. IX_ETH_DB_PUBLIC HashNode* ixEthDBAllocHashNode(void);
  453. IX_ETH_DB_PUBLIC void ixEthDBFreeHashNode(HashNode *);
  454. IX_ETH_DB_PUBLIC __smartpointer__ MacDescriptor* ixEthDBAllocMacDescriptor(void);
  455. IX_ETH_DB_PUBLIC __smartpointer__ MacDescriptor* ixEthDBCloneMacDescriptor(MacDescriptor *macDescriptor);
  456. IX_ETH_DB_PUBLIC __smartpointer__ void ixEthDBFreeMacDescriptor(MacDescriptor *);
  457. IX_ETH_DB_PUBLIC __smartpointer__ MacTreeNode* ixEthDBAllocMacTreeNode(void);
  458. IX_ETH_DB_PUBLIC __smartpointer__ MacTreeNode* ixEthDBCloneMacTreeNode(MacTreeNode *);
  459. IX_ETH_DB_PUBLIC __smartpointer__ void ixEthDBFreeMacTreeNode(MacTreeNode *);
  460. IX_ETH_DB_PUBLIC void ixEthDBPoolFreeMacTreeNode(MacTreeNode *);
  461. IX_ETH_DB_PUBLIC UINT32 ixEthDBSearchTreeUsageGet(MacTreeNode *tree);
  462. IX_ETH_DB_PUBLIC int ixEthDBShowMemoryStatus(void);
  463. /* Hash Table */
  464. IX_ETH_DB_PUBLIC void ixEthDBInitHash(HashTable *hashTable, UINT32 numBuckets, HashFunction entryHashFunction, MatchFunction *matchFunctions, FreeFunction freeFunction);
  465. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBAddHashEntry(HashTable *hashTable, void *entry);
  466. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBRemoveHashEntry(HashTable *hashTable, int keyType, void *reference);
  467. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBSearchHashEntry(HashTable *hashTable, int keyType, void *reference, HashNode **searchResult);
  468. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPeekHashEntry(HashTable *hashTable, int keyType, void *reference);
  469. IX_ETH_DB_PUBLIC void ixEthDBReleaseHashNode(HashNode *node);
  470. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBInitHashIterator(HashTable *hashTable, HashIterator *iterator);
  471. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBIncrementHashIterator(HashTable *hashTable, HashIterator *iterator);
  472. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBRemoveEntryAtHashIterator(HashTable *hashTable, HashIterator *iterator);
  473. IX_ETH_DB_PUBLIC void ixEthDBReleaseHashIterator(HashIterator *iterator);
  474. /* API Support */
  475. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortAddressSet(IxEthDBPortId portID, IxEthDBMacAddr *macAddr);
  476. IX_ETH_DB_PUBLIC void ixEthDBMaximumFrameSizeAckCallback(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
  477. /* DB Core functions */
  478. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBInit(void);
  479. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBAdd(MacDescriptor *newRecordTemplate, IxEthDBPortMap updateTrigger);
  480. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBRemove(MacDescriptor *templateRecord, IxEthDBPortMap updateTrigger);
  481. IX_ETH_DB_PUBLIC HashNode* ixEthDBSearch(IxEthDBMacAddr *macAddress, IxEthDBRecordType typeFilter);
  482. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPeek(IxEthDBMacAddr *macAddress, IxEthDBRecordType typeFilter);
  483. /* Learning support */
  484. IX_ETH_DB_PUBLIC UINT32 ixEthDBAddressCompare(UINT8 *mac1, UINT8 *mac2);
  485. IX_ETH_DB_PUBLIC BOOL ixEthDBAddressMatch(void *reference, void *entry);
  486. IX_ETH_DB_PUBLIC UINT32 ixEthDBEntryXORHash(void *macDescriptor);
  487. IX_ETH_DB_PUBLIC UINT32 ixEthDBKeyXORHash(void *macAddress);
  488. /* Port updates */
  489. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBNPEUpdateHandler(IxEthDBPortId portID, IxEthDBRecordType type);
  490. IX_ETH_DB_PUBLIC void ixEthDBUpdatePortLearningTrees(IxEthDBPortMap triggerPorts);
  491. IX_ETH_DB_PUBLIC void ixEthDBNPEAccessRequest(IxEthDBPortId portID);
  492. IX_ETH_DB_PUBLIC void ixEthDBUpdateLock(void);
  493. IX_ETH_DB_PUBLIC void ixEthDBUpdateUnlock(void);
  494. IX_ETH_DB_PUBLIC MacTreeNode* ixEthDBQuery(MacTreeNode *searchTree, IxEthDBPortMap query, IxEthDBRecordType recordFilter, UINT32 maximumEntries);
  495. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBFirewallUpdate(IxEthDBPortId portID, void *address, UINT32 epDelta);
  496. /* Init/unload */
  497. IX_ETH_DB_PUBLIC void ixEthDBPortSetAckCallback(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
  498. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBEventProcessorInit(void);
  499. IX_ETH_DB_PUBLIC void ixEthDBPortInit(IxEthDBPortId portID);
  500. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortEnable(IxEthDBPortId portID);
  501. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortDisable(IxEthDBPortId portID);
  502. IX_ETH_DB_PUBLIC void ixEthDBNPEUpdateAreasInit(void);
  503. IX_ETH_DB_PUBLIC UINT32 ixEthDBMatchMethodsRegister(MatchFunction *matchFunctions);
  504. IX_ETH_DB_PUBLIC UINT32 ixEthDBRecordSerializeMethodsRegister(void);
  505. IX_ETH_DB_PUBLIC UINT32 ixEthDBUpdateTypeRegister(BOOL *typeArray);
  506. IX_ETH_DB_PUBLIC void ixEthDBNPEUpdateAreasUnload(void);
  507. IX_ETH_DB_PUBLIC void ixEthDBFeatureCapabilityScan(void);
  508. IX_ETH_DB_PUBLIC UINT32 ixEthDBKeyTypeRegister(UINT32 *keyType);
  509. /* Event processing */
  510. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBDefaultEventCallbackEnable(IxEthDBPortId portID, BOOL enable);
  511. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBTriggerAddPortUpdate(IxEthDBMacAddr *macAddr, IxEthDBPortId portID, BOOL staticEntry);
  512. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBTriggerRemovePortUpdate(IxEthDBMacAddr *macAddr, IxEthDBPortId portID);
  513. IX_ETH_DB_PUBLIC void ixEthDBNPEEventCallback(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
  514. /* NPE adaptor */
  515. IX_ETH_DB_PUBLIC void ixEthDBGetMacDatabaseCbk(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
  516. IX_ETH_DB_PUBLIC void ixEthDBNpeMsgAck(IxNpeMhNpeId npeID, IxNpeMhMessage msg);
  517. IX_ETH_DB_PUBLIC void ixEthDBNPESyncScan(IxEthDBPortId portID, void *eltBaseAddress, UINT32 eltSize);
  518. IX_ETH_DB_PUBLIC void ixEthDBNPETreeWrite(IxEthDBRecordType type, UINT32 totalSize, void *baseAddress, MacTreeNode *tree, UINT32 *blocks, UINT32 *startIndex);
  519. IX_ETH_DB_PUBLIC void ixEthDBNPEGatewayNodeWrite(void *address, MacTreeNode *node);
  520. /* Other public API functions */
  521. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBStartLearningFunction(void);
  522. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBStopLearningFunction(void);
  523. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortUpdateEnableSet(IxEthDBPortId portID, BOOL enableUpdate);
  524. /* Maximum Tx/Rx public functions */
  525. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBFilteringPortMaximumRxFrameSizeSet(IxEthDBPortId portID, UINT32 maximumRxFrameSize);
  526. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBFilteringPortMaximumTxFrameSizeSet(IxEthDBPortId portID, UINT32 maximumTxFrameSize);
  527. /* VLAN-related */
  528. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBPortVlanTableSet(IxEthDBPortId portID, IxEthDBVlanSet portVlanTable, IxEthDBVlanSet vlanSet);
  529. /* Record search */
  530. IX_ETH_DB_PUBLIC BOOL ixEthDBAddressRecordMatch(void *untypedReference, void *untypedEntry);
  531. IX_ETH_DB_PUBLIC BOOL ixEthDBVlanRecordMatch(void *untypedReference, void *untypedEntry);
  532. IX_ETH_DB_PUBLIC BOOL ixEthDBPortRecordMatch(void *untypedReference, void *untypedEntry);
  533. IX_ETH_DB_PUBLIC BOOL ixEthDBNullMatch(void *reference, void *entry);
  534. IX_ETH_DB_PUBLIC HashNode* ixEthDBPortSearch(IxEthDBMacAddr *macAddress, IxEthDBPortId portID, IxEthDBRecordType typeFilter);
  535. IX_ETH_DB_PUBLIC HashNode* ixEthDBVlanSearch(IxEthDBMacAddr *macAddress, IxEthDBVlanId vlanID, IxEthDBRecordType typeFilter);
  536. /* Utilities */
  537. IX_ETH_DB_PUBLIC const char* mac2string(const unsigned char *mac);
  538. IX_ETH_DB_PUBLIC void showHashInfo(void);
  539. IX_ETH_DB_PUBLIC int ixEthDBAnalyzeHash(void);
  540. IX_ETH_DB_PUBLIC const char* errorString(IxEthDBStatus error);
  541. IX_ETH_DB_PUBLIC int numHashElements(void);
  542. IX_ETH_DB_PUBLIC void zapHashtable(void);
  543. IX_ETH_DB_PUBLIC BOOL ixEthDBCheckSingleBitValue(UINT32 value);
  544. /* Single Eth NPE Check */
  545. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBSingleEthNpeCheck(IxEthDBPortId portId);
  546. #endif /* IxEthDB_p_H */