Skip to content

Conversation

@pelwell
Copy link
Contributor

@pelwell pelwell commented Dec 18, 2025

commit 2c1fd53 upstream.

Data loss on serial line was observed during communication through serial ports ttyAMA1 and ttyAMA2 interconnected via RS485 transcievers. Both ports are in one BCM2711 (Compute Module CM40) and they share the same interrupt line.

The problem is caused by long waiting for tx queue flush in the function pl011_rs485_tx_stop. Udelay or mdelay are used to wait. The function is called from the interrupt handler. If multiple devices share a single interrupt line, late processing of pending interrupts and data loss may occur. When operation of both devices are synchronous, collisions are quite often.

This rework is based on the method used in tty/serial/imx.c Use hrtimer instead of udelay and mdelay calls.
Replace simple bool variable rs485_tx_started by 4-state variable rs485_tx_state.

Tested-by: Lino Sanfilippo [email protected]

Link: https://lore.kernel.org/r/[email protected]

@nbuchwitz
Copy link
Contributor

hrtimer_init(&uap->trigger_start_tx, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
hrtimer_init(&uap->trigger_stop_tx, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
uap->trigger_start_tx.function = pl011_trigger_start_tx;
uap->trigger_stop_tx.function = pl011_trigger_stop_tx;

is missing in pl011_axi_probe() in order to make this work with rp1

commit 2c1fd53 upstream.

Data loss on serial line was observed during communication through
serial ports ttyAMA1 and ttyAMA2 interconnected via RS485 transcievers.
Both ports are in one BCM2711 (Compute Module CM40) and they share
the same interrupt line.

The problem is caused by long waiting for tx queue flush in the function
pl011_rs485_tx_stop. Udelay or mdelay are used to wait.
The function is called from the interrupt handler. If multiple devices
share a single interrupt line, late processing of pending interrupts
and data loss may occur. When operation of both devices are synchronous,
collisions are quite often.

This rework is based on the method used in tty/serial/imx.c
Use hrtimer instead of udelay and mdelay calls.
Replace simple bool variable rs485_tx_started by 4-state variable
rs485_tx_state.

Tested-by: Lino Sanfilippo <[email protected]>
Signed-off-by: Miroslav Ondra <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
pl011_axi_probe was missing the equivlent hrtimer initialisation
from commit 2c1fd53 ("serial: amba-pl011: Fix RTS handling in RS485 mode")
and commit 8cb4418 ("serial: amba-pl011: Switch to use hrtimer_setup()")
resulting in the kernel blowing up as soon as pl011_rs485_stop_tx
tried to use them.

Add the hrtimer initialisation.

Fixes: 120c89e ("serial: pl011: rp1 uart support")
Signed-off-by: Dave Stevenson <[email protected]>
@pelwell
Copy link
Contributor Author

pelwell commented Jan 23, 2026

Like this?

@nbuchwitz
Copy link
Contributor

Yes, that's the same as what I tested here.

There is still a significant performance regression (essentially unusable) with our RS485-based backplane driver. I would really appreciate holding off on the merge until we have investigated this further. Otherwise, we would need to revert this downstream.

@pelwell pelwell marked this pull request as draft January 23, 2026 15:51
@pelwell
Copy link
Contributor Author

pelwell commented Jan 23, 2026

It's going nowhere for now.

@nbuchwitz
Copy link
Contributor

nbuchwitz commented Jan 27, 2026

I've put together a workaround that brings back stable functionality for our serdev-based backplane driver:

https://gitlab.com/revolutionpi/linux/-/commit/c3cae2df785ea604b49addfd2f7d75159e91475a

Since we'd like to get as much as possible into upstream, I'm still figuring out how to frame this in a way that makes sense for mainline. Before posting to the mailing list, I wanted to check if you or Jonathan have any thoughts on this.
Any feedback would be much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants