[PATCH v2 2/5] serial: 8250: extract serial8250_iir_txen_test()

Jiri Slaby (SUSE) posted 5 patches 3 months, 2 weeks ago
[PATCH v2 2/5] serial: 8250: extract serial8250_iir_txen_test()
Posted by Jiri Slaby (SUSE) 3 months, 2 weeks ago
After commit 795158691cc0 ("serial: 8250: extract
serial8250_initialize()"), split serial8250_initialize() even more --
the TX enable test part of this code can be separated into
serial8250_iir_txen_test().

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/8250/8250_port.c | 49 ++++++++++++++++-------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 0f85a2f292fc..5bb0ca04da55 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2230,16 +2230,19 @@ static void serial8250_init_mctrl(struct uart_port *port)
 	serial8250_set_mctrl(port, port->mctrl);
 }
 
-static void serial8250_initialize(struct uart_port *port)
+static void serial8250_iir_txen_test(struct uart_port *port)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
-	unsigned long flags;
 	bool lsr_TEMT, iir_NOINT;
 
-	serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
+	if (port->quirks & UPQ_NO_TXEN_TEST)
+		return;
 
-	uart_port_lock_irqsave(port, &flags);
-	serial8250_init_mctrl(port);
+	/* Do a quick test to see if we receive an interrupt when we enable the TX irq. */
+	serial_port_out(port, UART_IER, UART_IER_THRI);
+	lsr_TEMT = serial_port_in(port, UART_LSR) & UART_LSR_TEMT;
+	iir_NOINT = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
+	serial_port_out(port, UART_IER, 0);
 
 	/*
 	 * Serial over Lan (SoL) hack:
@@ -2247,26 +2250,30 @@ static void serial8250_initialize(struct uart_port *port)
 	 * Lan.  Those chips take a longer time than a normal serial device to signalize that a
 	 * transmission data was queued. Due to that, the above test generally fails. One solution
 	 * would be to delay the reading of iir. However, this is not reliable, since the timeout is
-	 * variable. So, let's just don't test if we receive TX irq.  This way, we'll never enable
-	 * UART_BUG_TXEN.
+	 * variable. So, in case of UPQ_NO_TXEN_TEST, let's just don't test if we receive TX irq.
+	 * This way, we'll never enable UART_BUG_TXEN.
 	 */
-	if (!(port->quirks & UPQ_NO_TXEN_TEST)) {
-		/* Do a quick test to see if we receive an interrupt when we enable the TX irq. */
-		serial_port_out(port, UART_IER, UART_IER_THRI);
-		lsr_TEMT = serial_port_in(port, UART_LSR) & UART_LSR_TEMT;
-		iir_NOINT = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
-		serial_port_out(port, UART_IER, 0);
-
-		if (lsr_TEMT && iir_NOINT) {
-			if (!(up->bugs & UART_BUG_TXEN)) {
-				up->bugs |= UART_BUG_TXEN;
-				dev_dbg(port->dev, "enabling bad tx status workarounds\n");
-			}
-		} else {
-			up->bugs &= ~UART_BUG_TXEN;
+	if (lsr_TEMT && iir_NOINT) {
+		if (!(up->bugs & UART_BUG_TXEN)) {
+			up->bugs |= UART_BUG_TXEN;
+			dev_dbg(port->dev, "enabling bad tx status workarounds\n");
 		}
+		return;
 	}
 
+	/* FIXME: why is this needed? */
+	up->bugs &= ~UART_BUG_TXEN;
+}
+
+static void serial8250_initialize(struct uart_port *port)
+{
+	unsigned long flags;
+
+	serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
+
+	uart_port_lock_irqsave(port, &flags);
+	serial8250_init_mctrl(port);
+	serial8250_iir_txen_test(port);
 	uart_port_unlock_irqrestore(port, flags);
 }
 
-- 
2.50.0

Re: [PATCH v2 2/5] serial: 8250: extract serial8250_iir_txen_test()
Posted by Andy Shevchenko 3 months, 2 weeks ago
On Tue, Jun 24, 2025 at 10:06:38AM +0200, Jiri Slaby (SUSE) wrote:
> After commit 795158691cc0 ("serial: 8250: extract
> serial8250_initialize()"), split serial8250_initialize() even more --
> the TX enable test part of this code can be separated into
> serial8250_iir_txen_test().

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 2/5] serial: 8250: extract serial8250_iir_txen_test()
Posted by Ilpo Järvinen 3 months, 2 weeks ago
On Tue, 24 Jun 2025, Jiri Slaby (SUSE) wrote:

> After commit 795158691cc0 ("serial: 8250: extract
> serial8250_initialize()"), split serial8250_initialize() even more --
> the TX enable test part of this code can be separated into
> serial8250_iir_txen_test().
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
>  drivers/tty/serial/8250/8250_port.c | 49 ++++++++++++++++-------------
>  1 file changed, 28 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 0f85a2f292fc..5bb0ca04da55 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2230,16 +2230,19 @@ static void serial8250_init_mctrl(struct uart_port *port)
>  	serial8250_set_mctrl(port, port->mctrl);
>  }
>  
> -static void serial8250_initialize(struct uart_port *port)
> +static void serial8250_iir_txen_test(struct uart_port *port)
>  {
>  	struct uart_8250_port *up = up_to_u8250p(port);
> -	unsigned long flags;
>  	bool lsr_TEMT, iir_NOINT;
>  
> -	serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
> +	if (port->quirks & UPQ_NO_TXEN_TEST)
> +		return;
>  
> -	uart_port_lock_irqsave(port, &flags);
> -	serial8250_init_mctrl(port);
> +	/* Do a quick test to see if we receive an interrupt when we enable the TX irq. */
> +	serial_port_out(port, UART_IER, UART_IER_THRI);
> +	lsr_TEMT = serial_port_in(port, UART_LSR) & UART_LSR_TEMT;
> +	iir_NOINT = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
> +	serial_port_out(port, UART_IER, 0);
>  
>  	/*
>  	 * Serial over Lan (SoL) hack:
> @@ -2247,26 +2250,30 @@ static void serial8250_initialize(struct uart_port *port)
>  	 * Lan.  Those chips take a longer time than a normal serial device to signalize that a
>  	 * transmission data was queued. Due to that, the above test generally fails. One solution
>  	 * would be to delay the reading of iir. However, this is not reliable, since the timeout is
> -	 * variable. So, let's just don't test if we receive TX irq.  This way, we'll never enable
> -	 * UART_BUG_TXEN.
> +	 * variable. So, in case of UPQ_NO_TXEN_TEST, let's just don't test if we receive TX irq.
> +	 * This way, we'll never enable UART_BUG_TXEN.
>  	 */
> -	if (!(port->quirks & UPQ_NO_TXEN_TEST)) {
> -		/* Do a quick test to see if we receive an interrupt when we enable the TX irq. */
> -		serial_port_out(port, UART_IER, UART_IER_THRI);
> -		lsr_TEMT = serial_port_in(port, UART_LSR) & UART_LSR_TEMT;
> -		iir_NOINT = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
> -		serial_port_out(port, UART_IER, 0);
> -
> -		if (lsr_TEMT && iir_NOINT) {
> -			if (!(up->bugs & UART_BUG_TXEN)) {
> -				up->bugs |= UART_BUG_TXEN;
> -				dev_dbg(port->dev, "enabling bad tx status workarounds\n");
> -			}
> -		} else {
> -			up->bugs &= ~UART_BUG_TXEN;
> +	if (lsr_TEMT && iir_NOINT) {
> +		if (!(up->bugs & UART_BUG_TXEN)) {
> +			up->bugs |= UART_BUG_TXEN;
> +			dev_dbg(port->dev, "enabling bad tx status workarounds\n");
>  		}
> +		return;
>  	}
>  
> +	/* FIXME: why is this needed? */
> +	up->bugs &= ~UART_BUG_TXEN;
> +}
> +
> +static void serial8250_initialize(struct uart_port *port)
> +{
> +	unsigned long flags;
> +
> +	serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
> +
> +	uart_port_lock_irqsave(port, &flags);
> +	serial8250_init_mctrl(port);
> +	serial8250_iir_txen_test(port);
>  	uart_port_unlock_irqrestore(port, flags);
>  }
>  
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.