From patchwork Sun Mar 27 15:01:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 88510 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2B7A0B6F82 for ; Mon, 28 Mar 2011 02:02:59 +1100 (EST) Received: from localhost ([127.0.0.1]:42497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3rUW-0001rz-5r for incoming@patchwork.ozlabs.org; Sun, 27 Mar 2011 11:02:56 -0400 Received: from [140.186.70.92] (port=49820 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3rTr-0001rM-8u for qemu-devel@nongnu.org; Sun, 27 Mar 2011 11:02:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q3rTq-00067E-Di for qemu-devel@nongnu.org; Sun, 27 Mar 2011 11:02:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q3rTq-000677-5S for qemu-devel@nongnu.org; Sun, 27 Mar 2011 11:02:14 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2RF2Dah029985 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 27 Mar 2011 11:02:13 -0400 Received: from redhat.com (vpn-200-81.tlv.redhat.com [10.35.200.81]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id p2RF2Aq4029818; Sun, 27 Mar 2011 11:02:11 -0400 Date: Sun, 27 Mar 2011 17:01:56 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20110327150156.GA7975@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, Jes.Sorensen@redhat.com, Alex Williamson , Juan Quintela Subject: [Qemu-devel] [PATCH] e1000: check buffer availability X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Reduce spurious packet drops on RX ring empty by verifying that we have at least 1 buffer ahead of the time. Signed-off-by: Michael S. Tsirkin Reviewed-by: Juan Quintela Acked-by: Kevin Wolf --- hw/e1000.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/e1000.c b/hw/e1000.c index 0a4574c..380d6fe 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -623,14 +623,6 @@ e1000_set_link_status(VLANClientState *nc) set_ics(s, 0, E1000_ICR_LSC); } -static int -e1000_can_receive(VLANClientState *nc) -{ - E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque; - - return (s->mac_reg[RCTL] & E1000_RCTL_EN); -} - static bool e1000_has_rxbufs(E1000State *s, size_t total_size) { int bufs; @@ -649,6 +641,14 @@ static bool e1000_has_rxbufs(E1000State *s, size_t total_size) return total_size <= bufs * s->rxbuf_size; } +static int +e1000_can_receive(VLANClientState *nc) +{ + E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque; + + return (s->mac_reg[RCTL] & E1000_RCTL_EN) && e1000_has_rxbufs(s, 1); +} + static ssize_t e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size) {