Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	Angelo Dureghello <angelo.dureghello@timesys.com>,
	Fugang Duan <fugang.duan@nxp.com>,
	Philippe Schenker <philippe.schenker@toradex.com>,
	Michael Walle <michael@walle.cc>
Subject: [PATCH 4/8] serial: fsl_lpuart: handle break and make sysrq work
Date: Tue, 11 May 2021 22:01:44 +0200	[thread overview]
Message-ID: <20210511200148.11934-5-michael@walle.cc> (raw)
In-Reply-To: <20210511200148.11934-1-michael@walle.cc>

Although there is already (broken) sysrq characters handling, a break
condition was never detected. There is also a possible deadlock because
we might call handle_sysrq() while still holding the port lock.

Add support for break detection and use the proper
uart_unlock_and_check_sysrq() to defer calling handle_sysrq().

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/tty/serial/fsl_lpuart.c | 36 ++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 37e02d992c0b..0a578ad31a19 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -910,6 +910,7 @@ static void lpuart32_rxint(struct lpuart_port *sport)
 	unsigned int flg, ignored = 0;
 	struct tty_port *port = &sport->port.state->port;
 	unsigned long rx, sr;
+	bool is_break;
 
 	spin_lock(&sport->port.lock);
 
@@ -924,14 +925,27 @@ static void lpuart32_rxint(struct lpuart_port *sport)
 		rx = lpuart32_read(&sport->port, UARTDATA);
 		rx &= UARTDATA_MASK;
 
-		if (uart_handle_sysrq_char(&sport->port, rx))
+		/*
+		 * The LPUART can't distinguish between a break and a framing error,
+		 * thus we assume it is a break if the received data is zero.
+		 */
+		is_break = sr & UARTSTAT_FE && !rx;
+
+		if (is_break && uart_handle_break(&sport->port))
+			continue;
+
+		if (uart_prepare_sysrq_char(&sport->port, rx))
 			continue;
 
 		if (sr & (UARTSTAT_PE | UARTSTAT_OR | UARTSTAT_FE)) {
-			if (sr & UARTSTAT_PE)
-				sport->port.icount.parity++;
-			else if (sr & UARTSTAT_FE)
+			if (sr & UARTSTAT_PE) {
+				if (is_break)
+					sport->port.icount.brk++;
+				else
+					sport->port.icount.parity++;
+			} else if (sr & UARTSTAT_FE) {
 				sport->port.icount.frame++;
+			}
 
 			if (sr & UARTSTAT_OR)
 				sport->port.icount.overrun++;
@@ -944,22 +958,24 @@ static void lpuart32_rxint(struct lpuart_port *sport)
 
 			sr &= sport->port.read_status_mask;
 
-			if (sr & UARTSTAT_PE)
-				flg = TTY_PARITY;
-			else if (sr & UARTSTAT_FE)
+			if (sr & UARTSTAT_PE) {
+				if (is_break)
+					flg = TTY_BREAK;
+				else
+					flg = TTY_PARITY;
+			} else if (sr & UARTSTAT_FE) {
 				flg = TTY_FRAME;
+			}
 
 			if (sr & UARTSTAT_OR)
 				flg = TTY_OVERRUN;
-
-			sport->port.sysrq = 0;
 		}
 
 		tty_insert_flip_char(port, rx, flg);
 	}
 
 out:
-	spin_unlock(&sport->port.lock);
+	uart_unlock_and_check_sysrq(&sport->port);
 
 	tty_flip_buffer_push(port);
 }
-- 
2.20.1


  parent reply	other threads:[~2021-05-11 20:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 20:01 [PATCH 0/8] serial: fsl_lpuart: sysrq, loopback support and fixes Michael Walle
2021-05-11 20:01 ` [PATCH 1/8] serial: fsl_lpuart: don't modify arbitrary data on lpuart32 Michael Walle
2021-05-11 20:01 ` [PATCH 2/8] serial: fsl_lpuart: use UARTDATA_MASK macro Michael Walle
2021-05-11 20:01 ` [PATCH 3/8] serial: fsl_lpuart: don't restore interrupt state in ISR Michael Walle
2021-05-12  9:25   ` Johan Hovold
2021-05-12  9:42     ` Michael Walle
2021-05-11 20:01 ` Michael Walle [this message]
2021-05-12  9:30   ` [PATCH 4/8] serial: fsl_lpuart: handle break and make sysrq work Johan Hovold
2021-05-12  9:46     ` Michael Walle
2021-05-12 10:07       ` Johan Hovold
2021-05-12 10:31         ` Michael Walle
2021-05-12 11:18           ` Johan Hovold
2021-05-11 20:01 ` [PATCH 5/8] serial: fsl_lpuart: remove RTSCTS handling from get_mctrl() Michael Walle
2021-05-11 20:01 ` [PATCH 6/8] serial: fsl_lpuart: remove manual RTSCTS control from 8-bit LPUART Michael Walle
2021-05-11 20:01 ` [PATCH 7/8] serial: fsl_lpuart: add loopback support Michael Walle
2021-05-11 20:01 ` [PATCH 8/8] serial: fsl_lpuart: disable DMA for console and fix sysrq Michael Walle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210511200148.11934-5-michael@walle.cc \
    --to=michael@walle.cc \
    --cc=angelo.dureghello@timesys.com \
    --cc=fugang.duan@nxp.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=philippe.schenker@toradex.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox