[PATCH 23/33] serial: 8250: extract serial8250_set_efr()

Jiri Slaby (SUSE) posted 33 patches 4 months ago
[PATCH 23/33] serial: 8250: extract serial8250_set_efr()
Posted by Jiri Slaby (SUSE) 4 months ago
serial8250_do_set_termios() consists of many registers and up flags
settings. Extract all these into separate functions. This time, setting
of EFR for UART_CAP_EFR ports.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 43 +++++++++++++++++------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 2c045a4369fc..0f16398cc86f 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2768,6 +2768,30 @@ static void serial8250_set_ier(struct uart_port *port, struct ktermios *termios)
 	serial_port_out(port, UART_IER, up->ier);
 }
 
+static void serial8250_set_efr(struct uart_port *port, struct ktermios *termios)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	u8 efr_reg = UART_EFR;
+	u8 efr = 0;
+
+	if (!(up->capabilities & UART_CAP_EFR))
+		return;
+
+	/*
+	 * TI16C752/Startech hardware flow control.  FIXME:
+	 * - TI16C752 requires control thresholds to be set.
+	 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
+	 */
+	if (termios->c_cflag & CRTSCTS)
+		efr |= UART_EFR_CTS;
+
+	if (port->flags & UPF_EXAR_EFR)
+		efr_reg = UART_XR_EFR;
+
+	serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
+	serial_port_out(port, efr_reg, efr);
+}
+
 void
 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
@@ -2797,24 +2821,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	uart_update_timeout(port, termios->c_cflag, baud);
 	serial8250_set_errors_and_ignores(port, termios);
 	serial8250_set_ier(port, termios);
-
-	if (up->capabilities & UART_CAP_EFR) {
-		unsigned char efr = 0;
-		/*
-		 * TI16C752/Startech hardware flow control.  FIXME:
-		 * - TI16C752 requires control thresholds to be set.
-		 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
-		 */
-		if (termios->c_cflag & CRTSCTS)
-			efr |= UART_EFR_CTS;
-
-		serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
-		if (port->flags & UPF_EXAR_EFR)
-			serial_port_out(port, UART_XR_EFR, efr);
-		else
-			serial_port_out(port, UART_EFR, efr);
-	}
-
+	serial8250_set_efr(port, termios);
 	serial8250_set_divisor(port, baud, quot, frac);
 
 	/*
-- 
2.49.0
Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
Posted by Ilpo Järvinen 4 months ago
On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_set_termios() consists of many registers and up flags
> settings. Extract all these into separate functions. This time, setting
> of EFR for UART_CAP_EFR ports.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 43 +++++++++++++++++------------
>  1 file changed, 25 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 2c045a4369fc..0f16398cc86f 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2768,6 +2768,30 @@ static void serial8250_set_ier(struct uart_port *port, struct ktermios *termios)
>  	serial_port_out(port, UART_IER, up->ier);
>  }
>  
> +static void serial8250_set_efr(struct uart_port *port, struct ktermios *termios)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +	u8 efr_reg = UART_EFR;
> +	u8 efr = 0;
> +
> +	if (!(up->capabilities & UART_CAP_EFR))
> +		return;
> +
> +	/*
> +	 * TI16C752/Startech hardware flow control.  FIXME:
> +	 * - TI16C752 requires control thresholds to be set.
> +	 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
> +	 */
> +	if (termios->c_cflag & CRTSCTS)
> +		efr |= UART_EFR_CTS;
> +
> +	if (port->flags & UPF_EXAR_EFR)

I wonder if it is possible to trigger this at all? Only 8250_exar.c sets 
this flag and does not contain have UART_CAP_EFR at all (nor uses 
UPF_BOOT_AUTOCONF)??

> +		efr_reg = UART_XR_EFR;
> +
> +	serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
> +	serial_port_out(port, efr_reg, efr);
> +}
> +
>  void
>  serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
> @@ -2797,24 +2821,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  	uart_update_timeout(port, termios->c_cflag, baud);
>  	serial8250_set_errors_and_ignores(port, termios);
>  	serial8250_set_ier(port, termios);
> -
> -	if (up->capabilities & UART_CAP_EFR) {
> -		unsigned char efr = 0;
> -		/*
> -		 * TI16C752/Startech hardware flow control.  FIXME:
> -		 * - TI16C752 requires control thresholds to be set.
> -		 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
> -		 */
> -		if (termios->c_cflag & CRTSCTS)
> -			efr |= UART_EFR_CTS;
> -
> -		serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
> -		if (port->flags & UPF_EXAR_EFR)
> -			serial_port_out(port, UART_XR_EFR, efr);
> -		else
> -			serial_port_out(port, UART_EFR, efr);
> -	}
> -
> +	serial8250_set_efr(port, termios);
>  	serial8250_set_divisor(port, baud, quot, frac);
>  
>  	/*
> 

-- 
 i.
Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
Posted by Jiri Slaby 4 months ago
On 11. 06. 25, 14:58, Ilpo Järvinen wrote:
> On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:
> 
>> serial8250_do_set_termios() consists of many registers and up flags
>> settings. Extract all these into separate functions. This time, setting
>> of EFR for UART_CAP_EFR ports.
>>
>> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
>> ---
>>   drivers/tty/serial/8250/8250_port.c | 43 +++++++++++++++++------------
>>   1 file changed, 25 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
>> index 2c045a4369fc..0f16398cc86f 100644
>> --- a/drivers/tty/serial/8250/8250_port.c
>> +++ b/drivers/tty/serial/8250/8250_port.c
>> @@ -2768,6 +2768,30 @@ static void serial8250_set_ier(struct uart_port *port, struct ktermios *termios)
>>   	serial_port_out(port, UART_IER, up->ier);
>>   }
>>   
>> +static void serial8250_set_efr(struct uart_port *port, struct ktermios *termios)
>> +{
>> +	struct uart_8250_port *up = up_to_u8250p(port);
>> +	u8 efr_reg = UART_EFR;
>> +	u8 efr = 0;
>> +
>> +	if (!(up->capabilities & UART_CAP_EFR))
>> +		return;
>> +
>> +	/*
>> +	 * TI16C752/Startech hardware flow control.  FIXME:
>> +	 * - TI16C752 requires control thresholds to be set.
>> +	 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
>> +	 */
>> +	if (termios->c_cflag & CRTSCTS)
>> +		efr |= UART_EFR_CTS;
>> +
>> +	if (port->flags & UPF_EXAR_EFR)
> 
> I wonder if it is possible to trigger this at all? Only 8250_exar.c sets
> this flag and does not contain UART_CAP_EFR at all (nor uses
> UPF_BOOT_AUTOCONF)??

Impossible as far as I can tell nowadays. Likely since:
commit 6be254c2113d18984bae002b3b3dfc133cf56ac5
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Wed Jul 31 20:05:56 2019 +0300

     serial: 8250_exar: No need to autoconfigure Exar ports

Andy?

The question is whether we need the code or we can drop it 8-).

> 
>> +		efr_reg = UART_XR_EFR;
>> +
>> +	serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
>> +	serial_port_out(port, efr_reg, efr);
>> +}
>> +
>>   void
>>   serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>>   		          const struct ktermios *old)


-- 
js
suse labs
Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
Posted by Andy Shevchenko 4 months ago
On Thu, Jun 12, 2025 at 12:01:29PM +0200, Jiri Slaby wrote:
> On 11. 06. 25, 14:58, Ilpo Järvinen wrote:
> > On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

...

> > > +	if (port->flags & UPF_EXAR_EFR)
> > 
> > I wonder if it is possible to trigger this at all? Only 8250_exar.c sets
> > this flag and does not contain UART_CAP_EFR at all (nor uses
> > UPF_BOOT_AUTOCONF)??

The file indeed does not contain it, BUT it sets it implicitly (via port type).
So, this is not a dead code. Please, do not remove it.

If you find a good way how to move it to the 8250_exar.c, I will appreciate
that solution. Ideally 8250_port.c should be quirk-free module.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
Posted by Jiri Slaby 3 months, 2 weeks ago
On 12. 06. 25, 20:54, Andy Shevchenko wrote:
> On Thu, Jun 12, 2025 at 12:01:29PM +0200, Jiri Slaby wrote:
>> On 11. 06. 25, 14:58, Ilpo Järvinen wrote:
>>> On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:
> 
> ...
> 
>>>> +	if (port->flags & UPF_EXAR_EFR)
>>>
>>> I wonder if it is possible to trigger this at all? Only 8250_exar.c sets
>>> this flag and does not contain UART_CAP_EFR at all (nor uses
>>> UPF_BOOT_AUTOCONF)??
> 
> The file indeed does not contain it, BUT it sets it implicitly (via port type).
> So, this is not a dead code. Please, do not remove it.

Ah, both PORT_XR17D15X and PORT_XR17V35X set UART_CAP_EFR in uart_config[].

thanks,
-- 
js
suse labs
Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
Posted by Jiri Slaby 4 months ago
On 12. 06. 25, 12:01, Jiri Slaby wrote:
> The question is whether we need the code or we can drop it 8-).

As it is now, we could drop UPF_EXAR_EFR altogether, right?

-- 
js
suse labs
Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
Posted by Andy Shevchenko 4 months ago
On Thu, Jun 12, 2025 at 12:04:27PM +0200, Jiri Slaby wrote:
> On 12. 06. 25, 12:01, Jiri Slaby wrote:
> > The question is whether we need the code or we can drop it 8-).
> 
> As it is now, we could drop UPF_EXAR_EFR altogether, right?

Let me check. It might be that there is a lurking regression nobody reported so far.

-- 
With Best Regards,
Andy Shevchenko