qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Weil <weil@mail.berlios.de>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH v2 04/10] eepro100: Pad received short frames
Date: Sat, 30 Apr 2011 22:40:07 +0200	[thread overview]
Message-ID: <1304196013-14432-5-git-send-email-weil@mail.berlios.de> (raw)
In-Reply-To: <1304196013-14432-1-git-send-email-weil@mail.berlios.de>

QEMU sends frames smaller than 60 bytes to ethernet nics.
This should be fixed in the networking code because normally
such frames are rejected by real NICs and their emulations.
To avoid this behaviour, other NIC emulations pad received
frames. This patch enables this workaround for eepro100, too.

All related code is marked with CONFIG_PAD_RECEIVED_FRAMES,
so emulation of the correct handling for short frames can
be restored as soon as QEMU's networking code is fixed.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 hw/eepro100.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/hw/eepro100.c b/hw/eepro100.c
index 82c6369..2104bc0 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -48,6 +48,14 @@
 #include "eeprom93xx.h"
 #include "sysemu.h"
 
+/* QEMU sends frames smaller than 60 bytes to ethernet nics.
+ * This should be fixed in the networking code because normally
+ * such frames are rejected by real nics and their emulations.
+ * To avoid this behaviour, other nic emulations pad received
+ * frames. The following definition enables this workaround for
+ * eepro100, too. */
+#define CONFIG_PAD_RECEIVED_FRAMES
+
 #define KiB 1024
 
 /* Debug EEPRO100 card. */
@@ -1656,19 +1664,32 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
      */
     EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     uint16_t rfd_status = 0xa000;
+#if defined(CONFIG_PAD_RECEIVED_FRAMES)
+    uint8_t min_buf[60];
+#endif
     static const uint8_t broadcast_macaddr[6] =
         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
+#if defined(CONFIG_PAD_RECEIVED_FRAMES)
+    /* Pad to minimum Ethernet frame length */
+    if (size < sizeof(min_buf)) {
+        memcpy(min_buf, buf, size);
+        memset(&min_buf[size], 0, sizeof(min_buf) - size);
+        buf = min_buf;
+        size = sizeof(min_buf);
+    }
+#endif
+
     if (s->configuration[8] & 0x80) {
         /* CSMA is disabled. */
         logout("%p received while CSMA is disabled\n", s);
         return -1;
+#if !defined(CONFIG_PAD_RECEIVED_FRAMES)
     } else if (size < 64 && (s->configuration[7] & BIT(0))) {
         /* Short frame and configuration byte 7/0 (discard short receive) set:
          * Short frame is discarded */
         logout("%p received short frame (%zu byte)\n", s, size);
         s->statistics.rx_short_frame_errors++;
-#if 0
         return -1;
 #endif
     } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & BIT(3))) {
@@ -1747,9 +1768,11 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
             "(%zu bytes); data truncated\n", rfd_size, size);
         size = rfd_size;
     }
+#if !defined(CONFIG_PAD_RECEIVED_FRAMES)
     if (size < 64) {
         rfd_status |= 0x0080;
     }
+#endif
     TRACE(OTHER, logout("command 0x%04x, link 0x%08x, addr 0x%08x, size %u\n",
           rfd_command, rx.link, rx.rx_buf_addr, rfd_size));
     stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, status),
-- 
1.7.2.5

  parent reply	other threads:[~2011-04-30 20:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-30 20:40 [Qemu-devel] [PULL v2] eepro100: Update of patch series (fixes and enhancements) Stefan Weil
2011-04-30 20:40 ` [Qemu-devel] [PATCH v2 01/10] eepro100: Avoid duplicate debug messages Stefan Weil
2011-04-30 20:40 ` [Qemu-devel] [PATCH v2 02/10] eepro100: Remove type casts which are no longer needed Stefan Weil
2011-04-30 20:40 ` [Qemu-devel] [PATCH v2 03/10] eepro100: Remove unused structure element Stefan Weil
2011-04-30 20:40 ` Stefan Weil [this message]
2011-05-05 13:00   ` [Qemu-devel] [PATCH v2 04/10] eepro100: Pad received short frames Michael S. Tsirkin
2011-05-05 16:19     ` Stefan Weil
2011-04-30 20:40 ` [Qemu-devel] [PATCH v2 05/10] eepro100: Fix endianness issues Stefan Weil
2011-04-30 20:40 ` [Qemu-devel] [PATCH v2 06/10] eepro100: Support byte/word writes to port address Stefan Weil
2011-04-30 20:40 ` [Qemu-devel] [PATCH v2 07/10] eepro100: Support byte/word writes to pointer register Stefan Weil
2011-04-30 20:40 ` [Qemu-devel] [PATCH v2 08/10] eepro100: Support byte/word read/write access to MDI control register Stefan Weil
2011-04-30 20:40 ` [Qemu-devel] [PATCH v2 09/10] eepro100: Support byte read access to general " Stefan Weil
2011-04-30 20:40 ` [Qemu-devel] [PATCH v2 10/10] eepro100: Support 32 bit read/write access to flash register Stefan Weil
2011-05-05 13:01 ` [Qemu-devel] [PULL v2] eepro100: Update of patch series (fixes and enhancements) Michael S. Tsirkin
2011-05-15 12:48 ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1304196013-14432-5-git-send-email-weil@mail.berlios.de \
    --to=weil@mail.berlios.de \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).