Re: git: 0d2fd5b99c95 - main - ns8250: use LSR_THRE instead of LSR_TEMT for checking tx flush

From: Michal Meloun <mmel_at_FreeBSD.org>
Date: Tue, 20 May 2025 18:28:57 UTC

On 20.05.2025 16:57, Andriy Gapon wrote:
> The branch main has been updated by avg:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=0d2fd5b99c95329085d0700a4dd38507a054a50d
> 
> commit 0d2fd5b99c95329085d0700a4dd38507a054a50d
> Author:     Andriy Gapon <avg@FreeBSD.org>
> AuthorDate: 2024-11-10 11:15:30 +0000
> Commit:     Andriy Gapon <avg@FreeBSD.org>
> CommitDate: 2025-05-20 14:55:18 +0000
> 
>      ns8250: use LSR_THRE instead of LSR_TEMT for checking tx flush
>      
>      LSR_TEMT bit is set if both transmit hold and shift registers are
>      empty, but the flush command flushes only the hold register.
I don't think that's true. Imho, ns8250_flush() is used also before 
changing baud rate, so we need to ensure that all bits are flushed, 
including the transmit register.

Michal

>      
>      While here, update the diagnostic message to report which registers
>      could not be flushed.
>      
>      MFC after:      2 weeks
> ---
>   sys/dev/uart/uart_dev_ns8250.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c
> index 1df39b499539..0f19ede6d9df 100644
> --- a/sys/dev/uart/uart_dev_ns8250.c
> +++ b/sys/dev/uart/uart_dev_ns8250.c
> @@ -265,12 +265,12 @@ ns8250_flush(struct uart_bas *bas, int what)
>   	 * https://github.com/rust-vmm/vm-superio/issues/83
>   	 */
>   	lsr = uart_getreg(bas, REG_LSR);
> -	if (((lsr & LSR_TEMT) == 0) && (what & UART_FLUSH_TRANSMITTER))
> +	if (((lsr & LSR_THRE) == 0) && (what & UART_FLUSH_TRANSMITTER))
>   		drain |= UART_DRAIN_TRANSMITTER;
>   	if ((lsr & LSR_RXRDY) && (what & UART_FLUSH_RECEIVER))
>   		drain |= UART_DRAIN_RECEIVER;
>   	if (drain != 0) {
> -		printf("uart: ns8250: UART FCR is broken\n");
> +		printf("uart: ns8250: UART FCR is broken (%#x)\n", drain);
>   		ns8250_drain(bas, drain);
>   	}
>   }