From patchwork Wed Oct 28 15:31:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 537424 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 3143F140323 for ; Thu, 29 Oct 2015 02:37:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ravellosystems_com.20150623.gappssmtp.com header.i=@ravellosystems_com.20150623.gappssmtp.com header.b=AxzaFECy; dkim-atps=neutral Received: from localhost ([::1]:38838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrSmY-0005ly-6k for incoming@patchwork.ozlabs.org; Wed, 28 Oct 2015 11:36:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrSiM-00074T-PP for qemu-devel@nongnu.org; Wed, 28 Oct 2015 11:32:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrSiI-0003YS-Q4 for qemu-devel@nongnu.org; Wed, 28 Oct 2015 11:32:38 -0400 Received: from mail-wi0-x22c.google.com ([2a00:1450:400c:c05::22c]:33992) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrSiI-0003YF-KG for qemu-devel@nongnu.org; Wed, 28 Oct 2015 11:32:34 -0400 Received: by wikq8 with SMTP id q8so257529129wik.1 for ; Wed, 28 Oct 2015 08:32:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ravellosystems_com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=thrwkOwSf1DLu3ztTNzOhaiUgK6t4NNChg3J9XVyOrg=; b=AxzaFECySpf0FDT0F+hXd/O7PfJAmMJm8K0Zgo/xBipmHdaC1I3Toj+BSxByjGjPyx o/vinE54XiEAKfAlqUf0pXD+Qx2kYRi1HQxaF7UPRBQF4VbrOYl1fWBa+kTWh4Yo2YCt fX1YE1dhTSmP+Bi4sDV87Rr7FBA6b7xDdlLGf8AJPwi3PKdjSX4bIlbD4MM2JF6hUZBx U4ybavsOLTsLyDP/tAxPDGBy2GL45JbODuDHj2ytLQRJgkmP+dRe4NPqf5VwAIeTDRjg jMHBPwGkXzMhSTOlizFs6SSiUHN9T4xBGunt4vpGqaKlthUqCNgpur1gGl2l7UGfRnYM 9WHA== 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=thrwkOwSf1DLu3ztTNzOhaiUgK6t4NNChg3J9XVyOrg=; b=W+uqjUu/4uTGV2ijm+Ec93AFgj/JyAzWYgLI/INZYE0iC4H9f0BGwtYXzWJ55wIWRv PYtBrB4bQi5gyAPwSXd98sTlJWTFRI8p6uzAE7Ky6Osj7FITjODfBvBo1/NAZE14HRaz PuY5bC/TtZThMYd7wMrMZBqylitxBFN8e/3DzcJK+5D3ZJ5f7Awv7/Nl+VCd7zUZvOk4 N63916WNB8FGkGwx8cDIURX8+FxtwZWAaoTdM8H2omZdTG7Z+Jwn3Cuqc5O4L85audcB Q9wnvwPcgKPJvBq3BMCtJTMGdEUh+LcE5qjOGwlDgYxiOwPtEyosfwoWnBugMnphFBPY KCfw== X-Gm-Message-State: ALoCoQkZG+ichzO58/nrvYgFoOhZoaoSVb0jG5NrauxrPnGHLCj1oBF6sEsRjAbQGgAJf6O8PLWx X-Received: by 10.194.174.202 with SMTP id bu10mr40740460wjc.74.1446046354139; Wed, 28 Oct 2015 08:32:34 -0700 (PDT) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id he3sm50495704wjc.48.2015.10.28.08.32.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Oct 2015 08:32:33 -0700 (PDT) From: Leonid Bloch To: qemu-devel@nongnu.org Date: Wed, 28 Oct 2015 17:31:26 +0200 Message-Id: <1446046288-25650-5-git-send-email-leonid.bloch@ravellosystems.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1446046288-25650-1-git-send-email-leonid.bloch@ravellosystems.com> References: <1446046288-25650-1-git-send-email-leonid.bloch@ravellosystems.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22c Cc: Dmitry Fleytman , Jason Wang , Leonid Bloch , Shmulik Ladkani Subject: [Qemu-devel] [PATCH v3 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, these 64-bit registers did not stick at their maximal values when (and if) they reached them, as they should do, according to the specs. This patch introduces a function that takes care of such registers, avoiding code duplication, making the relevant parts more compatible with the QEMU coding style, while ensuring that in the unlikely case of reaching the maximal value, the counter will stick there, as it supposed to. Signed-off-by: Leonid Bloch Signed-off-by: Dmitry Fleytman --- hw/net/e1000.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index f55a3f6..57c2596 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -583,6 +583,20 @@ inc_reg_if_not_full(E1000State *s, int index) } } +static void +grow_8reg_if_not_full(E1000State *s, int index, int size) +{ + uint64_t sum = s->mac_reg[index] | (uint64_t)s->mac_reg[index+1] << 32; + + if (sum + size < sum) { + sum = ~0ULL; + } else { + sum += size; + } + s->mac_reg[index] = sum; + s->mac_reg[index+1] = sum >> 32; +} + static inline int vlan_enabled(E1000State *s) { @@ -632,7 +646,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) { @@ -680,10 +694,8 @@ xmit_seg(E1000State *s) } 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 @@ -1098,11 +1110,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])