3 #include <galileo/gt64260R.h>
4 #include <galileo/core.h>
7 #include "eth_addrtbl.h"
14 #ifdef CONFIG_GT_USE_MAC_HASH_TABLE
16 static u32 addressTableHashMode[GAL_ETH_DEVS] = { 0, };
17 static u32 addressTableHashSize[GAL_ETH_DEVS] = { 0, };
18 static addrTblEntry *addressTableBase[GAL_ETH_DEVS] = { 0, };
19 static void *realAddrTableBase[GAL_ETH_DEVS] = { 0, };
21 static const u32 hashLength[2] = {
22 (0x8000), /* 8K * 4 entries */
23 (0x8000 / 16), /* 512 * 4 entries */
26 /* Initialize the address table for a port, if needed */
27 unsigned int initAddressTable (u32 port, u32 hashMode, u32 hashSizeSelector)
29 unsigned int tableBase;
31 if (port < 0 || port >= GAL_ETH_DEVS) {
32 printf ("%s: Invalid port number %d\n", __FUNCTION__, port);
37 printf ("%s: Invalid Hash Mode %d\n", __FUNCTION__, port);
41 if (realAddrTableBase[port] &&
42 (addressTableHashSize[port] != hashSizeSelector)) {
43 /* we have been here before,
44 * but now we want a different sized table
46 free (realAddrTableBase[port]);
47 realAddrTableBase[port] = 0;
48 addressTableBase[port] = 0;
52 tableBase = (unsigned int) addressTableBase[port];
53 /* we get called for every probe, so only do this once */
56 hashLength[hashSizeSelector] * sizeof (addrTblEntry);
58 realAddrTableBase[port] =
60 tableBase = (unsigned int)realAddrTableBase;
63 printf ("%s: alloc memory failed \n", __FUNCTION__);
67 /* align to octal byte */
69 tableBase = (tableBase + 63) & ~63;
71 addressTableHashMode[port] = hashMode;
72 addressTableHashSize[port] = hashSizeSelector;
73 addressTableBase[port] = (addrTblEntry *) tableBase;
75 memset ((void *) tableBase, 0, bytes);
82 * ----------------------------------------------------------------------------
83 * This function will calculate the hash function of the address.
84 * depends on the hash mode and hash size.
86 * macH - the 2 most significant bytes of the MAC address.
87 * macL - the 4 least significant bytes of the MAC address.
88 * hashMode - hash mode 0 or hash mode 1.
89 * hashSizeSelector - indicates number of hash table entries (0=0x8000,1=0x800)
91 * return the calculated entry.
93 u32 hashTableFunction (u32 macH, u32 macL, u32 HashSize, u32 hash_mode)
106 addrH = NIBBLE_SWAPPING_16_BIT (macH);
107 addrL = NIBBLE_SWAPPING_32_BIT (macL);
109 addrHSwapped = FLIP_4_BITS (addrH & 0xf)
110 + ((FLIP_4_BITS ((addrH >> 4) & 0xf)) << 4)
111 + ((FLIP_4_BITS ((addrH >> 8) & 0xf)) << 8)
112 + ((FLIP_4_BITS ((addrH >> 12) & 0xf)) << 12);
114 addrLSwapped = FLIP_4_BITS (addrL & 0xf)
115 + ((FLIP_4_BITS ((addrL >> 4) & 0xf)) << 4)
116 + ((FLIP_4_BITS ((addrL >> 8) & 0xf)) << 8)
117 + ((FLIP_4_BITS ((addrL >> 12) & 0xf)) << 12)
118 + ((FLIP_4_BITS ((addrL >> 16) & 0xf)) << 16)
119 + ((FLIP_4_BITS ((addrL >> 20) & 0xf)) << 20)
120 + ((FLIP_4_BITS ((addrL >> 24) & 0xf)) << 24)
121 + ((FLIP_4_BITS ((addrL >> 28) & 0xf)) << 28);
123 addrH = addrHSwapped;
124 addrL = addrLSwapped;
126 if (hash_mode == 0) {
127 addr0 = (addrL >> 2) & 0x03f;
128 addr1 = (addrL & 0x003) | ((addrL >> 8) & 0x7f) << 2;
129 addr2 = (addrL >> 15) & 0x1ff;
130 addr3 = ((addrL >> 24) & 0x0ff) | ((addrH & 1) << 8);
132 addr0 = FLIP_6_BITS (addrL & 0x03f);
133 addr1 = FLIP_9_BITS (((addrL >> 6) & 0x1ff));
134 addr2 = FLIP_9_BITS ((addrL >> 15) & 0x1ff);
135 addr3 = FLIP_9_BITS ((((addrL >> 24) & 0x0ff) |
136 ((addrH & 0x1) << 8)));
139 hashResult = (addr0 << 9) | (addr1 ^ addr2 ^ addr3);
141 if (HashSize == _8K_TABLE) {
142 hashResult = hashResult & 0xffff;
144 hashResult = hashResult & 0x07ff;
152 * ----------------------------------------------------------------------------
153 * This function will add an entry to the address table.
154 * depends on the hash mode and hash size that was initialized.
156 * port - ETHERNET port number.
157 * macH - the 2 most significant bytes of the MAC address.
158 * macL - the 4 least significant bytes of the MAC address.
159 * skip - if 1, skip this address.
160 * rd - the RD field in the address table.
162 * address table entry is added.
164 * FALSE if table full
166 int addAddressTableEntry (u32 port, u32 macH, u32 macL, u32 rd, u32 skip)
173 newLo = (((macH >> 4) & 0xf) << 15)
174 | (((macH >> 0) & 0xf) << 11)
175 | (((macH >> 12) & 0xf) << 7)
176 | (((macH >> 8) & 0xf) << 3)
177 | (((macL >> 20) & 0x1) << 31)
178 | (((macL >> 16) & 0xf) << 27)
179 | (((macL >> 28) & 0xf) << 23)
180 | (((macL >> 24) & 0xf) << 19)
181 | (skip << SKIP_BIT) | (rd << 2) | VALID;
183 newHi = (((macL >> 4) & 0xf) << 15)
184 | (((macL >> 0) & 0xf) << 11)
185 | (((macL >> 12) & 0xf) << 7)
186 | (((macL >> 8) & 0xf) << 3)
187 | (((macL >> 21) & 0x7) << 0);
190 * Pick the appropriate table, start scanning for free/reusable
191 * entries at the index obtained by hashing the specified MAC address
193 entry = addressTableBase[port];
194 entry += hashTableFunction (macH, macL, addressTableHashSize[port],
195 addressTableHashMode[port]);
196 for (i = 0; i < HOP_NUMBER; i++, entry++) {
197 if (!(entry->lo & VALID) /*|| (entry->lo & SKIP) */ ) {
199 } else { /* if same address put in same position */
200 if (((entry->lo & 0xfffffff8) == (newLo & 0xfffffff8))
201 && (entry->hi == newHi)) {
207 if (i == HOP_NUMBER) {
208 PRINTF ("addGT64260addressTableEntry: table section is full\n");
213 * Update the selected entry
217 DCACHE_FLUSH_N_SYNC ((u32) entry, MAC_ENTRY_SIZE);
221 #endif /* CONFIG_GT_USE_MAC_HASH_TABLE */