From 60aa1ca16860aa1f41a9bd944be1984fdcdf603d Mon Sep 17 00:00:00 2001
From: Michael S. Tsirkin <mst@redhat.com>
Date: Thu, 4 Nov 2010 18:34:57 -0200
Subject: [RHEL6 qemu-kvm PATCH 1/8] bz 603413: e1000: secrc support

RH-Author: Michael S. Tsirkin <mst@redhat.com>
Message-id: <20101104183457.GA3438@redhat.com>
Patchwork-id: 13232
O-Subject: [PATCH RHEL 6.0.x/6.1] bz 603413: e1000: secrc support
Bugzilla: 603413
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>

Add support for secrc field. Reportedly needed by old RHEL guests.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This is the same as commit e299209ce82c2ee7ca71013bea914208eb9d479b
bz 547276: e1000: secrc support in rhel5 tree.
Upstream commit: 55e8d1ce6b09300cc5f3adcd9a705156d168381d

Note:
This is not a straight backport from upstream because
upstream also has commit b0b900070c7cb29bbefb732ec00397abe5de6d73.
That one is cosmetic though and seems an unnecessary risk for 5.6.
---
 hw/e1000.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/e1000.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index a0faf5e..7467603 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -341,6 +341,15 @@ is_vlan_txd(uint32_t txd_lower)
     return ((txd_lower & E1000_TXD_CMD_VLE) != 0);
 }
 
+/* FCS aka Ethernet CRC-32. We don't get it from backends and can't
+ * fill it in, just pad descriptor length by 4 bytes unless guest
+ * told us to strip it off the packet. */
+static inline int
+fcs_len(E1000State *s)
+{
+    return (s->mac_reg[RCTL] & E1000_RCTL_SECRC) ? 0 : 4;
+}
+
 static void
 xmit_seg(E1000State *s)
 {
@@ -646,7 +655,7 @@ e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
     }
 
     rdh_start = s->mac_reg[RDH];
-    size += 4; // for the header
+    size += fcs_len(s);
     do {
         if (s->mac_reg[RDH] == s->mac_reg[RDT] && s->check_rxov) {
             set_ics(s, 0, E1000_ICS_RXO);
-- 
1.7.3.2

