Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2502190rdb; Wed, 4 Oct 2023 03:20:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJhyWJOMve7ImomjDECRK3xLai2Gwfo3KR67v1abo5Ge9ZRfYP0CecjNGiZ0hn3m7gb7y4 X-Received: by 2002:a17:903:244f:b0:1c6:2161:b191 with SMTP id l15-20020a170903244f00b001c62161b191mr2521447pls.8.1696414823762; Wed, 04 Oct 2023 03:20:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696414823; cv=none; d=google.com; s=arc-20160816; b=e1tyJEP/mIgqwgDrvy67hrzWXPWaom1wOTEgGtuChgwQ43IypheWz4duv8l2JgBcnd 7dP/vmdAl6Q3a/79FecYb88LP0ihFW0+tegLPbYUsBzqWR6r28uez3qKeSxrYwszMTsx LaxWPT2uI+xaBLERv2pGeeI/A5xa9ShmqPt59ouObCfyYtbqB6pvQ6EDQl+FK3EceEse 2HRw7KiObrpP8mIu9mj9biFu8I2GLw3NdKsJFWKWxrgblpkDNqd5Zf0oqqpzdz13HZ2O EzJQ3kXFSAzIS8Cc0JDoK6W871non17P2oVSO4x7YtiacrbdjO22wLA9hZHkpPE41yta mFIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=gk1aoTRuW/QL+JvbkqpcqBSOg2cC1GREHP9qpRZdRI4=; fh=AIYQSj8bKMHT+DITppY/2Wm033WmLrp28pwYTupbrwo=; b=gxDGRD07dIxZ3ZIKv74w5mT2JYgEZNa+uw+1zJ1fiivSBdj627wPouC2mhhZ7OQ2+6 jdy8XXabX2bbNF/y9EfJiIE/B6gE9Rl/1rarAaa4mLYbywkx8yqASrJdc/DLvMroSLNq cP6FbU4T56x8YL6+LWgSFaQ3zpddWSen3OaP1FvJS+vzr80/FF2eGuoEFAfoxfgGIBYr ugyg/91uc7qnMrBLAZooOLXLf8yOJ2nhTWrAvewikVv5FD+UMj2+5RpWQ2yyjrYc5GCo QqcuZbMWfKvQoGgqnYPqIZBSYKv8sftAxYk5IOvx2wCld2OsDdFSz9Pd1pxmYtsGM+a6 yHyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x19-20020a170902e05300b001c6069b659csi3140072plx.384.2023.10.04.03.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 03:20:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B571D810438E; Wed, 4 Oct 2023 03:20:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242099AbjJDKUV (ORCPT + 99 others); Wed, 4 Oct 2023 06:20:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233010AbjJDKUT (ORCPT ); Wed, 4 Oct 2023 06:20:19 -0400 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18EA695 for ; Wed, 4 Oct 2023 03:20:16 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qnyzB-0006b4-Ij; Wed, 04 Oct 2023 12:20:09 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnyzA-00B0Ww-JG; Wed, 04 Oct 2023 12:20:08 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1qnyzA-008v3I-9q; Wed, 04 Oct 2023 12:20:08 +0200 Date: Wed, 4 Oct 2023 12:20:08 +0200 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Paul Geurts Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] serial: imx: fix tx statemachine deadlock Message-ID: <20231004102008.giyogvnsc26ucx4k@pengutronix.de> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7bn7gd7f23wh6bot" Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 04 Oct 2023 03:20:21 -0700 (PDT) --7bn7gd7f23wh6bot Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Paul, On Wed, Oct 04, 2023 at 11:57:22AM +0200, Paul Geurts wrote: > 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. >=20 > 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. Sounds reasonable. A Fixes: line would be nice. > Signed-off-by: Paul Geurts > --- > drivers/tty/serial/imx.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c > index 13cb78340709..90a4b7841030 100644 > --- a/drivers/tty/serial/imx.c > +++ b/drivers/tty/serial/imx.c > @@ -421,13 +421,13 @@ static void imx_uart_stop_tx(struct uart_port *port) > ucr1 =3D imx_uart_readl(sport, UCR1); > imx_uart_writel(sport, ucr1 & ~UCR1_TRDYEN, UCR1); > =20 > + ucr4 =3D imx_uart_readl(sport, UCR4); > usr2 =3D 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; > } So the new thing is: If the hardware is still busy sending stuff but /dev/ttymxcX isn't open any more (i.e. .shutdown was called), the transmitter gets disabled. I wonder if in this case disabling the transmitter should be delayed until the shifter is empty? Or maybe this should be handled in .shutdown, that is only disable TCEN once the shifter is empty? Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | https://www.pengutronix.de/ | --7bn7gd7f23wh6bot Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmUdPFcACgkQj4D7WH0S /k6pIAgAhtQzFddfFAsyp+llHfHprz6jXLIyZ7bFBtvlyvmF9gW4YrfowVrrhW5j ITqbAMZ09+vg4YQn81euMB34qwkQJYv1oeQrdEb1aj/q991UySdETRiv9hujpxPo VShKNb3ktSOqqwbZSjlw+2+H1s5Vx4YGlVnNOz6J5pVMoZ6NEodp1iI9kiycs7Pf laxMn6XUXP4k1y/FO0D1fHXh4ZDvVbZA8wtchT0H8PNwC8SCTDHjWDa0qMlwl6ce yOY4kNo41VHZIMJ1z3nDRj9QOzwOk2Thloq4SU0vJPBXCcn6A9fZLrgjNqUYTJnC jUXlYXJmfBN6U9QnfewxKudVIxGgLA== =Y1On -----END PGP SIGNATURE----- --7bn7gd7f23wh6bot--