net/cadence_gem: Updating the GEM MAC IP to properly filter out multicast addresses.
PATCH v2 1/1 net/cadence_gem: Updating the GEM MAC IP to properly filter out multicast addresses.
From: bwasim <[email protected]>
The current code makes a bad assumption that the most-significant byte of the MAC address is used to determine if the address is multicast or unicast, but in reality only a single bit is used to determine this. This caused IPv6 to not work.. Fix is now in place and has been tested with ZCU102-A53 / IPv6 on a TAP interface. Works well..
--- hw/net/cadence_gem.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
hw/net/cadence_gem.c +12 -7
@@ -34,6 +34,7 @@#include "qemu/module.h" #include "sysemu/dma.h" #include "net/checksum.h" +#include "net/eth.h" #ifdef CADENCE_GEM_ERR_DEBUG #define DB_PRINT (...) do { \
@@ -601,7 +602,7 @@ static void gem_receive_updatestats(CadenceGEMState *s, const uint8_t *packet, }/* Error-free Multicast Frames counter */ -if (packet[0 ] ==0x01 ) { +if (is_multicast_ether_addr (packet)) { s->regs[GEM_RXMULTICNT ]++; }
@@ -690,21 +691,25 @@ static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet) }/* Accept packets -w- hash match? */ -if ((packet[0 ] ==0x01 && (s->regs[GEM_NWCFG ] &GEM_NWCFG_MCAST_HASH )) || - (packet[0 ] !=0x01 && (s->regs[GEM_NWCFG ] &GEM_NWCFG_UCAST_HASH ))) { +if ((is_multicast_ether_addr (packet) + && (s->regs[GEM_NWCFG ] &GEM_NWCFG_MCAST_HASH )) || + (is_unicast_ether_addr (packet) + && (s->regs[GEM_NWCFG ] &GEM_NWCFG_UCAST_HASH ))) {unsigned hash_index; hash_index =calc_mac_hash (packet);if (hash_index <32 ) {if (s->regs[GEM_HASHLO ] & (1 <<hash_index)) { -return packet[0 ] ==0x01 ?GEM_RX_MULTICAST_HASH_ACCEPT : -GEM_RX_UNICAST_HASH_ACCEPT ; +return is_multicast_ether_addr (packet) ? +GEM_RX_MULTICAST_HASH_ACCEPT : +GEM_RX_UNICAST_HASH_ACCEPT ; } }else { hash_index -=32 ;if (s->regs[GEM_HASHHI ] & (1 <<hash_index)) { -return packet[0 ] ==0x01 ?GEM_RX_MULTICAST_HASH_ACCEPT : -GEM_RX_UNICAST_HASH_ACCEPT ; +return is_multicast_ether_addr (packet) ? +GEM_RX_MULTICAST_HASH_ACCEPT : +GEM_RX_UNICAST_HASH_ACCEPT ; } } }
Signature · 1 line
2.19.1.windows.1
Quoted 7 lines · On Fri, Nov 29, 2019 at 01:52:16PM +0500, [email protected] wrote:
From: bwasim <[email protected]>
The current code makes a bad assumption that the most-significant byte of the MAC address is used to determine if the address is multicast or unicast, but in reality only a single bit is used to determine this. This caused IPv6 to not work.. Fix is now in place and has been tested with ZCU102-A53 / IPv6 on a TAP interface. Works well..
Thanks Bilal,
Sorry, just one more thing I had missed, we need to update gem_transmit_updatestats() aswell, in a similar way as we did with gem_receive_updatestats().
Cheers,
Edgar
Quoted 62 lines
Signed-off-by Bilal Wasim <[email protected]>--- hw/net/cadence_gem.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)hw/net/cadence_gem.c +12
-7@@ -34,6 +34,7 @@#include "qemu/module.h" #include "sysemu/dma.h" #include "net/checksum.h" +#include "net/eth.h" #ifdef CADENCE_GEM_ERR_DEBUG #define DB_PRINT (...) do { \@@ -601,7 +602,7 @@ static void gem_receive_updatestats(CadenceGEMState *s, const uint8_t *packet, }/* Error-free Multicast Frames counter */ -if (packet[0 ] ==0x01 ) { +if (is_multicast_ether_addr (packet)) { s->regs[GEM_RXMULTICNT ]++; }@@ -690,21 +691,25 @@ static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet) }/* Accept packets -w- hash match? */ -if ((packet[0 ] ==0x01 && (s->regs[GEM_NWCFG ] &GEM_NWCFG_MCAST_HASH )) || - (packet[0 ] !=0x01 && (s->regs[GEM_NWCFG ] &GEM_NWCFG_UCAST_HASH ))) { +if ((is_multicast_ether_addr (packet) + && (s->regs[GEM_NWCFG ] &GEM_NWCFG_MCAST_HASH )) || + (is_unicast_ether_addr (packet) + && (s->regs[GEM_NWCFG ] &GEM_NWCFG_UCAST_HASH ))) {unsigned hash_index; hash_index =calc_mac_hash (packet);if (hash_index <32 ) {if (s->regs[GEM_HASHLO ] & (1 <<hash_index)) { -return packet[0 ] ==0x01 ?GEM_RX_MULTICAST_HASH_ACCEPT : -GEM_RX_UNICAST_HASH_ACCEPT ; +return is_multicast_ether_addr (packet) ? +GEM_RX_MULTICAST_HASH_ACCEPT : +GEM_RX_UNICAST_HASH_ACCEPT ; } }else { hash_index -=32 ;if (s->regs[GEM_HASHHI ] & (1 <<hash_index)) { -return packet[0 ] ==0x01 ?GEM_RX_MULTICAST_HASH_ACCEPT : -GEM_RX_UNICAST_HASH_ACCEPT ; +return is_multicast_ether_addr (packet) ? +GEM_RX_MULTICAST_HASH_ACCEPT : +GEM_RX_UNICAST_HASH_ACCEPT ; } } }Signature · 1 line
2.19.1.windows.1
Thanks, Will do..
Quoted 88 lines · On Fri, 29 Nov 2019, 14:13 Edgar E. Iglesias, <[email protected]> wrote:
Quoted 7 lines · On Fri, Nov 29, 2019 at 01:52:16PM +0500, [email protected] wrote:
From: bwasim <[email protected]>
The current code makes a bad assumption that the most-significant byte of the MAC address is used to determine if the address is multicast or unicast, but in reality only a single bit is used to determine this. This caused IPv6 to not work.. Fix is now in place and has been tested with ZCU102-A53 / IPv6 on a TAP interface. Works well..
Thanks Bilal,
Sorry, just one more thing I had missed, we need to update
gem_transmit_updatestats()aswell, in a similar way as we did withgem_receive_updatestats().Cheers,
Edgarhw/net/cadence_gem.c static void gem_receive_updatestats(CadenceGEMState
Quoted 19 lines
Signed-off-by Bilal Wasim <[email protected]>--- hw/net/cadence_gem.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)hw/net/cadence_gem.c +1
-0@@ -34,6 +34,7 @@#include "qemu/module.h" #include "sysemu/dma.h" #include "net/checksum.h" +#include "net/eth.h" #ifdef CADENCE_GEM_ERR_DEBUG #define DB_PRINT (...) do { \@@ -601,7 +602,7 @@ static void gem_receive_updatestats(CadenceGEMState*s, const
uint8_t*packet,hw/net/cadence_gem.c static int gem_mac_address_filter(CadenceGEMState
Quoted 9 lines
hw/net/cadence_gem.c +1
-1}/* Error-free Multicast Frames counter */ -if (packet[0 ] ==0x01 ) { +if (is_multicast_ether_addr (packet)) { s->regs[GEM_RXMULTICNT ]++; }@@ -690,21 +691,25 @@ static int gem_mac_address_filter(CadenceGEMState*s, const
uint8_t*packet)hw/net/cadence_gem.c static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
Quoted 4 lines
hw/net/cadence_gem.c +0
-1}/* Accept packets -w- hash match? */ - if ((packet[0] == 0x01 && (s->regs[GEM_NWCFG] &
GEM_NWCFG_MCAST_HASH)) ||hw/net/cadence_gem.c static int gem_mac_address_filter(CadenceGEMState · line 694
Quoted 1 line
hw/net/cadence_gem.c +0
-1- (packet[0] != 0x01 && (s->regs[GEM_NWCFG] &
GEM_NWCFG_UCAST_HASH))) {hw/net/cadence_gem.c static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
Quoted 10 lines
hw/net/cadence_gem.c +4
-1+if ((is_multicast_ether_addr (packet) + && (s->regs[GEM_NWCFG ] &GEM_NWCFG_MCAST_HASH )) || + (is_unicast_ether_addr (packet) + && (s->regs[GEM_NWCFG ] &GEM_NWCFG_UCAST_HASH ))) {unsigned hash_index; hash_index =calc_mac_hash (packet);if (hash_index <32 ) {if (s->regs[GEM_HASHLO ] & (1 <<hash_index)) { - return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT:
hw/net/cadence_gem.c static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
Quoted 9 lines
hw/net/cadence_gem.c +3
-2-GEM_RX_UNICAST_HASH_ACCEPT ; +return is_multicast_ether_addr (packet) ? +GEM_RX_MULTICAST_HASH_ACCEPT : +GEM_RX_UNICAST_HASH_ACCEPT ; } }else { hash_index -=32 ;if (s->regs[GEM_HASHHI ] & (1 <<hash_index)) { - return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT:
Quoted 10 lines
hw/net/cadence_gem.c +3
-2-GEM_RX_UNICAST_HASH_ACCEPT ; +return is_multicast_ether_addr (packet) ? +GEM_RX_MULTICAST_HASH_ACCEPT : +GEM_RX_UNICAST_HASH_ACCEPT ; } } } --2.19.1.windows.1