From: Nicolai Buchwitz <nb@tipi-net.de>
To: sashiko-reviews@lists.linux.dev
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH v2 2/2] serial: amba-pl011: keep RS485 transmission running on reconfiguration
Date: Sat, 17 Oct 2026 11:07:37 +0200 [thread overview]
Message-ID: <b07a35b9f41ab5f312c4c5439e0dab42@tipi-net.de> (raw)
In-Reply-To: <sashiko-outbox-175339@kernel.org>
On 17.10.2026 08:45, sashiko-bot@kernel.org wrote:
> [...]
> [Severity: Medium]
> What happens if RS485 is enabled via TIOCSRS485 while a break is active
> on
> the port (or if RS485 is disabled during a break, clearing
> uap->rs485_break
> above while UART01x_LCRH_BRK remains set in REG_LCRH_TX, and then
> re-enabled)?
>
> While UART01x_LCRH_BRK is set, the PL011 keeps UART01x_FR_BUSY asserted
> in
> REG_FR, so pl011_tx_pending() returns true via !pl011_tx_empty() and
> enters
> pl011_rs485_tx_resume():
>
> drivers/tty/serial/amba-pl011.c:pl011_rs485_tx_resume() {
> ...
> if (stopped ||
> (kfifo_is_empty(&tport->xmit_fifo) && !pl011_dma_tx_queued(uap)))
> {
> uap->rs485_tx_state = WAIT_AFTER_SEND;
> hrtimer_start(&uap->trigger_stop_tx, uap->rs485_tx_drain_interval,
> HRTIMER_MODE_REL);
> } else {
> uap->rs485_tx_state = SEND;
> }
> }
>
> Because pl011_rs485_tx_resume() does not check REG_LCRH_TX for
> UART01x_LCRH_BRK and set uap->rs485_break = true, uap->rs485_break
> stays
> false. Could this cause pl011_trigger_stop_tx() ->
> pl011_rs485_tx_stop() to
> bypass the uap->rs485_break check and continuously re-arm
> trigger_stop_tx
> every character interval in hardirq context for the entire duration of
> the
> break?
>
>> - } else if (port->rs485.flags & SER_RS485_ENABLED) {
>> + } else if ((port->rs485.flags & SER_RS485_ENABLED) &&
>> + uap->rs485_tx_state == OFF) {
>> + /* Set the idle level now, a transmission sets it when done */
>> pl011_rs485_tx_stop(uap);
>> }
>
Agree. I verified on my CM4 that BUSY stays set during a break and the
drain timer
keeps polling until the break ends. Will fix this in v3.
> [Severity: Medium]
> During TIOCSRS485, uart_ioctl() -> uart_set_rs485_config() invokes
> port->rs485_config() before storing the new configuration into
> port->rs485:
>
> drivers/tty/serial/serial_core.c:uart_set_rs485_config() {
> ...
> ret = port->rs485_config(port, &tty->termios, &rs485);
> if (!ret) {
> port->rs485 = rs485;
> ...
> }
>
> And pl011_rs485_tx_stop() -> pl011_rs485_tx_stop_now() also reads
> port->rs485.flags:
>
> drivers/tty/serial/amba-pl011.c:pl011_rs485_tx_stop_now() {
> ...
> if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND)
> cr &= ~UART011_CR_RTS;
> else
> cr |= UART011_CR_RTS;
> ...
> }
>
> Because port->rs485 still holds the old settings here, can this cause
> two
> issues when configuring an idle port (uap->rs485_tx_state == OFF and
> !pl011_tx_pending()) via TIOCSRS485:
>
> 1. When enabling RS485 for the first time, port->rs485.flags &
> SER_RS485_ENABLED
> is still false, so pl011_rs485_tx_stop() is skipped, leaving
> UART011_CR_TXE
> enabled while uap->rs485_tx_state == OFF and leaving UART011_CR_RTS
> at its
> RS232 level?
>
> 2. When RS485 is already enabled and TIOCSRS485 changes the RTS
> polarity
> (SER_RS485_RTS_ON_SEND vs SER_RS485_RTS_AFTER_SEND),
> pl011_rs485_tx_stop_now() programs UART011_CR_RTS using the old
> port->rs485.flags instead of the new rs485->flags, driving the wrong
> RTS
> idle level?
>
> Should this branch check rs485->flags & SER_RS485_ENABLED and apply the
> new
> rs485->flags when setting the idle state?
IMHO this is a pre-existing issue. I even have a fix for this in my
local RS485
rework series, I plan to send for next cycle. So if there aren't any
objections,
I will skip this for v3.
Thanks,
Nicolai
prev parent reply other threads:[~2026-10-17 9:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 6:18 [PATCH v2 0/2] serial: amba-pl011: fix RS485 state on enable and reconfiguration Nicolai Buchwitz
2026-10-17 6:18 ` [PATCH v2 1/2] serial: amba-pl011: finish a transmission still running when RS485 is enabled Nicolai Buchwitz
2026-10-17 6:42 ` sashiko-bot
2026-10-17 6:18 ` [PATCH v2 2/2] serial: amba-pl011: keep RS485 transmission running on reconfiguration Nicolai Buchwitz
2026-10-17 6:45 ` sashiko-bot
2026-10-17 9:07 ` Nicolai Buchwitz [this message]
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=b07a35b9f41ab5f312c4c5439e0dab42@tipi-net.de \
--to=nb@tipi-net.de \
--cc=linux-serial@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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