From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVW16cfqz9s4Y for ; Sat, 14 Dec 2019 12:36:29 +1100 (AEDT) Received: from localhost ([::1]:55060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwM7-0004hA-R8 for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:36:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41240) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEd-00041n-1R for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEb-000166-KG for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:42 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEb-00014o-Fs; Fri, 13 Dec 2019 20:28:41 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id EAE5F227AE; Fri, 13 Dec 2019 20:28:40 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <7d220205700c43b15d6ae6cefd6520a97c763709.1576286757.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH 01/10] dp8393x: Mask EOL bit from descriptor addresses Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The LSB of descriptor address registers is used as an EOL flag. It has to be masked when those registers are to be used as actual addresses for copying memory around. But when the registers are to be updated the EOL bit should not be masked. Signed-off-by: Finn Thain --- hw/net/dp8393x.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 3d991af163..164311c055 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -197,7 +197,7 @@ static uint32_t dp8393x_crba(dp8393xState *s) static uint32_t dp8393x_crda(dp8393xState *s) { - return (s->regs[SONIC_URDA] << 16) | s->regs[SONIC_CRDA]; + return (s->regs[SONIC_URDA] << 16) | (s->regs[SONIC_CRDA] & 0xfffe); } static uint32_t dp8393x_rbwc(dp8393xState *s) @@ -217,7 +217,7 @@ static uint32_t dp8393x_tsa(dp8393xState *s) static uint32_t dp8393x_ttda(dp8393xState *s) { - return (s->regs[SONIC_UTDA] << 16) | s->regs[SONIC_TTDA]; + return (s->regs[SONIC_UTDA] << 16) | (s->regs[SONIC_TTDA] & 0xfffe); } static uint32_t dp8393x_wt(dp8393xState *s) @@ -506,8 +506,8 @@ static void dp8393x_do_transmit_packets(dp8393xState *s) sizeof(uint16_t) * (4 + 3 * s->regs[SONIC_TFC]) * width, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 0); - s->regs[SONIC_CTDA] = dp8393x_get(s, width, 0) & ~0x1; - if (dp8393x_get(s, width, 0) & 0x1) { + s->regs[SONIC_CTDA] = dp8393x_get(s, width, 0); + if (s->regs[SONIC_CTDA] & 0x1) { /* EOL detected */ break; } From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVM81h2Vz9sPW for ; Sat, 14 Dec 2019 12:29:38 +1100 (AEDT) Received: from localhost ([::1]:54938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwFS-000435-1b for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:29:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41470) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEd-00041s-SA for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEc-00018M-Ad for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:43 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEc-00014s-3r; Fri, 13 Dec 2019 20:28:42 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 04B54230A5; Fri, 13 Dec 2019 20:28:40 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <397259001f92f93620a618e83599463b1faa54ee.1576286757.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH 02/10] dp8393x: Clean up endianness hacks Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The in_use field is no different to the other words handled using dp8393x_put() and dp8393x_get(). Use the same technique for in_use that is used everywhere else. Signed-off-by: Finn Thain --- Laurent tells me that this clean-up has been tried before. He referred me to commit c744cf7879 ("dp8393x: fix dp8393x_receive()") and commit 409b52bfe1 ("net/dp8393x: correctly reset in_use field"). Both of those patches look wrong to me because they both pass the wrong byte count to address_space_rw(). It's possible that those patches were needed to work around some kind of bug elsewhere, for example, an off-by-one result from dp8393x_crda(). The preceding patch in this series might help there. This needs testing with the little endian MIPS Jazz emulation. --- hw/net/dp8393x.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 164311c055..3fd59bc1d4 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -760,8 +760,6 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, return -1; } - /* XXX: Check byte ordering */ - /* Check for EOL */ if (s->regs[SONIC_LLFA] & 0x1) { /* Are we still in resource exhaustion? */ @@ -831,15 +829,12 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, /* EOL detected */ s->regs[SONIC_ISR] |= SONIC_ISR_RDE; } else { - /* Clear in_use, but it is always 16bit wide */ + /* Clear in_use */ int offset = dp8393x_crda(s) + sizeof(uint16_t) * 6 * width; - if (s->big_endian && width == 2) { - /* we need to adjust the offset of the 16bit field */ - offset += sizeof(uint16_t); - } - s->data[0] = 0; + size = sizeof(uint16_t) * width; + dp8393x_put(s, width, 0, 0); address_space_rw(&s->as, offset, MEMTXATTRS_UNSPECIFIED, - (uint8_t *)s->data, sizeof(uint16_t), 1); + (uint8_t *)s->data, size, 1); s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; s->regs[SONIC_ISR] |= SONIC_ISR_PKTRX; s->regs[SONIC_RSC] = (s->regs[SONIC_RSC] & 0xff00) | (((s->regs[SONIC_RSC] & 0x00ff) + 1) & 0x00ff); From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVQW3lw7z9s4Y for ; Sat, 14 Dec 2019 12:32:35 +1100 (AEDT) Received: from localhost ([::1]:54996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwIK-0007mk-PQ for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:32:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41578) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEe-00041v-8W for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEc-00019q-OS for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:44 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEc-000157-5V; Fri, 13 Dec 2019 20:28:42 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 26EE72786C; Fri, 13 Dec 2019 20:28:40 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH 03/10] dp8393x: Have dp8393x_receive() return the packet size Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This function re-uses its 'size' argument as a scratch variable. Instead, declare a local 'size' variable for that purpose so that the function result doesn't get messed up. Signed-off-by: Finn Thain Reviewed-by: Philippe Mathieu-Daudé --- hw/net/dp8393x.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 3fd59bc1d4..462f8646e0 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -741,20 +741,21 @@ static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf, } static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, - size_t size) + size_t pkt_size) { dp8393xState *s = qemu_get_nic_opaque(nc); int packet_type; uint32_t available, address; - int width, rx_len = size; + int width, rx_len = pkt_size; 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); - packet_type = dp8393x_receive_filter(s, buf, size); + packet_type = dp8393x_receive_filter(s, buf, pkt_size); if (packet_type < 0) { DPRINTF("packet not for netcard\n"); return -1; @@ -848,7 +849,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, /* Done */ dp8393x_update_irq(s); - return size; + return pkt_size; } static void dp8393x_reset(DeviceState *dev) From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVM812RJz9s4Y for ; Sat, 14 Dec 2019 12:29:38 +1100 (AEDT) Received: from localhost ([::1]:54936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwFR-00042z-Uo for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:29:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41407) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEd-00041p-Iy for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEc-000185-7o for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:43 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47380) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEc-00014z-3J; Fri, 13 Dec 2019 20:28:42 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 17B8923555; Fri, 13 Dec 2019 20:28:41 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH 04/10] dp8393x: Don't advance RX descriptor twice Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Follow the algorithm given in the National Semiconductor DP83932C datasheet in sections 3.4.5 and 3.4.6. Signed-off-by: Finn Thain --- hw/net/dp8393x.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 462f8646e0..49d7d9769e 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -771,8 +771,6 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, if (dp8393x_get(s, width, 0) & 0x1) { /* Still EOL ; stop reception */ return -1; - } else { - s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; } } @@ -821,7 +819,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, address_space_rw(&s->as, dp8393x_crda(s), MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 1); - /* Move to next descriptor */ + /* Check link field */ size = sizeof(uint16_t) * width; address_space_rw(&s->as, dp8393x_crda(s) + sizeof(uint16_t) * 5 * width, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 0); @@ -836,6 +834,8 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, dp8393x_put(s, width, 0, 0); address_space_rw(&s->as, offset, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 1); + + /* Move to next descriptor */ s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; s->regs[SONIC_ISR] |= SONIC_ISR_PKTRX; s->regs[SONIC_RSC] = (s->regs[SONIC_RSC] & 0xff00) | (((s->regs[SONIC_RSC] & 0x00ff) + 1) & 0x00ff); From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVM81ty1z9sPh for ; Sat, 14 Dec 2019 12:29:38 +1100 (AEDT) Received: from localhost ([::1]:54940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwFS-00043I-P7 for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:29:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41313) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEd-00041o-8N for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEc-00017Z-5O for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:43 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEc-00016s-1J; Fri, 13 Dec 2019 20:28:42 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 3082C27451; Fri, 13 Dec 2019 20:28:41 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <42667d1214124065a82e661f38757fdfd0a47943.1576286757.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH 05/10] dp8393x: Update LLFA register Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If the chip used QEMU's algorithm it would need an extra word-sized register just to recheck the EOL bit, which would be a waste of silicon. Do it the way the chip would do it. No functional change. Signed-off-by: Finn Thain --- hw/net/dp8393x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 49d7d9769e..494deb42bf 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -768,7 +768,8 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, address = dp8393x_crda(s) + sizeof(uint16_t) * 5 * width; address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 0); - if (dp8393x_get(s, width, 0) & 0x1) { + s->regs[SONIC_LLFA] = dp8393x_get(s, width, 0); + if (s->regs[SONIC_LLFA] & 0x1) { /* Still EOL ; stop reception */ return -1; } From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVQS1Kp9z9s4Y for ; Sat, 14 Dec 2019 12:32:32 +1100 (AEDT) Received: from localhost ([::1]:54978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwIH-0007h5-DC for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:32:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41408) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEd-00041q-JF for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEc-00017v-7T for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:43 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47410) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEc-00016t-1D; Fri, 13 Dec 2019 20:28:42 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 4971D27C6B; Fri, 13 Dec 2019 20:28:41 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH 06/10] dp8393x: Clear RRRA command register bit only when appropriate Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It doesn't make sense to clear the command register bit unless the command was actually issued. Signed-off-by: Finn Thain Reviewed-by: Philippe Mathieu-Daudé --- hw/net/dp8393x.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 494deb42bf..3fdc6cc6f9 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -337,9 +337,6 @@ static void dp8393x_do_read_rra(dp8393xState *s) s->regs[SONIC_ISR] |= SONIC_ISR_RBE; dp8393x_update_irq(s); } - - /* Done */ - s->regs[SONIC_CR] &= ~SONIC_CR_RRRA; } static void dp8393x_do_software_reset(dp8393xState *s) @@ -548,8 +545,10 @@ static void dp8393x_do_command(dp8393xState *s, uint16_t command) dp8393x_do_start_timer(s); if (command & SONIC_CR_RST) dp8393x_do_software_reset(s); - if (command & SONIC_CR_RRRA) + if (command & SONIC_CR_RRRA) { dp8393x_do_read_rra(s); + s->regs[SONIC_CR] &= ~SONIC_CR_RRRA; + } if (command & SONIC_CR_LCAM) dp8393x_do_load_cam(s); } From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209592 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVTN6W5Hz9s4Y for ; Sat, 14 Dec 2019 12:35:03 +1100 (AEDT) Received: from localhost ([::1]:55020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwKh-0002im-TI for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:34:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41546) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEe-00041t-6i for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEc-00019F-KF for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:44 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEc-00016s-78; Fri, 13 Dec 2019 20:28:42 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 5238A27C43; Fri, 13 Dec 2019 20:28:41 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH 07/10] dp8393x: Implement TBWC0 and TBWC1 registers to restore buffer state Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Restore the receive buffer state when the SONIC runs out of receive descriptors. Otherwise it may write the next packet past the end of the buffer and corrupt guest memory. This implements behaviour described in section 3.4.6.2 in the datasheet. Signed-off-by: Finn Thain --- hw/net/dp8393x.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 3fdc6cc6f9..5e4494a945 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -39,7 +39,7 @@ static const char* reg_names[] = { "CR", "DCR", "RCR", "TCR", "IMR", "ISR", "UTDA", "CTDA", "TPS", "TFC", "TSA0", "TSA1", "TFS", "URDA", "CRDA", "CRBA0", "CRBA1", "RBWC0", "RBWC1", "EOBC", "URRA", "RSA", "REA", "RRP", - "RWP", "TRBA0", "TRBA1", "0x1b", "0x1c", "0x1d", "0x1e", "LLFA", + "RWP", "TRBA0", "TRBA1", "TBWC0", "TBWC1", "0x1d", "0x1e", "LLFA", "TTDA", "CEP", "CAP2", "CAP1", "CAP0", "CE", "CDP", "CDC", "SR", "WT0", "WT1", "RSC", "CRCT", "FAET", "MPT", "MDT", "0x30", "0x31", "0x32", "0x33", "0x34", "0x35", "0x36", "0x37", @@ -78,6 +78,8 @@ do { printf("sonic ERROR: %s: " fmt, __func__ , ## __VA_ARGS__); } while (0) #define SONIC_RWP 0x18 #define SONIC_TRBA0 0x19 #define SONIC_TRBA1 0x1a +#define SONIC_TBWC0 0x1b +#define SONIC_TBWC1 0x1c #define SONIC_LLFA 0x1f #define SONIC_TTDA 0x20 #define SONIC_CEP 0x21 @@ -777,6 +779,8 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, /* Save current position */ s->regs[SONIC_TRBA1] = s->regs[SONIC_CRBA1]; s->regs[SONIC_TRBA0] = s->regs[SONIC_CRBA0]; + s->regs[SONIC_TBWC1] = s->regs[SONIC_RBWC1]; + s->regs[SONIC_TBWC0] = s->regs[SONIC_RBWC0]; /* Calculate the ethernet checksum */ checksum = cpu_to_le32(crc32(0, buf, rx_len)); @@ -827,6 +831,12 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, if (s->regs[SONIC_LLFA] & 0x1) { /* EOL detected */ s->regs[SONIC_ISR] |= SONIC_ISR_RDE; + + /* Restore buffer state */ + s->regs[SONIC_CRBA1] = s->regs[SONIC_TRBA1]; + s->regs[SONIC_CRBA0] = s->regs[SONIC_TRBA0]; + s->regs[SONIC_RBWC1] = s->regs[SONIC_TBWC1]; + s->regs[SONIC_RBWC0] = s->regs[SONIC_TBWC0]; } else { /* Clear in_use */ int offset = dp8393x_crda(s) + sizeof(uint16_t) * 6 * width; From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209595 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVX31zsxz9s4Y for ; Sat, 14 Dec 2019 12:37:23 +1100 (AEDT) Received: from localhost ([::1]:55074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwMz-0005ak-0H for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:37:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41728) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEe-000424-Qu for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEd-0001A6-02 for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:44 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47422) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEc-00017i-Ex; Fri, 13 Dec 2019 20:28:42 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 6108D27C8C; Fri, 13 Dec 2019 20:28:41 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <0beefa36e1c95fabb6c46c4d68559c667e68cec9.1576286757.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH 08/10] dp8393x: Implement packet size limit and RBAE interrupt Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a bounds check to prevent a large packet from causing a buffer overflow. This is defensive programming -- I haven't actually tried sending an oversized packet or a jumbo ethernet frame. The SONIC handles packets that are too big for the buffer by raising the RBAE interrupt and dropping them. Linux uses that interrupt to count dropped packets. Signed-off-by: Finn Thain --- QEMU passes short packets to dp8393x_receive(). But a real SONIC rejects packets shorter than 64 bytes. For dp8393x, the effective limit is 60 bytes because packets passed to dp8393x_receive() lack a frame checksum. However, even 60 bytes proved too high and blocked ARP packets when I tried it. So the SONIC's mechanism for detecting runt packets (the RNT bit in the RCR register) remains unimplemented in dp8393x (i.e. they are still accepted). This packet length issue may have implications for guests that depend on the chip honouring the packet length threshold set in the EOBC register. --- hw/net/dp8393x.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 5e4494a945..24f2e19f07 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -139,6 +139,7 @@ do { printf("sonic ERROR: %s: " fmt, __func__ , ## __VA_ARGS__); } while (0) #define SONIC_TCR_CRCI 0x2000 #define SONIC_TCR_PINT 0x8000 +#define SONIC_ISR_RBAE 0x0010 #define SONIC_ISR_RBE 0x0020 #define SONIC_ISR_RDE 0x0040 #define SONIC_ISR_TC 0x0080 @@ -751,6 +752,14 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, uint32_t checksum; int size; + if (pkt_size + 4 > 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); + dp8393x_do_read_rra(s); + return pkt_size; + } + width = (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; s->regs[SONIC_RCR] &= ~(SONIC_RCR_PRX | SONIC_RCR_LBK | SONIC_RCR_FAER | From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209593 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVTP0mfTz9sPW for ; Sat, 14 Dec 2019 12:35:03 +1100 (AEDT) Received: from localhost ([::1]:55022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwKj-0002pI-3X for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:35:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41595) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEe-00041w-Bp for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEc-00019J-On for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:44 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47410) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEc-00016t-8z; Fri, 13 Dec 2019 20:28:42 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 70CAB27DAC; Fri, 13 Dec 2019 20:28:41 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH 09/10] dp8393x: Don't stop reception upon RBE interrupt assertion Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Section 5.4.7 of the datasheet explains that the RBE interrupt is an "early warning". It indicates that the last RBA is still available to receive a packet. It doesn't imply actual receive buffer exhaustion. This is an important distinction because Linux will not check and clear the RBE interrupt until it receives another packet. But that won't happen if can_receive returns false. So the SONIC becomes deaf (until reset). Fix this with a new flag to indicate actual receive buffer exhaustion. Signed-off-by: Finn Thain --- hw/net/dp8393x.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 24f2e19f07..8e66b1f5de 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -157,6 +157,7 @@ typedef struct dp8393xState { /* Hardware */ uint8_t it_shift; bool big_endian; + bool last_rba_is_full; qemu_irq irq; #ifdef DEBUG_SONIC int irq_level; @@ -311,6 +312,12 @@ static void dp8393x_do_read_rra(dp8393xState *s) { int width, size; + /* Already on the last RBA? */ + s->last_rba_is_full = s->regs[SONIC_ISR] & SONIC_ISR_RBE; + if (s->last_rba_is_full) { + return; + } + /* Read memory */ width = (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; size = sizeof(uint16_t) * 4 * width; @@ -334,7 +341,7 @@ static void dp8393x_do_read_rra(dp8393xState *s) s->regs[SONIC_RRP] = s->regs[SONIC_RSA]; } - /* Check resource exhaustion */ + /* Warn the host if this entry is the last one */ if (s->regs[SONIC_RRP] == s->regs[SONIC_RWP]) { s->regs[SONIC_ISR] |= SONIC_ISR_RBE; @@ -703,8 +710,9 @@ static int dp8393x_can_receive(NetClientState *nc) if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN)) return 0; - if (s->regs[SONIC_ISR] & SONIC_ISR_RBE) + if (s->last_rba_is_full) { return 0; + } return 1; } From patchwork Sat Dec 14 01:25:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1209591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZVQX0cycz9sPW for ; Sat, 14 Dec 2019 12:32:36 +1100 (AEDT) Received: from localhost ([::1]:54980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwIL-0007hy-Dw for incoming@patchwork.ozlabs.org; Fri, 13 Dec 2019 20:32:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41552) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwEe-00041u-70 for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifwEc-00019e-OZ for qemu-devel@nongnu.org; Fri, 13 Dec 2019 20:28:43 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47424) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ifwEc-00017q-FB; Fri, 13 Dec 2019 20:28:42 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 7702B27CBF; Fri, 13 Dec 2019 20:28:41 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <25b17f31c0bf60f6f1a2915709e9ee2d57f7f230.1576286757.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH 10/10] dp8393x: Don't clobber packet checksum Date: Sat, 14 Dec 2019 12:25:57 +1100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 98.124.60.144 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Herve Poussineau , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" A received packet consumes pkt_size bytes in the buffer and the frame checksum that's appended to it consumes another 4 bytes. The Receive Buffer Address register takes the former quantity into account but not the latter. So the next packet written to the buffer overwrites the frame checksum. Fix this. Signed-off-by: Finn Thain Reviewed-by: Philippe Mathieu-Daudé --- hw/net/dp8393x.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 8e66b1f5de..9f4162c98c 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -810,6 +810,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, address += rx_len; address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED, (uint8_t *)&checksum, 4, 1); + address += 4; rx_len += 4; s->regs[SONIC_CRBA1] = address >> 16; s->regs[SONIC_CRBA0] = address & 0xffff;