From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fG3X00PNz9sPW for ; Fri, 20 Dec 2019 15:29:11 +1100 (AEDT) Received: from localhost ([::1]:50590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9uX-0002CF-8B for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:29:09 -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 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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The LSB of descriptor address registers is used as an EOL flag. It has to be masked when those registers are to be used as actual addresses for copying memory around. But when the registers are to be updated the EOL bit should not be masked. Signed-off-by: Finn Thain --- Changed since v1: - Added macros to name constants as requested by Philippe Mathieu-Daudé. --- 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 +#define SONIC_DESC_EOL 0x0001 +#define SONIC_DESC_ADDR 0xFFFE + #define TYPE_DP8393X "dp8393x" #define DP8393X(obj) OBJECT_CHECK(dp8393xState, (obj), TYPE_DP8393X) @@ -197,7 +200,8 @@ static uint32_t dp8393x_crba(dp8393xState *s) static uint32_t dp8393x_crda(dp8393xState *s) { - return (s->regs[SONIC_URDA] << 16) | s->regs[SONIC_CRDA]; + return (s->regs[SONIC_URDA] << 16) | + (s->regs[SONIC_CRDA] & SONIC_DESC_ADDR); } static uint32_t dp8393x_rbwc(dp8393xState *s) @@ -217,7 +221,8 @@ static uint32_t dp8393x_tsa(dp8393xState *s) static uint32_t dp8393x_ttda(dp8393xState *s) { - return (s->regs[SONIC_UTDA] << 16) | s->regs[SONIC_TTDA]; + return (s->regs[SONIC_UTDA] << 16) | + (s->regs[SONIC_TTDA] & SONIC_DESC_ADDR); } 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] = dp8393x_get(s, width, 0) & ~0x1; - if (dp8393x_get(s, width, 0) & 0x1) { + s->regs[SONIC_CTDA] = dp8393x_get(s, width, 0); + if (s->regs[SONIC_CTDA] & SONIC_DESC_EOL) { /* EOL detected */ break; } @@ -763,13 +768,13 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, /* XXX: Check byte ordering */ /* Check for EOL */ - if (s->regs[SONIC_LLFA] & 0x1) { + if (s->regs[SONIC_LLFA] & SONIC_DESC_EOL) { /* Are we still in resource exhaustion? */ size = sizeof(uint16_t) * 1 * width; address = dp8393x_crda(s) + sizeof(uint16_t) * 5 * width; address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 0); - if (dp8393x_get(s, width, 0) & 0x1) { + 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, const uint8_t * buf, address_space_rw(&s->as, dp8393x_crda(s) + sizeof(uint16_t) * 5 * width, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 0); s->regs[SONIC_LLFA] = 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] |= SONIC_ISR_RDE; } else { From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213908 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fFwv2MFbz9sPW for ; Fri, 20 Dec 2019 15:23:27 +1100 (AEDT) Received: from localhost ([::1]:50504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9oy-0001Sb-NJ for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:23:24 -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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The in_use field is no different to the other words handled using dp8393x_put() and dp8393x_get(). Use the same technique for in_use that is used everywhere else. Signed-off-by: Finn Thain --- 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, const uint8_t * buf, return -1; } - /* 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, const uint8_t * buf, /* EOL detected */ s->regs[SONIC_ISR] |= SONIC_ISR_RDE; } else { - /* Clear in_use, but it is always 16bit wide */ - int offset = dp8393x_crda(s) + sizeof(uint16_t) * 6 * width; - if (s->big_endian && width == 2) { - /* we need to adjust the offset of the 16bit field */ - offset += sizeof(uint16_t); - } - s->data[0] = 0; - address_space_rw(&s->as, offset, MEMTXATTRS_UNSPECIFIED, - (uint8_t *)s->data, sizeof(uint16_t), 1); + /* Clear in_use */ + address = dp8393x_crda(s) + sizeof(uint16_t) * 6 * width; + size = 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] = s->regs[SONIC_LLFA]; s->regs[SONIC_ISR] |= SONIC_ISR_PKTRX; s->regs[SONIC_RSC] = (s->regs[SONIC_RSC] & 0xff00) | (((s->regs[SONIC_RSC] & 0x00ff) + 1) & 0x00ff); From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213906 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fFw95Kt6z9sRd for ; Fri, 20 Dec 2019 15:22:49 +1100 (AEDT) Received: from localhost ([::1]:50496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9oN-00005J-1c for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:22:47 -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 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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This function re-uses its 'size' argument as a scratch variable. Instead, declare a local 'size' variable for that purpose so that the function result doesn't get messed up. Signed-off-by: Finn Thain Reviewed-by: Philippe Mathieu-Daudé --- hw/net/dp8393x.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index b2cc768d9b..a3e3a82ff4 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -746,20 +746,21 @@ static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf, } static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, - size_t size) + size_t pkt_size) { dp8393xState *s = qemu_get_nic_opaque(nc); int packet_type; uint32_t available, address; - int width, rx_len = size; + int width, rx_len = pkt_size; uint32_t checksum; + int size; width = (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; s->regs[SONIC_RCR] &= ~(SONIC_RCR_PRX | SONIC_RCR_LBK | SONIC_RCR_FAER | SONIC_RCR_CRCR | SONIC_RCR_LPKT | SONIC_RCR_BC | SONIC_RCR_MC); - packet_type = dp8393x_receive_filter(s, buf, size); + packet_type = dp8393x_receive_filter(s, buf, pkt_size); if (packet_type < 0) { DPRINTF("packet not for netcard\n"); return -1; @@ -853,7 +854,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, /* Done */ dp8393x_update_irq(s); - return size; + return pkt_size; } static void dp8393x_reset(DeviceState *dev) From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fFyq5tr9z9sPW for ; Fri, 20 Dec 2019 15:25:07 +1100 (AEDT) Received: from localhost ([::1]:50524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9qb-0003t6-5r for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:25:05 -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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Follow the algorithm given in the National Semiconductor DP83932C datasheet in 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 --- 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, const uint8_t * buf, address = dp8393x_crda(s) + sizeof(uint16_t) * 5 * width; address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 0); - if (dp8393x_get(s, width, 0) & SONIC_DESC_EOL) { + s->regs[SONIC_LLFA] = dp8393x_get(s, width, 0); + if (s->regs[SONIC_LLFA] & SONIC_DESC_EOL) { /* Still EOL ; stop reception */ return -1; - } else { - s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; } + /* Link has been updated by host */ + s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; } /* Save current position */ @@ -826,7 +827,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, address_space_rw(&s->as, dp8393x_crda(s), MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 1); - /* Move to next descriptor */ + /* Check link field */ size = sizeof(uint16_t) * width; address_space_rw(&s->as, dp8393x_crda(s) + sizeof(uint16_t) * 5 * width, MEMTXATTRS_UNSPECIFIED, (uint8_t *)s->data, size, 0); @@ -841,6 +842,8 @@ static ssize_t dp8393x_receive(NetClientState *nc, const 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] = s->regs[SONIC_LLFA]; s->regs[SONIC_ISR] |= SONIC_ISR_PKTRX; s->regs[SONIC_RSC] = (s->regs[SONIC_RSC] & 0xff00) | (((s->regs[SONIC_RSC] & 0x00ff) + 1) & 0x00ff); From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fG432RySz9sPW for ; Fri, 20 Dec 2019 15:29:39 +1100 (AEDT) Received: from localhost ([::1]:50596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9uy-0002jP-NO for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:29:36 -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 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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It doesn't make sense to clear the command register bit unless the command was actually issued. Signed-off-by: Finn Thain Reviewed-by: Philippe Mathieu-Daudé --- hw/net/dp8393x.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 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] |= SONIC_ISR_RBE; dp8393x_update_irq(s); } - - /* Done */ - s->regs[SONIC_CR] &= ~SONIC_CR_RRRA; } 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] &= ~SONIC_CR_RRRA; + } if (command & SONIC_CR_LCAM) dp8393x_do_load_cam(s); } From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213913 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fG1j3KYtz9sRX for ; Fri, 20 Dec 2019 15:27:37 +1100 (AEDT) Received: from localhost ([::1]:50572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9t0-0007th-LS for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:27:34 -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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a bounds check to prevent a large packet from causing a buffer overflow. This is defensive programming -- I haven't actually tried sending an oversized packet or a jumbo ethernet frame. The SONIC handles packets that are too big for the buffer by raising the RBAE interrupt and dropping them. Linux uses that interrupt to count dropped packets. Signed-off-by: Finn Thain --- 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 +#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, const uint8_t * buf, s->regs[SONIC_RCR] &= ~(SONIC_RCR_PRX | SONIC_RCR_LBK | SONIC_RCR_FAER | SONIC_RCR_CRCR | SONIC_RCR_LPKT | SONIC_RCR_BC | SONIC_RCR_MC); + if (pkt_size + 4 > dp8393x_rbwc(s) * 2) { + DPRINTF("oversize packet, pkt_size is %d\n", pkt_size); + s->regs[SONIC_ISR] |= SONIC_ISR_RBAE; + dp8393x_update_irq(s); + dp8393x_do_read_rra(s); + return pkt_size; + } + packet_type = dp8393x_receive_filter(s, buf, pkt_size); if (packet_type < 0) { DPRINTF("packet not for netcard\n"); From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fG8C1DgCz9sP6 for ; Fri, 20 Dec 2019 15:33:15 +1100 (AEDT) Received: from localhost ([::1]:50652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9yT-0008QU-09 for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:33:13 -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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Section 5.4.7 of the datasheet explains that the RBE interrupt is an "early warning". It indicates that the last RBA is still available to receive a packet. It doesn't imply actual receive buffer exhaustion. This is an important distinction because Linux will not check and clear the RBE interrupt until it receives another packet. But that won't happen if can_receive returns false. So the SONIC becomes deaf (until reset). Fix this with a new flag to indicate actual receive buffer exhaustion. Signed-off-by: Finn Thain --- hw/net/dp8393x.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 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; + /* Already on the last RBA? */ + s->last_rba_is_full = s->regs[SONIC_ISR] & SONIC_ISR_RBE; + if (s->last_rba_is_full) { + return; + } + /* Read memory */ width = (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; size = sizeof(uint16_t) * 4 * width; @@ -337,7 +344,7 @@ static void dp8393x_do_read_rra(dp8393xState *s) s->regs[SONIC_RRP] = s->regs[SONIC_RSA]; } - /* Check resource exhaustion */ + /* Warn the host if this entry is the last one */ if (s->regs[SONIC_RRP] == s->regs[SONIC_RWP]) { s->regs[SONIC_ISR] |= SONIC_ISR_RBE; @@ -706,8 +713,9 @@ static int dp8393x_can_receive(NetClientState *nc) if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN)) return 0; - if (s->regs[SONIC_ISR] & SONIC_ISR_RBE) + if (s->last_rba_is_full) { return 0; + } return 1; } From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fG6g1sTYz9sPW for ; Fri, 20 Dec 2019 15:31:54 +1100 (AEDT) Received: from localhost ([::1]:50638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9x9-0006ON-PY for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:31:51 -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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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] = data & 0xfffe; + if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { + s->regs[reg] = data & 0xfffc; + } else { + s->regs[reg] = data & 0xfffe; + } break; /* Invert written value for some registers */ case SONIC_CRCT: From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fFyj48mQz9sPW for ; Fri, 20 Dec 2019 15:25:01 +1100 (AEDT) Received: from localhost ([::1]:50522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9qV-0003o6-1M for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:24:59 -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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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, const uint8_t * buf, dp8393xState *s = qemu_get_nic_opaque(nc); int packet_type; uint32_t available, address; - int width, rx_len = pkt_size; + int width, rx_len, padded_len; uint32_t checksum; int size; - width = (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; - s->regs[SONIC_RCR] &= ~(SONIC_RCR_PRX | SONIC_RCR_LBK | SONIC_RCR_FAER | SONIC_RCR_CRCR | SONIC_RCR_LPKT | SONIC_RCR_BC | SONIC_RCR_MC); - if (pkt_size + 4 > dp8393x_rbwc(s) * 2) { + rx_len = pkt_size + sizeof(checksum); + if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { + width = 2; + padded_len = ((rx_len - 1) | 3) + 1; + } else { + width = 1; + padded_len = ((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] |= SONIC_ISR_RBAE; dp8393x_update_irq(s); @@ -807,22 +814,32 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, s->regs[SONIC_TRBA0] = s->regs[SONIC_CRBA0]; /* Calculate the ethernet checksum */ - checksum = cpu_to_le32(crc32(0, buf, rx_len)); + checksum = cpu_to_le32(crc32(0, buf, pkt_size)); /* Put packet into RBA */ DPRINTF("Receive packet at %08x\n", dp8393x_crba(s)); address = dp8393x_crba(s); address_space_rw(&s->as, address, - MEMTXATTRS_UNSPECIFIED, (uint8_t *)buf, rx_len, 1); - address += rx_len; + MEMTXATTRS_UNSPECIFIED, (uint8_t *)buf, pkt_size, 1); + address += pkt_size; + + /* Put frame checksum into RBA */ address_space_rw(&s->as, address, - MEMTXATTRS_UNSPECIFIED, (uint8_t *)&checksum, 4, 1); - address += 4; - rx_len += 4; + MEMTXATTRS_UNSPECIFIED, (uint8_t *)&checksum, sizeof(checksum), 1); + address += sizeof(checksum); + + /* Pad short packets to keep pointers aligned */ + if (rx_len < padded_len) { + size = padded_len - rx_len; + address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED, + (uint8_t *)"\xFF\xFF\xFF", size, 1); + address += size; + } + s->regs[SONIC_CRBA1] = address >> 16; s->regs[SONIC_CRBA0] = address & 0xffff; available = dp8393x_rbwc(s); - available -= rx_len / 2; + available -= padded_len >> 1; s->regs[SONIC_RBWC1] = available >> 16; s->regs[SONIC_RBWC0] = available & 0xffff; From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fG126rz0z9sPW for ; Fri, 20 Dec 2019 15:27:02 +1100 (AEDT) Received: from localhost ([::1]:50562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9sS-0006pV-4l for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:27:00 -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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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, const uint8_t * buf, return -1; } /* Link has been updated by host */ + + /* Clear in_use */ + size = sizeof(uint16_t) * width; + address = 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] = s->regs[SONIC_LLFA]; } From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fG2j3HVwz9sPW for ; Fri, 20 Dec 2019 15:28:29 +1100 (AEDT) Received: from localhost ([::1]:50586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9tr-0001TB-1W for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:28:27 -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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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, const uint8_t * buf, /* Move to next descriptor */ s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; s->regs[SONIC_ISR] |= SONIC_ISR_PKTRX; - s->regs[SONIC_RSC] = (s->regs[SONIC_RSC] & 0xff00) | (((s->regs[SONIC_RSC] & 0x00ff) + 1) & 0x00ff); + } - if (s->regs[SONIC_RCR] & SONIC_RCR_LPKT) { - /* Read next RRA */ - dp8393x_do_read_rra(s); - } + s->regs[SONIC_RSC] = (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); } /* Done */ From patchwork Fri Dec 20 04:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 1213911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=telegraphics.com.au Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fG0D44YJz9sPW for ; Fri, 20 Dec 2019 15:26:20 +1100 (AEDT) Received: from localhost ([::1]:50556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii9rm-0005nG-0S for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 23:26:18 -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_?= =?utf-8?q?Poussineau?= , Laurent Vivier , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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] += size; /* Handle wrap */ - if (s->regs[SONIC_RRP] == s->regs[SONIC_REA]) { + if (s->regs[SONIC_RRP] == s->regs[SONIC_REA] + size) { s->regs[SONIC_RRP] = s->regs[SONIC_RSA]; }