Re: [PATCH tty-next v4 4/6] serial: 8250: Provide flag for IER toggling for RS485
From: Petr Mladek
Date: Mon Jan 06 2025 - 09:00:43 EST
On Sun 2025-01-05 01:32:00, John Ogness wrote:
> On 2025-01-03, Petr Mladek <pmladek@xxxxxxxx> wrote:
> > My understanding is that the nested IER manipulation does not
> > harm.
>
> This statement implies that it is OK for UART_IER_RLSI|UART_IER_RDI bits
> to be set in UART_IER even though the console will write to UART_TX,
> because the _nesting_ contexts would set those bits rather than
> restoring the original value of 0x0.
This is a misunderstanding. I am sorry I was not clear enough.
To be more clear. By the nested context I meant
if (em485) {
if (em485->tx_stopped)
up->rs485_start_tx(up);
call by serial8250_console_write(). The original code did:
+ up->rs485_start_tx()
+ serial8250_em485_start_tx()
+ serial8250_stop_rx()
, where serial8250_stop_rx() cleared the flags:
static void serial8250_stop_rx(struct uart_port *port)
{
[...]
up->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
serial_port_out(port, UART_IER, up->ier);
[...]
}
But the flags were already cleared by:
__serial8250_clear_IER(up);
called by serial8250_console_write() _earlier_. Which did:
static void __serial8250_clear_IER(struct uart_8250_port *up)
{
if (up->capabilities & UART_CAP_UUE)
serial_out(up, UART_IER, UART_IER_UUE);
else
serial_out(up, UART_IER, 0);
}
It means that the nested serial8250_stop_rx() did not change anything.
It was a NOP. The bits were already cleared.
Similar, the counter part. The bits were later set by
up->rs485_stop_tx(up)
which did:
+ serial8250_em485_stop_tx
void serial8250_em485_stop_tx(struct uart_8250_port *p, bool toggle_ier)
{
[...]
p->ier |= UART_IER_RLSI | UART_IER_RDI;
serial_port_out(&p->port, UART_IER, p->ier);
[...]
}
But it was after the writing the message so that it did not affect
the operation.
> I ran some tests and leaving these bits set during Tx does not appear to
> cause an issue, but it is difficult to say because the context
> interrupted by a nesting context will only print at most 1
> character. Also, it is writing under spin_lock_irqsave() so that might
> be masking any effects. Perhaps UART_IER is temporarly cleared because
> of other bits that would cause problems during Tx?
>
> I would need to create a specific test to investigate this
> further. Regardless, it still is a cosmetic ugliness that bits are not
> being properly restored, even if it turns out these particular bits are
> not problematic during Tx.
I think that you do not need to investigate it further. We should keep
IER cleared when writing the message.
> > All in all, the patch looks good to me.
> >
> > Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>
>
> Thanks for the review. I interpret it to mean that I do not need to make
> any changes to this patch for v5.
Yup, I am fine with the patch as it is.
Best Regards,
Petr