From patchwork Mon Apr 28 12:39:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 29233 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6619820553 for ; Mon, 28 Apr 2014 12:39:40 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lj1sf21382091pab.1 for ; Mon, 28 Apr 2014 05:39:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=DP2dQKVerofdhAM0XMdFOmjPG4xwM/LkknnE2rGF3dg=; b=Bj2EJ3rkYz3Zx6AEqslwrFT4W0DMuPGsVxCG1dcOeL+P/WpM8hEy9UkC40u0lb+EOR /J5+hl2/zcTlOyPU6p3etW/dBggz/QKE0Wx9HhTjXK9vmGLlp6/VzfSQzd5CRl8/ENw0 /tYTsBi4Guu2mCjis9juCqtUStw6u8ESZpso8GpUv8V7cmctGeTLhSL8mz4Ph4TNjvgJ TTZ395QlEK9ZtI0IIgArR+k5SNoPwYKUEVZX/3ptcKgYWrbFI5My05UczT18VgsB+MvP 8d2AGwOANuOop0yjfPE6ASJC3ttCIcjUMMy1yL+WuEYixYVkJfCWp1bG6W2W9eERkRGz RmSQ== X-Gm-Message-State: ALoCoQlJPofXe8ClHA4hokmwCrDYfT+MTL3J3yFzqHlQOXTUnQ4zr7CdpjRAVCjRVDi74YIvEhxR X-Received: by 10.66.159.36 with SMTP id wz4mr11318023pab.14.1398688779663; Mon, 28 Apr 2014 05:39:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.43.135 with SMTP id e7ls62967qga.70.gmail; Mon, 28 Apr 2014 05:39:39 -0700 (PDT) X-Received: by 10.220.113.11 with SMTP id y11mr135625vcp.40.1398688779498; Mon, 28 Apr 2014 05:39:39 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id fa16si3589372veb.28.2014.04.28.05.39.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Apr 2014 05:39:39 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id lh4so1215046vcb.34 for ; Mon, 28 Apr 2014 05:39:39 -0700 (PDT) X-Received: by 10.220.69.72 with SMTP id y8mr23532303vci.21.1398688779405; Mon, 28 Apr 2014 05:39:39 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp114320vcb; Mon, 28 Apr 2014 05:39:38 -0700 (PDT) X-Received: by 10.68.194.229 with SMTP id hz5mr25020254pbc.91.1398688774564; Mon, 28 Apr 2014 05:39:34 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id se7si10391163pbb.182.2014.04.28.05.39.33 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 28 Apr 2014 05:39:34 -0700 (PDT) Received-SPF: none (google.com: pm215@archaic.org.uk does not designate permitted sender hosts) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WekqI-0006DA-Sc; Mon, 28 Apr 2014 13:39:30 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, "Michael S. Tsirkin" , "Dr. David Alan Gilbert" Subject: [PATCH v3 6/7] hw/net/stellaris_enet: Get rid of rx_fifo pointer Date: Mon, 28 Apr 2014 13:39:29 +0100 Message-Id: <1398688770-23828-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398688770-23828-1-git-send-email-peter.maydell@linaro.org> References: <1398688770-23828-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The rx_fifo pointer is awkward to migrate, and is actually redundant since it is always possible to determine it from the current rx[].len/.data and rx_fifo_len. Remove both rx_fifo and rx_fifo_len from the state, replacing them with a simple rx_fifo_offset which points at the current location in the RX fifo. Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert --- hw/net/stellaris_enet.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c index 1cb95e0..9e8f143 100644 --- a/hw/net/stellaris_enet.c +++ b/hw/net/stellaris_enet.c @@ -67,8 +67,7 @@ typedef struct { uint8_t data[2048]; int len; } rx[31]; - uint8_t *rx_fifo; - int rx_fifo_len; + int rx_fifo_offset; int next_packet; NICState *nic; NICConf conf; @@ -216,21 +215,21 @@ static uint64_t stellaris_enet_read(void *opaque, hwaddr offset, case 0x0c: /* TCTL */ return s->tctl; case 0x10: /* DATA */ - if (s->rx_fifo_len == 0) { - if (s->np == 0) { - BADF("RX underflow\n"); - return 0; - } - s->rx_fifo_len = s->rx[s->next_packet].len; - s->rx_fifo = s->rx[s->next_packet].data; - DPRINTF("RX FIFO start packet len=%d\n", s->rx_fifo_len); + { + uint8_t *rx_fifo; + + if (s->np == 0) { + BADF("RX underflow\n"); + return 0; } - val = s->rx_fifo[0] | (s->rx_fifo[1] << 8) | (s->rx_fifo[2] << 16) - | (s->rx_fifo[3] << 24); - s->rx_fifo += 4; - s->rx_fifo_len -= 4; - if (s->rx_fifo_len <= 0) { - s->rx_fifo_len = 0; + + rx_fifo = s->rx[s->next_packet].data + s->rx_fifo_offset; + + val = rx_fifo[0] | (rx_fifo[1] << 8) | (rx_fifo[2] << 16) + | (rx_fifo[3] << 24); + s->rx_fifo_offset += 4; + if (s->rx_fifo_offset >= s->rx[s->next_packet].len) { + s->rx_fifo_offset = 0; s->next_packet++; if (s->next_packet >= 31) s->next_packet = 0; @@ -238,6 +237,7 @@ static uint64_t stellaris_enet_read(void *opaque, hwaddr offset, DPRINTF("RX done np=%d\n", s->np); } return val; + } case 0x14: /* IA0 */ return s->conf.macaddr.a[0] | (s->conf.macaddr.a[1] << 8) | (s->conf.macaddr.a[2] << 16) @@ -291,8 +291,8 @@ static void stellaris_enet_write(void *opaque, hwaddr offset, case 0x08: /* RCTL */ s->rctl = value; if (value & SE_RCTL_RSTFIFO) { - s->rx_fifo_len = 0; s->np = 0; + s->rx_fifo_offset = 0; stellaris_enet_update(s); } break; @@ -402,8 +402,7 @@ static void stellaris_enet_save(QEMUFile *f, void *opaque) } qemu_put_be32(f, s->next_packet); - qemu_put_be32(f, s->rx_fifo - s->rx[s->next_packet].data); - qemu_put_be32(f, s->rx_fifo_len); + qemu_put_be32(f, s->rx_fifo_offset); } static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id) @@ -432,8 +431,7 @@ static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id) } s->next_packet = qemu_get_be32(f); - s->rx_fifo = s->rx[s->next_packet].data + qemu_get_be32(f); - s->rx_fifo_len = qemu_get_be32(f); + s->rx_fifo_offset = qemu_get_be32(f); return 0; }