From: Max Filippov <jcmvbkbc@gmail.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Blue Swirl <blauwirbel@gmail.com>,
jcmvbkbc@gmail.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 4/7] opencores_eth: fix RX path: FCS, padding and TL
Date: Tue, 1 Nov 2011 02:17:32 +0400 [thread overview]
Message-ID: <1320099455-17326-8-git-send-email-jcmvbkbc@gmail.com> (raw)
In-Reply-To: <1320099455-17326-1-git-send-email-jcmvbkbc@gmail.com>
OpenCores 10/100 Mbps Ethernet MAC specification doesn't clearly state
whether FCS is counted in the RX frame length or not. Looks like it is.
Append zero FCS to the received frames.
Get rid of big static buffer for RX frame padding, optimize it for the
most common MINFL value range.
Set RXD_TL for the long frames only when HUGEN bit is set.
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
hw/opencores_eth.c | 29 ++++++++++++++++++++++++-----
1 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/hw/opencores_eth.c b/hw/opencores_eth.c
index 64b616e..2c1e475 100644
--- a/hw/opencores_eth.c
+++ b/hw/opencores_eth.c
@@ -382,6 +382,7 @@ static ssize_t open_eth_receive(VLANClientState *nc,
OpenEthState *s = DO_UPCAST(NICState, nc, nc)->opaque;
size_t maxfl = GET_REGFIELD(s, PACKETLEN, MAXFL);
size_t minfl = GET_REGFIELD(s, PACKETLEN, MINFL);
+ size_t fcsl = 4;
bool miss = true;
trace_open_eth_receive((unsigned)size);
@@ -418,6 +419,7 @@ static ssize_t open_eth_receive(VLANClientState *nc,
#else
{
#endif
+ static const uint8_t zero[64] = {0};
desc *desc = rx_desc(s);
size_t copy_size = GET_REGBIT(s, MODER, HUGEN) ? 65536 : maxfl;
@@ -426,11 +428,13 @@ static ssize_t open_eth_receive(VLANClientState *nc,
if (copy_size > size) {
copy_size = size;
+ } else {
+ fcsl = 0;
}
if (miss) {
desc->len_flags |= RXD_M;
}
- if (size > maxfl) {
+ if (GET_REGBIT(s, MODER, HUGEN) && size > maxfl) {
desc->len_flags |= RXD_TL;
}
#ifdef USE_RECSMALL
@@ -442,13 +446,28 @@ static ssize_t open_eth_receive(VLANClientState *nc,
cpu_physical_memory_write(desc->buf_ptr, buf, copy_size);
if (GET_REGBIT(s, MODER, PAD) && copy_size < minfl) {
- static const uint8_t zero[65536] = {0};
+ if (minfl - copy_size > fcsl) {
+ fcsl = 0;
+ } else {
+ fcsl -= minfl - copy_size;
+ }
+ while (copy_size < minfl) {
+ size_t zero_sz = minfl - copy_size < sizeof(zero) ?
+ minfl - copy_size : sizeof(zero);
- cpu_physical_memory_write(desc->buf_ptr + copy_size,
- zero, minfl - copy_size);
- copy_size = minfl;
+ cpu_physical_memory_write(desc->buf_ptr + copy_size,
+ zero, zero_sz);
+ copy_size += zero_sz;
+ }
}
+ /* There's no FCS in the frames handed to us by the QEMU, zero fill it.
+ * Don't do it if the frame is cut at the MAXFL or padded with 4 or
+ * more bytes to the MINFL.
+ */
+ cpu_physical_memory_write(desc->buf_ptr + copy_size, zero, fcsl);
+ copy_size += fcsl;
+
SET_FIELD(desc->len_flags, RXD_LEN, copy_size);
if ((desc->len_flags & RXD_WRAP) || s->rx_desc == 0x7f) {
--
1.7.6.4
next prev parent reply other threads:[~2011-10-31 22:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-31 22:17 [Qemu-devel] [PULL 0/7] target-xtensa patches for 1.0 Max Filippov
2011-10-31 22:17 ` [Qemu-devel] [PATCH 1/7] target-xtensa: mask out undefined bits of WINDOWBASE SR Max Filippov
2011-11-02 13:34 ` [Qemu-devel] [PATCH v2] target-xtensa: mask out undefined bits of WINDOWSTART SR Max Filippov
2011-10-31 22:17 ` [Qemu-devel] [PATCH 1/3] xtensa_lx60: add FLASH support Max Filippov
2011-10-31 22:17 ` [Qemu-devel] [PATCH 2/7] target-xtensa: handle cache options in the overlay tool Max Filippov
2011-10-31 22:17 ` [Qemu-devel] [PATCH 2/3] xtensa_lx60: pass kernel arguments from -append Max Filippov
2011-10-31 22:17 ` [Qemu-devel] [PATCH 3/7] target-xtensa: raise an exception for invalid and reserved opcodes Max Filippov
2011-10-31 22:17 ` [Qemu-devel] [PATCH 3/3] xtensa_lx60: fix build date code and change memory region names Max Filippov
2011-10-31 22:17 ` Max Filippov [this message]
2011-10-31 22:17 ` [Qemu-devel] [PATCH 5/7] xtensa_lx60: add FLASH support Max Filippov
2011-10-31 22:17 ` [Qemu-devel] [PATCH 6/7] xtensa_lx60: pass kernel arguments from -append Max Filippov
2011-10-31 22:17 ` [Qemu-devel] [PATCH 7/7] xtensa_lx60: fix build date code and change memory region names Max Filippov
2011-10-31 22:26 ` [Qemu-devel] [PULL 0/7] target-xtensa patches for 1.0 Max Filippov
2011-11-02 20:55 ` Blue Swirl
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=1320099455-17326-8-git-send-email-jcmvbkbc@gmail.com \
--to=jcmvbkbc@gmail.com \
--cc=aliguori@us.ibm.com \
--cc=blauwirbel@gmail.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).