From patchwork Tue May 13 15:31:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 30070 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 79B5F20369 for ; Tue, 13 May 2014 15:36:21 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id w8sf1215513qac.6 for ; Tue, 13 May 2014 08:36:21 -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:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=DP2dQKVerofdhAM0XMdFOmjPG4xwM/LkknnE2rGF3dg=; b=dvKg1BvYvwa+9+FJyHqDfW79O9ZejJoaofMbqg6rkKLRcDmDGAOeQ/AoCCbEAyo3Tt d8K9GmLL6F+sfxfiPbrfwt7kVjheivjp0J7422fT/7wK712jk1FXnPtM6SpwUHMnM66b rHUUpjcnMbbha9PCFiAOMdp9iaBDTKoV2E2Ks9RfX+i2XFk8dvjbfGRiEaIHzQlSx0uo M5fCZ5Ewp2+kjjynDCdyrIA897NHYUQm9LsHR4amrLyVnhfa/vPYORWeGrseID686gCT vWVgV3D/9HrczpBr3sZm3IHkJQFOI4aLNQozJuy3aJdFAPszd7WotjpdVdbK9TgW7pkO gaIw== X-Gm-Message-State: ALoCoQnJtK7eJpkX3WVCzG13QtfmZZ3yO005SsRoyu9EWACTVys8bbNLguOP2ky52rRQvRaYZsxl X-Received: by 10.236.36.33 with SMTP id v21mr14844973yha.53.1399995381182; Tue, 13 May 2014 08:36:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.85 with SMTP id 79ls431174qgk.41.gmail; Tue, 13 May 2014 08:36:21 -0700 (PDT) X-Received: by 10.58.169.97 with SMTP id ad1mr1033836vec.45.1399995381020; Tue, 13 May 2014 08:36:21 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id fa16si2708120veb.190.2014.05.13.08.36.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 08:36:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.172 as permitted sender) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id oz11so665185veb.17 for ; Tue, 13 May 2014 08:36:20 -0700 (PDT) X-Received: by 10.58.116.175 with SMTP id jx15mr29556442veb.9.1399995380939; Tue, 13 May 2014 08:36:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp160746vcb; Tue, 13 May 2014 08:36:20 -0700 (PDT) X-Received: by 10.140.27.245 with SMTP id 108mr45310185qgx.18.1399995380068; Tue, 13 May 2014 08:36:20 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id p8si7943692qag.76.2014.05.13.08.36.19 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 May 2014 08:36:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Received: from localhost ([::1]:45896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkEkd-0005Vn-Lw for patch@linaro.org; Tue, 13 May 2014 11:36:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkEgN-00085y-Cc for qemu-devel@nongnu.org; Tue, 13 May 2014 11:31:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkEgJ-0006AU-9n for qemu-devel@nongnu.org; Tue, 13 May 2014 11:31:55 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48125) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkEgJ-00066p-2s for qemu-devel@nongnu.org; Tue, 13 May 2014 11:31:51 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WkEg7-0006wZ-Gf; Tue, 13 May 2014 16:31:39 +0100 From: Peter Maydell To: Anthony Liguori Date: Tue, 13 May 2014 16:31:30 +0100 Message-Id: <1399995099-26635-9-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399995099-26635-1-git-send-email-peter.maydell@linaro.org> References: <1399995099-26635-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 08/17] hw/net/stellaris_enet: Get rid of rx_fifo pointer 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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; }