Received: from eggs.gnu.org ([2001:4830:134:3::10]:57633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zr4CJ-0001zE-Pu for qemu-devel@nongnu.org; Tue, 27 Oct 2015 09:21:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zr4CI-00023J-MJ for qemu-devel@nongnu.org; Tue, 27 Oct 2015 09:21:55 -0400 Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]:35929) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zr4CI-000236-Gw for qemu-devel@nongnu.org; Tue, 27 Oct 2015 09:21:54 -0400 Received: by wicfx6 with SMTP id fx6so159241735wic.1 for ; Tue, 27 Oct 2015 06:21:54 -0700 (PDT) From: Leonid Bloch Date: Tue, 27 Oct 2015 15:20:24 +0200 Message-Id: <1445952027-28541-4-git-send-email-leonid.bloch@ravellosystems.com> In-Reply-To: <1445952027-28541-1-git-send-email-leonid.bloch@ravellosystems.com> References: <1445952027-28541-1-git-send-email-leonid.bloch@ravellosystems.com> Subject: [Qemu-devel] [PATCH v2 3/6] e1000: Fixing the received/transmitted packets' counters List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Dmitry Fleytman , Jason Wang , Leonid Bloch , Shmulik Ladkani According to Intel's specs, these counters (as all the other Statistic registers) stick at 0xffffffff when the maximum value is reached. Previously, they would reset after the max. value. Signed-off-by: Leonid Bloch Signed-off-by: Dmitry Fleytman --- hw/net/e1000.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index bf43ab7..74d5e94 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -575,6 +575,14 @@ putsum(uint8_t *data, uint32_t n, uint32_t sloc, uint32_t css, uint32_t cse) } } +static inline void +inc_reg_if_not_full(E1000State *s, int index) +{ + if (s->mac_reg[index] != 0xffffffff) { + s->mac_reg[index]++; + } +} + static inline int vlan_enabled(E1000State *s) { @@ -671,8 +679,8 @@ xmit_seg(E1000State *s) e1000_send_packet(s, tp->data, tp->size); } - s->mac_reg[TPT]++; - s->mac_reg[GPTC]++; + inc_reg_if_not_full(s, TPT); + s->mac_reg[GPTC] = s->mac_reg[TPT]; n = s->mac_reg[TOTL]; if ((s->mac_reg[TOTL] += s->tx.size) < n) s->mac_reg[TOTH]++; @@ -1085,8 +1093,8 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) } } while (desc_offset < total_size); - s->mac_reg[GPRC]++; - s->mac_reg[TPR]++; + inc_reg_if_not_full(s, TPR); + s->mac_reg[GPRC] = s->mac_reg[TPR]; /* TOR - Total Octets Received: * This register includes bytes received in a packet from the field through the field, inclusively. -- 2.4.3