From patchwork Sun Oct 18 07:53:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 531936 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 84837140773 for ; Mon, 19 Oct 2015 00:27:48 +1100 (AEDT) Received: from localhost ([::1]:34000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zno02-0005VA-4j for incoming@patchwork.ozlabs.org; Sun, 18 Oct 2015 09:27:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Znimo-0000lo-K4 for qemu-devel@nongnu.org; Sun, 18 Oct 2015 03:53:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Znimk-00017z-3K for qemu-devel@nongnu.org; Sun, 18 Oct 2015 03:53:46 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:32884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Znimj-00017t-Td for qemu-devel@nongnu.org; Sun, 18 Oct 2015 03:53:42 -0400 Received: by wijp11 with SMTP id p11so59852995wij.0 for ; Sun, 18 Oct 2015 00:53:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IbV6nY2mCtLrYB/D+Er+643sfslxOkWX7B44Tdu79yU=; b=B+HnH03PF2C6hJ157VDD9tnSb1rNezF0PIHg4xfJ52nzh6OUJlC5t0Ff9VIOFbqSfL V+7w0O2qfOmWMc0GAc1fw8U2LEAe1bBEGlfPJR9pHcQUDDkJ9zvdNiDWwezYA2JJnvQ1 19zuM5ZBQdhUBXoDbSF6HmTxtbLSOUk6Qb2ZkNy95x9HsAMNwS6nlfotT36drFx4p+9l 7/TwmcJ9MhEMMwEAVSe7yeHUw7U+hyX3MIFQLWm9D4m3gC+aFKKjDJKv5qzgEvneR0xb 4ihHv5bgjB/1rIPdfyf6hkV7G+CQwnZkxTSEa0hdK0RrP8GIjGmpPgjhn2iU3aCzjyD8 wvVg== X-Gm-Message-State: ALoCoQnoVQLF7IhRJUeKhTNTDHjbPfQhaQr/nF8ZQrOgSu7ExWLaG4ajE9DhQbxCejnLkB9rASXO X-Received: by 10.180.8.197 with SMTP id t5mr13397058wia.90.1445154821411; Sun, 18 Oct 2015 00:53:41 -0700 (PDT) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id ex17sm9983596wid.23.2015.10.18.00.53.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Oct 2015 00:53:40 -0700 (PDT) From: Leonid Bloch To: qemu-devel@nongnu.org Date: Sun, 18 Oct 2015 10:53:17 +0300 Message-Id: <1445154799-31083-5-git-send-email-leonid.bloch@ravellosystems.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1445154799-31083-1-git-send-email-leonid.bloch@ravellosystems.com> References: <1445154799-31083-1-git-send-email-leonid.bloch@ravellosystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.174 X-Mailman-Approved-At: Sun, 18 Oct 2015 09:26:32 -0400 Cc: Dmitry Fleytman , Jason Wang , Leonid Bloch , Shmulik Ladkani Subject: [Qemu-devel] [PATCH 4/6] e1000: Fixing the received/transmitted octets' counters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Previously, the lower parts of these counters (TORL, TOTL) were resetting after reaching their maximal values, and since the continuation of counting in the higher parts (TORH, TOTH) was triggered by an overflow event of the lower parts, the count was not correct. Additionally, TORH and TOTH were counting the corresponding frames, and not the octets, as they supposed to do. Additionally, these 64-bit registers did not stick at their maximal values when (and if) they reached them. This fix resolves all the issues mentioned above, and makes the octet counters behave according to Intel's specs. Signed-off-by: Leonid Bloch Signed-off-by: Dmitry Fleytman --- hw/net/e1000.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 5530285..7f977b6 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -583,6 +583,28 @@ inc_reg_if_not_full(E1000State *s, int index) } } +static void +grow_8reg_if_not_full(E1000State *s, int index, int size) +{ + uint32_t lo = s->mac_reg[index]; + uint32_t hi = s->mac_reg[index+1]; + + if (lo == 0xffffffff) { + if ((hi += size) > s->mac_reg[index+1]) { + s->mac_reg[index+1] = hi; + } else if (s->mac_reg[index+1] != 0xffffffff) { + s->mac_reg[index+1] = 0xffffffff; + } + } else { + if (((lo += size) < s->mac_reg[index]) + && (s->mac_reg[index] = 0xffffffff)) { /* setting low to full */ + s->mac_reg[index+1] += ++lo; + } else { + s->mac_reg[index] = lo; + } + } +} + static inline int vlan_enabled(E1000State *s) { @@ -632,7 +654,7 @@ static void xmit_seg(E1000State *s) { uint16_t len, *sp; - unsigned int frames = s->tx.tso_frames, css, sofar, n; + unsigned int frames = s->tx.tso_frames, css, sofar; struct e1000_tx *tp = &s->tx; if (tp->tse && tp->cptse) { @@ -678,10 +700,8 @@ xmit_seg(E1000State *s) } else e1000_send_packet(s, tp->data, tp->size); inc_reg_if_not_full(s, TPT); + grow_8reg_if_not_full(s, TOTL, s->tx.size); 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]++; } static void @@ -1096,11 +1116,9 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) /* TOR - Total Octets Received: * This register includes bytes received in a packet from the field through the field, inclusively. + * Always include FCS length (4) in size. */ - n = s->mac_reg[TORL] + size + /* Always include FCS length. */ 4; - if (n < s->mac_reg[TORL]) - s->mac_reg[TORH]++; - s->mac_reg[TORL] = n; + grow_8reg_if_not_full(s, TORL, size+4); n = E1000_ICS_RXT0; if ((rdt = s->mac_reg[RDT]) < s->mac_reg[RDH])