qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 09/31] ftgmac100: compute maximum frame size depending on the protocol
Date: Fri,  8 Jun 2018 13:44:55 +0100	[thread overview]
Message-ID: <20180608124517.29475-10-peter.maydell@linaro.org> (raw)
In-Reply-To: <20180608124517.29475-1-peter.maydell@linaro.org>

From: Cédric Le Goater <clg@kaod.org>

The maximum frame size includes the CRC and depends if a VLAN tag is
inserted or not. Adjust the frame size limit in the transmit handler
using on the FTGMAC100State buffer size and in the receive handler use
the packet protocol.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20180530061711.23673-2-clg@kaod.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/hw/net/ftgmac100.h |  7 ++++++-
 hw/net/ftgmac100.c         | 23 ++++++++++++-----------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/include/hw/net/ftgmac100.h b/include/hw/net/ftgmac100.h
index d9bc589fbf7..94cfe053329 100644
--- a/include/hw/net/ftgmac100.h
+++ b/include/hw/net/ftgmac100.h
@@ -16,6 +16,11 @@
 #include "hw/sysbus.h"
 #include "net/net.h"
 
+/*
+ * Max frame size for the receiving buffer
+ */
+#define FTGMAC100_MAX_FRAME_SIZE    9220
+
 typedef struct FTGMAC100State {
     /*< private >*/
     SysBusDevice parent_obj;
@@ -26,7 +31,7 @@ typedef struct FTGMAC100State {
     qemu_irq irq;
     MemoryRegion iomem;
 
-    uint8_t *frame;
+    uint8_t frame[FTGMAC100_MAX_FRAME_SIZE];
 
     uint32_t irq_state;
     uint32_t isr;
diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c
index 3300e8ef4a8..425ac36cff8 100644
--- a/hw/net/ftgmac100.c
+++ b/hw/net/ftgmac100.c
@@ -207,16 +207,18 @@ typedef struct {
 /*
  * Max frame size for the receiving buffer
  */
-#define FTGMAC100_MAX_FRAME_SIZE    10240
+#define FTGMAC100_MAX_FRAME_SIZE    9220
 
 /* Limits depending on the type of the frame
  *
  *   9216 for Jumbo frames (+ 4 for VLAN)
  *   1518 for other frames (+ 4 for VLAN)
  */
-static int ftgmac100_max_frame_size(FTGMAC100State *s)
+static int ftgmac100_max_frame_size(FTGMAC100State *s, uint16_t proto)
 {
-    return (s->maccr & FTGMAC100_MACCR_JUMBO_LF ? 9216 : 1518) + 4;
+    int max = (s->maccr & FTGMAC100_MACCR_JUMBO_LF ? 9216 : 1518);
+
+    return max + (proto == ETH_P_VLAN ? 4 : 0);
 }
 
 static void ftgmac100_update_irq(FTGMAC100State *s)
@@ -408,7 +410,6 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,
     uint8_t *ptr = s->frame;
     uint32_t addr = tx_descriptor;
     uint32_t flags = 0;
-    int max_frame_size = ftgmac100_max_frame_size(s);
 
     while (1) {
         FTGMAC100Desc bd;
@@ -427,11 +428,12 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,
             flags = bd.des1;
         }
 
-        len = bd.des0 & 0x3FFF;
-        if (frame_size + len > max_frame_size) {
+        len = FTGMAC100_TXDES0_TXBUF_SIZE(bd.des0);
+        if (frame_size + len > sizeof(s->frame)) {
             qemu_log_mask(LOG_GUEST_ERROR, "%s: frame too big : %d bytes\n",
                           __func__, len);
-            len = max_frame_size - frame_size;
+            s->isr |= FTGMAC100_INT_XPKT_LOST;
+            len =  sizeof(s->frame) - frame_size;
         }
 
         if (dma_memory_read(&address_space_memory, bd.des3, ptr, len)) {
@@ -788,7 +790,8 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
     uint32_t buf_len;
     size_t size = len;
     uint32_t first = FTGMAC100_RXDES0_FRS;
-    int max_frame_size = ftgmac100_max_frame_size(s);
+    uint16_t proto = be16_to_cpu(PKT_GET_ETH_HDR(buf)->h_proto);
+    int max_frame_size = ftgmac100_max_frame_size(s, proto);
 
     if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN))
          != (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) {
@@ -820,9 +823,9 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
 
     /* Huge frames are truncated.  */
     if (size > max_frame_size) {
-        size = max_frame_size;
         qemu_log_mask(LOG_GUEST_ERROR, "%s: frame too big : %zd bytes\n",
                       __func__, size);
+        size = max_frame_size;
         flags |= FTGMAC100_RXDES0_FTL;
     }
 
@@ -940,8 +943,6 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
                           object_get_typename(OBJECT(dev)), DEVICE(dev)->id,
                           s);
     qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
-
-    s->frame = g_malloc(FTGMAC100_MAX_FRAME_SIZE);
 }
 
 static const VMStateDescription vmstate_ftgmac100 = {
-- 
2.17.1

  parent reply	other threads:[~2018-06-08 12:45 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-08 12:44 [Qemu-devel] [PULL 00/31] target-arm queue Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 01/31] arm_gicv3_kvm: kvm_dist_get/put: skip the registers banked by GICR Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 02/31] aspeed: remove ignore_memory_transaction_failures on all boards Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 03/31] aspeed: add support for the witherspoon-bmc board Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 04/31] aspeed: add an I2C RTC device to all machines Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 05/31] smbus: add a smbus_eeprom_init_one() routine Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 06/31] aspeed: Add EEPROM I2C devices Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 07/31] misc: add pca9552 LED blinker model Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 08/31] aspeed: add the pc9552 chips to the witherspoon machine Peter Maydell
2018-06-08 12:44 ` Peter Maydell [this message]
2018-06-08 12:44 ` [Qemu-devel] [PULL 10/31] ftgmac100: add IEEE 802.1Q VLAN support Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 11/31] ftgmac100: fix multicast hash routine Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 12/31] ftgmac100: remove check on runt messages Peter Maydell
2018-06-08 12:44 ` [Qemu-devel] [PULL 13/31] hw/arm: Remove the deprecated xlnx-ep108 machine Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 14/31] hw/i2c: Add trace events Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 15/31] hw/sd/milkymist-memcard: Add trailing '\n' to qemu_log() call Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 16/31] hw/digic: Add trailing '\n' to qemu_log() calls Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 17/31] xilinx-dp: Add trailing '\n' to qemu_log() call Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 18/31] ppc/pnv: Add trailing '\n' to qemu_log() calls Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 19/31] hw/core/register: Add trailing '\n' to qemu_log() call Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 20/31] hw/mips/boston: Add trailing '\n' to qemu_log() calls Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 21/31] stellaris: " Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 22/31] target/arm: " Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 23/31] target/m68k: Add trailing '\n' to qemu_log() call Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 24/31] RISC-V: Add trailing '\n' to qemu_log() calls Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 25/31] target/xtensa: " Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 26/31] sdcard: Update the Configuration Register (SCR) to Spec Version 1.10 Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 27/31] sdcard: Allow commands valid in SPI mode Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 28/31] sdcard: Add a 'spec_version' property, default to Spec v2.00 Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 29/31] sdcard: Disable SEND_IF_COND (CMD8) for Spec v1 Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 30/31] sdcard: Reflect when the Spec v3 is supported in the Config Register (SCR) Peter Maydell
2018-06-08 12:45 ` [Qemu-devel] [PULL 31/31] sdcard: Disable CMD19/CMD23 for Spec v2 Peter Maydell
2018-06-11 10:12 ` [Qemu-devel] [PULL 00/31] target-arm queue Peter Maydell

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=20180608124517.29475-10-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --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).