e1000: clear EOP for multi-buffer descriptors

Submitted by Michael S. Tsirkin on Feb. 7, 2011, 12:30 p.m.

Details

Message ID 20110207123026.GA18830@redhat.com
State New
Headers show

Commit Message

Michael S. Tsirkin Feb. 7, 2011, 12:30 p.m.
The e1000 spec says: if software statically allocates
buffers, and uses memory read to check for completed descriptors, it
simply has to zero the status byte in the descriptor to make it ready
for reuse by hardware. This is not a hardware requirement (moving the
hardware tail pointer is), but is necessary for performing an in–memory
scan.

Thus the guest does not have to clear the status byte.  In case it
doesn't we need to clear EOP for all descriptors
except the last.  While I don't know of any such guests,
it's probably a good idea to stick to the spec.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reported-by: Juan Quintela <quintela@redhat.com>

---
 hw/e1000.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

Comments

Juan Quintela Feb. 7, 2011, 12:32 p.m.
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> The e1000 spec says: if software statically allocates
> buffers, and uses memory read to check for completed descriptors, it
> simply has to zero the status byte in the descriptor to make it ready
> for reuse by hardware. This is not a hardware requirement (moving the
> hardware tail pointer is), but is necessary for performing an in–memory
> scan.
>
> Thus the guest does not have to clear the status byte.  In case it
> doesn't we need to clear EOP for all descriptors
> except the last.  While I don't know of any such guests,
> it's probably a good idea to stick to the spec.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> Reported-by: Juan Quintela <quintela@redhat.com>

reviewed-by: Juan Quintela <quintela@redhat.com>
Stefan Hajnoczi Feb. 7, 2011, 1:36 p.m.
On Mon, Feb 07, 2011 at 02:30:26PM +0200, Michael S. Tsirkin wrote:
> The e1000 spec says: if software statically allocates
> buffers, and uses memory read to check for completed descriptors, it
> simply has to zero the status byte in the descriptor to make it ready
> for reuse by hardware. This is not a hardware requirement (moving the
> hardware tail pointer is), but is necessary for performing an in–memory
> scan.
> 
> Thus the guest does not have to clear the status byte.  In case it
> doesn't we need to clear EOP for all descriptors
> except the last.  While I don't know of any such guests,
> it's probably a good idea to stick to the spec.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> Reported-by: Juan Quintela <quintela@redhat.com>
> 
> ---
>  hw/e1000.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)

This makes sense: if the guest didn't clear the end-of-packet bit but
we're receiving a multi-buffer packet, clear EOP for all but the last
descriptor.

Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Patch hide | download patch | download mbox

diff --git a/hw/e1000.c b/hw/e1000.c
index 3427ff3..7853c12 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -694,6 +694,9 @@  e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
                 desc.length = cpu_to_le16(desc_size + fcs_len(s));
                 desc.status |= E1000_RXD_STAT_EOP | E1000_RXD_STAT_IXSM;
             } else {
+                /* Guest zeroing out status is not a hardware requirement.
+                   Clear EOP in case guest didn't do it. */
+                desc.status &= ~E1000_RXD_STAT_EOP;
                 desc.length = cpu_to_le16(desc_size);
             }
         } else { // as per intel docs; skip descriptors with null buf addr