Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795041369; b=1ZeuAFvWQsTh8jWF3Dlz8OAqOXeOpBlKHz1yibNXZ30gq2FZXJuQMFWAVnbTOCNsTwJg P6KHfRxqL9WKRsMvGRUq26pYz1D+8Kh2SAS5DcqMy0bMgVNEl5JQG8T7rkaYJtnits4TA rrWlpcaYPuhSyecvMOL4AKJwRCs72JGoTbnkNVvB2aUw2h2ZfrT3E9hMpeYktdroa6iIs PNDYSdeIchaSLOuwv/BDFH705sgt1BEf+rJhVbZgq3KXCEsCMmtuV9zd4M0yea13KsHqU ym6V7/oQsg7pbfrrglz6rBt2lSEjg1bX7SK1r+Pf6qAkdZaabi+13nYDU6MK5Cx9Uyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795041369; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=2x6QDTCjxrmsoqgzGz3Gk9yxGB05t9/xs6D8k0X33WU=; b=ryBg++FkAEtjaT2bvyp4kUbQOUQA7130AGqxA2FSlQ3iHFLfnMZ1US9o+fYwyxdOhowZ /dNTD2nRh3MF7IymKuUwsBILc+OaQ5aCVDXrkArADIyUgyeGcIN/l6MxCtx5NQZ3f9H+X J0Ly4d2up54xBgj3LFW9QmwNSK+N0fhCWitq6H6D51hVRfAb/o3g/6avH4V+va2cgx/8y zHVB+zK7Gl3V4bXmilLaStN55rSEG4Tp6qK0rKqCvxCWPjAefzvjEPEJbhcPYA7mkbz1z yk//SVEe3uT3zxqR/17ijqqZXL3P2/CQ9nATepyAiBmXBBQIVOXVF7KKMwcNCeFI9nw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=aHl33pVL; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C39D606A31C; Wed, 18 Nov 2026 22:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=aHl33pVL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62ECD1F000C4; Wed, 18 Nov 2026 22:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795041368; bh=2x6QDTCjxrmsoqgzGz3Gk9yxGB05t9/xs6D8k0X33WU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aHl33pVLAy0RUYxhPZcgjgrC3OYzcRx0N6BsQSwdstXhLF4vAoZZrYx9AxiOBcPbj soF7N17JczKQOx44G19rIRNKriMs3vhJtCgm2/wAXk53TkoD+1TQWRxLGdLaHoAyip S9xnPPPlaeMy1xpXLgef9ibzW8QNRM5F9qx47Tmc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tapio Reijonen , Sasha Levin Subject: [PATCH 6.6 2788/3318] serial: max310x: fix breaks not reaching the wire in RS485 mode Date: Wed, 18 Nov 2026 15:56:50 +0100 Message-ID: <20261118150444.329693531@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tapio Reijonen [ Upstream commit 4efacb600bf98b13e0659f05afa4549795277e35 ] The chip's auto-RTS (MODE1.TRNSCVCTRL) asserts the RS485 transceiver only while FIFO data is shifting out, and a break is not FIFO data: on an RS485 port a requested break sets the TX break bit but the transceiver is never enabled, so the break never reaches the wire. Break-led protocols cannot work at all. Disable auto-RTS for the break duration and drive RTS manually via the LCR RTS bit, then restore auto-RTS when the break ends. Track the break in tx_break and leave MODE1 alone in the rs485-config worker while it is set - a TIOCSRS485 arriving mid-break would otherwise re-enable auto-RTS on top of the manual RTS and release the transceiver before the break ends; break_ctl() restores auto-RTS from the then-current configuration when the break completes. The worker runs under port->mutex - break_ctl() and set_termios() already do - so the tx_break test and the MODE1 write cannot straddle a break starting or ending, and startup() clears tx_break alongside the latched TXBREAK bit, since a port can be closed with a break still asserted. Only the break assertion is gated on RS485 being enabled; the restore at break end runs unconditionally and derives MODE1 from the current configuration. Returning early for a port whose RS485 was disabled mid-break - that reconfigure is deferred like any other - would leak the manually driven RTS and leave the transceiver holding the bus indefinitely after the break ends. On a non-RS485 port the restore is a no-op: nothing else writes the LCR RTS bit. Fixes: 55367c620aed ("serial: max310x: Add support for RS-485 mode") Assisted-by: Claude:claude-fable-5 Signed-off-by: Tapio Reijonen Link: https://patch.msgid.link/20261008-max310x-rs485-sw-delay-v8-2-6ba881f81e1f@vaisala.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/max310x.c | 49 ++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index b8aae5bc6083b..c83f351b7a199 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -283,6 +283,7 @@ struct max310x_one { struct work_struct md_work; struct work_struct rs_work; struct regmap *regmap; + bool tx_break; /* break_ctl() owns the transceiver */ u8 rx_buf[MAX310X_FIFO_SIZE]; }; @@ -655,6 +656,12 @@ static void max310x_batch_read(struct uart_port *port, u8 *rxbuf, unsigned int l regmap_noinc_read(one->regmap, MAX310X_RHR_REG, rxbuf, len); } +static void max310x_rts_ctl(struct uart_port *port, bool rts_state) +{ + max310x_port_update(port, MAX310X_LCR_REG, MAX310X_LCR_RTS_BIT, + rts_state ? MAX310X_LCR_RTS_BIT : 0); +} + static void max310x_handle_rx(struct uart_port *port, unsigned int rxlen) { struct max310x_one *one = to_max310x_port(port); @@ -890,9 +897,32 @@ static void max310x_set_mctrl(struct uart_port *port, unsigned int mctrl) static void max310x_break_ctl(struct uart_port *port, int break_state) { + struct max310x_one *one = to_max310x_port(port); + + one->tx_break = break_state; + max310x_port_update(port, MAX310X_LCR_REG, MAX310X_LCR_TXBREAK_BIT, break_state ? MAX310X_LCR_TXBREAK_BIT : 0); + + /* + * The chip's auto-RTS asserts the transceiver only while FIFO data is + * shifting out, and a break is not FIFO data. Disable auto-RTS for the + * break duration and drive RTS manually so the break reaches the wire; + * restore auto-RTS when the break ends. + */ + if (break_state) { + if (!(port->rs485.flags & SER_RS485_ENABLED)) + return; + max310x_port_update(port, MAX310X_MODE1_REG, + MAX310X_MODE1_TRNSCVCTRL_BIT, 0); + } else { + max310x_port_update(port, MAX310X_MODE1_REG, + MAX310X_MODE1_TRNSCVCTRL_BIT, + (port->rs485.flags & SER_RS485_ENABLED) ? + MAX310X_MODE1_TRNSCVCTRL_BIT : 0); + } + max310x_rts_ctl(port, break_state); } static void max310x_set_termios(struct uart_port *port, @@ -1014,6 +1044,13 @@ static void max310x_rs_proc(struct work_struct *ws) struct max310x_one *one = container_of(ws, struct max310x_one, rs_work); unsigned int delay, mode1 = 0, mode2 = 0; + /* + * Serialize against break_ctl() and set_termios(), which run under + * port->mutex: the tx_break test below and the MODE1 write must not + * straddle a break starting or ending. + */ + guard(mutex)(&one->port.state->port.mutex); + delay = (one->port.rs485.delay_rts_before_send << 4) | one->port.rs485.delay_rts_after_send; max310x_port_write(&one->port, MAX310X_HDPIXDELAY_REG, delay); @@ -1025,8 +1062,14 @@ static void max310x_rs_proc(struct work_struct *ws) mode2 = MAX310X_MODE2_ECHOSUPR_BIT; } - max310x_port_update(&one->port, MAX310X_MODE1_REG, - MAX310X_MODE1_TRNSCVCTRL_BIT, mode1); + /* + * A break owns the transceiver: break_ctl() disabled auto-RTS and + * drives RTS manually, and restores it when the break ends. Leave + * MODE1 alone meanwhile or the break goes undriven mid-way. + */ + if (!one->tx_break) + max310x_port_update(&one->port, MAX310X_MODE1_REG, + MAX310X_MODE1_TRNSCVCTRL_BIT, mode1); max310x_port_update(&one->port, MAX310X_MODE2_REG, MAX310X_MODE2_ECHOSUPR_BIT, mode2); } @@ -1049,6 +1092,7 @@ static int max310x_rs485_config(struct uart_port *port, struct ktermios *termios static int max310x_startup(struct uart_port *port) { + struct max310x_one *one = to_max310x_port(port); unsigned int val; max310x_power(port, 1); @@ -1058,6 +1102,7 @@ static int max310x_startup(struct uart_port *port) * closed with a break still asserted, and set_termios() no longer * rewrites it. */ + one->tx_break = false; max310x_port_update(port, MAX310X_LCR_REG, MAX310X_LCR_TXBREAK_BIT, 0); /* Configure MODE1 register */ -- 2.53.0