From nobody Sat May 4 07:14:35 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=1576816217; cv=none; d=zohomail.com; s=zohoarc; b=NW8Ufz68evBx5/Y8XYvi892ldfS5xM9CKwBzBzlWJ21C+g24vsw22xklsOOWlb01IxwAFO34SdEVrOPL577AkA1+xPVAL/92hWoEMF/GPLqmysvKmM8oxbze+iG+PjepiSASxODkUERpA8Ts+eOAzCuZRQrWTPOXAPJ4G7dc6jY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576816217; 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=64lqoiz8+BtQeYoMaFXqkhuR8fZ1Lugvf7LmUeq/2+4=; b=duwADAjkrf11Wx04lgWTXYsmneQDiZk+8Msih7JD9YJ7Akhz/IgZ0IS5Vt/XcJm6uY8WZoyXoSTU5jMWS9ABcm3Mq4EhOT762uCb397ZYTqlyJ5657SniECiU/kJ+vqGssAVHUU4ZVgde7ciA/w0faZwP9AHILjJtOjxIH32Vwg= 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 1576816217373615.7549789941436; Thu, 19 Dec 2019 20:30:17 -0800 (PST) Received: from localhost ([::1]:50600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9vb-0003f1-CX for importer@patchew.org; Thu, 19 Dec 2019 23:30:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59800) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9o0-0000bk-QS for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nz-0003OZ-Cu for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:24 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9nz-0001xA-61; Thu, 19 Dec 2019 23:22:23 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id E82152290B; Thu, 19 Dec 2019 23:22:01 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 01/13] dp8393x: Mask EOL bit from descriptor addresses MIME-Version: 1.0 Date: Fri, 20 Dec 2019 15:17:46 +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 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 Tested-by: Laurent Vivier --- 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 3d991af163..1957bd391e 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.23.0 From nobody Sat May 4 07:14:35 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=1576815854; cv=none; d=zohomail.com; s=zohoarc; b=eb0rrkyD06nZ9Ec75Dnmk6XctuGM2qArkNeyOnzc/yDzXbYsQzZqwsDpVNNF/HJJ5KkKw/GOJIRjj9epcTGnV2kZyHNxQOv6C5gza2KBVjcXfnsh940tqUVkz613NlUjedlvtGzlbb9G25jIc3nIF35J8WBsRKaOhwIIF6iYIO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576815854; 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=sM9ixUkQ9UNHxLnffShgKxs4FwTuK3fwVWXo3FKa8ww=; b=YPf8nNwEdX15goyRMI9cev/FYyuDUsako2Og9aAyBXVlJumEaowgH9Hyp2reJBDsJgkKY4Q5LhnGiQqSECVAwfPIzOi0cw8DBIkOz083MXAlj+Wp1KtalaU+OLwRpMSLIlMjG5H5m62bqNy6BWuCwYMvQ9cRdel17YfVoSdPSPQ= 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 1576815854693374.0049046123996; Thu, 19 Dec 2019 20:24:14 -0800 (PST) Received: from localhost ([::1]:50514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9pl-00034Z-15 for importer@patchew.org; Thu, 19 Dec 2019 23:24:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55693) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9ng-0008TI-4H for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9ne-0001yi-E5 for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:03 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34416) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9ne-0001xK-6E; Thu, 19 Dec 2019 23:22:02 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id EE6062829C; Thu, 19 Dec 2019 23:22:01 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 02/13] dp8393x: Clean up endianness hacks Date: Fri, 20 Dec 2019 15:17:46 +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 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 Tested-by: Laurent Vivier --- Changed since v1: - Use existing 'address' variable rather than declare a new one. 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. --- 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 1957bd391e..b2cc768d9b 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -765,8 +765,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? */ @@ -836,15 +834,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 */ + address =3D dp8393x_crda(s) + sizeof(uint16_t) * 6 * width; + size =3D sizeof(uint16_t) * 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.23.0 From nobody Sat May 4 07:14:35 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=1576815821; cv=none; d=zohomail.com; s=zohoarc; b=bF/S+3QgPxe/7rMKhh0k1iqgtl8OuHVFBm8fekd1XWgbnAxHrYCq9+T/Xw/5e6CWQATjNEsxz7TxE2J0JsVvhmSbixveyIPBHKyMobe+D8xRrDsWj0aTqNdaM7EMnqioqvq9S+Ouf1sRwpJ/CB2S28MUifIC0WLPeVTD0wWOq80= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576815821; 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=djimg/slKGFsJgOYTm0h2GvK0GuIFU4M9Yz/xhUxJWg=; b=P5CJn7/JuWvq1Jw+h3RfRVUiXsaPdvxr7H4a0rwME+5C5KzTXOWCOvwlIbSox/D9EJHV6wnzcJoHTgTTkVd9s8ITXT+YZv7fsMJMVgolbmO/gCZaVz+9Hlkvwb9Vh3jScNt477p3fMPrRl4bZCmFQ3hpDfMefx+k6Q3FAt1NLAY= 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 1576815821764826.9874389894364; Thu, 19 Dec 2019 20:23:41 -0800 (PST) Received: from localhost ([::1]:50508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9pD-00023c-Tw for importer@patchew.org; Thu, 19 Dec 2019 23:23:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55685) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9nf-0008T9-WB for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9ne-0001z6-HI for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:03 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34426) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9ne-0001xo-9T; Thu, 19 Dec 2019 23:22:02 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 1041628CC5; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <73bc39e93a9480aa5ed3ef2f85447c2504e4d8c8.1576815466.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 03/13] dp8393x: Have dp8393x_receive() return the packet size MIME-Version: 1.0 Date: Fri, 20 Dec 2019 15:17:46 +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 b2cc768d9b..a3e3a82ff4 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -746,20 +746,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; @@ -853,7 +854,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 Sat May 4 07:14:35 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=1576815963; cv=none; d=zohomail.com; s=zohoarc; b=Tbhl5H+7XDmMztSm0+YRNKJX+IqqFyaL9LinYdb5vXxTvRPttVs5mboQ2QQ+OVTAO8CYYYLrS3+DmiHm/GRmL6owbL3ef5bZLz5bonnnxhhEhgp89S62BmJg/aDjbazbmrpgMxnhfJ9L75c1g0A5vYwgf5xZATghubfawRMZe1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576815963; 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=4d3hlVBwDk5BKcxNOvcN/k1xS+JbdmhgH+3+PGViUyM=; b=XMeaE1wBi0Ne/aWMzdd4L+Axi/rpP74wf8NXyzeMKa6PSpyI4pcHCyVl1Q1bGIBGHQJdl7d3KkdmUCHxjOgPtTUTHSkgU4Rp+GG8hD37aIqwxDtAo/Jinff0dbSeZjHg7ZSka5r3exF4trylZJ1A2Yd6Snrn/FScQ79oo1V3Ido= 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 1576815963283404.97405192628503; Thu, 19 Dec 2019 20:26:03 -0800 (PST) Received: from localhost ([::1]:50550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9rV-0005cH-On for importer@patchew.org; Thu, 19 Dec 2019 23:26:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55776) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9ng-0008Tr-IA for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9ne-00020u-Tx for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:04 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34436) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9ne-0001y5-EA; Thu, 19 Dec 2019 23:22:02 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 216B928CD6; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <6e980c3ffe0a9a1f4e112ad16b1003e1f620d0ca.1576815466.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 04/13] dp8393x: Update LLFA and CRDA registers from rx descriptor Date: Fri, 20 Dec 2019 15:17:46 +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 a3e3a82ff4..1ead502a8f 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -773,12 +773,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 */ @@ -826,7 +827,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); @@ -841,6 +842,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.23.0 From nobody Sat May 4 07:14:35 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=1576816245; cv=none; d=zohomail.com; s=zohoarc; b=TBonFLeKy+2aBGcJYhcSAFLZV+oTKKd1wItQMF+1yIfnegOQABinIGqnf1qA6fMIwK8+SvqsyfmtiVPtiiO4oSFksgslJCpC8fDR6zuDDQrs5pQURptDGQdGyL9NwPKGiSh1zXM0sxKTXJwE0Zk0+QVMf1hOooqAnKaHvQObviw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576816245; 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=yfDlAC8hadmaWySaq/0nTJxh3cLbPJpoF1lJRA3YcIQ=; b=Gvtsybfr0IdPTYp1vYJnXETddLcciLXhC/gDz2sb2iBy1VWYpRmjEvnPo16mUBJl/I0whcjyIvHLVI+d4XR1t6+y0rcrsVIeFuhD/uIJxhoB+qblA9NH/U4SZrTa7EXBsWtrhE5mHuKISFZLSHEx0zUiMrir+9c7F4+Rup+79/Y= 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 1576816245134251.3822322961147; Thu, 19 Dec 2019 20:30:45 -0800 (PST) Received: from localhost ([::1]:50610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9w3-0004FX-An for importer@patchew.org; Thu, 19 Dec 2019 23:30:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55820) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9ng-0008U5-PZ for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nf-00022b-Ae for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:04 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34446) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9ne-00020J-WA; Thu, 19 Dec 2019 23:22:03 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 3124128D30; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <31602e6d8bf9a50154af6ab250efc7f4b1890c7e.1576815466.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 05/13] dp8393x: Clear RRRA command register bit only when appropriate MIME-Version: 1.0 Date: Fri, 20 Dec 2019 15:17:46 +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 1ead502a8f..593853244d 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -342,9 +342,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) @@ -553,8 +550,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 Sat May 4 07:14:35 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=1576816097; cv=none; d=zohomail.com; s=zohoarc; b=DCNL+Dc83/DZy0ofNQWPr/2XxdHrRYcET+zak+f6WWIUXoByya5Rrd5c1o4srvuKIHLgZr6eOK6KQpmXrZNxgnyw2xAgnj4UWXi1pJ/soGGics2vqwnxTuRmgZqrxKCPcDzWahCxe77FRss5o2KrbPSjjnxgKCYTVQej/e/HqR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576816097; 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=VyBwerilwaxo4w0ACGa6WRdY60vz0dl9o5GW+XsPSJ4=; b=MDIR9RkTn1XT12lPeVI/cbC6wWYluxT3fxukquLC3A/Ur+XbfBnC/C2iahJBw1fM+evvNtEa2L9ueRZD05DwjrxfXoV/rOj793hBie4oIAzBkV7XsUcytkoK8HDx+Qvk6rW7huGQfcdKi1NzMxs4v7L4c3Shxr4eR6MdZ3gcdwI= 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 1576816097715493.69752179957663; Thu, 19 Dec 2019 20:28:17 -0800 (PST) Received: from localhost ([::1]:50584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9tg-0001Nw-3v for importer@patchew.org; Thu, 19 Dec 2019 23:28:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55813) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9ng-0008U3-NO for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nf-00022P-8s for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:04 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34450) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9nf-00020I-09; Thu, 19 Dec 2019 23:22:03 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 409D628D32; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <8f8d4dcf6323eb4fe8535914772053c0857f0e5e.1576815466.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 06/13] dp8393x: Implement packet size limit and RBAE interrupt Date: Fri, 20 Dec 2019 15:17:46 +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 593853244d..9d2c205dce 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 @@ -759,6 +760,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.23.0 From nobody Sat May 4 07:14:35 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=1576816416; cv=none; d=zohomail.com; s=zohoarc; b=V2j8Z9CJXi0donhkd4WevkgpLHWuusgV+FN/5maYs1z0QJ7s1QHVjNaDMnKW0ekaa1UnbaSgiJuyJT5M7fcFxFl/OPsacFWXhASKhhjnlPAobXrUY4Vp5bZyOFf/M3cLC1S0YFwdHj6EU4nKpoxeVjZewtwNBGV5c6ovUwa1NRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576816416; 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=kDzK/KEW+GisQNBE57DB8wRYlFJfY0y3qJT8VzYTZg8=; b=JkOUBcsRq8+/OrkR30udVBAacfTK8CsaDIWt1rYUbGI9PAAu0ksGoDHg2sdAWqc75LaQ21hkXMhR4cyEHwgTnY8iWqrA0+kawRVT8FS7jOK9zvRzQfRJ3Q4rFq6vpwqyT0OUdGvhTG55wL1mozHZRctRzsX4WhA15K/FRgFlix8= 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 1576816416514396.50739643568534; Thu, 19 Dec 2019 20:33:36 -0800 (PST) Received: from localhost ([::1]:50654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9yp-0000NZ-3E for importer@patchew.org; Thu, 19 Dec 2019 23:33:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55875) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9nh-0008UV-7g for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nf-00022p-Bj for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:04 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9ne-00020K-WB; Thu, 19 Dec 2019 23:22:03 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 4C3C428D35; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <7c5e49e72ef576db03d6290759d3cd01f17197c8.1576815466.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 07/13] dp8393x: Don't stop reception upon RBE interrupt assertion Date: Fri, 20 Dec 2019 15:17:46 +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 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 Tested-by: Laurent Vivier --- 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 9d2c205dce..46b92ebf65 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; @@ -314,6 +315,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; @@ -337,7 +344,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; @@ -706,8 +713,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 Sat May 4 07:14:35 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=1576815819; cv=none; d=zohomail.com; s=zohoarc; b=FRs1sULYc83h9pagSfzzoUx+UhM8jz6AvMYfxHC3MSwlk+ugz1qtJ3vvWhvuUH/y5YXUvDCPFzA3jkMEj4+QGanKgJmXXtXVNY43WsMyVKfYxHb90nC5PNgErHqnvSO/bL3tjRZES7YPorUq/J4mkoi84KTW32DEslg+Cpf63lk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576815819; 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=g/rkiXvE3W6NuAbXWEAxuc/ZwTfc9m+4p0DiWPGI7sQ=; b=UExaBOczwYSnJggDisZMyR13mVYdv0gCL5UTtXbdwzolkKiTdmR3rgIZhkNKv+Ndsgd9X8NWIgIJ1is1a79TL61VntD3gdgmWDBJFzDrlhLhQ1EcdUQM/NngW6eEzVTGEy/TJOuVdL1cPutfaEKCwKu3oSrCX+5YRopJ1VrO0sY= 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 157681581976789.0096624927603; Thu, 19 Dec 2019 20:23:39 -0800 (PST) Received: from localhost ([::1]:50510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9pC-00026g-4p for importer@patchew.org; Thu, 19 Dec 2019 23:23:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55765) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9ng-0008Tl-GL for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nf-00022Q-8U for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:04 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34452) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9nf-00020M-13; Thu, 19 Dec 2019 23:22:03 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id A6E7628D42; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 08/13] dp8393x: Don't clobber packet checksum MIME-Version: 1.0 Date: Fri, 20 Dec 2019 15:17:46 +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 46b92ebf65..d722bbe8c1 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -813,6 +813,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 From nobody Sat May 4 07:14:35 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=1576816355; cv=none; d=zohomail.com; s=zohoarc; b=JmdIkrPk0GYqqRu9hSPDgGe4m3dBg3Iqv7716msdK2UHUrDKGzA9QV8QR5lwhZE83CF7f3MKLV5A9oWFeP0SO5ScxC1NDDMqDOu9pNGJKrLToSrl79VWqbv9uNGdExDwuVVqEUt91NsqwHax29JusTd3Ug8yEhMr2QwMw/aeL2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576816355; 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=m7iuPPS0j6HrvPD1C6NqD0pIWUqoin2M+5kk3+keTAE=; b=Z+x4uWm1fu8adYXWz/eANkfflFjB9sMQplNR8v+k+c2HvLylWS1xtnLI0wIvhIPUv+0Bm0CxgPJQ37JR4CWldZZFepQXWcmA1xqCaBn1Z1pLPEZJ9P3goIyV3Jc2DfE3cYcIpievg+dsgeNQS7a/OOc6PFAeeDUWX0p4ph+Tfvo= 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 1576816355237393.3123035927681; Thu, 19 Dec 2019 20:32:35 -0800 (PST) Received: from localhost ([::1]:50646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9xp-0007kv-R8 for importer@patchew.org; Thu, 19 Dec 2019 23:32:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55881) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9nh-0008UX-7Z for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nf-00023M-K8 for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:04 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34454) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9nf-00020y-0p; Thu, 19 Dec 2019 23:22:03 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id B1EDD28523; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <7e4a17ec16270797b1d47042f95263c3dcbeea5a.1576815466.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 09/13] dp8393x: Use long-word-aligned RRA pointers in 32-bit mode Date: Fri, 20 Dec 2019 15:17:46 +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 --- 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 d722bbe8c1..a3936d3b7b 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -659,12 +659,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 data & 0xfffe; + if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { + s->regs[reg] =3D data & 0xfffc; + } else { + s->regs[reg] =3D data & 0xfffe; + } break; /* Invert written value for some registers */ case SONIC_CRCT: --=20 2.23.0 From nobody Sat May 4 07:14:35 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=1576815958; cv=none; d=zohomail.com; s=zohoarc; b=R/mONRqnM3OEjck5UgCH8Lg7rZVMDBgm1U4oUepxfLhq7ZGDtHl1NrP5z1KCIzCb8Sxzh3NCHjXASbp5oN7Z5oeUGALGM1hvuejm3cFyjsn2bL1qoBRnfb7pcJd/tKT0UEjgr1ImzLaIDw6t/NP+zClmlTVVH0rB5n0uqGVotYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576815958; 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=1OX4tDX32KzaFYwbyOx+mLimiRVz4mjEMKDEnkubNqs=; b=WoGsXYweTZVDLZrHdxtNReVLqpIOomG/Tz87rZQ65eOSEAJHhg7F+xDzYmlOuAu8AfMhQ890xr/gFiLDLPUITfmkWvYulVsnd/1W0vuoCzhhLuY9ksQRPbqUmDcjH8WZHTpVSkAbDZMbmtihFLr/QPkRShcVTaZpXfnERcD5qDk= 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 15768159586891022.1518907157832; Thu, 19 Dec 2019 20:25:58 -0800 (PST) Received: from localhost ([::1]:50540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9rQ-0005Uq-VC for importer@patchew.org; Thu, 19 Dec 2019 23:25:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55882) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9nh-0008UY-8A for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nf-00024L-Oi for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:04 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34456) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9nf-000214-3S; Thu, 19 Dec 2019 23:22:03 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id BF0D828D48; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 10/13] dp8393x: Pad frames to word or long word boundary Date: Fri, 20 Dec 2019 15:17:46 +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 --- 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 a3936d3b7b..f35b8b48aa 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -763,16 +763,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); @@ -807,22 +814,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.23.0 From nobody Sat May 4 07:14:35 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=1576816077; cv=none; d=zohomail.com; s=zohoarc; b=fXsIMRUunM58rc7oaaG6XLh8IAx3BjJjz2uJK2GZPzLc8no6psf7PvFkEvip+bRzw8ZhIcriqyfSmPTfOYYdKUXneOYlVROYto/KTipNmUnE28TsyCjRiig3f4T0KVqPIWuSLxdLtYP0YOP9if9fHeYYKdKo3LmSv88YrA3sh9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576816077; 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=gFaAlDoVXRsA3/Uie50UUzvWBWjcfJK/0e8XgRn1AIw=; b=nOlxipBqYR26BVJ51kbGdhS1V7kxp3aQabOr3Yj92P+xkwz4WIiCi2GlGvMHvTwWfMakDXw5/+0sNLraILXyo0WgHGaRzEk28V5FCghBDeiWyUXsA3ZRgpTDi6kjqjPP7bP8EwGDahqENZZdlF2X1+3YOo56vW/ncIsezkN3Bac= 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 1576816077916878.1149021110884; Thu, 19 Dec 2019 20:27:57 -0800 (PST) Received: from localhost ([::1]:50578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9tM-0000i3-Ae for importer@patchew.org; Thu, 19 Dec 2019 23:27:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59723) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9o0-0000b8-Gh for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nz-0003Oi-DT for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:24 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34446) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9nz-00020J-8I; Thu, 19 Dec 2019 23:22:23 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id D5C2C28D4F; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 11/13] dp8393x: Clear descriptor in_use field when necessary Date: Fri, 20 Dec 2019 15:17:46 +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" This is in accordance with section 3.4.7 of the datasheet: When the system appends more descriptors, the SONIC releases ownership of the descriptor after writing 0000h to the RXpkt.in_use field. Signed-off-by: Finn Thain Tested-by: Laurent Vivier --- hw/net/dp8393x.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index f35b8b48aa..6b69cca329 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -806,6 +806,15 @@ 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]; } =20 --=20 2.23.0 From nobody Sat May 4 07:14:35 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=1576816166; cv=none; d=zohomail.com; s=zohoarc; b=Bxj3gyKvpbpXGzsGE9xh46ExecUFzgwDdi1JFkIWyS20A1CyWl+hrz87P2NaPf4EH3F1Mr6dLzEk1FlIOlKYPALRFt2XaR39QgeWPpDnt2fvYGOleiIsLZAqpuJXQza2ecc0Wf/gCSNNCedqf3RxozcZiHuiGak//1P0Wrzv5G4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576816166; 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=4c5y/+zsdNU470f+mtFXvS6eHhIBKBcFMJlUii7PILs=; b=kP4oe462IAKGb6Kq9JiMcPYZCaijf1IVKliLZv5ucdEbmnaiCIA2G1aGdF+8dSHohRHdEYlW/7hhnGTRSG9KXStFgm/XKx+4te6D84XQ5Ind+fDuup3P3eLLXMQWOCshwFWlZgynO8+EZGSxwpt7KfFtVy7V5uk44I5ZtJ8vKgY= 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 1576816166381584.9250750317916; Thu, 19 Dec 2019 20:29:26 -0800 (PST) Received: from localhost ([::1]:50594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9um-0002cK-MG for importer@patchew.org; Thu, 19 Dec 2019 23:29:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59815) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9o1-0000c4-31 for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nz-0003PB-JT for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:24 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9nz-00020K-9q; Thu, 19 Dec 2019 23:22:23 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id DFF8B28D67; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <1367b9572494f04722aebcf4b90d3ff31b935ab1.1576815466.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 12/13] dp8393x: Always update RRA pointers and sequence numbers Date: Fri, 20 Dec 2019 15:17:46 +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). 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 6b69cca329..bd92fa28f6 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -893,12 +893,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.23.0 From nobody Sat May 4 07:14:35 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=1576816039; cv=none; d=zohomail.com; s=zohoarc; b=kWmBJKgznXYZYnfDPzz2/icz2aFPRBFqGZBJmxUF1/3pEIlyLaqM9hgBRO6XryNOv4e2uS2/IMP1IOygaxrEbzBX2s97EBSRJKY0W2Pk97nhDELSG9WfaSkyngLZBCNH9UHYOOVgJ/6NwlnPoE7qcUlhuQNPzoDwG2ERVyszEoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576816038; 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=QTu0aVe1NJrPQWhzCkbNYOac+gKMmGtpwHsovH6/1PE=; b=ZCnN/z89N0g7p9Ijf5gnwyDRqaXmGa8a0z7YAhWn/IOoIfYFtbDY/BZdZafQFZV5f8TcENnbzpzoi2WLK0JcDLUvIlwSgmzLVtBffa774JonElIHmQeWMkb9xle/RoDdyX3AadbCI6SPL15E5mqLq4TeJgtwRCn6I8jJNPavP+c= 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 1576816038998717.3295240479295; Thu, 19 Dec 2019 20:27:18 -0800 (PST) Received: from localhost ([::1]:50570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9sj-0007sA-2t for importer@patchew.org; Thu, 19 Dec 2019 23:27:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59790) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9o0-0000bh-On for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii9nz-0003Pt-Pk for qemu-devel@nongnu.org; Thu, 19 Dec 2019 23:22:24 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:34470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ii9nz-00022I-GW; Thu, 19 Dec 2019 23:22:23 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id F10F128D4D; Thu, 19 Dec 2019 23:22:02 -0500 (EST) To: Jason Wang , qemu-devel@nongnu.org Message-Id: <05a689e082735b2ad972b3372ceeb7cfe47d4bd4.1576815466.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v2 13/13] dp8393x: Correctly advance RRP Date: Fri, 20 Dec 2019 15:17:46 +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 last entry in the RRA is at the address given by the REA register. The address wrap-around logic is off-by-one entry. The last resource never gets used and RRP can jump over the RWP. The guest driver fails badly because the SONIC starts re-using old buffer addresses. Fix this. Signed-off-by: Finn Thain Tested-by: Laurent Vivier --- hw/net/dp8393x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index bd92fa28f6..92a30f9f69 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -340,7 +340,7 @@ static void dp8393x_do_read_rra(dp8393xState *s) s->regs[SONIC_RRP] +=3D size; =20 /* Handle wrap */ - if (s->regs[SONIC_RRP] =3D=3D s->regs[SONIC_REA]) { + if (s->regs[SONIC_RRP] =3D=3D s->regs[SONIC_REA] + size) { s->regs[SONIC_RRP] =3D s->regs[SONIC_RSA]; } =20 --=20 2.23.0