[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 6/8] dp8393x: Store CRC using device configured endianess
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v3 6/8] dp8393x: Store CRC using device configured endianess |
Date: |
Sat, 10 Jul 2021 19:49:52 +0200 |
Little-Endian CRC is dubious. The datasheet does not
specify it being little-endian. Use big-endian access
when the device is configured in such endianess.
(This is a theoretical bug fix.)
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/net/dp8393x.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c
index 68516241a1f..ac93412f70b 100644
--- a/hw/net/dp8393x.c
+++ b/hw/net/dp8393x.c
@@ -827,7 +827,7 @@ 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, pkt_size));
+ checksum = crc32(0, buf, pkt_size);
/* Put packet into RBA */
trace_dp8393x_receive_packet(dp8393x_crba(s));
@@ -837,8 +837,13 @@ static ssize_t dp8393x_receive(NetClientState *nc, const
uint8_t * buf,
address += pkt_size;
/* Put frame checksum into RBA */
- address_space_write(&s->as, address, MEMTXATTRS_UNSPECIFIED,
- &checksum, sizeof(checksum));
+ if (s->big_endian) {
+ address_space_stl_be(&s->as, address, checksum,
+ MEMTXATTRS_UNSPECIFIED, NULL);
+ } else {
+ address_space_stl_le(&s->as, address, checksum,
+ MEMTXATTRS_UNSPECIFIED, NULL);
+ }
address += sizeof(checksum);
/* Pad short packets to keep pointers aligned */
--
2.31.1
- Re: [PATCH v3 1/8] dp8393x: Replace address_space_rw(is_write=1) by address_space_write(), (continued)
- [PATCH v3 3/8] dp8393x: Only shift the device registers mapping by 1 bit, Philippe Mathieu-Daudé, 2021/07/10
- [PATCH v3 2/8] dp8393x: Replace 0x40 magic value by SONIC_REG16_COUNT definition, Philippe Mathieu-Daudé, 2021/07/10
- [PATCH v3 4/8] dp8393x: Store CAM registers as 16-bit, Philippe Mathieu-Daudé, 2021/07/10
- [PATCH v3 5/8] dp8393x: Migrate registers as array of uint16, Philippe Mathieu-Daudé, 2021/07/10
- [PATCH v3 6/8] dp8393x: Store CRC using device configured endianess,
Philippe Mathieu-Daudé <=
- [NOTFORMERGE PATCH v3 7/8] dp8393x: Rewrite dp8393x_get() / dp8393x_put(), Philippe Mathieu-Daudé, 2021/07/10
- [NOTFORMERGE PATCH v3 8/8] dp8393x: don't force 32-bit register access, Philippe Mathieu-Daudé, 2021/07/10
- Re: [PATCH v3 0/8] dp8393x: fixes and improvements, Finn Thain, 2021/07/10