IxEthDBNPEAdaptor.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /**
  2. * @file IxEthDBDBNPEAdaptor.c
  3. *
  4. * @brief Routines that read and write learning/search trees in NPE-specific format
  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. #include "IxEthDB_p.h"
  45. #include "IxEthDBLog_p.h"
  46. /* forward prototype declarations */
  47. IX_ETH_DB_PUBLIC void ixEthDBELTShow(IxEthDBPortId portID);
  48. IX_ETH_DB_PUBLIC void ixEthDBShowNpeMsgHistory(void);
  49. /* data */
  50. UINT8* ixEthDBNPEUpdateArea[IX_ETH_DB_NUMBER_OF_PORTS];
  51. UINT32 dumpEltSize;
  52. /* private data */
  53. IX_ETH_DB_PRIVATE IxEthDBNoteWriteFn ixEthDBNPENodeWrite[IX_ETH_DB_MAX_RECORD_TYPE_INDEX + 1];
  54. #define IX_ETH_DB_MAX_DELTA_ZONES (6) /* at most 6 EP Delta zones, according to NPE FS */
  55. IX_ETH_DB_PRIVATE UINT32 ixEthDBEPDeltaOffset[IX_ETH_DB_MAX_RECORD_TYPE_INDEX + 1][IX_ETH_DB_MAX_DELTA_ZONES];
  56. IX_ETH_DB_PRIVATE UINT32 ixEthDBEPDelta[IX_ETH_DB_MAX_RECORD_TYPE_INDEX + 1][IX_ETH_DB_MAX_DELTA_ZONES];
  57. /**
  58. * @brief allocates non-cached or contiguous NPE tree update areas for all the ports
  59. *
  60. * This function is called only once at initialization time from
  61. * @ref ixEthDBInit().
  62. *
  63. * @warning do not call manually
  64. *
  65. * @see ixEthDBInit()
  66. *
  67. * @internal
  68. */
  69. IX_ETH_DB_PUBLIC
  70. void ixEthDBNPEUpdateAreasInit(void)
  71. {
  72. UINT32 portIndex;
  73. PortUpdateMethod *update;
  74. for (portIndex = 0 ; portIndex < IX_ETH_DB_NUMBER_OF_PORTS ; portIndex++)
  75. {
  76. update = &ixEthDBPortInfo[portIndex].updateMethod;
  77. if (ixEthDBPortDefinitions[portIndex].type == IX_ETH_NPE)
  78. {
  79. update->npeUpdateZone = IX_OSAL_CACHE_DMA_MALLOC(FULL_ELT_BYTE_SIZE);
  80. update->npeGwUpdateZone = IX_OSAL_CACHE_DMA_MALLOC(FULL_GW_BYTE_SIZE);
  81. update->vlanUpdateZone = IX_OSAL_CACHE_DMA_MALLOC(FULL_VLAN_BYTE_SIZE);
  82. if (update->npeUpdateZone == NULL
  83. || update->npeGwUpdateZone == NULL
  84. || update->vlanUpdateZone == NULL)
  85. {
  86. ERROR_LOG("Fatal error: IX_ACC_DRV_DMA_MALLOC() returned NULL, no NPE update zones available\n");
  87. }
  88. else
  89. {
  90. memset(update->npeUpdateZone, 0, FULL_ELT_BYTE_SIZE);
  91. memset(update->npeGwUpdateZone, 0, FULL_GW_BYTE_SIZE);
  92. memset(update->vlanUpdateZone, 0, FULL_VLAN_BYTE_SIZE);
  93. }
  94. }
  95. else
  96. {
  97. /* unused */
  98. update->npeUpdateZone = NULL;
  99. update->npeGwUpdateZone = NULL;
  100. update->vlanUpdateZone = NULL;
  101. }
  102. }
  103. }
  104. /**
  105. * @brief deallocates the NPE update areas for all the ports
  106. *
  107. * This function is called at component de-initialization time
  108. * by @ref ixEthDBUnload().
  109. *
  110. * @warning do not call manually
  111. *
  112. * @internal
  113. */
  114. IX_ETH_DB_PUBLIC
  115. void ixEthDBNPEUpdateAreasUnload(void)
  116. {
  117. UINT32 portIndex;
  118. for (portIndex = 0 ; portIndex < IX_ETH_DB_NUMBER_OF_PORTS ; portIndex++)
  119. {
  120. if (ixEthDBPortDefinitions[portIndex].type == IX_ETH_NPE)
  121. {
  122. IX_OSAL_CACHE_DMA_FREE(ixEthDBPortInfo[portIndex].updateMethod.npeUpdateZone);
  123. IX_OSAL_CACHE_DMA_FREE(ixEthDBPortInfo[portIndex].updateMethod.npeGwUpdateZone);
  124. IX_OSAL_CACHE_DMA_FREE(ixEthDBPortInfo[portIndex].updateMethod.vlanUpdateZone);
  125. }
  126. }
  127. }
  128. /**
  129. * @brief general-purpose NPE callback function
  130. *
  131. * @param npeID NPE ID
  132. * @param msg NPE message
  133. *
  134. * This function will unblock the caller by unlocking
  135. * the npeAckLock mutex defined for each NPE port
  136. *
  137. * @internal
  138. */
  139. IX_ETH_DB_PUBLIC
  140. void ixEthDBNpeMsgAck(IxNpeMhNpeId npeID, IxNpeMhMessage msg)
  141. {
  142. IxEthDBPortId portID = IX_ETH_DB_NPE_TO_PORT_ID(npeID);
  143. PortInfo *portInfo;
  144. if (portID >= IX_ETH_DB_NUMBER_OF_PORTS)
  145. {
  146. /* invalid port */
  147. return;
  148. }
  149. if (ixEthDBPortDefinitions[portID].type != IX_ETH_NPE)
  150. {
  151. /* not an NPE */
  152. return;
  153. }
  154. portInfo = &ixEthDBPortInfo[portID];
  155. ixOsalMutexUnlock(&portInfo->npeAckLock);
  156. }
  157. /**
  158. * @brief synchronizes the database with tree
  159. *
  160. * @param portID port ID of the NPE whose tree is to be scanned
  161. * @param eltBaseAddress memory base address of the NPE serialized tree
  162. * @param eltSize size in bytes of the NPE serialized tree
  163. *
  164. * Scans the NPE learning tree and resets the age of active database records.
  165. *
  166. * @internal
  167. */
  168. IX_ETH_DB_PUBLIC
  169. void ixEthDBNPESyncScan(IxEthDBPortId portID, void *eltBaseAddress, UINT32 eltSize)
  170. {
  171. UINT32 eltEntryOffset;
  172. UINT32 entryPortID;
  173. /* invalidate cache */
  174. IX_OSAL_CACHE_INVALIDATE(eltBaseAddress, eltSize);
  175. for (eltEntryOffset = ELT_ROOT_OFFSET ; eltEntryOffset < eltSize ; eltEntryOffset += ELT_ENTRY_SIZE)
  176. {
  177. /* (eltBaseAddress + eltEntryOffset) points to a valid NPE tree node
  178. *
  179. * the format of the node is MAC[6 bytes]:PortID[1 byte]:Reserved[6 bits]:Active[1 bit]:Valid[1 bit]
  180. * therefore we can just use the pointer for database searches as only the first 6 bytes are checked
  181. */
  182. void *eltNodeAddress = (void *) ((UINT32) eltBaseAddress + eltEntryOffset);
  183. /* debug */
  184. IX_ETH_DB_NPE_VERBOSE_TRACE("DB: (NPEAdaptor) checking node at offset %d...\n", eltEntryOffset / ELT_ENTRY_SIZE);
  185. if (IX_EDB_NPE_NODE_VALID(eltNodeAddress) != TRUE)
  186. {
  187. IX_ETH_DB_NPE_VERBOSE_TRACE("\t... node is empty\n");
  188. }
  189. else if (eltEntryOffset == ELT_ROOT_OFFSET)
  190. {
  191. IX_ETH_DB_NPE_VERBOSE_TRACE("\t... node is root\n");
  192. }
  193. if (IX_EDB_NPE_NODE_VALID(eltNodeAddress))
  194. {
  195. entryPortID = IX_ETH_DB_NPE_LOGICAL_ID_TO_PORT_ID(IX_EDB_NPE_NODE_PORT_ID(eltNodeAddress));
  196. /* check only active entries belonging to this port */
  197. if (ixEthDBPortInfo[portID].agingEnabled && IX_EDB_NPE_NODE_ACTIVE(eltNodeAddress) && (portID == entryPortID)
  198. && ((ixEthDBPortDefinitions[portID].capabilities & IX_ETH_ENTRY_AGING) == 0))
  199. {
  200. /* search record */
  201. HashNode *node = ixEthDBSearch((IxEthDBMacAddr *) eltNodeAddress, IX_ETH_DB_ALL_FILTERING_RECORDS);
  202. /* safety check, maybe user deleted record right before sync? */
  203. if (node != NULL)
  204. {
  205. /* found record */
  206. MacDescriptor *descriptor = (MacDescriptor *) node->data;
  207. IX_ETH_DB_NPE_VERBOSE_TRACE("DB: (NPEAdaptor) synced entry [%s] already in the database, updating fields\n", mac2string(eltNodeAddress));
  208. /* reset age - set to -1 so that maintenance will restore it to 0 (or more) when incrementing */
  209. if (!descriptor->recordData.filteringData.staticEntry)
  210. {
  211. if (descriptor->type == IX_ETH_DB_FILTERING_RECORD)
  212. {
  213. descriptor->recordData.filteringData.age = AGE_RESET;
  214. }
  215. else if (descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD)
  216. {
  217. descriptor->recordData.filteringVlanData.age = AGE_RESET;
  218. }
  219. }
  220. /* end transaction */
  221. ixEthDBReleaseHashNode(node);
  222. }
  223. }
  224. else
  225. {
  226. IX_ETH_DB_NPE_VERBOSE_TRACE("\t... found portID %d, we check only port %d\n", entryPortID, portID);
  227. }
  228. }
  229. }
  230. }
  231. /**
  232. * @brief writes a search tree in NPE format
  233. *
  234. * @param type type of records to be written into the NPE update zone
  235. * @param totalSize maximum size of the linearized tree
  236. * @param baseAddress memory base address where to write the NPE tree into
  237. * @param tree search tree to write in NPE format
  238. * @param blocks number of written 64-byte blocks
  239. * @param startIndex optimal binary search start index
  240. *
  241. * Serializes the given tree in NPE linear format
  242. *
  243. * @return none
  244. *
  245. * @internal
  246. */
  247. IX_ETH_DB_PUBLIC
  248. void ixEthDBNPETreeWrite(IxEthDBRecordType type, UINT32 totalSize, void *baseAddress, MacTreeNode *tree, UINT32 *epDelta, UINT32 *blocks)
  249. {
  250. MacTreeNodeStack *stack;
  251. UINT32 maxOffset = 0;
  252. UINT32 emptyOffset;
  253. stack = ixOsalCacheDmaMalloc(sizeof (MacTreeNodeStack));
  254. if (stack == NULL)
  255. {
  256. ERROR_LOG("DB: (NPEAdaptor) failed to allocate the node stack for learning tree linearization, out of memory?\n");
  257. return;
  258. }
  259. /* zero out empty root */
  260. memset(baseAddress, 0, ELT_ENTRY_SIZE);
  261. NODE_STACK_INIT(stack);
  262. if (tree != NULL)
  263. {
  264. /* push tree root at offset 1 */
  265. NODE_STACK_PUSH(stack, tree, 1);
  266. maxOffset = 1;
  267. }
  268. while (NODE_STACK_NONEMPTY(stack))
  269. {
  270. MacTreeNode *node;
  271. UINT32 offset;
  272. NODE_STACK_POP(stack, node, offset);
  273. /* update maximum offset */
  274. if (offset > maxOffset)
  275. {
  276. maxOffset = offset;
  277. }
  278. IX_ETH_DB_NPE_VERBOSE_TRACE("DB: (NPEAdaptor) writing MAC [%s] at offset %d\n", mac2string(node->descriptor->macAddress), offset);
  279. /* add node to NPE ELT at position indicated by offset */
  280. if (offset < MAX_ELT_SIZE)
  281. {
  282. ixEthDBNPENodeWrite[type]((void *) (((UINT32) baseAddress) + offset * ELT_ENTRY_SIZE), node);
  283. }
  284. if (node->left != NULL)
  285. {
  286. NODE_STACK_PUSH(stack, node->left, LEFT_CHILD_OFFSET(offset));
  287. }
  288. else
  289. {
  290. /* ensure this entry is zeroed */
  291. memset((void *) ((UINT32) baseAddress + LEFT_CHILD_OFFSET(offset) * ELT_ENTRY_SIZE), 0, ELT_ENTRY_SIZE);
  292. }
  293. if (node->right != NULL)
  294. {
  295. NODE_STACK_PUSH(stack, node->right, RIGHT_CHILD_OFFSET(offset));
  296. }
  297. else
  298. {
  299. /* ensure this entry is zeroed */
  300. memset((void *) ((UINT32) baseAddress + RIGHT_CHILD_OFFSET(offset) * ELT_ENTRY_SIZE), 0, ELT_ENTRY_SIZE);
  301. }
  302. }
  303. emptyOffset = maxOffset + 1;
  304. /* zero out rest of the tree */
  305. IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Emptying tree from offset %d, address 0x%08X, %d bytes\n",
  306. emptyOffset, ((UINT32) baseAddress) + emptyOffset * ELT_ENTRY_SIZE, totalSize - (emptyOffset * ELT_ENTRY_SIZE));
  307. if (emptyOffset < MAX_ELT_SIZE - 1)
  308. {
  309. memset((void *) (((UINT32) baseAddress) + (emptyOffset * ELT_ENTRY_SIZE)), 0, totalSize - (emptyOffset * ELT_ENTRY_SIZE));
  310. }
  311. /* flush cache */
  312. IX_OSAL_CACHE_FLUSH(baseAddress, totalSize);
  313. /* debug */
  314. IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Ethernet learning/filtering tree XScale wrote at address 0x%08X (max %d bytes):\n\n",
  315. (UINT32) baseAddress, FULL_ELT_BYTE_SIZE);
  316. IX_ETH_DB_NPE_DUMP_ELT(baseAddress, FULL_ELT_BYTE_SIZE);
  317. /* compute number of 64-byte blocks */
  318. if (blocks != NULL)
  319. {
  320. *blocks = maxOffset != 0 ? 1 + maxOffset / 8 : 0;
  321. IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Wrote %d 64-byte blocks\n", *blocks);
  322. }
  323. /* compute epDelta - start index for binary search */
  324. if (epDelta != NULL)
  325. {
  326. UINT32 deltaIndex = 0;
  327. *epDelta = 0;
  328. for (; deltaIndex < IX_ETH_DB_MAX_DELTA_ZONES ; deltaIndex ++)
  329. {
  330. if (ixEthDBEPDeltaOffset[type][deltaIndex] >= maxOffset)
  331. {
  332. *epDelta = ixEthDBEPDelta[type][deltaIndex];
  333. break;
  334. }
  335. }
  336. IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Computed epDelta %d (based on maxOffset %d)\n", *epDelta, maxOffset);
  337. }
  338. ixOsalCacheDmaFree(stack);
  339. }
  340. /**
  341. * @brief implements a dummy node serialization function
  342. *
  343. * @param address address of where the node is to be serialized (unused)
  344. * @param node tree node to be serialized (unused)
  345. *
  346. * This function is registered for safety reasons and should
  347. * never be called. It will display an error message if this
  348. * function is called.
  349. *
  350. * @return none
  351. *
  352. * @internal
  353. */
  354. IX_ETH_DB_PRIVATE
  355. void ixEthDBNullSerialize(void *address, MacTreeNode *node)
  356. {
  357. IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Warning, the NullSerialize function was called, wrong record type?\n");
  358. }
  359. /**
  360. * @brief writes a filtering entry in NPE linear format
  361. *
  362. * @param address memory address to write node to
  363. * @param node node to be written
  364. *
  365. * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree
  366. * in NPE-readable format.
  367. *
  368. * @internal
  369. */
  370. IX_ETH_DB_PRIVATE
  371. void ixEthDBNPELearningNodeWrite(void *address, MacTreeNode *node)
  372. {
  373. /* copy mac address */
  374. memcpy(address, node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE);
  375. /* copy port ID */
  376. NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_ELT_PORT_ID_OFFSET) = IX_ETH_DB_PORT_ID_TO_NPE_LOGICAL_ID(node->descriptor->portID);
  377. /* copy flags (valid and not active, as the NPE sets it to active) and clear reserved section (bits 2-7) */
  378. NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_ELT_FLAGS_OFFSET) = (UINT8) IX_EDB_FLAGS_INACTIVE_VALID;
  379. IX_ETH_DB_NPE_VERBOSE_TRACE("DB: (NPEAdaptor) writing ELT node 0x%08x:0x%08x\n", * (UINT32 *) address, * (((UINT32 *) (address)) + 1));
  380. }
  381. /**
  382. * @brief writes a WiFi header conversion record in
  383. * NPE linear format
  384. *
  385. * @param address memory address to write node to
  386. * @param node node to be written
  387. *
  388. * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree
  389. * in NPE-readable format.
  390. *
  391. * @internal
  392. */
  393. IX_ETH_DB_PRIVATE
  394. void ixEthDBNPEWiFiNodeWrite(void *address, MacTreeNode *node)
  395. {
  396. /* copy mac address */
  397. memcpy(address, node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE);
  398. /* copy index */
  399. NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_WIFI_INDEX_OFFSET) = node->descriptor->recordData.wifiData.gwAddressIndex;
  400. /* copy flags (type and valid) */
  401. NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_WIFI_FLAGS_OFFSET) = node->descriptor->recordData.wifiData.type << 1 | IX_EDB_FLAGS_VALID;
  402. }
  403. /**
  404. * @brief writes a WiFi gateway header conversion record in
  405. * NPE linear format
  406. *
  407. * @param address memory address to write node to
  408. * @param node node to be written
  409. *
  410. * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree
  411. * in NPE-readable format.
  412. *
  413. * @internal
  414. */
  415. IX_ETH_DB_PUBLIC
  416. void ixEthDBNPEGatewayNodeWrite(void *address, MacTreeNode *node)
  417. {
  418. /* copy mac address */
  419. memcpy(address, node->descriptor->recordData.wifiData.gwMacAddress, IX_IEEE803_MAC_ADDRESS_SIZE);
  420. /* set reserved field, two bytes */
  421. NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_RESERVED_OFFSET) = 0;
  422. NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_RESERVED_OFFSET + 1) = 0;
  423. }
  424. /**
  425. * @brief writes a firewall record in
  426. * NPE linear format
  427. *
  428. * @param address memory address to write node to
  429. * @param node node to be written
  430. *
  431. * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree
  432. * in NPE-readable format.
  433. *
  434. * @internal
  435. */
  436. IX_ETH_DB_PRIVATE
  437. void ixEthDBNPEFirewallNodeWrite(void *address, MacTreeNode *node)
  438. {
  439. /* set reserved field */
  440. NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_RESERVED_OFFSET) = 0;
  441. /* set flags */
  442. NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_FLAGS_OFFSET) = IX_EDB_FLAGS_VALID;
  443. /* copy mac address */
  444. memcpy((void *) ((UINT32) address + IX_EDB_NPE_NODE_FW_ADDR_OFFSET), node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE);
  445. }
  446. /**
  447. * @brief registers the NPE serialization methods
  448. *
  449. * This functions registers NPE serialization methods
  450. * for writing the following types of records in NPE
  451. * readable linear format:
  452. * - filtering records
  453. * - WiFi header conversion records
  454. * - WiFi gateway header conversion records
  455. * - firewall records
  456. *
  457. * Note that this function should be called by the
  458. * component initialization function.
  459. *
  460. * @return number of registered record types
  461. *
  462. * @internal
  463. */
  464. IX_ETH_DB_PUBLIC
  465. UINT32 ixEthDBRecordSerializeMethodsRegister()
  466. {
  467. int i;
  468. /* safety - register a blank method for everybody first */
  469. for ( i = 0 ; i < IX_ETH_DB_MAX_RECORD_TYPE_INDEX + 1 ; i++)
  470. {
  471. ixEthDBNPENodeWrite[i] = ixEthDBNullSerialize;
  472. }
  473. /* register real methods */
  474. ixEthDBNPENodeWrite[IX_ETH_DB_FILTERING_RECORD] = ixEthDBNPELearningNodeWrite;
  475. ixEthDBNPENodeWrite[IX_ETH_DB_FILTERING_VLAN_RECORD] = ixEthDBNPELearningNodeWrite;
  476. ixEthDBNPENodeWrite[IX_ETH_DB_WIFI_RECORD] = ixEthDBNPEWiFiNodeWrite;
  477. ixEthDBNPENodeWrite[IX_ETH_DB_FIREWALL_RECORD] = ixEthDBNPEFirewallNodeWrite;
  478. ixEthDBNPENodeWrite[IX_ETH_DB_GATEWAY_RECORD] = ixEthDBNPEGatewayNodeWrite;
  479. /* EP Delta arrays */
  480. memset(ixEthDBEPDeltaOffset, 0, sizeof (ixEthDBEPDeltaOffset));
  481. memset(ixEthDBEPDelta, 0, sizeof (ixEthDBEPDelta));
  482. /* filtering records */
  483. ixEthDBEPDeltaOffset[IX_ETH_DB_FILTERING_RECORD][0] = 1;
  484. ixEthDBEPDelta[IX_ETH_DB_FILTERING_RECORD][0] = 0;
  485. ixEthDBEPDeltaOffset[IX_ETH_DB_FILTERING_RECORD][1] = 3;
  486. ixEthDBEPDelta[IX_ETH_DB_FILTERING_RECORD][1] = 7;
  487. ixEthDBEPDeltaOffset[IX_ETH_DB_FILTERING_RECORD][2] = 511;
  488. ixEthDBEPDelta[IX_ETH_DB_FILTERING_RECORD][2] = 14;
  489. /* wifi records */
  490. ixEthDBEPDeltaOffset[IX_ETH_DB_WIFI_RECORD][0] = 1;
  491. ixEthDBEPDelta[IX_ETH_DB_WIFI_RECORD][0] = 0;
  492. ixEthDBEPDeltaOffset[IX_ETH_DB_WIFI_RECORD][1] = 3;
  493. ixEthDBEPDelta[IX_ETH_DB_WIFI_RECORD][1] = 7;
  494. ixEthDBEPDeltaOffset[IX_ETH_DB_WIFI_RECORD][2] = 511;
  495. ixEthDBEPDelta[IX_ETH_DB_WIFI_RECORD][2] = 14;
  496. /* firewall records */
  497. ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][0] = 0;
  498. ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][0] = 0;
  499. ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][1] = 1;
  500. ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][1] = 5;
  501. ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][2] = 3;
  502. ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][2] = 13;
  503. ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][3] = 7;
  504. ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][3] = 21;
  505. ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][4] = 15;
  506. ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][4] = 29;
  507. ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][5] = 31;
  508. ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][5] = 37;
  509. return 5; /* 5 methods registered */
  510. }
  511. #ifndef IX_NDEBUG
  512. IX_ETH_DB_PUBLIC UINT32 npeMsgHistory[IX_ETH_DB_NPE_MSG_HISTORY_DEPTH][2];
  513. IX_ETH_DB_PUBLIC UINT32 npeMsgHistoryLen = 0;
  514. /**
  515. * When compiled in DEBUG mode, this function can be used to display
  516. * the history of messages sent to the NPEs (up to 100).
  517. */
  518. IX_ETH_DB_PUBLIC
  519. void ixEthDBShowNpeMsgHistory()
  520. {
  521. UINT32 i = 0;
  522. UINT32 base, len;
  523. if (npeMsgHistoryLen <= IX_ETH_DB_NPE_MSG_HISTORY_DEPTH)
  524. {
  525. base = 0;
  526. len = npeMsgHistoryLen;
  527. }
  528. else
  529. {
  530. base = npeMsgHistoryLen % IX_ETH_DB_NPE_MSG_HISTORY_DEPTH;
  531. len = IX_ETH_DB_NPE_MSG_HISTORY_DEPTH;
  532. }
  533. printf("NPE message history [last %d messages, from least to most recent]:\n", len);
  534. for (; i < len ; i++)
  535. {
  536. UINT32 pos = (base + i) % IX_ETH_DB_NPE_MSG_HISTORY_DEPTH;
  537. printf("msg[%d]: 0x%08x:0x%08x\n", i, npeMsgHistory[pos][0], npeMsgHistory[pos][1]);
  538. }
  539. }
  540. IX_ETH_DB_PUBLIC
  541. void ixEthDBELTShow(IxEthDBPortId portID)
  542. {
  543. IxNpeMhMessage message;
  544. IX_STATUS result;
  545. /* send EDB_GetMACAddressDatabase message */
  546. FILL_GETMACADDRESSDATABASE(message,
  547. 0 /* reserved */,
  548. IX_OSAL_MMU_VIRT_TO_PHYS(ixEthDBPortInfo[portID].updateMethod.npeUpdateZone));
  549. IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result);
  550. if (result == IX_SUCCESS)
  551. {
  552. /* analyze NPE copy */
  553. UINT32 eltEntryOffset;
  554. UINT32 entryPortID;
  555. UINT32 eltBaseAddress = (UINT32) ixEthDBPortInfo[portID].updateMethod.npeUpdateZone;
  556. UINT32 eltSize = FULL_ELT_BYTE_SIZE;
  557. /* invalidate cache */
  558. IX_OSAL_CACHE_INVALIDATE((void *) eltBaseAddress, eltSize);
  559. printf("Listing records in main learning tree for port %d\n", portID);
  560. for (eltEntryOffset = ELT_ROOT_OFFSET ; eltEntryOffset < eltSize ; eltEntryOffset += ELT_ENTRY_SIZE)
  561. {
  562. /* (eltBaseAddress + eltEntryOffset) points to a valid NPE tree node
  563. *
  564. * the format of the node is MAC[6 bytes]:PortID[1 byte]:Reserved[6 bits]:Active[1 bit]:Valid[1 bit]
  565. * therefore we can just use the pointer for database searches as only the first 6 bytes are checked
  566. */
  567. void *eltNodeAddress = (void *) ((UINT32) eltBaseAddress + eltEntryOffset);
  568. if (IX_EDB_NPE_NODE_VALID(eltNodeAddress))
  569. {
  570. HashNode *node;
  571. entryPortID = IX_ETH_DB_NPE_LOGICAL_ID_TO_PORT_ID(IX_EDB_NPE_NODE_PORT_ID(eltNodeAddress));
  572. /* search record */
  573. node = ixEthDBSearch((IxEthDBMacAddr *) eltNodeAddress, IX_ETH_DB_ALL_RECORD_TYPES);
  574. printf("%s - port %d - %s ", mac2string((unsigned char *) eltNodeAddress), entryPortID,
  575. IX_EDB_NPE_NODE_ACTIVE(eltNodeAddress) ? "active" : "inactive");
  576. /* safety check, maybe user deleted record right before sync? */
  577. if (node != NULL)
  578. {
  579. /* found record */
  580. MacDescriptor *descriptor = (MacDescriptor *) node->data;
  581. printf("- %s ",
  582. descriptor->type == IX_ETH_DB_FILTERING_RECORD ? "filtering" :
  583. descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD ? "vlan" :
  584. descriptor->type == IX_ETH_DB_WIFI_RECORD ? "wifi" : "other (check main DB)");
  585. if (descriptor->type == IX_ETH_DB_FILTERING_RECORD) printf("- age %d - %s ",
  586. descriptor->recordData.filteringData.age,
  587. descriptor->recordData.filteringData.staticEntry ? "static" : "dynamic");
  588. if (descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD) printf("- age %d - %s - tci %d ",
  589. descriptor->recordData.filteringVlanData.age,
  590. descriptor->recordData.filteringVlanData.staticEntry ? "static" : "dynamic",
  591. descriptor->recordData.filteringVlanData.ieee802_1qTag);
  592. /* end transaction */
  593. ixEthDBReleaseHashNode(node);
  594. }
  595. else
  596. {
  597. printf("- not synced");
  598. }
  599. printf("\n");
  600. }
  601. }
  602. }
  603. else
  604. {
  605. ixOsalLog(IX_OSAL_LOG_LVL_FATAL, IX_OSAL_LOG_DEV_STDOUT,
  606. "EthDB: (ShowELT) Could not complete action (communication failure)\n",
  607. portID, 0, 0, 0, 0, 0);
  608. }
  609. }
  610. #endif