Skip to contentSkip to conversation

net/cadence_gem: Updating the GEM MAC IP to properly filter out multicast addresses.

PATCH In review [email protected] 3 participants 3 messages Nov 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 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 | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
hw/net/cadence_gem.c +13 -8
index b8be73dc55..6400b3653b 100644
@@ -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;
             }
         }
     }
@@ -1083,7 +1088,7 @@ static void gem_transmit_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_TXMCNT]++;
     }
 
Signature · 1 line
2.19.1.windows.1
Reviewed-by Tested-by on v3 1/1
#1 lore raw
Quoted 7 lines · On Fri, Nov 29, 2019 at 03:24:14PM +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,

I ran this through our internal test-suite, looks good.

Cheers,
Edgar

Quoted 71 lines
---
 hw/net/cadence_gem.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
hw/net/cadence_gem.c +13 -8
index b8be73dc55..6400b3653b 100644
@@ -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;
             }
         }
     }
@@ -1083,7 +1088,7 @@ static void gem_transmit_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_TXMCNT]++;
     }
 
Signature · 1 line
2.19.1.windows.1
Reviewed-by Edgar E. Iglesias Tested-by Edgar E. Iglesias
#2 lore raw

Thanks for also helping me get through the "somewhat" tedious patch process of QEMU.. Will be helpful for future submissions..

- Bilal

-----Original Message-----
From: Edgar E. Iglesias [mailto:[email protected]]
Sent: Friday, November 29, 2019 4:22 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Wasim, Bilal <[email protected]>; [email protected]
Subject: Re: [PATCH v3] net/cadence_gem: Updating the GEM MAC IP to properly filter out multicast addresses.

Quoted 7 lines · On Fri, Nov 29, 2019 at 03:24:14PM +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,

I ran this through our internal test-suite, looks good.

Cheers,
Edgar

Quoted 71 lines
---
 hw/net/cadence_gem.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
hw/net/cadence_gem.c index renamed from hw/net/cadence_gem.c +0 -0

b8be73dc55..6400b3653b 100644

hw/net/cadence_gem.c +13 -9
@@ -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;
             }
         }
     }
@@ -1083,7 +1088,7 @@ static void gem_transmit_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_TXMCNT]++;
     }
 
--

2.19.1.windows.1