From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287409; cv=none; d=zohomail.com; s=zohoarc; b=UcuSvFbx4Z0Wiy2wh4EcZUHhLVWmqdf/HOm26hn2aB6IKJjcU35om6hpzBJ8CC5k36vGjPPVWr4Vwp4FI9Xh4eGQeyGxzvJABeTaZJp01QxWNRvFs9hZpNwIctXEgqPC2YyZ4BKwXZ5OSxQbeBKzTkvvbjOSKyWiORpCXW5jleY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287409; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Rwp/GSp/LeR0ge8T1uoebp4Emo8jbuS5xBxsFQEG17s=; b=ZpqHgUEM4t0Pd9LxK+sYHSVY8euO+/eyV991fKDV0kTwNAffNXP0e2z6LHLz42pR6VI+Jvio8dlJ5OLnQPjt0sjUtLBfnLRbKzUr6ONT2Gx+GiAj/Z5NiOvv/PqOikVcq0RJRqdFUwZOt8iygN+anp7EYGDaFvntOkqo//cZ+8I= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576287409768117.08894007105164; Fri, 13 Dec 2019 17:36:49 -0800 (PST) Received: from localhost ([::1]:55070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwMS-0005A2-AC for importer@patchew.org; Fri, 13 Dec 2019 20:36:48 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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) =20 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); } =20 static uint32_t dp8393x_rbwc(dp8393xState *s) @@ -217,7 +217,7 @@ static uint32_t dp8393x_tsa(dp8393xState *s) =20 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); } =20 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] =3D dp8393x_get(s, width, 0) & ~0x1; - if (dp8393x_get(s, width, 0) & 0x1) { + s->regs[SONIC_CTDA] =3D dp8393x_get(s, width, 0); + if (s->regs[SONIC_CTDA] & 0x1) { /* EOL detected */ break; } --=20 2.23.0 From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287048; cv=none; d=zohomail.com; s=zohoarc; b=iHfDXb8KXP1R5+8Weeoqmk728vyc3RINn30SrfFAbO3Lt6a/qWhENstq6qv8o2dtf/xEbrV2xozXgI0VIe3xn5iZFMZOshr+fE9ilMf8trL0P7TGB2PDERyQjoikrDP8XXGGi1RZiBIfyXqZPivawGNLQNJazKITlmVmp0O4vTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287048; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=EZvppGDmYqKpIIQxK16bSiZTTpjgdjRUDeBhcYZoTQ0=; b=feHIOergURfDmHmoXMXbvyn9C15SAGvhXLFPxqu8HByuuh8q8y8wdd1hTx3RuZS4R2FmV+CU8EI3catBUiwJaUWHSRevVFpk5Lgwy0It9BIrPq55UI/W5SG9wPX3jZnMEa1OXtj9cTQn1iYL8hgE9Zwv4hEyohNHYFXFUtawHIo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576287048482990.0192281938339; Fri, 13 Dec 2019 17:30:48 -0800 (PST) Received: from localhost ([::1]:54948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwGc-0005go-Ge for importer@patchew.org; Fri, 13 Dec 2019 20:30:46 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, cons= t uint8_t * buf, return -1; } =20 - /* 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, co= nst uint8_t * buf, /* EOL detected */ s->regs[SONIC_ISR] |=3D SONIC_ISR_RDE; } else { - /* Clear in_use, but it is always 16bit wide */ + /* Clear in_use */ int offset =3D dp8393x_crda(s) + sizeof(uint16_t) * 6 * width; - if (s->big_endian && width =3D=3D 2) { - /* we need to adjust the offset of the 16bit field */ - offset +=3D sizeof(uint16_t); - } - s->data[0] =3D 0; + size =3D 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] =3D s->regs[SONIC_LLFA]; s->regs[SONIC_ISR] |=3D SONIC_ISR_PKTRX; s->regs[SONIC_RSC] =3D (s->regs[SONIC_RSC] & 0xff00) | (((s->regs[= SONIC_RSC] & 0x00ff) + 1) & 0x00ff); --=20 2.23.0 From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287239; cv=none; d=zohomail.com; s=zohoarc; b=msnyQfcGns4K1X9TOxucHp/HYM/O9tFMCTNAYbC1yo27pBSTx8yO/4g3d85sKP8xI+QS2K2EkMC4sVMaZIHSK9Z1/xukN74p9PN+T5N3f4OzY93o+89S9dACUZ0KedaHG4mnIkCDiVf3ATD+gLzt5XKDWjTa5/JP0s3aEDIEbOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287239; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=kaQ4pb+KdgYb81Qshhmkw66dtxdK7G7qN80ths0CbH4=; b=UwdaFzRYKN/4XxPyvJLzz6y3EBqHqgMmrn4YC9xm1WIRwIzfudiAKtC2DBHDpDGs321ldpcKCKMXdyte8+ekVbME8T2/o0I2ihtWvoh2DxpSaQ0UfiqPsfMBLpSe6GL00Ro3K2OiH+b57N7+n5hXc8hZt74TOen5XjfCSTp8QK0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576287239564875.7623344807071; Fri, 13 Dec 2019 17:33:59 -0800 (PST) Received: from localhost ([::1]:55008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwJh-0000uR-Tl for importer@patchew.org; Fri, 13 Dec 2019 20:33:57 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=C3=A9 --- 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, co= nst uint8_t * buf, } =20 static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, - size_t size) + size_t pkt_size) { dp8393xState *s =3D qemu_get_nic_opaque(nc); int packet_type; uint32_t available, address; - int width, rx_len =3D size; + int width, rx_len =3D pkt_size; uint32_t checksum; + int size; =20 width =3D (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; =20 s->regs[SONIC_RCR] &=3D ~(SONIC_RCR_PRX | SONIC_RCR_LBK | SONIC_RCR_FA= ER | SONIC_RCR_CRCR | SONIC_RCR_LPKT | SONIC_RCR_BC | SONIC_RCR_MC); =20 - packet_type =3D dp8393x_receive_filter(s, buf, size); + packet_type =3D 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, cons= t uint8_t * buf, /* Done */ dp8393x_update_irq(s); =20 - return size; + return pkt_size; } =20 static void dp8393x_reset(DeviceState *dev) --=20 2.23.0 From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287048; cv=none; d=zohomail.com; s=zohoarc; b=n5eEoDKUe9F6Bud+ihlPA96dT6CuP5KRZlBxJin9u1/cbNXDnpZsGET1SEK7UGRkNSYXJol+JEtoMuPfaGMAhuoCZ6tUFpqBTWXObHAmnIlQwc95TUNaNL7/7oVIRrnaULn8d0CwnlV/88h4XlUJG2wsNEqOzZw/+A4u3d6ZxVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287048; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=dJiIEIcJEaIqAx5LSprA1W2wayjlH8HOWdOaEjyJZAk=; b=gMvcBD9k0O/w5RwCpOpT39wK6hPzKK1tWNWymgCrTSb+QObZez7wnbVinTDeAjWr5CByOICXOwxODrTW+Xo6lR1N6zpWc2/lSzPsy+xaZuJW5uXJmYdo16BI7bwrhubwdg3H/KcckDwlXVAWU4edD2Wb+r51nlnUnb+eDMZjago= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157628704807829.981865957165155; Fri, 13 Dec 2019 17:30:48 -0800 (PST) Received: from localhost ([::1]:54946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwGc-0005gU-0c for importer@patchew.org; Fri, 13 Dec 2019 20:30:46 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, cons= t uint8_t * buf, if (dp8393x_get(s, width, 0) & 0x1) { /* Still EOL ; stop reception */ return -1; - } else { - s->regs[SONIC_CRDA] =3D s->regs[SONIC_LLFA]; } } =20 @@ -821,7 +819,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, cons= t uint8_t * buf, address_space_rw(&s->as, dp8393x_crda(s), MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 1); =20 - /* Move to next descriptor */ + /* Check link field */ size =3D sizeof(uint16_t) * width; address_space_rw(&s->as, dp8393x_crda(s) + sizeof(uint16_t) * 5 * widt= h, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 0); @@ -836,6 +834,8 @@ static ssize_t dp8393x_receive(NetClientState *nc, cons= t 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] =3D s->regs[SONIC_LLFA]; s->regs[SONIC_ISR] |=3D SONIC_ISR_PKTRX; s->regs[SONIC_RSC] =3D (s->regs[SONIC_RSC] & 0xff00) | (((s->regs[= SONIC_RSC] & 0x00ff) + 1) & 0x00ff); --=20 2.23.0 From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287047; cv=none; d=zohomail.com; s=zohoarc; b=ivG5DaoCBIWZl8N/Y0gvtMSs5SN8BtgoSLAXB9j+e9BdqZ1vGn2CvdANI8t6+FPSplm9at+bHxpFjkgRcmnbHvejbRnH/MJQP/Bykjxe0xcxMyUx9TdxkPxVFJ2tfdNjeuGtEfLFaoFD3HHxJL1nUUxIvEZuKdyyXqY4V1E4pp0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287047; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=YzCAq002iFA3smj3eIXKwvoAHct1ohJo7j5nQOrr6ug=; b=UHmPH7XrInvkkkkN6fLz0Xoy/vYl8j8oVJA4BTV0XuH5zn5md2wwH2n4mluHoN4Nl6wLZic043qQn+fvBSfwH6cqaSqTgbshpqS/Omsgm+E6knpq/mcuGsEnu3SNob4xfMv4u7A7srJRcidgk+CpBDR85683uEb6XXcFB0aagLU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576287047575193.65214950615587; Fri, 13 Dec 2019 17:30:47 -0800 (PST) Received: from localhost ([::1]:54944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwGa-0005fs-2U for importer@patchew.org; Fri, 13 Dec 2019 20:30:44 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, cons= t uint8_t * buf, address =3D 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] =3D dp8393x_get(s, width, 0); + if (s->regs[SONIC_LLFA] & 0x1) { /* Still EOL ; stop reception */ return -1; } --=20 2.23.0 From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287232; cv=none; d=zohomail.com; s=zohoarc; b=g44RsLyUe5yjz83W8M4JqM9ZwMeFHcms+n9iAuDhPPzRuchRvsXoOP24QFcbvt7WbWtSD2HXPt9dqcTYtwkB5l/nyAErSJKYc09yZ6oHp1Lc1wHkISDp5oykEeFSsfOsrKwf7lxa3jpVw6QWCixgUwBYRA8vapKszueG/DvIhtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287232; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=lNZC7uRFU10K3LU0dfuTjSvRIXBb+B/C/zkDjV0TkGg=; b=kufqtDV/DndGgNZxdvM8o35KJH/EhFvpJndey9uaoml/wWjeoV7aF93SapljU54dzy7BK7xc29ZnR6i50xT63aTCMwrzCiJ9UM00DIx5XERzZIM72mSVjug3hzZ5M5bMvQC15DD4i3hpMdXOmtJIDwIT8+upbho9w/GJeky6HPA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576287232564911.380747313348; Fri, 13 Dec 2019 17:33:52 -0800 (PST) Received: from localhost ([::1]:55006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwJb-0000nh-7k for importer@patchew.org; Fri, 13 Dec 2019 20:33:51 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=C3=A9 --- 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] |=3D SONIC_ISR_RBE; dp8393x_update_irq(s); } - - /* Done */ - s->regs[SONIC_CR] &=3D ~SONIC_CR_RRRA; } =20 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] &=3D ~SONIC_CR_RRRA; + } if (command & SONIC_CR_LCAM) dp8393x_do_load_cam(s); } --=20 2.23.0 From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287335; cv=none; d=zohomail.com; s=zohoarc; b=gms4uB5wxcPCfrbxxgrgqOaT7gDTlz/Y7AqQH4hf956prYUkLDcFQFBbeOgsXSBU+ELdCM1Ts8WLvPDdNA1Sqh9yzlDkQvszBmhctetlKkL6IpOiwr7sDc51PdPjUy3HX+SJ6MGHkFSFGNrOPOneZXTQxOpGiB62OmFujPgkwzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287335; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Pv6iTB/+luvtgLhdJ7SnEucsGRTg7i2AKKbZUFpKWXc=; b=mWKqSVI2eFrBtH93EZyvdQgnKdl7Me80GSwlUaNxqw/dpU4QTwywb80SS0iKaW8llaJy2VP3m1CaaIG0wMFriWiZUiIM+FsQTaxRl67BJ2io+zTgmsW+AnNaiRSA5VOcQGBA3FYAbz85NLQ42ZYGY2DYlEVulhCfAsdmtC2WQJw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576287335534214.42508400473014; Fri, 13 Dec 2019 17:35:35 -0800 (PST) Received: from localhost ([::1]:55050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwLG-0003o5-D4 for importer@patchew.org; Fri, 13 Dec 2019 20:35:34 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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[] =3D { "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_A= RGS__); } 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, cons= t uint8_t * buf, /* Save current position */ s->regs[SONIC_TRBA1] =3D s->regs[SONIC_CRBA1]; s->regs[SONIC_TRBA0] =3D s->regs[SONIC_CRBA0]; + s->regs[SONIC_TBWC1] =3D s->regs[SONIC_RBWC1]; + s->regs[SONIC_TBWC0] =3D s->regs[SONIC_RBWC0]; =20 /* Calculate the ethernet checksum */ checksum =3D cpu_to_le32(crc32(0, buf, rx_len)); @@ -827,6 +831,12 @@ static ssize_t dp8393x_receive(NetClientState *nc, con= st uint8_t * buf, if (s->regs[SONIC_LLFA] & 0x1) { /* EOL detected */ s->regs[SONIC_ISR] |=3D SONIC_ISR_RDE; + + /* Restore buffer state */ + s->regs[SONIC_CRBA1] =3D s->regs[SONIC_TRBA1]; + s->regs[SONIC_CRBA0] =3D s->regs[SONIC_TRBA0]; + s->regs[SONIC_RBWC1] =3D s->regs[SONIC_TBWC1]; + s->regs[SONIC_RBWC0] =3D s->regs[SONIC_TBWC0]; } else { /* Clear in_use */ int offset =3D dp8393x_crda(s) + sizeof(uint16_t) * 6 * width; --=20 2.23.0 From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287462; cv=none; d=zohomail.com; s=zohoarc; b=Ojqx5bkUrpu6Sd6iE6KQMd5KSvSXiCU94+eIlS6yGv+/C5pwI7y3r9J48mULisK/hNtW51dwdVp2A1d4Nx3UOSSxvS02Gf+iP5X7IVHYY9rHqF7qVq4y0Yh+6XPhd8QkEUamwbjRapON+v1qRLZQtOvzJbJ+JtFPybokyn2qU/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287462; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=X3t2NDHlYWlymMFzdAkKYynp2N2tcdr+MuypdHc928w=; b=IBQcBUkGrUimVzmBhV47B9u9GA3HkpOos5DACDzW2IciTZgy+DWNCj3xQWRiNrO8P2PpC9qqO9PrvultMkpRdY6PPXSXKXYaFNgZiNsb4nKycVXT5aCp1+/Pc1yLyNi9WuNHBmEt/WhU5Rj8dnhvWDfFS4S5Llo55DWjUvpeBds= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576287462926856.2061071633171; Fri, 13 Dec 2019 17:37:42 -0800 (PST) Received: from localhost ([::1]:55078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwNJ-0005zl-S3 for importer@patchew.org; Fri, 13 Dec 2019 20:37:41 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =20 +#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, con= st uint8_t * buf, uint32_t checksum; int size; =20 + if (pkt_size + 4 > dp8393x_rbwc(s) * 2) { + DPRINTF("oversize packet, pkt_size is %d\n", pkt_size); + s->regs[SONIC_ISR] |=3D SONIC_ISR_RBAE; + dp8393x_update_irq(s); + dp8393x_do_read_rra(s); + return pkt_size; + } + width =3D (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; =20 s->regs[SONIC_RCR] &=3D ~(SONIC_RCR_PRX | SONIC_RCR_LBK | SONIC_RCR_FA= ER | --=20 2.23.0 From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287337; cv=none; d=zohomail.com; s=zohoarc; b=fiyj2Cx/FiDsElsLo8eyXssxJbvBoFZi5v1tAZH8vIs3BjIQLmdQ6UMAvTPXizPNWjUCjQOH5wR4Olqd2d3L+wG1b7n6IuD4W4/UHrjzm9BzUn1uFczL2KAkXfJIMfnIinnsrej/8UQ8SMMDi/CaPfRFqPcanzo3Ipikuv34a4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287337; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ES4c7FhoIYn/I9kQ0IF/gtwaMfF+/h6q4OvAQ+Z+QA8=; b=DFTul7fRh1R9jRPzGbAxEiMBwxL5LreL5rnek7oo8S59rilv2gmcPpILOIKr8zUjz0OBzAmJTn+KYMxn/P3HoNoqehiYk+o6LP/VkoXRA+IfFOTQdcP5gg1LLqyfwzaT2qtiuOHOgsgsc4+GtklUatWVO81820IkFAUGJl8vMZ8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576287337318402.90697926042526; Fri, 13 Dec 2019 17:35:37 -0800 (PST) Received: from localhost ([::1]:55054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwLI-0003ow-8h for importer@patchew.org; Fri, 13 Dec 2019 20:35:36 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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; =20 + /* Already on the last RBA? */ + s->last_rba_is_full =3D s->regs[SONIC_ISR] & SONIC_ISR_RBE; + if (s->last_rba_is_full) { + return; + } + /* Read memory */ width =3D (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; size =3D sizeof(uint16_t) * 4 * width; @@ -334,7 +341,7 @@ static void dp8393x_do_read_rra(dp8393xState *s) s->regs[SONIC_RRP] =3D s->regs[SONIC_RSA]; } =20 - /* Check resource exhaustion */ + /* Warn the host if this entry is the last one */ if (s->regs[SONIC_RRP] =3D=3D s->regs[SONIC_RWP]) { s->regs[SONIC_ISR] |=3D SONIC_ISR_RBE; @@ -703,8 +710,9 @@ static int dp8393x_can_receive(NetClientState *nc) =20 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; } =20 --=20 2.23.0 From nobody Mon Apr 29 15:10:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576287240; cv=none; d=zohomail.com; s=zohoarc; b=k7qFkjpFi+9qvUJ8SUr45q0hxw0Q0ixZ+JMtSesRD+a0GBgPJUznL4/phVCmF0lsa+IdgBf1Fj5y8s4X4t8bgVXvIXpr/ZnrQijJnzVF2OBbGmrqYDuWHre/GYoXe8FZd1isDLnfXsCTJEwZgAqSubFiXJVitP1x8mmUaJKOPfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576287240; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Ft95PPGcKM3Nl2VamYFkA2hl35BMqxYeyk2gYW3x/7M=; b=E21IEP1BdzytHJGIKVa9n42VvT6HZSrowPBk13ny0Lj7XLkGRsUzGh7zAo2G6GJx7mW7Ywp00FC7x8nEvc91K1CG1e08mEbcYFX9a1Jg6YTxka2nMqnPqNIYUY+FPAAkbb8QPoZA8bDbxZEv2STqCjDtYpdDbuvdoQsKQp1qwXo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576287240084634.1844997828808; Fri, 13 Dec 2019 17:34:00 -0800 (PST) Received: from localhost ([::1]:55010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifwJi-0000vp-Ej for importer@patchew.org; Fri, 13 Dec 2019 20:33:58 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=C3=A9 --- 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, cons= t uint8_t * buf, address +=3D rx_len; address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED, (uint8_t *)&checksum, 4, 1); + address +=3D 4; rx_len +=3D 4; s->regs[SONIC_CRBA1] =3D address >> 16; s->regs[SONIC_CRBA0] =3D address & 0xffff; --=20 2.23.0