From patchwork Sat Mar 26 18:37:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 88475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DF507B6F9C for ; Sun, 27 Mar 2011 05:39:59 +1100 (EST) Received: from localhost ([127.0.0.1]:56339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3YOx-00049Q-V3 for incoming@patchwork.ozlabs.org; Sat, 26 Mar 2011 14:39:56 -0400 Received: from [140.186.70.92] (port=49605 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3YOF-00047t-P5 for qemu-devel@nongnu.org; Sat, 26 Mar 2011 14:39:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q3YN9-0007AG-LR for qemu-devel@nongnu.org; Sat, 26 Mar 2011 14:38:04 -0400 Received: from mo-p00-ob.rzone.de ([81.169.146.161]:32691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q3YN9-0007A8-6z for qemu-devel@nongnu.org; Sat, 26 Mar 2011 14:38:03 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1301164680; l=1965; s=domk; d=kevin-wolf.de; h=Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH; bh=wwkrE3oMIiD6EfaQB7V0qfeFYko=; b=bBBC/Le43pWr5QbV5VLm12p0HlgNi3NruxpS+LZs2UfR/64uRRmhiujoV6lRKGy/254 0MQPmDIrXfpgRfeYx1yMZkzDVoDoT/FZpGLrnXBW6uHJ5yY403zoqOm5Dib8ZdnRAyIfg VZ1aQBOjNQyvlYEVn81Q/705wnJko3+XSOo= X-RZG-AUTH: :IW0NeWCjfulXIi4BrEKXhgYy2jE0QmIac4DjsXgwMU4hzYlVkmoGek+9mob1xkMQ X-RZG-CLASS-ID: mo00 Received: from localhost.localdomain (p57A5EBDB.dip.t-dialin.net [87.165.235.219]) by post.strato.de (jimi mo43) (RZmta 25.8) with ESMTPA id Q0262bn2QEVfrx ; Sat, 26 Mar 2011 19:37:59 +0100 (MET) From: Kevin Wolf To: qemu-devel@nongnu.org Date: Sat, 26 Mar 2011 19:37:56 +0100 Message-Id: <1301164676-27078-1-git-send-email-mail@kevin-wolf.de> X-Mailer: git-send-email 1.6.0.2 X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 81.169.146.161 Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH] e1000: Mask out lower bits of RDBAL/TDBAL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Rx and Tx descriptors are 16 byte aligned, so the lower bits are ignored by real hardware. In fact, they always read back as zero on real hardware, but probably nobody relies on that. Signed-off-by: Kevin Wolf --- hw/e1000.c | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-) diff --git a/hw/e1000.c b/hw/e1000.c index 2a4d5c7..a65fc7a 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -517,6 +517,14 @@ txdesc_writeback(target_phys_addr_t base, struct e1000_tx_desc *dp) return E1000_ICR_TXDW; } +static uint64_t tx_desc_base(E1000State *s) +{ + uint64_t bah = s->mac_reg[TDBAH]; + uint64_t bal = s->mac_reg[TDBAL] & ~0xf; + + return (bah << 32) + bal; +} + static void start_xmit(E1000State *s) { @@ -530,7 +538,7 @@ start_xmit(E1000State *s) } while (s->mac_reg[TDH] != s->mac_reg[TDT]) { - base = ((uint64_t)s->mac_reg[TDBAH] << 32) + s->mac_reg[TDBAL] + + base = tx_desc_base(s) + sizeof(struct e1000_tx_desc) * s->mac_reg[TDH]; cpu_physical_memory_read(base, (void *)&desc, sizeof(desc)); @@ -651,6 +659,14 @@ static bool e1000_has_rxbufs(E1000State *s, size_t total_size) return total_size <= bufs * s->rxbuf_size; } +static uint64_t rx_desc_base(E1000State *s) +{ + uint64_t bah = s->mac_reg[RDBAH]; + uint64_t bal = s->mac_reg[RDBAL] & ~0xf; + + return (bah << 32) + bal; +} + static ssize_t e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size) { @@ -700,8 +716,7 @@ e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size) if (desc_size > s->rxbuf_size) { desc_size = s->rxbuf_size; } - base = ((uint64_t)s->mac_reg[RDBAH] << 32) + s->mac_reg[RDBAL] + - sizeof(desc) * s->mac_reg[RDH]; + base = rx_desc_base(s) + sizeof(desc) * s->mac_reg[RDH]; cpu_physical_memory_read(base, (void *)&desc, sizeof(desc)); desc.special = vlan_special; desc.status |= (vlan_status | E1000_RXD_STAT_DD);