From patchwork Fri Oct 14 10:49:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 119767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BEACBB6F9C for ; Fri, 14 Oct 2011 21:50:17 +1100 (EST) Received: from localhost ([::1]:51892 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REfL4-0007Ky-Sy for incoming@patchwork.ozlabs.org; Fri, 14 Oct 2011 06:50:06 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REfKy-0007KX-5p for qemu-devel@nongnu.org; Fri, 14 Oct 2011 06:50:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1REfKw-0003pw-Re for qemu-devel@nongnu.org; Fri, 14 Oct 2011 06:50:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REfKw-0003pn-Jy for qemu-devel@nongnu.org; Fri, 14 Oct 2011 06:49:58 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9EAnYEv030041 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 14 Oct 2011 06:49:34 -0400 Received: from dhcp-8-146.nay.redhat.com (dhcp-8-146.nay.redhat.com [10.66.8.146]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9EAnVjb031415; Fri, 14 Oct 2011 06:49:32 -0400 To: blauwirbel@gmail.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com, mst@redhat.com From: Jason Wang Date: Fri, 14 Oct 2011 18:49:28 +0800 Message-ID: <20111014104927.22252.96179.stgit@dhcp-8-146.nay.redhat.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] rtl8139: check the buffer availiability 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 Reduce spurious packet drops on RX ring empty when in c+ mode by verifying that we have at least 1 buffer ahead of the time. Signed-off-by: Jason Wang --- hw/rtl8139.c | 43 +++++++++++++++++++++++++++++-------------- 1 files changed, 29 insertions(+), 14 deletions(-) diff --git a/hw/rtl8139.c b/hw/rtl8139.c index 3753950..c654d5d 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -84,6 +84,19 @@ #define VLAN_TCI_LEN 2 #define VLAN_HLEN (ETHER_TYPE_LEN + VLAN_TCI_LEN) +/* w0 ownership flag */ +#define CP_RX_OWN (1<<31) +/* w0 end of ring flag */ +#define CP_RX_EOR (1<<30) +/* w0 bits 0...12 : buffer size */ +#define CP_RX_BUFFER_SIZE_MASK ((1<<13) - 1) +/* w1 tag available flag */ +#define CP_RX_TAVA (1<<16) +/* w1 bits 0...15 : VLAN tag */ +#define CP_RX_VLAN_TAG_MASK ((1<<16) - 1) +/* w2 low 32bit of Rx buffer ptr */ +/* w3 high 32bit of Rx buffer ptr */ + #if defined (DEBUG_RTL8139) # define DPRINTF(fmt, ...) \ do { fprintf(stderr, "RTL8139: " fmt, ## __VA_ARGS__); } while (0) @@ -805,6 +818,21 @@ static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high) #endif } +/* Verify that we have at least one available rx buffer */ +static int rtl8139_cp_has_rxbuf(RTL8139State *s) +{ + uint32_t val, rxdw0; + target_phys_addr_t cplus_rx_ring_desc = rtl8139_addr64(s->RxRingAddrLO, + s->RxRingAddrHI); + cplus_rx_ring_desc += 16 * s->currCPlusRxDesc; + cpu_physical_memory_read(cplus_rx_ring_desc, (uint8_t *)&val, 4); + rxdw0 = le32_to_cpu(val); + if (rxdw0 & CP_RX_OWN) + return 1; + else + return 0; +} + static int rtl8139_can_receive(VLANClientState *nc) { RTL8139State *s = DO_UPCAST(NICState, nc, nc)->opaque; @@ -819,7 +847,7 @@ static int rtl8139_can_receive(VLANClientState *nc) if (rtl8139_cp_receiver_enabled(s)) { /* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ - return 1; + return rtl8139_cp_has_rxbuf(s); } else { avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, s->RxBufferSize); @@ -965,19 +993,6 @@ static ssize_t rtl8139_do_receive(VLANClientState *nc, const uint8_t *buf, size_ /* begin C+ receiver mode */ -/* w0 ownership flag */ -#define CP_RX_OWN (1<<31) -/* w0 end of ring flag */ -#define CP_RX_EOR (1<<30) -/* w0 bits 0...12 : buffer size */ -#define CP_RX_BUFFER_SIZE_MASK ((1<<13) - 1) -/* w1 tag available flag */ -#define CP_RX_TAVA (1<<16) -/* w1 bits 0...15 : VLAN tag */ -#define CP_RX_VLAN_TAG_MASK ((1<<16) - 1) -/* w2 low 32bit of Rx buffer ptr */ -/* w3 high 32bit of Rx buffer ptr */ - int descriptor = s->currCPlusRxDesc; target_phys_addr_t cplus_rx_ring_desc;