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 tableBase = (unsigned int) realAddrTableBase[port] =
62 printf ("%s: alloc memory failed \n", __FUNCTION__);
66 /* align to octal byte */
68 tableBase = (tableBase + 63) & ~63;
70 addressTableHashMode[port] = hashMode;
71 addressTableHashSize[port] = hashSizeSelector;
72 addressTableBase[port] = (addrTblEntry *) tableBase;
74 memset ((void *) tableBase, 0, bytes);
81 * ----------------------------------------------------------------------------
82 * This function will calculate the hash function of the address.
83 * depends on the hash mode and hash size.
85 * macH - the 2 most significant bytes of the MAC address.
86 * macL - the 4 least significant bytes of the MAC address.
87 * hashMode - hash mode 0 or hash mode 1.
88 * hashSizeSelector - indicates number of hash table entries (0=0x8000,1=0x800)
90 * return the calculated entry.
92 u32 hashTableFunction (u32 macH, u32 macL, u32 HashSize, u32 hash_mode)
105 addrH = NIBBLE_SWAPPING_16_BIT (macH);
106 addrL = NIBBLE_SWAPPING_32_BIT (macL);
108 addrHSwapped = FLIP_4_BITS (addrH & 0xf)
109 + ((FLIP_4_BITS ((addrH >> 4) & 0xf)) << 4)
110 + ((FLIP_4_BITS ((addrH >> 8) & 0xf)) << 8)
111 + ((FLIP_4_BITS ((addrH >> 12) & 0xf)) << 12);
113 addrLSwapped = FLIP_4_BITS (addrL & 0xf)
114 + ((FLIP_4_BITS ((addrL >> 4) & 0xf)) << 4)
115 + ((FLIP_4_BITS ((addrL >> 8) & 0xf)) << 8)
116 + ((FLIP_4_BITS ((addrL >> 12) & 0xf)) << 12)
117 + ((FLIP_4_BITS ((addrL >> 16) & 0xf)) << 16)
118 + ((FLIP_4_BITS ((addrL >> 20) & 0xf)) << 20)
119 + ((FLIP_4_BITS ((addrL >> 24) & 0xf)) << 24)
120 + ((FLIP_4_BITS ((addrL >> 28) & 0xf)) << 28);
122 addrH = addrHSwapped;
123 addrL = addrLSwapped;
125 if (hash_mode == 0) {
126 addr0 = (addrL >> 2) & 0x03f;
127 addr1 = (addrL & 0x003) | ((addrL >> 8) & 0x7f) << 2;
128 addr2 = (addrL >> 15) & 0x1ff;
129 addr3 = ((addrL >> 24) & 0x0ff) | ((addrH & 1) << 8);
131 addr0 = FLIP_6_BITS (addrL & 0x03f);
132 addr1 = FLIP_9_BITS (((addrL >> 6) & 0x1ff));
133 addr2 = FLIP_9_BITS ((addrL >> 15) & 0x1ff);
134 addr3 = FLIP_9_BITS ((((addrL >> 24) & 0x0ff) |
135 ((addrH & 0x1) << 8)));
138 hashResult = (addr0 << 9) | (addr1 ^ addr2 ^ addr3);
140 if (HashSize == _8K_TABLE) {
141 hashResult = hashResult & 0xffff;
143 hashResult = hashResult & 0x07ff;
151 * ----------------------------------------------------------------------------
152 * This function will add an entry to the address table.
153 * depends on the hash mode and hash size that was initialized.
155 * port - ETHERNET port number.
156 * macH - the 2 most significant bytes of the MAC address.
157 * macL - the 4 least significant bytes of the MAC address.
158 * skip - if 1, skip this address.
159 * rd - the RD field in the address table.
161 * address table entry is added.
163 * FALSE if table full
165 int addAddressTableEntry (u32 port, u32 macH, u32 macL, u32 rd, u32 skip)
172 newLo = (((macH >> 4) & 0xf) << 15)
173 | (((macH >> 0) & 0xf) << 11)
174 | (((macH >> 12) & 0xf) << 7)
175 | (((macH >> 8) & 0xf) << 3)
176 | (((macL >> 20) & 0x1) << 31)
177 | (((macL >> 16) & 0xf) << 27)
178 | (((macL >> 28) & 0xf) << 23)
179 | (((macL >> 24) & 0xf) << 19)
180 | (skip << SKIP_BIT) | (rd << 2) | VALID;
182 newHi = (((macL >> 4) & 0xf) << 15)
183 | (((macL >> 0) & 0xf) << 11)
184 | (((macL >> 12) & 0xf) << 7)
185 | (((macL >> 8) & 0xf) << 3)
186 | (((macL >> 21) & 0x7) << 0);
189 * Pick the appropriate table, start scanning for free/reusable
190 * entries at the index obtained by hashing the specified MAC address
192 entry = addressTableBase[port];
193 entry += hashTableFunction (macH, macL, addressTableHashSize[port],
194 addressTableHashMode[port]);
195 for (i = 0; i < HOP_NUMBER; i++, entry++) {
196 if (!(entry->lo & VALID) /*|| (entry->lo & SKIP) */ ) {
198 } else { /* if same address put in same position */
199 if (((entry->lo & 0xfffffff8) == (newLo & 0xfffffff8))
200 && (entry->hi == newHi)) {
206 if (i == HOP_NUMBER) {
207 PRINTF ("addGT64260addressTableEntry: table section is full\n");
212 * Update the selected entry
216 DCACHE_FLUSH_N_SYNC ((u32) entry, MAC_ENTRY_SIZE);
220 #endif /* CONFIG_GT_USE_MAC_HASH_TABLE */