From nobody Sat Jun 13 17:05:56 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FC3830BF6B; Wed, 6 May 2026 12:16:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069770; cv=none; b=ghrJLK0q5IxFYs7SYyx5Zv5dEyaNKoNqo/8JuydsuBi/DCG7xumGy4z9g7fdWfRMZTyBCDj2ry0BLIIPqUQ+0e5pFZEKjIYTfQnZaGx9sDasdL0oJj2S/gvk7s5uozFOu/DYojc9pw0P/U4dklFAbG7hBmBXx55KGW2In2yh+zI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069770; c=relaxed/simple; bh=avWyrmKeg9ZZo9XDck9W7JKhxinIKZr03E1hHcoJdSo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cCvZfHQG4urzX5n/VjQV+4HcRWd3ch1kdLNzcOL8oXkg0D/h8f3qgz6HFaVE0ikaVw5HsFhIbV+8mD2ZSiyXvaMSFYVzQjrhyEd5iIfqumMMHWmb62VH86eECrAS7Mu50NfPSsqpuV/bzUUgMPcId5kRsVWSMjbAB08jLkgCCKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ND1fDR4E; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=39IC3B2H; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ND1fDR4E"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="39IC3B2H" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1778069767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SXGNRsgNxJJCUIR2fDCouVm7b7oiVL7S8VFK1HxgPzI=; b=ND1fDR4EE9Fgxsko4CKSyqluJHTm4xwpQ7Hh0LVGD56Fh6TqMdHw3G72/cGqqGUCBBn7eC yfJ4h1zkFcERV6xL5X8zdQeK2r+SlsXBDrmx6HhFZxVn/a6ZhaLccZ+vAePg8DeW/bFxda ZnuqLSihFrqGQUYQIp9kOCe/Eq36tKjmBSdizDxhsXkZ6pXQVFqIiRXb0A+v4YTppSbOGd BusPVfWagkUcZSCSK8PzwQTejhVrBCycHOFrevqoCD2yVKS5JoJ0Y6FnucbUV6Z8n3boF2 FGlNPRRnkLUC4l4YA8t43/fNlDjg7eYxlk3Ix849G+tib6ox8SRcyL+43KbbqQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1778069767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SXGNRsgNxJJCUIR2fDCouVm7b7oiVL7S8VFK1HxgPzI=; b=39IC3B2HDxqF3inerDCUVGlTyYlhfDs2w2PUCj0lMx0x2Doedhzblu8xBejVw1/ohgfCte zWl03j7Bv091jQAQ== To: "Greg Kroah-Hartman" , Jiri Slaby Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH tty v4 1/6] serial: core: Add dedicated uart_port field for console flow Date: Wed, 6 May 2026 14:21:56 +0206 Message-ID: <20260506121606.5805-2-john.ogness@linutronix.de> In-Reply-To: <20260506121606.5805-1-john.ogness@linutronix.de> References: <20260506121606.5805-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently the UPF_CONS_FLOW bit in the uart_port.flags field is used by serial console drivers to identify if a user has configured flow control on the console. Usually this policy is setup during early boot, but can be changed at runtime. The bits in uart_port.flags are either hardware and driver properties that are initialized before usage or are properties that can be changed via the tty layer. The UPF_CONS_FLOW bit is an exception because it is a console-only policy that can change at runtime and its setting and usage have nothing to do with the tty layer. This actually causes a problem for its usage because uart_port.flags is synchronized by a related tty_port.mutex, but a console has no relation to a tty (other than sharing the port). This is probably why console flow control is not properly available for most serial drivers. And it is hindering being able to provide a proper implementation. Commit d01f4d181c92 ("serial: core: Privatize tty->hw_stopped") addressed a similar issue to deal with software assisted CTS flow state tracking. Add a new uart_port boolean field "cons_flow" to store the user configuration for console flow control. Add getter/setter wrappers to allow for adding more policies later and/or locking constraint validation. Mark UPF_CONS_FLOW as deprecated. Signed-off-by: John Ogness --- include/linux/serial_core.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 666430b478997..4f7bbdd900176 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -533,6 +533,7 @@ struct uart_port { #define UPF_HARD_FLOW ((__force upf_t) (UPF_AUTO_CTS | UPF_AUTO_RTS)) /* Port has hardware-assisted s/w flow control */ #define UPF_SOFT_FLOW ((__force upf_t) BIT_ULL(22)) +/* Deprecated: use uart_set_cons_flow_enabled()/uart_cons_flow_enabled() i= nstead. */ #define UPF_CONS_FLOW ((__force upf_t) BIT_ULL(23)) #define UPF_SHARE_IRQ ((__force upf_t) BIT_ULL(24)) #define UPF_EXAR_EFR ((__force upf_t) BIT_ULL(25)) @@ -567,6 +568,7 @@ struct uart_port { #define UPSTAT_SYNC_FIFO ((__force upstat_t) (1 << 5)) =20 bool hw_stopped; /* sw-assisted CTS flow state */ + bool cons_flow; /* user specified console flow control */ unsigned int mctrl; /* current modem ctrl settings */ unsigned int frame_time; /* frame timing in ns */ unsigned int type; /* port type */ @@ -1163,6 +1165,16 @@ static inline bool uart_softcts_mode(struct uart_por= t *uport) return ((uport->status & mask) =3D=3D UPSTAT_CTS_ENABLE); } =20 +static inline void uart_set_cons_flow_enabled(struct uart_port *uport, boo= l enabled) +{ + uport->cons_flow =3D enabled; +} + +static inline bool uart_cons_flow_enabled(const struct uart_port *uport) +{ + return uport->cons_flow; +} + /* * The following are helper functions for the low level drivers. */ --=20 2.47.3 From nobody Sat Jun 13 17:05:56 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F00E441033; Wed, 6 May 2026 12:16:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069771; cv=none; b=mroLRdhq4riAaRRm5L2aaH0fsSjbbPGs4x6wRnscQtvPodPI4AR9Y6Sul96e9r70+FtEiZ7dfe8tiE0sQXNBQOL6OWYgHnqtQrjMAyZPRJazFfmRwkMyDLzPZh1XYEvUxlmLbHrKXk8kXhSAvAZD5xMf71CiZ87DJ2hQGaoBoqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069771; c=relaxed/simple; bh=oGdnYzwS2KxBBPOTkydJBt0oLCQIbgX6je1aQYE6Afo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AJVBrWuqGibX7oi70CJE+dcirs9A0Ufx+aTr1bATT0zMAWLILHjrb+grZLFzw/EQOOJJiAky0V7PZNacDtonUR/CWQ7nlUUpn2Zs8nDqQrZRvRVP3YuxeZ4LPARUMM7ZOPXsvvPVq84x2zkakclLqgNVkSt+mPsk8lk+tZYcahM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xFWnkskh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gbuMKKHK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xFWnkskh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gbuMKKHK" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1778069768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vE7RdfFrv3z5SE91ZG6pmeFTFDF5vNPcNpZ+sQ+T1TI=; b=xFWnkskhPGgbQOkrcHPHBsstkhAM00sSjLFAeRB7VzAGCrQd59JlHjM9TCgWEEmGIKRJ7/ k2bYdKFleAMOKjMHNIcEOl/uTVR6/5zhe5UfT+ah4SV/9UC470291f5Cy/OCazslWDWX3V xI6AOJHY9Vb5Z2Lp18gttQNdO12+m3FCXz6EmHkgsFQUYkycZ8y3QKUZ5oZcfRs2vDSzmj YmuN2wQMvqAVxj4MMcrOqjRtJ2ArZt9u3FxssTpjJjUKGlc5XPAzpreqPcNTFrUBhU7jHQ YG0pjdXUpioFaEKxBXJ8HfUjc7XqkwLCAtnbUgsUvojn6RE1WMGAdJ0N6g3NbA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1778069768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vE7RdfFrv3z5SE91ZG6pmeFTFDF5vNPcNpZ+sQ+T1TI=; b=gbuMKKHK9iOhMyI9k4nDA6P3GImdUXN5z+ClLWkNQ4asJJ6vbp9KZQCLfDC7BZWxClqLI0 b8SM7ivQMkIu1fDQ== To: "Greg Kroah-Hartman" , Jiri Slaby Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, Krzysztof Kozlowski , Alim Akhtar , "David S. Miller" , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , Thomas Fourier , Kees Cook , linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, sparclinux@vger.kernel.org Subject: [PATCH tty v4 2/6] serial: Replace driver usage of UPF_CONS_FLOW Date: Wed, 6 May 2026 14:21:57 +0206 Message-ID: <20260506121606.5805-3-john.ogness@linutronix.de> In-Reply-To: <20260506121606.5805-1-john.ogness@linutronix.de> References: <20260506121606.5805-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather than using the UPF_CONS_FLOW bit of uart_port.flags to track the user configuration of console flow control, use the newly added uart_port.cons_flow (via its getter/setter functions). A coccinelle script was used to perform the search/replace. Note1: The sh-sci driver is blindly copying platform data configuration flags to uart_port.flags. Thus UPF_CONS_FLOW could get set for uart_port.flags. A follow-up commit will address this. Note2: The samsung_tty driver is using UPF_CONS_FLOW as a platform data configuration flag. However, the driver explicitly checks for this configuration flag and thus setting UPF_CONS_FLOW in uart_port.flags is avoided. Signed-off-by: John Ogness --- drivers/tty/serial/8250/8250_port.c | 4 ++-- drivers/tty/serial/bcm63xx_uart.c | 2 +- drivers/tty/serial/omap-serial.c | 2 +- drivers/tty/serial/pch_uart.c | 2 +- drivers/tty/serial/pxa.c | 2 +- drivers/tty/serial/samsung_tty.c | 8 ++++---- drivers/tty/serial/serial_txx9.c | 4 ++-- drivers/tty/serial/sunsu.c | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/= 8250_port.c index af78cc02f38e7..dbed5e5767541 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1988,7 +1988,7 @@ static void wait_for_xmitr(struct uart_8250_port *up,= int bits) wait_for_lsr(up, bits); =20 /* Wait up to 1s for flow control if necessary */ - if (up->port.flags & UPF_CONS_FLOW) { + if (uart_cons_flow_enabled(&up->port)) { for (tmout =3D 1000000; tmout; tmout--) { unsigned int msr =3D serial_in(up, UART_MSR); up->msr_saved_flags |=3D msr & MSR_SAVE_FLAGS; @@ -3351,7 +3351,7 @@ void serial8250_console_write(struct uart_8250_port *= up, const char *s, * it regardless of the CTS state. Therefore, only use fifo * if we don't use control flow. */ - !(up->port.flags & UPF_CONS_FLOW); + !uart_cons_flow_enabled(&up->port); =20 if (likely(use_fifo)) serial8250_console_fifo_write(up, s, count); diff --git a/drivers/tty/serial/bcm63xx_uart.c b/drivers/tty/serial/bcm63xx= _uart.c index 51df9d2d8bfc5..544695cb184c3 100644 --- a/drivers/tty/serial/bcm63xx_uart.c +++ b/drivers/tty/serial/bcm63xx_uart.c @@ -675,7 +675,7 @@ static void wait_for_xmitr(struct uart_port *port) } =20 /* Wait up to 1s for flow control if necessary */ - if (port->flags & UPF_CONS_FLOW) { + if (uart_cons_flow_enabled(port)) { tmout =3D 1000000; while (--tmout) { unsigned int val; diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-ser= ial.c index 0b85f47ff19e0..a689d190940cf 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -1092,7 +1092,7 @@ static void __maybe_unused wait_for_xmitr(struct uart= _omap_port *up) } while (!uart_lsr_tx_empty(status)); =20 /* Wait up to 1s for flow control if necessary */ - if (up->port.flags & UPF_CONS_FLOW) { + if (uart_cons_flow_enabled(&up->port)) { for (tmout =3D 1000000; tmout; tmout--) { unsigned int msr =3D serial_in(up, UART_MSR); =20 diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index 6729d8e83c3c5..2f72cd62e2488 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -1444,7 +1444,7 @@ static void wait_for_xmitr(struct eg20t_port *up, int= bits) } =20 /* Wait up to 1s for flow control if necessary */ - if (up->port.flags & UPF_CONS_FLOW) { + if (uart_cons_flow_enabled(&up->port)) { unsigned int tmout; for (tmout =3D 1000000; tmout; tmout--) { unsigned int msr =3D ioread8(up->membase + UART_MSR); diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c index fea0255067ccd..10fc8990579b5 100644 --- a/drivers/tty/serial/pxa.c +++ b/drivers/tty/serial/pxa.c @@ -573,7 +573,7 @@ static void wait_for_xmitr(struct uart_pxa_port *up) } while (!uart_lsr_tx_empty(status)); =20 /* Wait up to 1s for flow control if necessary */ - if (up->port.flags & UPF_CONS_FLOW) { + if (uart_cons_flow_enabled(&up->port)) { tmout =3D 1000000; while (--tmout && ((serial_in(up, UART_MSR) & UART_MSR_CTS) =3D=3D 0)) diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_= tty.c index e27806bf2cf3e..2f94fc798cffb 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -319,7 +319,7 @@ static void s3c24xx_serial_stop_tx(struct uart_port *po= rt) ourport->tx_enabled =3D 0; ourport->tx_in_progress =3D 0; =20 - if (port->flags & UPF_CONS_FLOW) + if (uart_cons_flow_enabled(port)) s3c24xx_serial_rx_enable(port); =20 ourport->tx_mode =3D 0; @@ -493,7 +493,7 @@ static void s3c24xx_serial_start_tx(struct uart_port *p= ort) struct tty_port *tport =3D &port->state->port; =20 if (!ourport->tx_enabled) { - if (port->flags & UPF_CONS_FLOW) + if (uart_cons_flow_enabled(port)) s3c24xx_serial_rx_disable(port); =20 ourport->tx_enabled =3D 1; @@ -781,7 +781,7 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx= _uart_port *ourport) uerstat =3D rd_regl(port, S3C2410_UERSTAT); ch =3D rd_reg(port, S3C2410_URXH); =20 - if (port->flags & UPF_CONS_FLOW) { + if (uart_cons_flow_enabled(port)) { bool txe =3D s3c24xx_serial_txempty_nofifo(port); =20 if (ourport->rx_enabled) { @@ -1830,7 +1830,7 @@ static int s3c24xx_serial_init_port(struct s3c24xx_ua= rt_port *ourport, =20 if (cfg->uart_flags & UPF_CONS_FLOW) { dev_dbg(port->dev, "enabling flow control\n"); - port->flags |=3D UPF_CONS_FLOW; + uart_set_cons_flow_enabled(port, true); } =20 /* sort our the physical and virtual addresses for each UART */ diff --git a/drivers/tty/serial/serial_txx9.c b/drivers/tty/serial/serial_t= xx9.c index 436a559234dfe..4ae9a45c8e3a3 100644 --- a/drivers/tty/serial/serial_txx9.c +++ b/drivers/tty/serial/serial_txx9.c @@ -422,7 +422,7 @@ static void wait_for_xmitr(struct uart_port *up) udelay(1); =20 /* Wait up to 1s for flow control if necessary */ - if (up->flags & UPF_CONS_FLOW) { + if (uart_cons_flow_enabled(up)) { tmout =3D 1000000; while (--tmout && (sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS)) @@ -857,7 +857,7 @@ serial_txx9_console_write(struct console *co, const cha= r *s, unsigned int count) * Disable flow-control if enabled (and unnecessary) */ flcr =3D sio_in(up, TXX9_SIFLCR); - if (!(up->flags & UPF_CONS_FLOW) && (flcr & TXX9_SIFLCR_TES)) + if (!uart_cons_flow_enabled(up) && (flcr & TXX9_SIFLCR_TES)) sio_out(up, TXX9_SIFLCR, flcr & ~TXX9_SIFLCR_TES); =20 uart_console_write(up, s, count, serial_txx9_console_putchar); diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c index 6505a1930da9a..4ff3e5c41dab9 100644 --- a/drivers/tty/serial/sunsu.c +++ b/drivers/tty/serial/sunsu.c @@ -1245,7 +1245,7 @@ static void wait_for_xmitr(struct uart_sunsu_port *up) } while (!uart_lsr_tx_empty(status)); =20 /* Wait up to 1s for flow control if necessary */ - if (up->port.flags & UPF_CONS_FLOW) { + if (uart_cons_flow_enabled(&up->port)) { tmout =3D 1000000; while (--tmout && ((serial_in(up, UART_MSR) & UART_MSR_CTS) =3D=3D 0)) --=20 2.47.3 From nobody Sat Jun 13 17:05:56 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC93A4418DB; Wed, 6 May 2026 12:16:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069771; cv=none; b=ZsJgbJnGfCOdgBTU7gS7pTQ+6vY/+jYYRUpK58uZgebLKriownNzN6eAFAfFn479sfKJTGK73LlwmJY3E5nXavqqSk5OqyHfpHcu/v56QsA1ZqPKaUMsuFZd/xrgT1UvwjVqjOTo0i3VE/qLzSwqMh9tLAwv0T0JSdobAqOy6Fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069771; c=relaxed/simple; bh=8IiTdQ06fzqy60Mm7+cFMWGC38P/MeXTqUDPLPEZXqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ucFlhZZGUphmQM7ufTtiT9LYf3/3a+ERViae3iyuLarQWVsSn45yz2sLeKn4UK+tt8gQPtHDjJ7H+gLCJPXiDY72P41fxOGBF/vAox8+6+rVzXmxQIdtIegI1qrUf98S/hnX1LRUdR8yh6cNbJ1JrFxmQ/Jz81UexS7ee5KgIi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JaR8OlvU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kdPWKe4g; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JaR8OlvU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kdPWKe4g" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1778069768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fg3GZ8rSJr7vLPo7KPLI57+/qD3MxzntSQWRoVBb4to=; b=JaR8OlvUAsTtZ10Yo3HbI50WIIRszAI6nVd+MUj0P4znxqRN6gs4tRrQZB7QD9+QfiLUv2 kqsV387TJ3s+adkdmfuaT3JzRSrJ/THUF5LXsdZ2vBJGfuQD4utYBok9nbICkWhu2K+yBZ 5W43rGNj23+zk0QuEItAYXvleIaN/kEzj+/SulNkBhGKKpuw0VOvxbHE34qIWWyT97d1cc ZimRAtPm5uviICqP7H56JWsf4/KHuMKqTPhikZ98UUz4btLAJSvEjXJErqHsrimV8dnYHP b4JZxRuBZFBE1jeLnfjIlrXALB5n0RK7HeBZpLGQmbCFW08P6Iy/raEngvvG4Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1778069768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fg3GZ8rSJr7vLPo7KPLI57+/qD3MxzntSQWRoVBb4to=; b=kdPWKe4gO+V4WODj7TFgnkaiOEO2mkmXK2McTyTh/66k2zHmJ8UV10UcaaZy741KhLFGDU Xfkz1e2d33BYByAw== To: "Greg Kroah-Hartman" , Jiri Slaby Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, Biju Das , Geert Uytterhoeven , Lad Prabhakar , Thierry Bultel , linux-serial@vger.kernel.org Subject: [PATCH tty v4 3/6] serial: sh-sci: Avoid deprecated UPF_CONS_FLOW Date: Wed, 6 May 2026 14:21:58 +0206 Message-ID: <20260506121606.5805-4-john.ogness@linutronix.de> In-Reply-To: <20260506121606.5805-1-john.ogness@linutronix.de> References: <20260506121606.5805-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid setting the uart_port.flags deprecated UPF_CONS_FLOW bit if it has been configured in the platform data. Use the new cons_flow wrappers instead. Signed-off-by: John Ogness --- drivers/tty/serial/sh-sci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 6c819b6b24258..a1328a3b6638d 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3369,9 +3369,12 @@ static int sci_init_single(struct platform_device *d= ev, } =20 port->type =3D SCI_PUBLIC_PORT_ID(p->type); - port->flags =3D UPF_FIXED_PORT | UPF_BOOT_AUTOCONF | p->flags; + port->flags =3D UPF_FIXED_PORT | UPF_BOOT_AUTOCONF | + (p->flags & ~UPF_CONS_FLOW); port->fifosize =3D sci_port->params->fifosize; =20 + uart_set_cons_flow_enabled(port, p->flags & UPF_CONS_FLOW); + if (p->type =3D=3D PORT_SCI && !dev->dev.of_node) { if (sci_port->reg_size >=3D 0x20) port->regshift =3D 2; --=20 2.47.3 From nobody Sat Jun 13 17:05:56 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF9184418E3; Wed, 6 May 2026 12:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069772; cv=none; b=UFfAzikttPn/TCqrCdSNmyHQ5qxS2wET+VTlW0A4NV2Yqmt7MzCkeI+0GbHHPQ8RG6AOWsZVFfWbykFfF2El0s6fbgJj1JDbgGpI5+FhnRqQoI/sA6K0jMbezXtK26jFonXG/9BrZeehSsfExthzQIi6K5RjbA6+rlvyef0Rl9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069772; c=relaxed/simple; bh=HqK9WI/4RERvi25TuZkJmKmoMaOvZ4CUokoGM8wn3Yw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cBSWa0DVrDlaTC2C4vv/q9Wg8GRTUoUqzrnduX3GnTtLC5KKIhdAtvorys8JcfWxmU9UGIyz8Feya9Ko0s7HhTjspwRGrlQWD5VPEyYTKSNorbvYqlFoeTbNeCvIdhLZjDYe0ZKeqJB4ARa5CXYtokRyniQF2VEunLuGE/2dZh8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XTtN0F9b; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rQf/Z1Uh; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XTtN0F9b"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rQf/Z1Uh" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1778069768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SrOyFhVPontbzgEAbyb/2JFaAOM/AqtJ/5aPb0vTYtY=; b=XTtN0F9btUC8YasjBJhOye0iwPO+dbwbp/eOOolW3QOjE9rNmdQXkIVebs0Hw6tBOk2yj4 rCf60YOg7oPmy80cMYoDTND+4tloB1XHRjGd+4HNBl7CBUNnZU6iRVIs+SMrYv1xvtLmpl VQmJI7czLtsRJ9QUhi4Uonm8Io+kfNh5ZaX8gjTC1NcjRCL7wKpNzJ3+4qq1P9qinqdC7e daBIDdwAZr8+Tao7AKqn1Jrh0nC1KfoaKNXeJEyQ1m0XTj6OINtmnpLEM8bP5wZI5jO73C eTxz2SPfSSbtzqIHTbZqJ6QBl9Wipzt8YjF19FfM7gyROaghyoUJSmYWElt1jg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1778069768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SrOyFhVPontbzgEAbyb/2JFaAOM/AqtJ/5aPb0vTYtY=; b=rQf/Z1Uhmgn3jow7oP5aWU2mRJyRGhfJkbEeZDV4hB7QLigd1sN5ZbM2IfWGm5DAY4HvLc IeMgtiy0QLAT5cAA== To: "Greg Kroah-Hartman" , Jiri Slaby Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Osama Abdelkader , Kees Cook , Ingo Molnar , linux-serial@vger.kernel.org Subject: [PATCH tty v4 4/6] serial: 8250: Set cons_flow on port registration Date: Wed, 6 May 2026 14:21:59 +0206 Message-ID: <20260506121606.5805-5-john.ogness@linutronix.de> In-Reply-To: <20260506121606.5805-1-john.ogness@linutronix.de> References: <20260506121606.5805-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since console flow control policy is no longer part of uart_port.flags, explicitly set the policy for the port. Signed-off-by: John Ogness --- drivers/tty/serial/8250/8250_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/= 8250_core.c index a428e88938eb7..b0275204e1167 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -746,6 +746,8 @@ int serial8250_register_8250_port(const struct uart_825= 0_port *up) uart->lsr_save_mask =3D up->lsr_save_mask; uart->dma =3D up->dma; =20 + uart_set_cons_flow_enabled(&uart->port, uart_cons_flow_enabled(&up->port)= ); + /* Take tx_loadsz from fifosize if it wasn't set separately */ if (uart->port.fifosize && !uart->tx_loadsz) uart->tx_loadsz =3D uart->port.fifosize; --=20 2.47.3 From nobody Sat Jun 13 17:05:56 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42A1B44D020; Wed, 6 May 2026 12:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069773; cv=none; b=egZPYSRua3hAAil5KxWpfXB0kAS2JAVEgI/SU6TO9ULjgp23UcXcjtoLtz+2QJ3wbJgBpVFsAhwXi5SLjDNtpwCbPdR06dvrB72VhM4hVrdnckTKNKGZ+Wr1TebdxXvRa5LkeO2kOwNQxIqxEz/CRJ7MvQ6RYMxahjHX3Y/ttMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069773; c=relaxed/simple; bh=SB34X/ZdUpzR6E7fbHBweup02Nl2fDDJs+9DMnt2sOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hDUfup323FU950qNdNNC76PCjMsmQsoMMhI5hCXfutkDQx+GT/HDeVXxp+n25c7hCkdjLU/QHkn/dfen7jL6EJlH09x16duKq+KJ0wPh+gL4uRhchX/jKBNyufguzBJi7zk4Iugco3q5A6B7LXaZ/dzDMSpEoIzLj0I4VEF4o+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vmx4N+4Z; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YhRd+XBI; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vmx4N+4Z"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YhRd+XBI" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1778069769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AHAqtTbvwO8xcfrhhVzAqkOIkaPCLZmg1OdSKQBShJY=; b=vmx4N+4ZD8ZtCecZ3/fS+PVChHQ6FkU6NZPXuVpZ48fZPB2e9wILqgifq4f0NkzTqd8jCg JgdEAy8fJi3t7WMpHixD5hlPs61ECqztD/AzNFA34Y0aELAgDCDHCRZSDCw8140MLwYown GzbMmSEM4X6ZxSoyiiAjxYTu4rvfuJHjCu8Ayz33LJo+P83jnBDPytEcZZi6R3i+Wnl4jC 0w42e5G63kODdlgCo5XSTlHt0MawCQzvviIm2cXqBscXLgsKMCCC31oXFXYhNvO+Fl0BX9 bifSeaIEyX/heZLeHwAPgido1wUNifzb+6r/mLVmzjJ554Qdd0gbBCM/j7uT/Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1778069769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AHAqtTbvwO8xcfrhhVzAqkOIkaPCLZmg1OdSKQBShJY=; b=YhRd+XBI4sxmJsa98D1SN3IWbItEqGq735CxSRCZq3OOk8Sm8IlCBuXXOwLfn6x88e/n8u 2NeQM70luCZHJuDg== To: "Greg Kroah-Hartman" , Jiri Slaby Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , linux-serial@vger.kernel.org Subject: [PATCH tty v4 5/6] serial: 8250: Check LSR timeout on console flow control Date: Wed, 6 May 2026 14:22:00 +0206 Message-ID: <20260506121606.5805-6-john.ogness@linutronix.de> In-Reply-To: <20260506121606.5805-1-john.ogness@linutronix.de> References: <20260506121606.5805-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" wait_for_xmitr() calls wait_for_lsr() to wait for the transmission registers to be empty. wait_for_lsr() can timeout after a reasonable amount of time. When console flow control is active, wait_for_xmitr() additionally polls CTS, waiting for the peer to signal that it is ready to receive more data. If hardware flow control is enabled (auto CTS) and the peer deasserts CTS, wait_for_lsr() will timeout. If additionally console flow control is active and while polling CTS the peer asserts CTS, the console will assume it can immediately transmit, even though the transmission registers may not be empty. This can lead to data loss. Avoid this problem by performing an extra wait_for_lsr() upon CTS assertion if wait_for_lsr() previously timed out. Signed-off-by: John Ogness --- drivers/tty/serial/8250/8250_port.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/= 8250_port.c index dbed5e5767541..719789013f6df 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1984,16 +1984,20 @@ static bool wait_for_lsr(struct uart_8250_port *up,= int bits) static void wait_for_xmitr(struct uart_8250_port *up, int bits) { unsigned int tmout; + bool tx_ready; =20 - wait_for_lsr(up, bits); + tx_ready =3D wait_for_lsr(up, bits); =20 /* Wait up to 1s for flow control if necessary */ if (uart_cons_flow_enabled(&up->port)) { for (tmout =3D 1000000; tmout; tmout--) { unsigned int msr =3D serial_in(up, UART_MSR); up->msr_saved_flags |=3D msr & MSR_SAVE_FLAGS; - if (msr & UART_MSR_CTS) + if (msr & UART_MSR_CTS) { + if (!tx_ready) + wait_for_lsr(up, bits); break; + } udelay(1); touch_nmi_watchdog(); } --=20 2.47.3 From nobody Sat Jun 13 17:05:56 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 426AA44D01F; Wed, 6 May 2026 12:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069774; cv=none; b=YEFORl9Atq2BQ57AZNO70JCq4eCiOkFB4U7MirI9mPusYf0I38zLNWoeop5Rk39JRjyjp875c9dLnrLULbB+mCqqM30hieVWUyiOMnnjVyDsRu1utjrB3U8CxReI+/Pgcs3YMig7SFek+Jo4vrW3fOnLhMRJwu3neqVFtOXh944= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778069774; c=relaxed/simple; bh=OwK2+KUiqVlBtuRKWTGsaku1Osmx+eiL0WY4SFFVsOc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NTM4zXhDUE2dCEdKdLYXQMsorhxacrtGWMGpsbUTtGjZq0O0LPbByJQqMXqQUJsy3nFLgq6S9cO9SJuQkdkOX+mSFM6TgB576y1QzhR64Jiue2vbnWdmSKlPURy8HElDPeNkQKr0dXpEL0AA23WZHWFXqmcALd8XPB9uI7uVPO4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WBLLmWLn; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xS3RfLb5; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WBLLmWLn"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xS3RfLb5" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1778069770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rAPOjJugKWAvr3Uc5M20TcCUXRCkx0HO6mcN/GZ90rA=; b=WBLLmWLnlmpWwVAjsBVQKsDU43a2+1pi1EuRE2heYyjd6IlXSvOYOjXATVJNm8k33+EOYx jPqAziBN0J51e+eVD/16PfRnsj16rHXsXOiQIcPS/NKdTwS8LMh+gWJL7NDKF0fUFmF5SO ZK+/bHUP913QrEc/z8pphy5L9WM4CpD8+kzS0jSvXEj38SIFe+6H0+1o/b4GifqdIa/0hV 3HL+9zK27mO6ggjfwldy0XCows6PgshdC+f6o9scyWQV9vQcjFnH2CVuQkx5DGF/0UZQKr VmYpcfHXiyvbOPLWsK3HFN23olIoDeI0KBHn2YktMwUFgEAx84iQ/Zvv+mJrIw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1778069770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rAPOjJugKWAvr3Uc5M20TcCUXRCkx0HO6mcN/GZ90rA=; b=xS3RfLb5iBZfRTrJhAEwrA3n9BiVnPdiQrXAhBMlUFbR/kpD7vW+aiXgyxAWAVn6O4ogxM ioZHKGJgCSDZF0Bw== To: "Greg Kroah-Hartman" , Jiri Slaby Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Ingo Molnar , Kees Cook , Xin Zhao , Joseph Tilahun , Krzysztof Kozlowski , Lukas Wunner , "Dr. David Alan Gilbert" , linux-serial@vger.kernel.org Subject: [PATCH tty v4 6/6] serial: 8250: Add support for console flow control Date: Wed, 6 May 2026 14:22:01 +0206 Message-ID: <20260506121606.5805-7-john.ogness@linutronix.de> In-Reply-To: <20260506121606.5805-1-john.ogness@linutronix.de> References: <20260506121606.5805-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The kernel documentation specifies that the console option 'r' can be used to enable hardware flow control for console writes. The 8250 driver does include code for hardware flow control on the console if cons_flow is set, but there is no code path that actually sets this. However, that is not the only issue. The problems are: 1. Specifying the console option 'r' does not lead to cons_flow being set. 2. Even if cons_flow would be set, serial8250_register_8250_port() clears it. 3. When the console option 'r' is specified, uart_set_options() attempts to initialize the port for CRTSCTS. However, afterwards it does not set the UPSTAT_CTS_ENABLE status bit and therefore on boot, uart_cts_enabled() is always false. This policy bit is important for console drivers as a criteria if they may poll CTS. 4. Even though uart_set_options() attempts to initialize the port for CRTSCTS, the 8250 set_termios() callback does not enable the RTS signal (TIOCM_RTS) and thus the hardware is not properly initialized for CTS polling. 5. Even if modem control was properly setup for CTS polling (TIOCM_RTS), uart_configure_port() clears TIOCM_RTS, thus breaking CTS polling. 6. wait_for_xmitr() and serial8250_console_write() use cons_flow to decide if CTS polling should occur. However, the condition should also include a check that it is not in RS485 mode and CRTSCTS is actually enabled in the hardware. Address all these issues as conservatively as possible by gating them behind checks focussed on the user specifying console hardware flow control support and the hardware being configured for CTS polling at the time of the write to the UART. Since checking the UPSTAT_CTS_ENABLE status bit is a part of the new condition gate, these changes also support runtime termios updates to disable/enable CRTSCTS. Signed-off-by: John Ogness --- drivers/tty/serial/8250/8250_core.c | 6 +++++- drivers/tty/serial/8250/8250_port.c | 13 +++++++++++-- drivers/tty/serial/serial_core.c | 21 ++++++++++++++++++++- include/linux/serial_core.h | 8 ++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/= 8250_core.c index b0275204e1167..1f03da85e3414 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -693,6 +693,7 @@ static void serial_8250_overrun_backoff_work(struct wor= k_struct *work) int serial8250_register_8250_port(const struct uart_8250_port *up) { struct uart_8250_port *uart; + bool cons_flow; int ret; =20 if (up->port.uartclk =3D=3D 0) @@ -716,6 +717,9 @@ int serial8250_register_8250_port(const struct uart_825= 0_port *up) if (uart->port.type =3D=3D PORT_8250_CIR) return -ENODEV; =20 + /* Preserve specified console flow control. */ + cons_flow =3D uart_cons_flow_enabled(&uart->port); + if (uart->port.dev) uart_remove_one_port(&serial8250_reg, &uart->port); =20 @@ -746,7 +750,7 @@ int serial8250_register_8250_port(const struct uart_825= 0_port *up) uart->lsr_save_mask =3D up->lsr_save_mask; uart->dma =3D up->dma; =20 - uart_set_cons_flow_enabled(&uart->port, uart_cons_flow_enabled(&up->port)= ); + uart_set_cons_flow_enabled(&uart->port, uart_cons_flow_enabled(&up->port)= | cons_flow); =20 /* Take tx_loadsz from fifosize if it wasn't set separately */ if (uart->port.fifosize && !uart->tx_loadsz) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/= 8250_port.c index 719789013f6df..9ba3876bffa50 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1989,7 +1989,7 @@ static void wait_for_xmitr(struct uart_8250_port *up,= int bits) tx_ready =3D wait_for_lsr(up, bits); =20 /* Wait up to 1s for flow control if necessary */ - if (uart_cons_flow_enabled(&up->port)) { + if (uart_console_hwflow_active(&up->port)) { for (tmout =3D 1000000; tmout; tmout--) { unsigned int msr =3D serial_in(up, UART_MSR); up->msr_saved_flags |=3D msr & MSR_SAVE_FLAGS; @@ -2786,6 +2786,12 @@ serial8250_do_set_termios(struct uart_port *port, st= ruct ktermios *termios, serial8250_set_efr(port, termios); serial8250_set_divisor(port, baud, quot, frac); serial8250_set_fcr(port, termios); + /* Consoles manually poll CTS for hardware flow control. */ + if (uart_console(port) && + !(port->rs485.flags & SER_RS485_ENABLED) + && termios->c_cflag & CRTSCTS) { + port->mctrl |=3D TIOCM_RTS; + } serial8250_set_mctrl(port, port->mctrl); } =20 @@ -3355,7 +3361,7 @@ void serial8250_console_write(struct uart_8250_port *= up, const char *s, * it regardless of the CTS state. Therefore, only use fifo * if we don't use control flow. */ - !uart_cons_flow_enabled(&up->port); + !uart_console_hwflow_active(&up->port); =20 if (likely(use_fifo)) serial8250_console_fifo_write(up, s, count); @@ -3425,6 +3431,9 @@ int serial8250_console_setup(struct uart_port *port, = char *options, bool probe) if (ret) return ret; =20 + /* Track user-specified console flow control. */ + uart_set_cons_flow_enabled(port, flow =3D=3D 'r'); + if (port->dev) pm_runtime_get_sync(port->dev); =20 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c index 89cebdd278410..840336f95c5f6 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2235,6 +2235,18 @@ uart_set_options(struct uart_port *port, struct cons= ole *co, port->mctrl |=3D TIOCM_DTR; =20 port->ops->set_termios(port, &termios, &dummy); + + /* + * If console hardware flow control was specified and is supported, + * the related policy UPSTAT_CTS_ENABLE must be set to allow console + * drivers to identify if CTS should be used for polling. + */ + if (flow =3D=3D 'r' && (termios.c_cflag & CRTSCTS)) { + /* Synchronize @status RMW update against the console. */ + guard(uart_port_lock_irqsave)(port); + port->status |=3D UPSTAT_CTS_ENABLE; + } + /* * Allow the setting of the UART parameters with a NULL console * too: @@ -2541,7 +2553,14 @@ uart_configure_port(struct uart_driver *drv, struct = uart_state *state, * We probably don't need a spinlock around this, but */ scoped_guard(uart_port_lock_irqsave, port) { - port->mctrl &=3D TIOCM_DTR; + unsigned int mask =3D TIOCM_DTR; + + /* Console hardware flow control polls CTS. */ + if (uart_console_hwflow_active(port)) + mask |=3D TIOCM_RTS; + + port->mctrl &=3D mask; + if (!(port->rs485.flags & SER_RS485_ENABLED)) port->ops->set_mctrl(port, port->mctrl); } diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 4f7bbdd900176..17fcff466e301 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -1175,6 +1175,14 @@ static inline bool uart_cons_flow_enabled(const stru= ct uart_port *uport) return uport->cons_flow; } =20 +static inline bool uart_console_hwflow_active(struct uart_port *uport) +{ + return uart_console(uport) && + !(uport->rs485.flags & SER_RS485_ENABLED) && + uart_cons_flow_enabled(uport) && + uart_cts_enabled(uport); +} + /* * The following are helper functions for the low level drivers. */ --=20 2.47.3