qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net/cadence_gem: Updating the GEM MAC IP to properly filter out multicast addresses.
@ 2019-11-29  8:52 bilalwasim676
  2019-11-29  9:13 ` Edgar E. Iglesias
  0 siblings, 1 reply; 3+ messages in thread
From: bilalwasim676 @ 2019-11-29  8:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: edgar.iglesias, qemu-arm, bilal_wasim, alistair, peter.maydell

From: bwasim <bilal_wasim@mentor.com>

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..

Signed-off-by: Bilal Wasim <bilal_wasim@mentor.com>
---
 hw/net/cadence_gem.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index b8be73dc55..042188c1ba 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -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;
             }
         }
     }
-- 
2.19.1.windows.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] net/cadence_gem: Updating the GEM MAC IP to properly filter out multicast addresses.
  2019-11-29  8:52 [PATCH v2] net/cadence_gem: Updating the GEM MAC IP to properly filter out multicast addresses bilalwasim676
@ 2019-11-29  9:13 ` Edgar E. Iglesias
  2019-11-29  9:32   ` Bilal Wasim
  0 siblings, 1 reply; 3+ messages in thread
From: Edgar E. Iglesias @ 2019-11-29  9:13 UTC (permalink / raw)
  To: bilalwasim676; +Cc: peter.maydell, qemu-arm, bilal_wasim, qemu-devel, alistair

On Fri, Nov 29, 2019 at 01:52:16PM +0500, bilalwasim676@gmail.com wrote:
> From: bwasim <bilal_wasim@mentor.com>
> 
> 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


> 
> Signed-off-by: Bilal Wasim <bilal_wasim@mentor.com>
> ---
>  hw/net/cadence_gem.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
> index b8be73dc55..042188c1ba 100644
> --- a/hw/net/cadence_gem.c
> +++ b/hw/net/cadence_gem.c
> @@ -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;
>              }
>          }
>      }
> -- 
> 2.19.1.windows.1
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] net/cadence_gem: Updating the GEM MAC IP to properly filter out multicast addresses.
  2019-11-29  9:13 ` Edgar E. Iglesias
@ 2019-11-29  9:32   ` Bilal Wasim
  0 siblings, 0 replies; 3+ messages in thread
From: Bilal Wasim @ 2019-11-29  9:32 UTC (permalink / raw)
  To: Edgar E. Iglesias
  Cc: peter.maydell, qemu-arm, bilal_wasim, qemu-devel, alistair

[-- Attachment #1: Type: text/plain, Size: 3264 bytes --]

Thanks, Will do..

On Fri, 29 Nov 2019, 14:13 Edgar E. Iglesias, <edgar.iglesias@gmail.com>
wrote:

> On Fri, Nov 29, 2019 at 01:52:16PM +0500, bilalwasim676@gmail.com wrote:
> > From: bwasim <bilal_wasim@mentor.com>
> >
> > 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
>
>
> >
> > Signed-off-by: Bilal Wasim <bilal_wasim@mentor.com>
> > ---
> >  hw/net/cadence_gem.c | 19 ++++++++++++-------
> >  1 file changed, 12 insertions(+), 7 deletions(-)
> >
> > diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
> > index b8be73dc55..042188c1ba 100644
> > --- a/hw/net/cadence_gem.c
> > +++ b/hw/net/cadence_gem.c
> > @@ -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;
> >              }
> >          }
> >      }
> > --
> > 2.19.1.windows.1
> >
>

[-- Attachment #2: Type: text/html, Size: 4607 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-29 13:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29  8:52 [PATCH v2] net/cadence_gem: Updating the GEM MAC IP to properly filter out multicast addresses bilalwasim676
2019-11-29  9:13 ` Edgar E. Iglesias
2019-11-29  9:32   ` Bilal Wasim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).