From patchwork Fri Nov 24 12:53:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Geurts X-Patchwork-Id: 13467649 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 B15B2C61D97 for ; Fri, 24 Nov 2023 12:55:47 +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=xv2JFS4yRc7RTnzLaiH4KOKMlqWN/e2igk03QfNES5Q=; b=BnJ1xqai4we41P VZarI2DWHx1ygACqiv8/xmSfNetWUfyPS5ZLUDvItKCZGZMAAPyPXLwBBgyNEbABnB00sqrtQlUQ1 VZQq7IKSGigvrx2h0h6PLHpd2wBTse6KwARrYSSB4N38jMtya7BjRi6C6qwucJ0ObGBDSMfXJRE0G wWSkkyGIm9U/Cgr33ga5HEsG7RBdE7xK4eHTqR2v1LLgTTOXGqB6zq7rAnwoNUO+8ebJxzYtMH8Uq aAVKHsoXx0TMCFCxaATqQf9MHbLS5f3TG0HbFRilXll+8OIYfYFirug/mTVhU6zHi6efToVMOjMo+ q3TsewdSIH2bFUqwz8ZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r6ViD-007FZC-2F; Fri, 24 Nov 2023 12:55:13 +0000 Received: from mail-vi1eur05olkn20800.outbound.protection.outlook.com ([2a01:111:f400:7d00::800] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r6ViB-007FXz-1U for linux-arm-kernel@lists.infradead.org; Fri, 24 Nov 2023 12:55:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R/Lar9S/xa9c3xQ6ooZrZB+Akrckwp32KyxUc5Z2qiL7gwx61ns2HJ+MkCs7y6ZJZCVtc7QKIGALQoins7AjGVJCDcDmxqFiKTVUAnrVhU/x5ZvMOyLfkAETbAyqy/+LHa0094QCJtSWf0+vnaFfJKcVt2r9nao1yPbGf6MzIJFj5IVkEPqCiHLAoxXM2bTDN87YTULbfD7WlMqLlnvdkCFb7AcssNWyjnrtmqTVLNrmmEJLgG9P4WRY4cBDN5CGa6o678ubhlB0vY16Vi5Zqes8Tsa3fI2OkOM5KK6gx8a7fUjWNVL74rR77izFH9h7UFQxfwii2SGezTxKsLS2rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QGBRIRhdKtgEeatKM6MRByr9zwGxeeBvzcOVc28Iuko=; b=HSKBmaSFhXiRUW/7yPX8tAliCB7WpQ1zXNdAoZpsLkYevik3MJ/8sT1u1gtXlAkH4Q+lZ8rC1RViudhy9+2Yl7Ck4UpFZRdeGCTvnEaPdiEk9aO9PYQliuTYrvmPhIeTZidHLVKHk3nykmTmhRpGNefICLdloFiAigGA2KiO1DfHI3DJxT44wvLMuM74GCHUkK6A6j2Nvg0Smfw4mfthVXrn96JmkNoYgzItHDg82aArMqWJ+sniumh0jB1ynmig/mKWum8eEIEHybeo9B98EGUjBSsV530DHPhXixxZDi2oJslYPY5ZutyyLuOxjz4j56SOZuNGH9LfTVxGVF1m9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from AM0PR09MB2675.eurprd09.prod.outlook.com (2603:10a6:208:d3::24) by PR3PR09MB5345.eurprd09.prod.outlook.com (2603:10a6:102:178::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Fri, 24 Nov 2023 12:55:04 +0000 Received: from AM0PR09MB2675.eurprd09.prod.outlook.com ([fe80::279b:7d4f:cf90:e9c9]) by AM0PR09MB2675.eurprd09.prod.outlook.com ([fe80::279b:7d4f:cf90:e9c9%3]) with mapi id 15.20.7025.020; Fri, 24 Nov 2023 12:55:04 +0000 From: Paul Geurts To: gregkh@linuxfoundation.org, jirislaby@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, u.kleine-koenig@pengutronix.de, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Paul Geurts Subject: [PATCH v2] serial: imx: fix tx statemachine deadlock Date: Fri, 24 Nov 2023 13:53:06 +0100 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <2023100450-charger-disregard-9683@gregkh> References: <2023100450-charger-disregard-9683@gregkh> X-TMN: [BWGTXt8QdPS/08DN25SOwJ92iJ5Gai/bHl3A9XBGuOhIaofzhZ+iMtj5DcWn+7uH] X-ClientProxiedBy: AS4P189CA0033.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:5dd::6) To AM0PR09MB2675.eurprd09.prod.outlook.com (2603:10a6:208:d3::24) X-Microsoft-Original-Message-ID: <20231124125305.1206-1-paul_geurts@live.nl> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR09MB2675:EE_|PR3PR09MB5345:EE_ X-MS-Office365-Filtering-Correlation-Id: d0564d1c-8185-4c62-06e6-08dbecec93e2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ajVBa0R4pIP8w2kTOcaVXJAoXFNPsmXN40+btRTFutCzE+SUjBrHqlrGX2QzpW81rKPhUHyY1Y3J1z6tF+C/JYKdjkVyczLKbD2X4FbCQYO2IuEtjXW29kog9zp6dkclKWhtIQ9mgeEr3s3tBWQ3gI3/jIJkbbPsfq4qQ637PsDQbJvTnKtMu2m9CamzMBTULVgya1uGr2WF55FC3zbRJ4E4zJLdg00iYzc1pbVBzFg1tribfBY3tr4B6ze7WG77gdwwKi2m7ybG4UZlS3NTgHaaKZF0yhAIp5oR2hCPKR7dNcT/AxwIH7WH27d27pCpqBoV40b3yR5MTG/C8zAeidp0Mz+W5qHqlcJeUnvgGBL8Sboh0o1Gdjb3iYU0jf/hTRvOlx8AmXf1ItPssjqoz61pSCOMZyzxjzVEM9ZhStlhJY35g0MvjpeF2RkUwuTRqtMkqSm0vT4AxfkLkblTKcAd2fjXMrP/o18+FPVqsgzpebogmdXfg3dRCqBWEDV1y9wFCKJ8DFBkE5n0sk6/O2uwWz9PrdhQjye8E1Rixd0hR70ZWg+pqUk5Fygh6tONkAbN3DB2vf8pOZMKbFAHPMXsP7n4oVxKTTa0Z1UKO4SxhYqmu2nSUd30s0yJVYKI X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pzyL7wxmAR6PmjQy+4vHGh4InY3cFAw/eUKLZzPwqADmDAMR6UCRpiOZkuL+SuT6gZ7cNKENbV4AuIC6AFrs/Cwlv8C+X62JxE1KLUNPYuJLKyBNpfmlnI7/72+2eld0iKZjdbwHFi6RwT/kwQhuGkHduRfggWhiPCCzMUZS0StI9hXffLXO2aejRHwUFYg0wOY2HsQo0tPCyvwvb4E7bGC/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BVhgjyfXKP5iMVK6A== X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-64da6.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: d0564d1c-8185-4c62-06e6-08dbecec93e2 X-MS-Exchange-CrossTenant-AuthSource: AM0PR09MB2675.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2023 12:55:04.6173 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR09MB5345 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231124_045511_501778_8917E7DA X-CRM114-Status: GOOD ( 12.94 ) 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 When using the serial port as RS485 port, the tx statemachine is used to control the RTS pin to drive the RS485 transceiver TX_EN pin. When the TTY port is closed in the middle of a transmission (for instance during userland application crash), imx_uart_shutdown disables the interface and disables the Transmission Complete interrupt. afer that, imx_uart_stop_tx bails on an incomplete transmission, to be retriggered by the TC interrupt. This interrupt is disabled and therefore the tx statemachine never transitions out of SEND. The statemachine is in deadlock now, and the TX_EN remains low, making the interface useless. imx_uart_stop_tx now checks for incomplete transmission AND whether TC interrupts are enabled before bailing to be retriggered. This makes sure the state machine handling is reached, and is properly set to WAIT_AFTER_SEND. Fixes: cb1a60923609 serial: imx: implement rts delaying for rs485 Signed-off-by: Paul Geurts --- V1 -> V2: Added fixes line to the commit message drivers/tty/serial/imx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 708b9852a575..ad36c49c7898 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -415,13 +415,13 @@ static void imx_uart_stop_tx(struct uart_port *port) ucr1 = imx_uart_readl(sport, UCR1); imx_uart_writel(sport, ucr1 & ~UCR1_TRDYEN, UCR1); + ucr4 = imx_uart_readl(sport, UCR4); usr2 = imx_uart_readl(sport, USR2); - if (!(usr2 & USR2_TXDC)) { + if ((!(usr2 & USR2_TXDC)) && (ucr4 & UCR4_TCEN)) { /* The shifter is still busy, so retry once TC triggers */ return; } - ucr4 = imx_uart_readl(sport, UCR4); ucr4 &= ~UCR4_TCEN; imx_uart_writel(sport, ucr4, UCR4);