IxEthDB_p.h 28 KB

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