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