qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] e1000: Mask out lower bits of RDBAL/TDBAL
@ 2011-03-26 18:37 Kevin Wolf
  2011-04-03 22:15 ` Aurelien Jarno
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Wolf @ 2011-03-26 18:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf

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 <mail@kevin-wolf.de>
---
 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);
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] e1000: Mask out lower bits of RDBAL/TDBAL
  2011-03-26 18:37 [Qemu-devel] [PATCH] e1000: Mask out lower bits of RDBAL/TDBAL Kevin Wolf
@ 2011-04-03 22:15 ` Aurelien Jarno
  0 siblings, 0 replies; 2+ messages in thread
From: Aurelien Jarno @ 2011-04-03 22:15 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel

On Sat, Mar 26, 2011 at 07:37:56PM +0100, Kevin Wolf wrote:
> 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 <mail@kevin-wolf.de>
> ---
>  hw/e1000.c |   21 ++++++++++++++++++---
>  1 files changed, 18 insertions(+), 3 deletions(-)

Thanks, applied.

> 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);
> -- 
> 1.6.0.2
> 
> 
> 

-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-03 22:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-26 18:37 [Qemu-devel] [PATCH] e1000: Mask out lower bits of RDBAL/TDBAL Kevin Wolf
2011-04-03 22:15 ` Aurelien Jarno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).