From patchwork Wed Jan 10 20:38:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Christophe Dubois X-Patchwork-Id: 10156081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3707C601A1 for ; Wed, 10 Jan 2018 20:39:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25F10269B2 for ; Wed, 10 Jan 2018 20:39:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 167C424BFE; Wed, 10 Jan 2018 20:39:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 23FD724BFE for ; Wed, 10 Jan 2018 20:39:41 +0000 (UTC) Received: from localhost ([::1]:38489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZN9w-00006x-MW for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 Jan 2018 15:39:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZN95-00082m-90 for qemu-devel@nongnu.org; Wed, 10 Jan 2018 15:38:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZN94-00054b-BO for qemu-devel@nongnu.org; Wed, 10 Jan 2018 15:38:47 -0500 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:53789) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eZN91-0004yM-Mo; Wed, 10 Jan 2018 15:38:43 -0500 Received: from localhost.localdomain (unknown [IPv6:2a01:e34:eebf:9c0:418e:be1e:e2ef:ab3]) (Authenticated sender: jcd@tribudubois.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 6BE3317209B; Wed, 10 Jan 2018 21:38:38 +0100 (CET) From: Jean-Christophe Dubois To: peter.maydell@linaro.org Date: Wed, 10 Jan 2018 21:38:23 +0100 Message-Id: <20180110203823.22292-1-jcd@tribudubois.net> X-Mailer: git-send-email 2.14.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4b98:c:538::196 Subject: [Qemu-devel] [PATCH] i.MX: Fix FEC/ENET receive funtions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fyleo45@gmail.com, Jason Wang , qemu-devel@nongnu.org, Jean-Christophe Dubois , qemu-arm@nongnu.org, Peter Chubb Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The actual imx_eth_enable_rx() function is buggy. It updates s->regs[ENET_RDAR] after calling qemu_flush_queued_packets(). qemu_flush_queued_packets() is going to call imx_XXX_receive() which itself is going to call imx_eth_enable_rx(). By updating s->regs[ENET_RDAR] after calling qemu_flush_queued_packets() we end up updating the register with an outdated value which might lead to disabling the receive function in the i.MX FEC/ENET device. This patch change the place where the register update is done so that the register value stays up to date and the receive function can keep running. Reported-by: Fyleo Tested-by: Fyleo Signed-off-by: Jean-Christophe Dubois --- hw/net/imx_fec.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c index 90e6ee35ba..04a5cf12f1 100644 --- a/hw/net/imx_fec.c +++ b/hw/net/imx_fec.c @@ -536,19 +536,16 @@ static void imx_eth_do_tx(IMXFECState *s) static void imx_eth_enable_rx(IMXFECState *s) { IMXFECBufDesc bd; - bool tmp; imx_fec_read_bd(&bd, s->rx_descriptor); - tmp = ((bd.flags & ENET_BD_E) != 0); + s->regs[ENET_RDAR] = (bd.flags & ENET_BD_E) ? ENET_RDAR_RDAR : 0; - if (!tmp) { + if (!s->regs[ENET_RDAR]) { FEC_PRINTF("RX buffer full\n"); - } else if (!s->regs[ENET_RDAR]) { + } else { qemu_flush_queued_packets(qemu_get_queue(s->nic)); } - - s->regs[ENET_RDAR] = tmp ? ENET_RDAR_RDAR : 0; } static void imx_eth_reset(DeviceState *d) @@ -806,7 +803,6 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, case ENET_RDAR: if (s->regs[ENET_ECR] & ENET_ECR_ETHEREN) { if (!s->regs[index]) { - s->regs[index] = ENET_RDAR_RDAR; imx_eth_enable_rx(s); } } else {