From nobody Sun May 5 07:24:46 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=1579475956; cv=none; d=zohomail.com; s=zohoarc; b=WnOeRdxZWAAwQOsgV6Y6m4pUgvbJOS3/aV6CMgz0OH2HJ2X7eaqcqn590zn2hNbcV7gu7/nRwguNc1q0/gmnhGBC/WZjQsYKb0hNAMuKndFpyC/roPPcWPwF3fgr2F1RG915tQ/jh7XIUZdLIqFp8LjXP2Q7wuWs43Q9CX/62Lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475956; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fO42TolE7tjssEllM8TS9mJnqKeTsf4fQN4JChq4sp4=; b=KCly1Xa7U3bO/UoVBYBbC1IBAXxv3c3NGiY4sN5Fj3k8RBjU4Y0kVxxlkUd6TMVdTGWO2OKC4+ztDqJhEgrdhXwfwhOIeB3I00af6HIEIunWdyblvfFHZKCw3U4Lqx2FcJjxVUqJdZD141iGapc2LuZBBCH4mBN4fWMqVXArHaI= 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 15794759563963.6639947691575117; Sun, 19 Jan 2020 15:19:16 -0800 (PST) Received: from localhost ([::1]:55008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJqc-0002Rb-NY for importer@patchew.org; Sun, 19 Jan 2020 18:19:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55971) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfj-0004AN-I0 for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfh-0003mR-Dx for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfh-0003jv-85; Sun, 19 Jan 2020 18:07:57 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id DAE6728DF0; Sun, 19 Jan 2020 18:07:54 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 01/14] dp8393x: Mask EOL bit from descriptor addresses MIME-Version: 1.0 Date: Mon, 20 Jan 2020 09:59:21 +1100 Content-Transfer-Encoding: quoted-printable 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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The Least Significant bit of a descriptor address register is used as an EOL flag. It has to be masked when the register value is to be used as an actual address for copying memory around. But when the registers are to be updated the EOL bit should not be masked. Signed-off-by: Finn Thain Tested-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Changed since v1: - Added macros to name constants as requested by Philippe Mathieu-Daud=C3= =A9. --- hw/net/dp8393x.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index cdc2631c0c..14901c1445 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -145,6 +145,9 @@ do { printf("sonic ERROR: %s: " fmt, __func__ , ## __VA= _ARGS__); } while (0) #define SONIC_ISR_PINT 0x0800 #define SONIC_ISR_LCD 0x1000 =20 +#define SONIC_DESC_EOL 0x0001 +#define SONIC_DESC_ADDR 0xFFFE + #define TYPE_DP8393X "dp8393x" #define DP8393X(obj) OBJECT_CHECK(dp8393xState, (obj), TYPE_DP8393X) =20 @@ -197,7 +200,8 @@ 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] & SONIC_DESC_ADDR); } =20 static uint32_t dp8393x_rbwc(dp8393xState *s) @@ -217,7 +221,8 @@ 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] & SONIC_DESC_ADDR); } =20 static uint32_t dp8393x_wt(dp8393xState *s) @@ -506,8 +511,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] & SONIC_DESC_EOL) { /* EOL detected */ break; } @@ -763,13 +768,13 @@ static ssize_t dp8393x_receive(NetClientState *nc, co= nst uint8_t * buf, /* XXX: Check byte ordering */ =20 /* Check for EOL */ - if (s->regs[SONIC_LLFA] & 0x1) { + if (s->regs[SONIC_LLFA] & SONIC_DESC_EOL) { /* Are we still in resource exhaustion? */ size =3D sizeof(uint16_t) * 1 * width; 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) { + if (dp8393x_get(s, width, 0) & SONIC_DESC_EOL) { /* Still EOL ; stop reception */ return -1; } else { @@ -827,7 +832,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, cons= t uint8_t * buf, address_space_rw(&s->as, dp8393x_crda(s) + sizeof(uint16_t) * 5 * widt= h, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 0); s->regs[SONIC_LLFA] =3D dp8393x_get(s, width, 0); - if (s->regs[SONIC_LLFA] & 0x1) { + if (s->regs[SONIC_LLFA] & SONIC_DESC_EOL) { /* EOL detected */ s->regs[SONIC_ISR] |=3D SONIC_ISR_RDE; } else { --=20 2.24.1 From nobody Sun May 5 07:24:46 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=1579475384; cv=none; d=zohomail.com; s=zohoarc; b=RLiTmlIGe5ZAhLvHKcZqRdSZ4wBgQN0zKvxJ0Y1eLFHTU1Lxz7IBeT2Gvu68crsMkV3EzF5dmq96UGRZpMjhR5uqpsXEc51h0fnmxWXcVrWn5/UTNeF4xOpwlgVnv336KwQgH62b414BboiCFyua5t41+e5Z3TnipryThhFT+Xg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475384; 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=L3lLv/Fz4oa0R2T/yn02b0eYwD4a3Zp3090aB9l5GyE=; b=dERSky/vO8VkyThF3HuqjzE+305OJvHy+f5vLUUydOlQXu7jpoaMyxC7ewf9UrTKHl8cer0ZPFBAhavoDVpQjGzeC4ajnUDFOoxMl2b0r2gkOW45r1IcZHq1H7erGqHpJRGKABEBogOZWbBLGZ23Pca0BmpHwUjfiO9p6a5Hvj4= 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 1579475384971731.9809290901187; Sun, 19 Jan 2020 15:09:44 -0800 (PST) Received: from localhost ([::1]:54806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJhO-0005u8-OS for importer@patchew.org; Sun, 19 Jan 2020 18:09:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55891) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfi-00049W-6g for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfg-0003kx-Ng for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:58 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54650) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfg-0003k5-Ij; Sun, 19 Jan 2020 18:07:56 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id EF3702991A; Sun, 19 Jan 2020 18:07:54 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <484f90e6295afd927c38c25d5d216233551846d2.1579474761.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 02/14] dp8393x: Always use 32-bit accesses Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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 DP83932 and DP83934 have 32 data lines. The datasheet says, Data Bus: These bidirectional lines are used to transfer data on the system bus. When the SONIC is a bus master, 16-bit data is transferred on D15-D0 and 32-bit data is transferred on D31-D0. When the SONIC is accessed as a slave, register data is driven onto lines D15-D0. D31-D16 are held TRI-STATE if SONIC is in 16-bit mode. If SONIC is in 32-bit mode, they are driven, but invalid. Always use 32-bit accesses both as bus master and bus slave. Force the MSW to zero in bus master mode. This gets the Linux 'jazzsonic' driver working, and avoids the need for prior hacks to make the NetBSD 'sn' driver work. Signed-off-by: Finn Thain Tested-by: Laurent Vivier --- hw/net/dp8393x.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 14901c1445..b2fd44bc2f 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -246,9 +246,19 @@ static void dp8393x_put(dp8393xState *s, int width, in= t offset, uint16_t val) { if (s->big_endian) { - s->data[offset * width + width - 1] =3D cpu_to_be16(val); + if (width =3D=3D 2) { + s->data[offset * 2] =3D 0; + s->data[offset * 2 + 1] =3D cpu_to_be16(val); + } else { + s->data[offset] =3D cpu_to_be16(val); + } } else { - s->data[offset * width] =3D cpu_to_le16(val); + if (width =3D=3D 2) { + s->data[offset * 2] =3D cpu_to_le16(val); + s->data[offset * 2 + 1] =3D 0; + } else { + s->data[offset] =3D cpu_to_le16(val); + } } } =20 @@ -588,7 +598,7 @@ static uint64_t dp8393x_read(void *opaque, hwaddr addr,= unsigned int size) =20 DPRINTF("read 0x%04x from reg %s\n", val, reg_names[reg]); =20 - return val; + return s->big_endian ? val << 16 : val; } =20 static void dp8393x_write(void *opaque, hwaddr addr, uint64_t data, @@ -596,13 +606,14 @@ static void dp8393x_write(void *opaque, hwaddr addr, = uint64_t data, { dp8393xState *s =3D opaque; int reg =3D addr >> s->it_shift; + uint32_t val =3D s->big_endian ? data >> 16 : data; =20 - DPRINTF("write 0x%04x to reg %s\n", (uint16_t)data, reg_names[reg]); + DPRINTF("write 0x%04x to reg %s\n", (uint16_t)val, reg_names[reg]); =20 switch (reg) { /* Command register */ case SONIC_CR: - dp8393x_do_command(s, data); + dp8393x_do_command(s, val); break; /* Prevent write to read-only registers */ case SONIC_CAP2: @@ -615,36 +626,36 @@ static void dp8393x_write(void *opaque, hwaddr addr, = uint64_t data, /* Accept write to some registers only when in reset mode */ case SONIC_DCR: if (s->regs[SONIC_CR] & SONIC_CR_RST) { - s->regs[reg] =3D data & 0xbfff; + s->regs[reg] =3D val & 0xbfff; } else { DPRINTF("writing to DCR invalid\n"); } break; case SONIC_DCR2: if (s->regs[SONIC_CR] & SONIC_CR_RST) { - s->regs[reg] =3D data & 0xf017; + s->regs[reg] =3D val & 0xf017; } else { DPRINTF("writing to DCR2 invalid\n"); } break; /* 12 lower bytes are Read Only */ case SONIC_TCR: - s->regs[reg] =3D data & 0xf000; + s->regs[reg] =3D val & 0xf000; break; /* 9 lower bytes are Read Only */ case SONIC_RCR: - s->regs[reg] =3D data & 0xffe0; + s->regs[reg] =3D val & 0xffe0; break; /* Ignore most significant bit */ case SONIC_IMR: - s->regs[reg] =3D data & 0x7fff; + s->regs[reg] =3D val & 0x7fff; dp8393x_update_irq(s); break; /* Clear bits by writing 1 to them */ case SONIC_ISR: - data &=3D s->regs[reg]; - s->regs[reg] &=3D ~data; - if (data & SONIC_ISR_RBE) { + val &=3D s->regs[reg]; + s->regs[reg] &=3D ~val; + if (val & SONIC_ISR_RBE) { dp8393x_do_read_rra(s); } dp8393x_update_irq(s); @@ -657,17 +668,17 @@ static void dp8393x_write(void *opaque, hwaddr addr, = uint64_t data, case SONIC_REA: case SONIC_RRP: case SONIC_RWP: - s->regs[reg] =3D data & 0xfffe; + s->regs[reg] =3D val & 0xfffe; break; /* Invert written value for some registers */ case SONIC_CRCT: case SONIC_FAET: case SONIC_MPT: - s->regs[reg] =3D data ^ 0xffff; + s->regs[reg] =3D val ^ 0xffff; break; /* All other registers have no special contrainst */ default: - s->regs[reg] =3D data; + s->regs[reg] =3D val; } =20 if (reg =3D=3D SONIC_WT0 || reg =3D=3D SONIC_WT1) { @@ -678,8 +689,8 @@ static void dp8393x_write(void *opaque, hwaddr addr, ui= nt64_t data, static const MemoryRegionOps dp8393x_ops =3D { .read =3D dp8393x_read, .write =3D dp8393x_write, - .impl.min_access_size =3D 2, - .impl.max_access_size =3D 2, + .impl.min_access_size =3D 4, + .impl.max_access_size =3D 4, .endianness =3D DEVICE_NATIVE_ENDIAN, }; =20 --=20 2.24.1 From nobody Sun May 5 07:24:46 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=1579475862; cv=none; d=zohomail.com; s=zohoarc; b=BOf+PCopU4R3rwMQvgZlUglZMzYexSl7NuoqwMIBl0pHoCCfNw+9jzHqhtuGB6gas4ViFn1ks31lJCdoZVBKEhmVDd9uG6gROUOnT9upXcx5CfzlVWccZsxU1P2T7/ECa2jrGxnyvfdYsu2P0TQ4VRuXqbfCBq8kqCgTUVxXcnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475862; 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=XPxJe7hnCS4GSOsC+vJKQVHb76bISRzec7YQGqW2BH4=; b=PTWq89D403ZZDSJkJHsSA6RjC7zdmPhbA3cXXLJg+G6OIUInQtaZdj6UWfZEKRaMqn4+4ukmSL8Rw1yS5U3iYb2ou9yW1kjChz/evSQrlI3VTgUmBLrNmL6n6VlDd21ltYtUMwqaQ8dtG7iRFUqLVOCfCPrppxOBi8XzEMB5fXw= 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 1579475862893726.3008978748222; Sun, 19 Jan 2020 15:17:42 -0800 (PST) Received: from localhost ([::1]:54976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJp7-0000NW-Ls for importer@patchew.org; Sun, 19 Jan 2020 18:17:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55977) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfj-0004AU-KB for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfh-0003mX-E0 for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfh-0003k6-7O; Sun, 19 Jan 2020 18:07:57 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 0A10B2991B; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <9c3243048ebb89a2af674847c0570d0c84cc3e79.1579474761.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 03/14] dp8393x: Clean up endianness hacks Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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" According to the datasheet, section 3.4.4, "in 32-bit mode ... the SONIC always writes long words". Therefore, use the same technique for the 'in_use' field that is used everywhere else, and write the full long word. Signed-off-by: Finn Thain Tested-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Changed since v1: - Use existing 'address' variable rather than declare a new one. Laurent tells me that a similar 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"). I believe the underlying issue has been fixed by the preceding patch, as this no longer breaks NetBSD 5.1. --- hw/net/dp8393x.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index b2fd44bc2f..2d2ace2549 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -776,8 +776,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] & SONIC_DESC_EOL) { /* Are we still in resource exhaustion? */ @@ -847,15 +845,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 */ - 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; - address_space_rw(&s->as, offset, MEMTXATTRS_UNSPECIFIED, - (uint8_t *)s->data, sizeof(uint16_t), 1); + /* Clear in_use */ + size =3D sizeof(uint16_t) * width; + address =3D dp8393x_crda(s) + sizeof(uint16_t) * 6 * width; + dp8393x_put(s, width, 0, 0); + address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED, + (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.24.1 From nobody Sun May 5 07:24:46 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=1579475642; cv=none; d=zohomail.com; s=zohoarc; b=hAuizL73uc4efEXXOe1Iifygte1J43IZirZkYOVV8B7JLt2ajXX/duqKkScquxX2oSpHcyw0y8VRUUL791vyOeaQVYA1cUI3tMExSs8Bx/nwPzb6oEa5db5dOswulYipfLCmhI9saRqIYBfvZLi89BVwm7n5qhqv7ZO2cqe43PM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475642; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q8K42ifhADZ45uCEIZUINUQHTwSVprcz0SnoRqTG4oA=; b=Ha7rL7IhPPFdlZGfmDp8TQtG5dr7r6nZHl02E0/XHyKdglHX5wFibngsyPVuMnYK6RkpQHVnkoO5DHXJHE8DrCuVZXw4Z9cuF9xcoFsInruBIQteEEteYtRKQDQPIVdTVVeYhd0d++0BH6zO9wRtduD1MU7tAu01m1qda/7/zLs= 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 1579475642758594.0639208909307; Sun, 19 Jan 2020 15:14:02 -0800 (PST) Received: from localhost ([::1]:54890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJlZ-00049B-LO for importer@patchew.org; Sun, 19 Jan 2020 18:14:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55968) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfj-0004AH-Hr for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfh-0003mI-DD for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54662) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfh-0003k7-6q; Sun, 19 Jan 2020 18:07:57 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 18EF02991F; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 04/14] dp8393x: Have dp8393x_receive() return the packet size MIME-Version: 1.0 Date: Mon, 20 Jan 2020 09:59:21 +1100 Content-Transfer-Encoding: quoted-printable 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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 Tested-by: Laurent Vivier --- 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 2d2ace2549..ece72cbf42 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -757,20 +757,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; @@ -864,7 +865,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.24.1 From nobody Sun May 5 07:24:46 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=1579475387; cv=none; d=zohomail.com; s=zohoarc; b=KPU2uigz4Io5tE77T2TwCq9fpvhIXF01MamVN+E8EcxACWjceyuTWIReK3Wbkm+J8/vc+1KHkyoFi/32OESIIPkJqvcQjZjhevm8BE78kZnfZPv9alPn2G11ipIUUVV3BB2IlBbClXb7bX8zkO50/6019nhUMRlGe/rGGeqZmtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475387; 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=HxI4rA0AHwxEfTFWKrwioX1M/WCOOQD0eRwtnP1z+qo=; b=RcZaJ+aJf9iAn96He7FcgiluBa7olv/Nxz0viOSZsmg2kXqWfPAkqZ2A1TaS/ZTF4BcZAbJXH3A0DmLjSF0AuR+n4UCMUnC1Ol5FySAuEHVwCfHpvspV9HkeoVQ1TF1AK0vaLURzRLyMZFUR9F2mP0agkWIDUTyR73GIG2ocXgA= 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 1579475387185603.6767307204158; Sun, 19 Jan 2020 15:09:47 -0800 (PST) Received: from localhost ([::1]:54808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJhR-0005zP-HI for importer@patchew.org; Sun, 19 Jan 2020 18:09:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55889) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfi-00049T-6D for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfg-0003lK-Uu for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:58 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfg-0003l4-R7; Sun, 19 Jan 2020 18:07:56 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 278E42996D; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 05/14] dp8393x: Update LLFA and CRDA registers from rx descriptor Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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 section 3.4.7: At the next reception, the SONIC re-reads the last RXpkt.link field, and updates its CRDA register to point to the next descriptor. The chip is designed to allow the host to provide a new list of descriptors in this way. Signed-off-by: Finn Thain Tested-by: Laurent Vivier --- Changed since v1: - Update CRDA register from LLFA register after EOL is cleared. --- hw/net/dp8393x.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index ece72cbf42..249be403af 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -784,12 +784,13 @@ static ssize_t dp8393x_receive(NetClientState *nc, co= nst 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) & SONIC_DESC_EOL) { + s->regs[SONIC_LLFA] =3D dp8393x_get(s, width, 0); + if (s->regs[SONIC_LLFA] & SONIC_DESC_EOL) { /* Still EOL ; stop reception */ return -1; - } else { - s->regs[SONIC_CRDA] =3D s->regs[SONIC_LLFA]; } + /* Link has been updated by host */ + s->regs[SONIC_CRDA] =3D s->regs[SONIC_LLFA]; } =20 /* Save current position */ @@ -837,7 +838,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); @@ -852,6 +853,8 @@ static ssize_t dp8393x_receive(NetClientState *nc, cons= t uint8_t * buf, dp8393x_put(s, width, 0, 0); address_space_rw(&s->as, address, 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.24.1 From nobody Sun May 5 07:24:46 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=1579475641; cv=none; d=zohomail.com; s=zohoarc; b=kl0HVSlADwF+sT4Zl+Lqxy8cH7bVMlK5WQFhe9ZzOhqLqwmvKqg2F7xWzKofnly2QgQ4d0iSY20u6xyQUiToh1xMztLcI+T6uXZzymWWDJAoVkyIbLwZJI8GIy+yhoqpq5frOqiU+JGfGxybrzpuB2dwUySI59v02u7Utp4YXSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475641; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IALhyYGbPrqp6p0VmmthUVoqcHNIkV62h4kul31BlU0=; b=R1Bx50/JivftlUKQWy2UG76ausRQ4mmJc2oCzpCCrPYdO7VSJbrCuBmVd96+t1Xu9Q0FXwaHo4ODGMJbvH4pYGmdKxGVycMcJTFeq+EQEeNTA0DfB4Puv0j+FpQEXU8sEV14GyycKPdfqmBNZBgPivt17JCDif4HWiX2r3Ayl1Q= 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 1579475641475521.3408262466429; Sun, 19 Jan 2020 15:14:01 -0800 (PST) Received: from localhost ([::1]:54888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJlY-00047C-9j for importer@patchew.org; Sun, 19 Jan 2020 18:14:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55890) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfi-00049V-7v for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfg-0003lQ-Vg for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:58 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfg-0003lA-Rh; Sun, 19 Jan 2020 18:07:56 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 36E7D2996F; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <620ed4e86dd176b7382d9b115350a135d00687b5.1579474761.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 06/14] dp8393x: Clear RRRA command register bit only when appropriate MIME-Version: 1.0 Date: Mon, 20 Jan 2020 09:59:21 +1100 Content-Transfer-Encoding: quoted-printable 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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 Tested-by: Laurent Vivier --- 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 249be403af..2e976781e2 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -352,9 +352,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) @@ -563,8 +560,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.24.1 From nobody Sun May 5 07:24:46 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=1579475388; cv=none; d=zohomail.com; s=zohoarc; b=iHb8uJSRRKOH/nw/MvQLTTKZ0PDD3vVm88n4qgpXDneX61h5RLAo3C1kf94zDFJX7BqofG5bO9nNdgi2ULUZOcEn8Tjfbq+9lv8LkzaR+lxMwxx7P4bAWlVJtJpdV+OTtCN74mVaTh/euFi90RC55Y2W6OM4/7fU3DQPBs+hHfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475388; 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=tupVri3rQpvhX+f6f/dKGzAXmTJ48d2fmW1A9hYeZ94=; b=h6i828dWj6WePY7Of78llw3c/Dmt6azrqGeh6C8+Yj2i48/amXC4SqvyGAVYy2RZ0iZ1686AeLtVgkm8aXpl9yVjbE5EBFyCyqDAhNL27Cf8O+O41v3gwUBlqJJRll6hz3XglfOI5+q1Nl5BC/jQtUJq7/AtY00kFTgJ3TA8fM0= 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 1579475388169369.78747901019005; Sun, 19 Jan 2020 15:09:48 -0800 (PST) Received: from localhost ([::1]:54810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJhS-00063r-H9 for importer@patchew.org; Sun, 19 Jan 2020 18:09:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55897) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfi-00049h-H4 for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfh-0003la-42 for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:58 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfh-0003l4-0C; Sun, 19 Jan 2020 18:07:57 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 45CEB29970; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <8b743099e180360402c7362cca7f30c47abe49e1.1579474761.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 07/14] dp8393x: Implement packet size limit and RBAE interrupt Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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 Tested-by: Laurent Vivier --- Changed since v1: - Perform length check after Recieve Control Register initialization. --- hw/net/dp8393x.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 2e976781e2..0309365fda 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -137,6 +137,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 @@ -770,6 +771,14 @@ static ssize_t dp8393x_receive(NetClientState *nc, con= st uint8_t * buf, 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 + 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; + } + packet_type =3D dp8393x_receive_filter(s, buf, pkt_size); if (packet_type < 0) { DPRINTF("packet not for netcard\n"); --=20 2.24.1 From nobody Sun May 5 07:24:46 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=1579475717; cv=none; d=zohomail.com; s=zohoarc; b=ljSWqmGVUn4O8jCkSWXJLGiDQlpPYDwD2iwBpXM7IY62Mp6Hs4EAn8Db1UwkeqQnSUnhzRo8DFwP0B7FkZa7RivNEqkK4Qn6hjZWnA9Zi3NQth1vmaLdUC6kMeXwagxPH2VuclUW30kIzRs3R4flAcHDfLqa4qghLUvRRTZztBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475717; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fwkpAneObcBWxlaXe61lHS44RXhkJU6kDOHlyjqTiF4=; b=KbnX0u1fvnRuPwQV/4Tf+/vwhy5eEOHEwGhfvf/ZjF0zomHNhR9Lu+vgC5iehSAf6n8SDUsaaw5AyYgnUkNnKlfRVTY06eKhAchBEUAA3Boy/Gt0R0xYfLgpahc2PPTqnkQLzchtKYNXe2xqfPAqJlCd3eKBdPFkm1gEsoybU/s= 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 1579475717576849.7032954546394; Sun, 19 Jan 2020 15:15:17 -0800 (PST) Received: from localhost ([::1]:54918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJml-0006M8-N5 for importer@patchew.org; Sun, 19 Jan 2020 18:15:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55906) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfi-00049i-Le for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfh-0003ls-7f for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:58 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54736) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfh-0003lU-3K; Sun, 19 Jan 2020 18:07:57 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 507472997B; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 08/14] dp8393x: Don't clobber packet checksum MIME-Version: 1.0 Date: Mon, 20 Jan 2020 09:59:21 +1100 Content-Transfer-Encoding: quoted-printable 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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 Tested-by: Laurent Vivier --- hw/net/dp8393x.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 0309365fda..947ceef37c 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -816,6 +816,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.24.1 From nobody Sun May 5 07:24:46 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=1579475523; cv=none; d=zohomail.com; s=zohoarc; b=In1ep37CYZTxCzrBSvoAOww0zTSiOlT1RDf050j4D8reHl0e7XhcrsrXzuDxYxyhVxxMD2LPf1wRZOgknoj18QRQKuLjfYS5QvqNdXf0HSaYXAkzNSH1vbfRICbBKutDLUMt2WB4MRfoASdI7cSvxjAN91ERMiGwBZOXPo5wS1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475523; 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=NdpOeSwhZo77vxA6/D3U7ogdeUwOTjR4NEN8huYrTlk=; b=cB6OEQqYh96Ng4Iu964W5lnj9ylCmJ8OwASDeli7Zjh4RogMJBouIipxCp8bZb8nWXExaG+o2uZvnMX25k1bkYRO+298Mp/WHyfkVsj8HTXaz0vmobtZWx3W7uSmqN3IlET3HAGsbzl93AwYmV+ntl5boSn5EW/r7GPcjGHACF4= 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 1579475523113753.8961378578009; Sun, 19 Jan 2020 15:12:03 -0800 (PST) Received: from localhost ([::1]:54854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJjd-0001CH-Qi for importer@patchew.org; Sun, 19 Jan 2020 18:12:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55896) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfi-00049g-GC for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfh-0003lg-52 for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:58 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfh-0003lA-0s; Sun, 19 Jan 2020 18:07:57 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 5AF022997C; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 09/14] dp8393x: Use long-word-aligned RRA pointers in 32-bit mode Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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 3.4.1 of the datasheet says, The alignment of the RRA is confined to either word or long word boundaries, depending upon the data width mode. In 16-bit mode, the RRA must be aligned to a word boundary (A0 is always zero) and in 32-bit mode, the RRA is aligned to a long word boundary (A0 and A1 are always zero). This constraint has been implemented for 16-bit mode; implement it for 32-bit mode too. Signed-off-by: Finn Thain Tested-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/dp8393x.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 947ceef37c..b052e2c854 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -663,12 +663,16 @@ static void dp8393x_write(void *opaque, hwaddr addr, = uint64_t data, qemu_flush_queued_packets(qemu_get_queue(s->nic)); } break; - /* Ignore least significant bit */ + /* The guest is required to store aligned pointers here */ case SONIC_RSA: case SONIC_REA: case SONIC_RRP: case SONIC_RWP: - s->regs[reg] =3D val & 0xfffe; + if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { + s->regs[reg] =3D val & 0xfffc; + } else { + s->regs[reg] =3D val & 0xfffe; + } break; /* Invert written value for some registers */ case SONIC_CRCT: --=20 2.24.1 From nobody Sun May 5 07:24:46 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=1579475717; cv=none; d=zohomail.com; s=zohoarc; b=UiZqvqMKWTzu0yGGf8adzeNAR642EOQdZB+w7KLh5PpJijzvtkFQhPz8+hxGA0Um66CKFgcaqyQXssasyXvCKa+cZwg1xARZvvXnyUIjqu+Mnrp9uRPkM68dQ9xBT+4Wx4Wqq5WhbCz5WqkAQn3BrPP+rOV5h9WHbdz9m+O8MMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475717; 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=H2haCm402I5zJpI3Rv4MTSMQ8iZtXu+gNJBru7/94Jg=; b=RUEx/w6ylklr9yQjd/PYuzwGo8vQ+uH8P+ZfupIVgW7ZnaJqwS+UGVokxjN3vkG6Y/aQMLkTXLIxKXmdDlCofhXTFKD5eUu0bPUDn711Jjgyrfdly90WHvzmsd1iehYmGdkQcBTWo4GHr9EAtfAGsMQxFPiy1sqdY5GKXQtSnqs= 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 1579475717587251.30045085044492; Sun, 19 Jan 2020 15:15:17 -0800 (PST) Received: from localhost ([::1]:54920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJml-0006MC-KQ for importer@patchew.org; Sun, 19 Jan 2020 18:15:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55966) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfj-0004AF-Gk for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfh-0003m1-AN for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54738) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfh-0003lW-3q; Sun, 19 Jan 2020 18:07:57 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 5F5F029633; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <49ee52289db03344afc627dd49706ae81eb7d165.1579474761.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 10/14] dp8393x: Pad frames to word or long word boundary Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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 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 Tested-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 b052e2c854..13513986f0 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -766,16 +766,23 @@ static ssize_t dp8393x_receive(NetClientState *nc, co= nst uint8_t * buf, dp8393xState *s =3D qemu_get_nic_opaque(nc); int packet_type; uint32_t available, address; - int width, rx_len =3D pkt_size; + int width, rx_len, padded_len; uint32_t checksum; int size; =20 - width =3D (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; - 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 - if (pkt_size + 4 > dp8393x_rbwc(s) * 2) { + rx_len =3D pkt_size + sizeof(checksum); + if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { + width =3D 2; + padded_len =3D ((rx_len - 1) | 3) + 1; + } else { + width =3D 1; + padded_len =3D ((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] |=3D SONIC_ISR_RBAE; dp8393x_update_irq(s); @@ -810,22 +817,32 @@ static ssize_t dp8393x_receive(NetClientState *nc, co= nst uint8_t * buf, s->regs[SONIC_TRBA0] =3D s->regs[SONIC_CRBA0]; =20 /* Calculate the ethernet checksum */ - checksum =3D cpu_to_le32(crc32(0, buf, rx_len)); + checksum =3D cpu_to_le32(crc32(0, buf, pkt_size)); =20 /* Put packet into RBA */ DPRINTF("Receive packet at %08x\n", dp8393x_crba(s)); address =3D dp8393x_crba(s); address_space_rw(&s->as, address, - MEMTXATTRS_UNSPECIFIED, (uint8_t *)buf, rx_len, 1); - address +=3D rx_len; + MEMTXATTRS_UNSPECIFIED, (uint8_t *)buf, pkt_size, 1); + address +=3D pkt_size; + + /* Put frame checksum into RBA */ address_space_rw(&s->as, address, - MEMTXATTRS_UNSPECIFIED, (uint8_t *)&checksum, 4, 1); - address +=3D 4; - rx_len +=3D 4; + MEMTXATTRS_UNSPECIFIED, (uint8_t *)&checksum, sizeof(checksum), 1); + address +=3D sizeof(checksum); + + /* Pad short packets to keep pointers aligned */ + if (rx_len < padded_len) { + size =3D padded_len - rx_len; + address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED, + (uint8_t *)"\xFF\xFF\xFF", size, 1); + address +=3D size; + } + s->regs[SONIC_CRBA1] =3D address >> 16; s->regs[SONIC_CRBA0] =3D address & 0xffff; available =3D dp8393x_rbwc(s); - available -=3D rx_len / 2; + available -=3D padded_len >> 1; s->regs[SONIC_RBWC1] =3D available >> 16; s->regs[SONIC_RBWC0] =3D available & 0xffff; =20 --=20 2.24.1 From nobody Sun May 5 07:24:46 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=1579475524; cv=none; d=zohomail.com; s=zohoarc; b=R9y7gsYH8A0fQ9BIaKbcOWSih587qdV8U54o4IrbzRh/jfZRm5hzhIpx2vt+XkRmnoDgMU4+zA8XZA4OW3D+ooJBUkAWE7ST76vQLMWfpWr6Dud8zqR9wl2jGmZJSREYSB3XiOnaQGp9dOQ9Rp+XNh5GCVHs6kvJuw4xoFRft6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475524; 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=GHwb6KfPQY1k9VK2cDGrO7xKZR7xMaOHuzNZQ66ONbE=; b=k7aPAtAezb0lOGJqc1P8n4Th/6Pw+5W7fxrmF5SuoPpAumD4ugLUoj909ykVl3lwelTX8g7lWuI3WFx5lddKzLuiACWoBy3i7WWQAJ8Vhh02sbJXLC9zFOWa2oYuyLQYWOjmc1MT/Fx8L80lbdeNPd8HQxCXrntfMwTy6R5Bd1U= 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 1579475524261713.1963300212445; Sun, 19 Jan 2020 15:12:04 -0800 (PST) Received: from localhost ([::1]:54856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJje-0001FJ-Bu for importer@patchew.org; Sun, 19 Jan 2020 18:12:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55963) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJfj-0004A6-EC for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJfh-0003m6-Ai for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:07:59 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJfh-0003l4-5e; Sun, 19 Jan 2020 18:07:57 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 6FD8729980; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <72b54c52328400d92add805f9ebb935c478556fb.1579474761.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 11/14] dp8393x: Clear descriptor in_use field to release packet Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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" When the SONIC receives a packet into the last available descriptor, it retains ownership of that descriptor for as long as necessary. Section 3.4.7 of the datasheet says, When the system appends more descriptors, the SONIC releases ownership of the descriptor after writing 0000h to the RXpkt.in_use field. The packet can now be processed by the host, so raise a PKTRX interrupt, just like the normal case. Signed-off-by: Finn Thain Tested-by: Laurent Vivier --- Changed since v2: - Assert PKTRX interrupt when releasing withheld packet. --- hw/net/dp8393x.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 13513986f0..99c5dad7c4 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -809,7 +809,17 @@ static ssize_t dp8393x_receive(NetClientState *nc, con= st uint8_t * buf, return -1; } /* Link has been updated by host */ + + /* Clear in_use */ + size =3D sizeof(uint16_t) * width; + address =3D dp8393x_crda(s) + sizeof(uint16_t) * 6 * width; + dp8393x_put(s, width, 0, 0); + address_space_rw(&s->as, address, 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; } =20 /* Save current position */ --=20 2.24.1 From nobody Sun May 5 07:24:46 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=1579476088; cv=none; d=zohomail.com; s=zohoarc; b=koaV6ZYxRkzHWRBfS8lPawbRTRDYzpx4rHYoQ8drghtWZlNFyhDV9OZTdnPS16lCzZzvOFXCB4LaKInC81SbKy+9cO+XQROFWc7Tp8A9ZjiMz4XVD6wO2Q5tq4jLe/X0yyJ0gTXZ6F5hCqAzm6oBO+KA3B7Le62duRsD7FhxKBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579476088; 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=sULzcnlkl5ULRJ6tGehrHSB6oY3wLOsp1ppfMBsUkRI=; b=W3OmkcMxB/2d3zh7MJ3eOodf9RfaG+QR/vDXEegmo4Eg09OeXHv82f2HZFaowFZkASTX71+s5VI2gQdNKFFQpjPUXRSNOvmJH633/xcbmrFqIF0HJM9BWg8fI6Lg2H5aMWkiSUhVs3/X+CCPTCJdYKcqqy3QSrfli8pP437kf5k= 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 1579476088141217.81930388715375; Sun, 19 Jan 2020 15:21:28 -0800 (PST) Received: from localhost ([::1]:55058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJsk-0004na-QI for importer@patchew.org; Sun, 19 Jan 2020 18:21:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56283) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJg2-0004ez-Ar for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJg1-00041G-CH for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:18 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54740) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJg1-0003lk-8R; Sun, 19 Jan 2020 18:08:17 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 747F32997F; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 12/14] dp8393x: Always update RRA pointers and sequence numbers Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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" These operations have to take place regardless of whether or not rx descriptors have been used up (that is, EOL flag was observed). The algorithm is the now the same for a packet that was withheld as for a packet that was not. Signed-off-by: Finn Thain Tested-by: Laurent Vivier --- hw/net/dp8393x.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 99c5dad7c4..1b73a8703b 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -897,12 +897,14 @@ static ssize_t dp8393x_receive(NetClientState *nc, co= nst uint8_t * buf, /* 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 - if (s->regs[SONIC_RCR] & SONIC_RCR_LPKT) { - /* Read next RRA */ - dp8393x_do_read_rra(s); - } + s->regs[SONIC_RSC] =3D (s->regs[SONIC_RSC] & 0xff00) | + ((s->regs[SONIC_RSC] + 1) & 0x00ff); + + if (s->regs[SONIC_RCR] & SONIC_RCR_LPKT) { + /* Read next RRA */ + dp8393x_do_read_rra(s); } =20 /* Done */ --=20 2.24.1 From nobody Sun May 5 07:24:46 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=1579475443; cv=none; d=zohomail.com; s=zohoarc; b=Q6h6cGpT13pqsw33OM/c8i1SQvm2Zx4e5yrFqYATGcUaSz8Od4iKkOY/bNB+r3l1LSFmyl70znPSjQvA2Lyga4x2Jzzea7knsiNc4wzXuYPDcBUp/9P8scHAdiKVfntwbBMQfmcYYyCipsEo6UfiF0XE06GLYXsnJHkOijgGjO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579475443; 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=1+vDReAwcClvLBRsHGBrvIIo0yt8JKSDF6y6GRK5oBw=; b=jM8+/TeELxs18l78vTRPr6f2II4BhbLxKivCyZGnJm8tv604hovnimcQeabUgjrGeQQe49emzgXktdejrl3j5xji10CPaulUsaM2ujWiuE67DI5UXSQZGoKN9utcSggvn0Sv4VRb3MkLLwaVHLKim8FIZXmXlrxOJtAVNcT+kMY= 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 157947544337885.8955696572549; Sun, 19 Jan 2020 15:10:43 -0800 (PST) Received: from localhost ([::1]:54812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJiL-0007Uc-Lj for importer@patchew.org; Sun, 19 Jan 2020 18:10:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56284) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJg2-0004f0-Bm for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJg1-00041A-BN for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:18 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJg1-0003lA-7K; Sun, 19 Jan 2020 18:08:17 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 8469D29984; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <34caf9dea82cd30dc51b4f8768adb7a90b236bf2.1579474761.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 13/14] dp8393x: Don't reset Silicon Revision register Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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 jazzsonic driver in Linux uses the Silicon Revision register value to probe the chip. The driver fails unless the SR register contains 4. Unfortunately, reading this register in QEMU usually returns 0 because the s->regs[] array gets wiped after a software reset. Fixes: bd8f1ebce4 ("net/dp8393x: fix hardware reset") Signed-off-by: Finn Thain Tested-by: Laurent Vivier --- hw/net/dp8393x.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 1b73a8703b..71af0fad51 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -591,6 +591,10 @@ static uint64_t dp8393x_read(void *opaque, hwaddr addr= , unsigned int size) val |=3D s->cam[s->regs[SONIC_CEP] & 0xf][2* (SONIC_CAP0 -= reg)]; } break; + /* Read-only */ + case SONIC_SR: + val =3D 4; /* only revision recognized by Linux/mips */ + break; /* All other registers have no special contrainst */ default: val =3D s->regs[reg]; @@ -971,7 +975,6 @@ static void dp8393x_realize(DeviceState *dev, Error **e= rrp) qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); =20 s->watchdog =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, dp8393x_watchdog, s); - s->regs[SONIC_SR] =3D 0x0004; /* only revision recognized by Linux */ =20 memory_region_init_ram(&s->prom, OBJECT(dev), "dp8393x-prom", SONIC_PROM_SIZE, &local_err); --=20 2.24.1 From nobody Sun May 5 07:24:46 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=1579476145; cv=none; d=zohomail.com; s=zohoarc; b=jNBdjzbEfl4pyL6jOT8paUjH+Diyphr2McXPEEqGqTH+vPIhCyisTlWhnDlBH8cWYD7Ck/WdiyVo2j02tHFRT9XPNlVFUXg9aZUU3BwA10KtB9brUMHxZADu8nnx2FchFQkSanuig/BQdYG+RdHyB8yuF6sATJZJlu8vcrjxU/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579476145; 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=TMlOShUiYzrjN7iLuzQY7NQ7u+FwjTOT33xWboI8Z1s=; b=GmllUmESm+c+v1lMFqYp6pgn/kjctLvONXcR6g+Wvgc1lVSiG/kXdilQUptU+1cHF0l/xzqdndoCr4UdjguPz6sLazzDtKwwxhYR4MipD8JbOfYfGCikFRbnw1FeQIYL+1BFITyuDKOdwTcMEgs6imOObuXp/zDrJ+KCo6TY7w0= 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 1579476145872654.7938297623558; Sun, 19 Jan 2020 15:22:25 -0800 (PST) Received: from localhost ([::1]:55124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJtg-0006BE-PM for importer@patchew.org; Sun, 19 Jan 2020 18:22:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56325) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itJg4-0004jE-Mg for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itJg2-00041r-Er for qemu-devel@nongnu.org; Sun, 19 Jan 2020 18:08:20 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:54742) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1itJg2-0003lo-8l; Sun, 19 Jan 2020 18:08:18 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 8AD4A29983; Sun, 19 Jan 2020 18:07:55 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 14/14] dp8393x: Don't stop reception upon RBE interrupt assertion Date: Mon, 20 Jan 2020 09:59:21 +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 , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , 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 3.4.7 of the datasheet explains that, The RBE bit in the Interrupt Status register is set when the SONIC finishes using the second to last receive buffer and reads the last RRA descriptor. Actually, the SONIC is not truly out of resources, but gives the system an early warning of an impending out of resources condition. RBE does not mean actual receive buffer exhaustion, and reception should not be stopped. This is important 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. This bug causes the SONIC to become deaf (until reset). Fix this with a new flag to indicate actual receive buffer exhaustion. Signed-off-by: Finn Thain Tested-by: Laurent Vivier --- Changed since v2: - Don't use can_receive to suspend packet reception. - Don't misuse the RBE interrupt flag as a proxy for RRP =3D=3D RWP. --- hw/net/dp8393x.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 71af0fad51..1ccee0c189 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -158,6 +158,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; @@ -347,12 +348,15 @@ 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 CRBA now has the last available resource */ if (s->regs[SONIC_RRP] =3D=3D s->regs[SONIC_RWP]) { s->regs[SONIC_ISR] |=3D SONIC_ISR_RBE; dp8393x_update_irq(s); } + + /* Allow packet reception */ + s->last_rba_is_full =3D false; } =20 static void dp8393x_do_software_reset(dp8393xState *s) @@ -663,9 +667,6 @@ static void dp8393x_write(void *opaque, hwaddr addr, ui= nt64_t data, dp8393x_do_read_rra(s); } dp8393x_update_irq(s); - if (dp8393x_can_receive(s->nic->ncs)) { - qemu_flush_queued_packets(qemu_get_queue(s->nic)); - } break; /* The guest is required to store aligned pointers here */ case SONIC_RSA: @@ -725,8 +726,6 @@ 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) - return 0; return 1; } =20 @@ -777,6 +776,10 @@ static ssize_t dp8393x_receive(NetClientState *nc, con= st uint8_t * buf, 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 + if (s->last_rba_is_full) { + return pkt_size; + } + rx_len =3D pkt_size + sizeof(checksum); if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { width =3D 2; @@ -790,8 +793,8 @@ static ssize_t dp8393x_receive(NetClientState *nc, cons= t uint8_t * buf, 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; + s->regs[SONIC_RCR] |=3D SONIC_RCR_LPKT; + goto done; } =20 packet_type =3D dp8393x_receive_filter(s, buf, pkt_size); @@ -903,17 +906,23 @@ static ssize_t dp8393x_receive(NetClientState *nc, co= nst uint8_t * buf, s->regs[SONIC_ISR] |=3D SONIC_ISR_PKTRX; } =20 + dp8393x_update_irq(s); + s->regs[SONIC_RSC] =3D (s->regs[SONIC_RSC] & 0xff00) | ((s->regs[SONIC_RSC] + 1) & 0x00ff); =20 +done: + if (s->regs[SONIC_RCR] & SONIC_RCR_LPKT) { - /* Read next RRA */ - dp8393x_do_read_rra(s); + if (s->regs[SONIC_RRP] =3D=3D s->regs[SONIC_RWP]) { + /* Stop packet reception */ + s->last_rba_is_full =3D true; + } else { + /* Read next resource */ + dp8393x_do_read_rra(s); + } } =20 - /* Done */ - dp8393x_update_irq(s); - return pkt_size; } =20 --=20 2.24.1