From: Jason Wang <jasowang@redhat.com>
To: peter.maydell@linaro.org
Cc: Jason Wang <jasowang@redhat.com>,
qemu-devel@nongnu.org, Finn Thain <fthain@telegraphics.com.au>
Subject: [PULL V2 10/23] dp8393x: Pad frames to word or long word boundary
Date: Tue, 3 Mar 2020 18:10:29 +0800 [thread overview]
Message-ID: <1583230242-14597-11-git-send-email-jasowang@redhat.com> (raw)
In-Reply-To: <1583230242-14597-1-git-send-email-jasowang@redhat.com>
From: Finn Thain <fthain@telegraphics.com.au>
The existing code has a bug where the Remaining Buffer Word Count (RBWC)
is calculated with a truncating division, which gives the wrong result
for odd-sized packets.
Section 1.4.1 of the datasheet says,
Once the end of the packet has been reached, the serializer will
fill out the last word (16-bit mode) or long word (32-bit mode)
if the last byte did not end on a word or long word boundary
respectively. The fill byte will be 0FFh.
Implement buffer padding so that buffer limits are correctly enforced.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Tested-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
hw/net/dp8393x.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c
index d8bf248..22b4d36 100644
--- a/hw/net/dp8393x.c
+++ b/hw/net/dp8393x.c
@@ -768,16 +768,23 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf,
dp8393xState *s = qemu_get_nic_opaque(nc);
int packet_type;
uint32_t available, address;
- int width, rx_len = pkt_size;
+ int width, rx_len, padded_len;
uint32_t checksum;
int size;
- width = (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1;
-
s->regs[SONIC_RCR] &= ~(SONIC_RCR_PRX | SONIC_RCR_LBK | SONIC_RCR_FAER |
SONIC_RCR_CRCR | SONIC_RCR_LPKT | SONIC_RCR_BC | SONIC_RCR_MC);
- if (pkt_size + 4 > dp8393x_rbwc(s) * 2) {
+ rx_len = pkt_size + sizeof(checksum);
+ if (s->regs[SONIC_DCR] & SONIC_DCR_DW) {
+ width = 2;
+ padded_len = ((rx_len - 1) | 3) + 1;
+ } else {
+ width = 1;
+ padded_len = ((rx_len - 1) | 1) + 1;
+ }
+
+ if (padded_len > dp8393x_rbwc(s) * 2) {
DPRINTF("oversize packet, pkt_size is %d\n", pkt_size);
s->regs[SONIC_ISR] |= SONIC_ISR_RBAE;
dp8393x_update_irq(s);
@@ -812,22 +819,32 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf,
s->regs[SONIC_TRBA0] = s->regs[SONIC_CRBA0];
/* Calculate the ethernet checksum */
- checksum = cpu_to_le32(crc32(0, buf, rx_len));
+ checksum = cpu_to_le32(crc32(0, buf, pkt_size));
/* Put packet into RBA */
DPRINTF("Receive packet at %08x\n", dp8393x_crba(s));
address = dp8393x_crba(s);
address_space_write(&s->as, address, MEMTXATTRS_UNSPECIFIED,
- buf, rx_len);
- address += rx_len;
+ buf, pkt_size);
+ address += pkt_size;
+
+ /* Put frame checksum into RBA */
address_space_write(&s->as, address, MEMTXATTRS_UNSPECIFIED,
- &checksum, 4);
- address += 4;
- rx_len += 4;
+ &checksum, sizeof(checksum));
+ address += sizeof(checksum);
+
+ /* Pad short packets to keep pointers aligned */
+ if (rx_len < padded_len) {
+ size = padded_len - rx_len;
+ address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED,
+ (uint8_t *)"\xFF\xFF\xFF", size, 1);
+ address += size;
+ }
+
s->regs[SONIC_CRBA1] = address >> 16;
s->regs[SONIC_CRBA0] = address & 0xffff;
available = dp8393x_rbwc(s);
- available -= rx_len / 2;
+ available -= padded_len >> 1;
s->regs[SONIC_RBWC1] = available >> 16;
s->regs[SONIC_RBWC0] = available & 0xffff;
--
2.5.0
next prev parent reply other threads:[~2020-03-03 10:15 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 10:10 [PULL V2 00/23] Net patches Jason Wang
2020-03-03 10:10 ` [PULL V2 01/23] dp8393x: Mask EOL bit from descriptor addresses Jason Wang
2020-03-03 22:44 ` Finn Thain
2020-03-04 2:43 ` Jason Wang
2020-03-03 10:10 ` [PULL V2 02/23] dp8393x: Always use 32-bit accesses Jason Wang
2020-03-03 10:10 ` [PULL V2 03/23] dp8393x: Clean up endianness hacks Jason Wang
2020-03-03 10:10 ` [PULL V2 04/23] dp8393x: Have dp8393x_receive() return the packet size Jason Wang
2020-03-03 10:10 ` [PULL V2 05/23] dp8393x: Update LLFA and CRDA registers from rx descriptor Jason Wang
2020-03-03 10:10 ` [PULL V2 06/23] dp8393x: Clear RRRA command register bit only when appropriate Jason Wang
2020-03-03 10:10 ` [PULL V2 07/23] dp8393x: Implement packet size limit and RBAE interrupt Jason Wang
2020-03-03 10:10 ` [PULL V2 08/23] dp8393x: Don't clobber packet checksum Jason Wang
2020-03-03 10:10 ` [PULL V2 09/23] dp8393x: Use long-word-aligned RRA pointers in 32-bit mode Jason Wang
2020-03-03 10:10 ` Jason Wang [this message]
2020-03-03 10:10 ` [PULL V2 11/23] dp8393x: Clear descriptor in_use field to release packet Jason Wang
2020-03-03 10:10 ` [PULL V2 12/23] dp8393x: Always update RRA pointers and sequence numbers Jason Wang
2020-03-03 10:10 ` [PULL V2 13/23] dp8393x: Don't reset Silicon Revision register Jason Wang
2020-03-03 10:10 ` [PULL V2 14/23] dp8393x: Don't stop reception upon RBE interrupt assertion Jason Wang
2020-03-03 10:10 ` [PULL V2 15/23] e1000e: Avoid hw_error if legacy mode used Jason Wang
2020-03-03 10:10 ` [PULL V2 16/23] NetRxPkt: Introduce support for additional hash types Jason Wang
2020-03-03 10:10 ` [PULL V2 17/23] NetRxPkt: fix hash calculation of IPV6 TCP Jason Wang
2020-03-03 10:10 ` [PULL V2 18/23] hw: net: cadence_gem: Fix build errors in DB_PRINT() Jason Wang
2020-03-03 10:10 ` [PULL V2 19/23] block/replication.c: Ignore requests after failover Jason Wang
2020-03-03 10:10 ` [PULL V2 20/23] tests/test-replication.c: Add test for for secondary node continuing replication Jason Wang
2020-03-03 10:10 ` [PULL V2 21/23] net/filter.c: Add Options to insert filters anywhere in the filter list Jason Wang
2020-03-03 10:10 ` [PULL V2 22/23] colo: Update Documentation for continuous replication Jason Wang
2020-03-03 10:10 ` [PULL V2 23/23] l2tpv3: fix RFC number typo in qemu-options.hx Jason Wang
2020-03-03 13:45 ` [PULL V2 00/23] Net patches 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=1583230242-14597-11-git-send-email-jasowang@redhat.com \
--to=jasowang@redhat.com \
--cc=fthain@telegraphics.com.au \
--cc=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).