From patchwork Wed Jul 15 10:19:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 495765 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 82D7C140293 for ; Wed, 15 Jul 2015 20:23:59 +1000 (AEST) Received: from localhost ([::1]:34951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFJr3-0005LN-KJ for incoming@patchwork.ozlabs.org; Wed, 15 Jul 2015 06:23:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFJnb-00078H-3q for qemu-devel@nongnu.org; Wed, 15 Jul 2015 06:20:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFJnW-00076w-2O for qemu-devel@nongnu.org; Wed, 15 Jul 2015 06:20:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58284) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFJnV-000761-Th for qemu-devel@nongnu.org; Wed, 15 Jul 2015 06:20:17 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 7EA13A2C0A; Wed, 15 Jul 2015 10:20:17 +0000 (UTC) Received: from ad.nay.redhat.com. (dhcp-15-42.nay.redhat.com [10.66.15.42]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6FAJFqg031226; Wed, 15 Jul 2015 06:20:12 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 15 Jul 2015 18:19:11 +0800 Message-Id: <1436955553-22791-11-git-send-email-famz@redhat.com> In-Reply-To: <1436955553-22791-1-git-send-email-famz@redhat.com> References: <1436955553-22791-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Peter Crosthwaite , Rob Herring , jasowang@redhat.com, Michael Walle , Gerd Hoffmann , stefanha@redhat.com, "Edgar E. Iglesias" Subject: [Qemu-devel] [PATCH v2 for-2.4 10/12] stellaris_enet: Flush queued packets when read done 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 If s->np reaches 31, the queue will be disabled by peer when it sees stellaris_enet_can_receive() returns false, until we explicitly flushes it which notifies the peer. Do this when guest is done reading all existing data. Move the semantics to stellaris_enet_receive, by returning 0 when the buffer is full, so that new packets will be queued. In stellaris_enet_read, flush and restart the queue when guest has done reading. Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- hw/net/stellaris_enet.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c index 278a654..21a4773 100644 --- a/hw/net/stellaris_enet.c +++ b/hw/net/stellaris_enet.c @@ -228,8 +228,7 @@ static ssize_t stellaris_enet_receive(NetClientState *nc, const uint8_t *buf, si if ((s->rctl & SE_RCTL_RXEN) == 0) return -1; if (s->np >= 31) { - DPRINTF("Packet dropped\n"); - return -1; + return 0; } DPRINTF("Received packet len=%zu\n", size); @@ -260,13 +259,8 @@ static ssize_t stellaris_enet_receive(NetClientState *nc, const uint8_t *buf, si return size; } -static int stellaris_enet_can_receive(NetClientState *nc) +static int stellaris_enet_can_receive(stellaris_enet_state *s) { - stellaris_enet_state *s = qemu_get_nic_opaque(nc); - - if ((s->rctl & SE_RCTL_RXEN) == 0) - return 1; - return (s->np < 31); } @@ -307,6 +301,9 @@ static uint64_t stellaris_enet_read(void *opaque, hwaddr offset, s->next_packet = 0; s->np--; DPRINTF("RX done np=%d\n", s->np); + if (!s->np && stellaris_enet_can_receive(s)) { + qemu_flush_queued_packets(qemu_get_queue(s->nic)); + } } return val; } @@ -454,7 +451,6 @@ static void stellaris_enet_reset(stellaris_enet_state *s) static NetClientInfo net_stellaris_enet_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), - .can_receive = stellaris_enet_can_receive, .receive = stellaris_enet_receive, };