From patchwork Tue Apr 1 22:14:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 27583 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3BDD220341 for ; Tue, 1 Apr 2014 22:15:03 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kq14sf28717469pab.10 for ; Tue, 01 Apr 2014 15:15:02 -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=nnFYah/9gfVDrqQ4JOUyRYj/xndLX+zTZ6lQIBwcH60=; b=BCDo8IUkmJcw4+5QQaM8kFOAlzkudx7ivSLwNcIYtaF+Jg6gRUc+Uw+kv2JWDmdozE Hc9i4B0blu/rMQ1vi2DyOCxZi3SgYfZuBFY6qWQAag+Mw2ysy+/i4db7oknwgqFaHiXw u7DGBl2uHN3AFe95gt28dEmpw9s0enZkcjWP+tdDE2ggR9BNTOfAEHScoQRZ4NYWNPGW 6wFZgrCa+ybB8qLqgvGI1j929CxP1hD3oYCDaGjCvEmaG0eX0+6b/LWrEmtVXhI8l5In olXyaSHKhPRiRS8y4M6OyRsg/4cb+/e+KbU+pqPovjTgoyBrbIdRJz8FrzgVNgthk0Gl bR3A== X-Gm-Message-State: ALoCoQnNHGxxk5yNbMsmKYJCKQma6H/BLBp5n+/qakL+QOXdPJgQGjLhqzkyIPlaML9Dnps0PWKC X-Received: by 10.66.219.69 with SMTP id pm5mr14122187pac.8.1396390502088; Tue, 01 Apr 2014 15:15:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.103.77 with SMTP id x71ls162611qge.31.gmail; Tue, 01 Apr 2014 15:15:02 -0700 (PDT) X-Received: by 10.52.164.237 with SMTP id yt13mr26399301vdb.18.1396390501972; Tue, 01 Apr 2014 15:15:01 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id wy9si4008829vdc.19.2014.04.01.15.15.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Apr 2014 15:15:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id ij19so10468826vcb.24 for ; Tue, 01 Apr 2014 15:15:01 -0700 (PDT) X-Received: by 10.52.90.37 with SMTP id bt5mr26447823vdb.7.1396390501895; Tue, 01 Apr 2014 15:15:01 -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.12.8 with SMTP id v8csp273746vcv; Tue, 1 Apr 2014 15:15:01 -0700 (PDT) X-Received: by 10.194.82.9 with SMTP id e9mr13604033wjy.45.1396390498998; Tue, 01 Apr 2014 15:14:58 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id 43si30067691eer.27.2014.04.01.15.14.58 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 01 Apr 2014 15:14:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WV6xM-0002KW-00; Tue, 01 Apr 2014 23:14:56 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, "Michael S. Tsirkin" , "Dr. David Alan Gilbert" Subject: [PATCH v2 6/7] hw/net/stellaris_enet: Get rid of rx_fifo pointer Date: Tue, 1 Apr 2014 23:14:54 +0100 Message-Id: <1396390495-8908-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396390495-8908-1-git-send-email-peter.maydell@linaro.org> References: <1396390495-8908-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: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c index e818b9d..af1c3ef 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; } @@ -469,7 +467,7 @@ static int stellaris_enet_init(SysBusDevice *sbd) qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); stellaris_enet_reset(s); - register_savevm(dev, "stellaris_enet", -1, 2, + register_savevm(dev, "stellaris_enet", -1, 3, stellaris_enet_save, stellaris_enet_load, s); return 0; }