From patchwork Wed Apr 10 07:18:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Esben Haabendal X-Patchwork-Id: 13623665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2AA48CD1296 for ; Wed, 10 Apr 2024 07:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GuXBRa0iQNvOO0/Z2EipTUkI1sNiczfKyEuvv8kqbIY=; b=SkBIl119hwg2AZ DRvnK8XOZ40c7TNYIOxaqX75b9PPkzRavu0qctAcH1SxjP6Fb9r+MuLUq/R0EtAbNIM7/T66WpDFZ XVydpMukNyyzNUFqrIJSaalLH4cyNZSOovyXxW1QJ7bgbE0uJj/LxIcXweuYW47W3jBQoyu7VXALR 4iir5nD2t+R5UMmDQzFCQhagF8Wurft2ajIqQ57XRvEZnZ3W8z8XaiTIZHhmjisfv0xygPFB2eiCh HdMF7dnkX2kFBRmdbIDmeIBQUHw+HN9u379T/7ND3VREIs1odA6Sh3bOtcIMwJ5npvNTocJ44pjb2 tldrswGTqAgwSvd8gsow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruSEH-00000005ZhK-3RqQ; Wed, 10 Apr 2024 07:18:46 +0000 Received: from www530.your-server.de ([188.40.30.78]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruSED-00000005Zdk-1YIf for linux-arm-kernel@lists.infradead.org; Wed, 10 Apr 2024 07:18:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=geanix.com; s=default2211; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=b9HwsGx8UBYMPhvje+pNsQ88H4qwhSzndrcngWNjVww=; b=Mfe6GFIXKP2zIgXBGNMo3SbDxL zOi6QHfMFYmag9ttqt614Hp9lOQ9EH65k3w8EHBVBlfoSvaaa8tsPtnJzPcZR+E4AV76hUAzMDoTn SpdgyYgnFX1gYaZDtzZCTGzsEj5JQfRGG87J9XS7dcmV+1rAKdRhuKE2L2dHgfNzr7s8C7/1PspMu Zb1xR1uAhnR8EkMYBofp+Z/ZM/K285fQaExP7fhj5+fWyRg/Cd8hDIiUpDmUpqqOpEXBD+vo5Y0Hu sVArq21qGUq4tp4+wpUnXzk51J2PLwvavGGzV8n5FB5r1vxonLWBEe6VAnK/zOdJTLegmicGo16s0 wLOxcY6w==; Received: from sslproxy05.your-server.de ([78.46.172.2]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ruSE4-000BJC-Tg; Wed, 10 Apr 2024 09:18:32 +0200 Received: from [185.17.218.86] (helo=localhost) by sslproxy05.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruSE4-009Fmd-0I; Wed, 10 Apr 2024 09:18:32 +0200 From: Esben Haabendal To: Marc Kleine-Budde , Sergey Organov , Greg Kroah-Hartman , Jiri Slaby , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] serial: imx: Introduce timeout when waiting on transmitter empty Date: Wed, 10 Apr 2024 09:18:32 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: <76cf9ce9cbf9dcdf78bc00ce7a919db1776ebce1.1712309058.git.esben@geanix.com> References: <76cf9ce9cbf9dcdf78bc00ce7a919db1776ebce1.1712309058.git.esben@geanix.com> MIME-Version: 1.0 X-Authenticated-Sender: esben@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.10/27240/Tue Apr 9 10:26:56 2024) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240410_001841_834480_6CACE4DD X-CRM114-Status: GOOD ( 12.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org By waiting at most 1 second for USR2_TXDC to be set, we avoid a potential deadlock. In case of the timeout, there is not much we can do, so we simply ignore the transmitter state and optimistically try to continue. v2: - Fixed commit message typo - Remove reference to patch series it originated from. This is a stand-alone patch Signed-off-by: Esben Haabendal Acked-by: Marc Kleine-Budde --- drivers/tty/serial/imx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index e14813250616..09c1678ddfd4 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -2010,7 +2011,7 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count) struct imx_port *sport = imx_uart_ports[co->index]; struct imx_port_ucrs old_ucr; unsigned long flags; - unsigned int ucr1; + unsigned int ucr1, usr2; int locked = 1; if (sport->port.sysrq) @@ -2041,8 +2042,8 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count) * Finally, wait for transmitter to become empty * and restore UCR1/2/3 */ - while (!(imx_uart_readl(sport, USR2) & USR2_TXDC)); - + read_poll_timeout_atomic(imx_uart_readl, usr2, usr2 & USR2_TXDC, + 0, USEC_PER_SEC, false, sport, USR2); imx_uart_ucrs_restore(sport, &old_ucr); if (locked)