qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

net: cadence_gem: Fix RX address filtering

Two defects are fixed:

1/ Detection of multicast frames
2/ Treating drop of mis-addressed frames as non-error

Signed-off-by: Tong Ho <tong.ho@xilinx.com>
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>

authored by

Tong Ho and committed by
Jason Wang
fbc14a09 fdd35195

+11 -15
+11 -15
hw/net/cadence_gem.c
··· 34 34 #include "qemu/module.h" 35 35 #include "sysemu/dma.h" 36 36 #include "net/checksum.h" 37 + #include "net/eth.h" 37 38 38 39 #define CADENCE_GEM_ERR_DEBUG 0 39 40 #define DB_PRINT(...) do {\ ··· 702 703 static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet) 703 704 { 704 705 uint8_t *gem_spaddr; 705 - int i; 706 + int i, is_mc; 706 707 707 708 /* Promiscuous mode? */ 708 709 if (s->regs[GEM_NWCFG] & GEM_NWCFG_PROMISC) { ··· 718 719 } 719 720 720 721 /* Accept packets -w- hash match? */ 721 - if ((packet[0] == 0x01 && (s->regs[GEM_NWCFG] & GEM_NWCFG_MCAST_HASH)) || 722 - (packet[0] != 0x01 && (s->regs[GEM_NWCFG] & GEM_NWCFG_UCAST_HASH))) { 722 + is_mc = is_multicast_ether_addr(packet); 723 + if ((is_mc && (s->regs[GEM_NWCFG] & GEM_NWCFG_MCAST_HASH)) || 724 + (!is_mc && (s->regs[GEM_NWCFG] & GEM_NWCFG_UCAST_HASH))) { 725 + uint64_t buckets; 723 726 unsigned hash_index; 724 727 725 728 hash_index = calc_mac_hash(packet); 726 - if (hash_index < 32) { 727 - if (s->regs[GEM_HASHLO] & (1<<hash_index)) { 728 - return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT : 729 - GEM_RX_UNICAST_HASH_ACCEPT; 730 - } 731 - } else { 732 - hash_index -= 32; 733 - if (s->regs[GEM_HASHHI] & (1<<hash_index)) { 734 - return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT : 735 - GEM_RX_UNICAST_HASH_ACCEPT; 736 - } 729 + buckets = ((uint64_t)s->regs[GEM_HASHHI] << 32) | s->regs[GEM_HASHLO]; 730 + if ((buckets >> hash_index) & 1) { 731 + return is_mc ? GEM_RX_MULTICAST_HASH_ACCEPT 732 + : GEM_RX_UNICAST_HASH_ACCEPT; 737 733 } 738 734 } 739 735 ··· 958 954 /* Is this destination MAC address "for us" ? */ 959 955 maf = gem_mac_address_filter(s, buf); 960 956 if (maf == GEM_RX_REJECT) { 961 - return -1; 957 + return size; /* no, drop siliently b/c it's not an error */ 962 958 } 963 959 964 960 /* Discard packets with receive length error enabled ? */