linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: imx: fix tx statemachine deadlock
@ 2023-10-04  9:57 Paul Geurts
  2023-10-04 10:20 ` Uwe Kleine-König
  2023-10-04 12:13 ` Greg KH
  0 siblings, 2 replies; 14+ messages in thread
From: Paul Geurts @ 2023-10-04  9:57 UTC (permalink / raw)
  To: gregkh, jirislaby, shawnguo, s.hauer, kernel, festevam, linux-imx,
	linux-kernel, linux-serial, linux-arm-kernel
  Cc: Paul Geurts

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.

Signed-off-by: Paul Geurts <paul_geurts@live.nl>
---
 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 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 = 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);
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-12-01 16:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-04  9:57 [PATCH] serial: imx: fix tx statemachine deadlock Paul Geurts
2023-10-04 10:20 ` Uwe Kleine-König
2023-10-05  8:51   ` Paul Geurts
2023-10-04 12:13 ` Greg KH
2023-11-24 12:38   ` [PATCH v2] " Paul Geurts
2023-11-24 12:45     ` Greg KH
2023-11-24 12:53   ` Paul Geurts
2023-11-24 12:58     ` Fabio Estevam
2023-11-24 13:03       ` Greg KH
2023-11-24 13:11         ` [PATCH v3] " Paul Geurts
2023-11-24 13:37           ` Rasmus Villemoes
2023-11-24 13:55             ` Paul Geurts
2023-11-30  9:09             ` Rasmus Villemoes
2023-12-01 16:55               ` Eberhard Stoll

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).