This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS570LC4357: How to generate values for setting up the MAC Hash registers

Part Number: TMS570LC4357

Hi,

I want to know how to setup the MAC Hash register for the TMS570LC4357. Can you please provide me an example of how this works ? 

I see the following formula to calculate the hash values in the TRM. But how does one populate the registers afterwards ? 

Hash_fun(0)=DA(0) XOR DA(6) XOR DA(12) XOR DA(18) XOR DA(24) XOR DA(30) XOR DA(36) XOR DA(42);

Hash_fun(1)=DA(1) XOR DA(7) XOR DA(13) XOR DA(19) XOR DA(25) XOR DA(31) XOR DA(37) XOR DA(43);

Hash_fun(2)=DA(2) XOR DA(8) XOR DA(14) XOR DA(20) XOR DA(26) XOR DA(32) XOR DA(38) XOR DA(44);

Hash_fun(3)=DA(3) XOR DA(9) XOR DA(15) XOR DA(21) XOR DA(27) XOR DA(33) XOR DA(39) XOR DA(45);

Hash_fun(4)=DA(4) XOR DA(10) XOR DA(16) XOR DA(22) XOR DA(28) XOR DA(34) XOR DA(40) XOR DA(46);

Hash_fun(5)=DA(5) XOR DA(11) XOR DA(17) XOR DA(23) XOR DA(29) XOR DA(35) XOR DA(41) XOR DA(47);

For e.g. I f i have a MAC address 01:00:5E:00:00:00 and MAC address 01:00:5E:00:00:01 from where I would want to receive packets from , what would I need to set the MACHASH1 and MACHASH registers to ? if you could provide a detailed explanation, that would be useful, as I see this question is repeated often on the forum, without a clear explanation.

  • Hi,

    I looked at the LWIP demo code, we have 

    void EMACFrameSelect(uint32 emacBase, uint64 hashTable)
    {
    HWREG(emacBase + EMAC_MACHASH1) = (uint32)(hashTable & 0xFFFFFFFFU);
    HWREG(emacBase + EMAC_MACHASH2) = (uint32)(hashTable >> 32U);
    }

    But this function is never been called. The example is not multicast. Are you trying to do multicast in your case?

    From reading the 570LC4357 TRM, 32.5.37 MAC Hash Address Register 1 (MACHASH1) 

    You have a MAC address this is 48-bit, then you can calculate the hash_function with those bits:

    Hash_fun(0)=DA(0) XOR DA(6) XOR DA(12) XOR DA(18) XOR DA(24) XOR DA(30) XOR DA(36) XOR DA(42);
    Hash_fun(1)=DA(1) XOR DA(7) XOR DA(13) XOR DA(19) XOR DA(25) XOR DA(31) XOR DA(37) XOR DA(43);
    Hash_fun(2)=DA(2) XOR DA(8) XOR DA(14) XOR DA(20) XOR DA(26) XOR DA(32) XOR DA(38) XOR DA(44);
    Hash_fun(3)=DA(3) XOR DA(9) XOR DA(15) XOR DA(21) XOR DA(27) XOR DA(33) XOR DA(39) XOR DA(45);
    Hash_fun(4)=DA(4) XOR DA(10) XOR DA(16) XOR DA(22) XOR DA(28) XOR DA(34) XOR DA(40) XOR DA(46);
    Hash_fun(5)=DA(5) XOR DA(11) XOR DA(17) XOR DA(23) XOR DA(29) XOR DA(35) XOR DA(41) XOR DA(47);

    Your output is a 6-bit Hash_fun(5 ... 0), totaling 2^6=64 index range. 

    Then you have  MACHASH2 (bit32-63) and MACHASH1 (bit31-0) programmed, each bit can be 0 or 1. If indexing Hash_fun(5...0) into this table and that bit position is 0, then the MAC is rejected. If it is 1, it is accepted. 

    As you want to accept two MAC addresses, you need to compute the Hash_fun(5...0) for both addresses and make that index position = 1 in the hash table. 

    Regards, Eric

  • Hi Eric,

    Yup, I am trying to use Multicast filtering. We have a bunch of sources that are multicasting, and in order to limit the number of packets we need to process I am attempting to use this H/W filter.

    Based on the above approach you mentioned, does this mean, that I can only allow only packets from 64 unique Multicast addresses ? 

    i.e MAC Address: 01:00:5E:00:00:00 and MAC address  01:00:5E:00:00:41 would hash to the same bit i.e bit 0xF (15). 

    As  for  01:00:5E:00:00:00 -> we get 

    Hash_fun(0) = 0 (MSB)

    Hash_fun(1) = 0

    Hash_fun(2) = 1

    Hash_fun(3) = 1

    Hash_fun(4) = 1

    Hash_fun(5) = 1 (LSB)

    And also for 01:00:5E:00:00:41 -> we get 

    Hash_fun(0) = 0  (MSB)

    Hash_fun(1) = 0

    Hash_fun(2) = 1

    Hash_fun(3) = 1

    Hash_fun(4) = 1

    Hash_fun(5) = 1    (LSB)

    Which would mean, if i set bit 15 in the MAC hash registers, packets from both address would come through ? 

  • Hi,

    There are MAC addresses that produce the same hash function value, as you showed above. So if you set bit 15, both MAC addresses are accepted. So you can have more than 64 different MAC address.

    Regards, Eric

  • Hi Eric,

    Thanks for confirming. The issue is that we have both addresses multicasting, a lot of packets. And I would like to listen to only one of those addresses ( 01:00:5E:00:00:00). And setting bit 15 basically allows packets from both addresses to make its way into the network stack, which results in additional processing overhead.