Skip to contentSkip to conversation

Allow hardware flow control to be used

PATCH In review Jason Uy 8 participants 21 messages Jan 11, 2017 – Mar 14, 2017 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore
author
#1 lore raw

PATCH v2 1/1 serial: 8250_dw: Allow hardware flow control to be used

In the most common use case, the Synopsys DW UART driver does not set the set_termios callback function. This prevents UPSTAT_AUTOCTS from being set when the UART flag CRTSCTS is set. As a result, the driver will use software flow control as opposed to hardware flow control.

To fix the problem, the set_termios callback function is set to the DW specific function. The logic to set UPSTAT_AUTOCTS is moved so that any clock error will not affect setting the hardware flow control.

---
 drivers/tty/serial/8250/8250_dw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tty/serial/8250/8250_dw.c +2 -3
index c89fafc..c89ae45 100644
@@ -248,11 +248,11 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
 	if (!ret)
 		p->uartclk = rate;
 
+out:
 	p->status &= ~UPSTAT_AUTOCTS;
 	if (termios->c_cflag & CRTSCTS)
 		p->status |= UPSTAT_AUTOCTS;
 
-out:
 	serial8250_do_set_termios(p, termios, old);
 }
 
@@ -326,13 +326,11 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 			p->serial_in = dw8250_serial_in32;
 			data->uart_16550_compatible = true;
 		}
-		p->set_termios = dw8250_set_termios;
 	}
 
 	/* Platforms with iDMA */
 	if (platform_get_resource_byname(to_platform_device(p->dev),
 					 IORESOURCE_MEM, "lpss_priv")) {
-		p->set_termios = dw8250_set_termios;
 		data->dma.rx_param = p->dev->parent;
 		data->dma.tx_param = p->dev->parent;
 		data->dma.fn = dw8250_idma_filter;
@@ -414,6 +412,7 @@ static int dw8250_probe(struct platform_device *pdev)
 	p->serial_in	= dw8250_serial_in;
 	p->serial_out	= dw8250_serial_out;
 	p->set_ldisc	= dw8250_set_ldisc;
+	p->set_termios	= dw8250_set_termios;
 
 	p->membase = devm_ioremap(dev, regs->start, resource_size(regs));
 	if (!p->membase)
Signature · 1 line
1.9.1
reviewer Reviewed-by on v2 1/1
#2 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Quoted 6 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not set the set_termios callback function.  This prevents UPSTAT_AUTOCTS from being set when the UART flag CRTSCTS is set.  As a result, the driver will use software flow control as opposed to hardware flow control.

Quoted 7 lines

To fix the problem, the set_termios callback function is set to the DW specific function.  The logic to set UPSTAT_AUTOCTS is moved so that any clock error will not affect setting the hardware flow control.

FWIW:

Quoted 50 lines

---
 drivers/tty/serial/8250/8250_dw.c | 5 ++---

 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tty/serial/8250/8250_dw.c +0 -0
index c89fafc..c89ae45 100644
@@ -248,11 +248,11 @@ static void dw8250_set_termios(struct uart_port
 *p, struct ktermios *termios,
  	if (!ret)
  		p->uartclk = rate;


+out:
  p->status &= ~UPSTAT_AUTOCTS;
  if (termios->c_cflag & CRTSCTS) p->status |= UPSTAT_AUTOCTS;
-out:
  serial8250_do_set_termios(p, termios, old); }

drivers/tty/serial/8250/8250_dw.c +0 -1
@@ -326,13 +326,11 @@ static void dw8250_quirks(struct uart_port *p,
 struct dw8250_data *data)
  			p->serial_in = dw8250_serial_in32;
  			data->uart_16550_compatible = true;
  		}
-		p->set_termios = dw8250_set_termios;
  	}


  /* Platforms with iDMA */
  if (platform_get_resource_byname(to_platform_device(p->dev), IORESOURCE_MEM, "lpss_priv")) {

drivers/tty/serial/8250/8250_dw.c +0 -1
-		p->set_termios = dw8250_set_termios;

  data->dma.rx_param = p->dev->parent; data->dma.tx_param = p->dev->parent; data->dma.fn = dw8250_idma_filter;

drivers/tty/serial/8250/8250_dw.c +1 -0
@@ -414,6 +412,7 @@ static int dw8250_probe(struct platform_device
 *pdev)
  	p->serial_in	= dw8250_serial_in;
  	p->serial_out	= dw8250_serial_out;
  	p->set_ldisc	= dw8250_set_ldisc;
+	p->set_termios	= dw8250_set_termios;


  p->membase = devm_ioremap(dev, regs->start, resource_size(regs));
  if (!p->membase)

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
Reviewed-by on v2 1/1
#3 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

In reply to Jason Uy
Quoted 6 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not set the set_termios callback function. This prevents UPSTAT_AUTOCTS from being set when the UART flag CRTSCTS is set. As a result, the driver will use software flow control as opposed to hardware flow control.

Quoted 8 lines

To fix the problem, the set_termios callback function is set to the DW specific function. The logic to set UPSTAT_AUTOCTS is moved so that any clock error will not affect setting the hardware flow control.

Quoted 44 lines
---
 drivers/tty/serial/8250/8250_dw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tty/serial/8250/8250_dw.c +2 -3
index c89fafc..c89ae45 100644
@@ -248,11 +248,11 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
 	if (!ret)
 		p->uartclk = rate;
 
+out:
 	p->status &= ~UPSTAT_AUTOCTS;
 	if (termios->c_cflag & CRTSCTS)
 		p->status |= UPSTAT_AUTOCTS;
 
-out:
 	serial8250_do_set_termios(p, termios, old);
 }
 
@@ -326,13 +326,11 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 			p->serial_in = dw8250_serial_in32;
 			data->uart_16550_compatible = true;
 		}
-		p->set_termios = dw8250_set_termios;
 	}
 
 	/* Platforms with iDMA */
 	if (platform_get_resource_byname(to_platform_device(p->dev),
 					 IORESOURCE_MEM, "lpss_priv")) {
-		p->set_termios = dw8250_set_termios;
 		data->dma.rx_param = p->dev->parent;
 		data->dma.tx_param = p->dev->parent;
 		data->dma.fn = dw8250_idma_filter;
@@ -414,6 +412,7 @@ static int dw8250_probe(struct platform_device *pdev)
 	p->serial_in	= dw8250_serial_in;
 	p->serial_out	= dw8250_serial_out;
 	p->set_ldisc	= dw8250_set_ldisc;
+	p->set_termios	= dw8250_set_termios;
 
 	p->membase = devm_ioremap(dev, regs->start, resource_size(regs));
 	if (!p->membase)

A message that is not in the archive (sent off-list or not yet received): CAAG0J9-n0toSJL8Ze8Esq81dYnpfrTd42bMiR94zw_btBLjsww@mail.gmail.com

#5 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Quoted 28 lines · James Hogan
Quoted 10 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not set the set_termios callback function.  This prevents UPSTAT_AUTOCTS from being set when the UART flag CRTSCTS is set.  As a result, the driver will use software flow control as opposed to hardware flow control.

To fix the problem, the set_termios callback function is set to the DW specific function.  The logic to set UPSTAT_AUTOCTS is moved so that any clock error will not affect setting the hardware flow control.

Bisection shows that this patch, commit 6a171b29937984a5e0bf29d6577b055998f03edb, has broken boot of the Cavium Octeon III based UTM-8 board (MIPS architecture).

I now get the following warning:

[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8
Quoted 3 lines

Then it hangs and the watchdog restarts the machine.

Any ideas?

1. Does it use clock on that platform?
2. Check if termios is not NULL there.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#6 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Quoted 29 lines · Andy Shevchenko
Quoted 27 lines · James Hogan
Quoted 10 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not set the set_termios callback function.  This prevents UPSTAT_AUTOCTS from being set when the UART flag CRTSCTS is set.  As a result, the driver will use software flow control as opposed to hardware flow control.

To fix the problem, the set_termios callback function is set to the DW specific function.  The logic to set UPSTAT_AUTOCTS is moved so that any clock error will not affect setting the hardware flow control.

Bisection shows that this patch, commit 6a171b29937984a5e0bf29d6577b055998f03edb, has broken boot of the Cavium Octeon III based UTM-8 board (MIPS architecture).

I now get the following warning:

[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8
Quoted 5 lines
Quoted 3 lines

Then it hangs and the watchdog restarts the machine.

Any ideas?

1. Does it use clock on that platform?

btw, sorry for HTML email blocked from lists, gmail tricked me into it :-(

I've now dug a little deeper. Essentially what is going on is:

1) CONFIG_HAVE_CLK=n (Octeon doesn't select it)
2) The CONFIG_HAVE_CLK=n implementation of devm_clk_get() returns NULL
3) The "if (IS_ERR(d->clk) || !old) {" check in dw8250_set_termios() doesn't match, since !IS_ERR(NULL)
4) The CONFIG_HAVE_CLK=n implementation of clk_round_rate() returns 0
5) The CONFIG_HAVE_CLK=n implementation of clk_set_rate(d->clk, 0) returns 0
6) dw8250_set_termios() thinks the frequency for that baud rate has been set successfully and writes 0 into uartclk
7) it all goes wrong from there...

The CONFIG_HAVE_CLK=n implementation of devm_clk_get() in particular seems highly questionable to me, given that commit 93abe8e4b13a ("clk:
add non CONFIG_HAVE_CLK routines") which added it 5 years ago says:

Quoted 1 line

These calls will return error for platforms that don't select HAVE_CLK

And NULL isn't an error in this API.

Cc'ing some clk folk.

Cheers
James

#7 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Heiko, you might be interested in this as well.

Quoted 42 lines · James Hogan
Quoted 35 lines · Andy Shevchenko
Quoted 34 lines · James Hogan
Quoted 10 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not
set the set_termios callback function.  This prevents UPSTAT_AUTOCTS
from being set when the UART flag CRTSCTS is set.  As a result, the
driver will use software flow control as opposed to hardware flow
control.

Quoted 6 lines

To fix the problem, the set_termios callback function is set to the
DW specific function.  The logic to set UPSTAT_AUTOCTS is moved so
that any clock error will not affect setting the hardware flow control.

Bisection shows that this patch, commit 6a171b29937984a5e0bf29d6577b055998f03edb, has broken boot of the Cavium Octeon III based UTM-8 board (MIPS architecture).

I now get the following warning:

[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8

Then it hangs and the watchdog restarts the machine.

Quoted 3 lines
Quoted 1 line

Any ideas?

1. Does it use clock on that platform?

I've now dug a little deeper. Essentially what is going on is:

Quoted 11 lines

1) CONFIG_HAVE_CLK=n (Octeon doesn't select it)
2) The CONFIG_HAVE_CLK=n implementation of devm_clk_get() returns NULL
3) The "if (IS_ERR(d->clk) || !old) {" check in dw8250_set_termios() doesn't match, since !IS_ERR(NULL)
4) The CONFIG_HAVE_CLK=n implementation of clk_round_rate() returns 0
5) The CONFIG_HAVE_CLK=n implementation of clk_set_rate(d->clk, 0) returns 0
6) dw8250_set_termios() thinks the frequency for that baud rate has been
   set successfully and writes 0 into uartclk
7) it all goes wrong from there...

So, it means we have need special care of NULL case here, and honestly, I don't like it. But it seems the only feasible (quick) fix right now.

Quoted 8 lines

The CONFIG_HAVE_CLK=n implementation of devm_clk_get() in particular seems highly questionable to me, given that commit 93abe8e4b13a ("clk:
add non CONFIG_HAVE_CLK routines") which added it 5 years ago says:

Quoted 2 lines

These calls will return error for platforms that don't select HAVE_CLK

And NULL isn't an error in this API.

Which is okay. I dunno what should be returned from clk_round_rate() if clk is NULL. I would fix CLK framework, though I would like to gather more details.

Btw, I hope you also noticed this one:

http://www.spinics.net/lists/linux-serial/msg25314.html

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#8 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Hi Andy/Jason,

Quoted 57 lines · Andy Shevchenko

Heiko, you might be interested in this as well.

Quoted 42 lines · James Hogan
Quoted 35 lines · Andy Shevchenko
Quoted 34 lines · James Hogan
Quoted 10 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not
set the set_termios callback function. This prevents UPSTAT_AUTOCTS
from being set when the UART flag CRTSCTS is set. As a result, the
driver will use software flow control as opposed to hardware flow
control.

Quoted 6 lines

To fix the problem, the set_termios callback function is set to the
DW specific function. The logic to set UPSTAT_AUTOCTS is moved so
that any clock error will not affect setting the hardware flow control.

Bisection shows that this patch, commit 6a171b29937984a5e0bf29d6577b055998f03edb, has broken boot of the Cavium Octeon III based UTM-8 board (MIPS architecture).

I now get the following warning:

[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8

Then it hangs and the watchdog restarts the machine.

Quoted 3 lines
Quoted 1 line

Any ideas?

1. Does it use clock on that platform?

I've now dug a little deeper. Essentially what is going on is:

Quoted 11 lines

1) CONFIG_HAVE_CLK=n (Octeon doesn't select it)
2) The CONFIG_HAVE_CLK=n implementation of devm_clk_get() returns NULL
3) The "if (IS_ERR(d->clk) || !old) {" check in dw8250_set_termios() doesn't match, since !IS_ERR(NULL)
4) The CONFIG_HAVE_CLK=n implementation of clk_round_rate() returns 0
5) The CONFIG_HAVE_CLK=n implementation of clk_set_rate(d->clk, 0) returns 0
6) dw8250_set_termios() thinks the frequency for that baud rate has been
set successfully and writes 0 into uartclk
7) it all goes wrong from there...

Quoted 2 lines

So, it means we have need special care of NULL case here, and honestly, I don't like it. But it seems the only feasible (quick) fix right now.

I agree. I think it should have been:

if (IS_ERR_OR_NULL(d->clk) || !old)

    goto out;

I think it makes sense to validate to make sure the 'clk' pointer is valid before proceeding any further down below (regardless of how well or how not well the clock framework handles it).

Thanks,

Ray

Quoted 18 lines
Quoted 9 lines

The CONFIG_HAVE_CLK=n implementation of devm_clk_get() in particular seems highly questionable to me, given that commit 93abe8e4b13a ("clk:
add non CONFIG_HAVE_CLK routines") which added it 5 years ago says:

Quoted 2 lines

These calls will return error for platforms that don't select HAVE_CLK

And NULL isn't an error in this API.

Which is okay. I dunno what should be returned from clk_round_rate() if clk is NULL. I would fix CLK framework, though I would like to gather more details.

Btw, I hope you also noticed this one:

http://www.spinics.net/lists/linux-serial/msg25314.html

author
#9 lore raw

RE: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

James,

Can you verify that changing the code to the following fixes your problem?

if (IS_ERR_OR_NULL(d->clk) || !old)

    goto out;

Regards,
Jason

-----Original Message-----
From: Ray Jui [mailto:[email protected]]
Sent: March-03-17 9:34 AM
To: Andy Shevchenko <[email protected]>; James Hogan <[email protected]>; Heiko Stuebner <[email protected]>
Cc: Jason Uy <[email protected]>; Greg Kroah-Hartman <[email protected]>; Jiri Slaby <[email protected]>; Kefeng Wang <[email protected]>; Noam Camus <[email protected]>; Heikki Krogerus <[email protected]>; Wang Hongcheng <[email protected]>; [email protected]; LKML <[email protected]>; [email protected]; Linux MIPS Mailing List <[email protected]>; David Daney <[email protected]>; Russell King <[email protected]>; [email protected]; Viresh Kumar <[email protected]>
Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Hi Andy/Jason,

Quoted 52 lines · Andy Shevchenko

Heiko, you might be interested in this as well.

Quoted 36 lines · James Hogan
Quoted 29 lines · Andy Shevchenko
Quoted 28 lines · James Hogan
Quoted 10 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not set the set_termios callback function. This prevents UPSTAT_AUTOCTS from being set when the UART flag CRTSCTS is set. As a result, the driver will use software flow control as opposed to hardware flow control.

To fix the problem, the set_termios callback function is set to the DW specific function. The logic to set UPSTAT_AUTOCTS is moved so that any clock error will not affect setting the hardware flow control.

Bisection shows that this patch, commit 6a171b29937984a5e0bf29d6577b055998f03edb, has broken boot of the Cavium Octeon III based UTM-8 board (MIPS architecture).

I now get the following warning:

[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8 Then it hangs and the

watchdog restarts the machine.

Quoted 3 lines
Quoted 1 line

Any ideas?

1. Does it use clock on that platform?

I've now dug a little deeper. Essentially what is going on is:

Quoted 12 lines

1) CONFIG_HAVE_CLK=n (Octeon doesn't select it)
2) The CONFIG_HAVE_CLK=n implementation of devm_clk_get() returns NULL
3) The "if (IS_ERR(d->clk) || !old) {" check in dw8250_set_termios() doesn't match, since !IS_ERR(NULL)
4) The CONFIG_HAVE_CLK=n implementation of clk_round_rate() returns 0
5) The CONFIG_HAVE_CLK=n implementation of clk_set_rate(d->clk, 0) returns 0
6) dw8250_set_termios() thinks the frequency for that baud rate has been
set successfully and writes 0 into uartclk
7) it all goes wrong from there...

Quoted 3 lines

So, it means we have need special care of NULL case here, and honestly, I don't like it. But it seems the only feasible (quick) fix right now.

I agree. I think it should have been:

if (IS_ERR_OR_NULL(d->clk) || !old)

    goto out;

I think it makes sense to validate to make sure the 'clk' pointer is valid before proceeding any further down below (regardless of how well or how not well the clock framework handles it).

Thanks,

Ray

Quoted 18 lines
Quoted 9 lines

The CONFIG_HAVE_CLK=n implementation of devm_clk_get() in particular seems highly questionable to me, given that commit 93abe8e4b13a ("clk:
add non CONFIG_HAVE_CLK routines") which added it 5 years ago says:

Quoted 2 lines

These calls will return error for platforms that don't select HAVE_CLK

And NULL isn't an error in this API.

Which is okay. I dunno what should be returned from clk_round_rate() if clk is NULL. I would fix CLK framework, though I would like to gather more details.

Btw, I hope you also noticed this one:

http://www.spinics.net/lists/linux-serial/msg25314.html

#10 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Hi Jason,

Quoted 6 lines · Jason Uy

James,

Can you verify that changing the code to the following fixes your problem?

if (IS_ERR_OR_NULL(d->clk) || !old)

    goto out;

It does, however I'm not at all convinced it is correct. clk_get either returns a valid opaque clock cookie that can be passed to other clock functions (which includes NULL), or ERR_PTR(-errno), which IS_ERR() should catch for errors.

According to this thread:

https://lists.gt.net/linux/kernel/2102623

we should stick to the clk API and use IS_ERR() rather than IS_ERR_OR_NULL(), but shouldn't be blindly accepting the result of clk_get_rate() (or I suppose clk_round_rate()), but rather checking for the value 0 and handling that case as "we don't have a usable clock from the clk api, fall back to something else".

Cheers
James

Quoted 111 lines

Regards,
Jason

-----Original Message-----
From: Ray Jui [mailto:[email protected]]
Sent: March-03-17 9:34 AM
To: Andy Shevchenko <[email protected]>; James Hogan <[email protected]>; Heiko Stuebner <[email protected]>
Cc: Jason Uy <[email protected]>; Greg Kroah-Hartman <[email protected]>; Jiri Slaby <[email protected]>; Kefeng Wang <[email protected]>; Noam Camus <[email protected]>; Heikki Krogerus <[email protected]>; Wang Hongcheng <[email protected]>; [email protected]; LKML <[email protected]>; [email protected]; Linux MIPS Mailing List <[email protected]>; David Daney <[email protected]>; Russell King <[email protected]>; [email protected]; Viresh Kumar <[email protected]>
Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Hi Andy/Jason,

Quoted 52 lines · Andy Shevchenko

Heiko, you might be interested in this as well.

Quoted 36 lines · James Hogan
Quoted 29 lines · Andy Shevchenko
Quoted 28 lines · James Hogan
Quoted 10 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not set the set_termios callback function. This prevents UPSTAT_AUTOCTS from being set when the UART flag CRTSCTS is set. As a result, the driver will use software flow control as opposed to hardware flow control.

To fix the problem, the set_termios callback function is set to the DW specific function. The logic to set UPSTAT_AUTOCTS is moved so that any clock error will not affect setting the hardware flow control.

Bisection shows that this patch, commit 6a171b29937984a5e0bf29d6577b055998f03edb, has broken boot of the Cavium Octeon III based UTM-8 board (MIPS architecture).

I now get the following warning:

[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8 Then it hangs and the

watchdog restarts the machine.

Quoted 3 lines
Quoted 1 line

Any ideas?

1. Does it use clock on that platform?

I've now dug a little deeper. Essentially what is going on is:

Quoted 12 lines

1) CONFIG_HAVE_CLK=n (Octeon doesn't select it)
2) The CONFIG_HAVE_CLK=n implementation of devm_clk_get() returns NULL
3) The "if (IS_ERR(d->clk) || !old) {" check in dw8250_set_termios() doesn't match, since !IS_ERR(NULL)
4) The CONFIG_HAVE_CLK=n implementation of clk_round_rate() returns 0
5) The CONFIG_HAVE_CLK=n implementation of clk_set_rate(d->clk, 0) returns 0
6) dw8250_set_termios() thinks the frequency for that baud rate has been
set successfully and writes 0 into uartclk
7) it all goes wrong from there...

Quoted 3 lines

So, it means we have need special care of NULL case here, and honestly, I don't like it. But it seems the only feasible (quick) fix right now.

I agree. I think it should have been:

if (IS_ERR_OR_NULL(d->clk) || !old)

    goto out;

I think it makes sense to validate to make sure the 'clk' pointer is valid before proceeding any further down below (regardless of how well or how not well the clock framework handles it).

Thanks,

Ray

Quoted 18 lines
Quoted 9 lines

The CONFIG_HAVE_CLK=n implementation of devm_clk_get() in particular seems highly questionable to me, given that commit 93abe8e4b13a ("clk:
add non CONFIG_HAVE_CLK routines") which added it 5 years ago says:

Quoted 2 lines

These calls will return error for platforms that don't select HAVE_CLK

And NULL isn't an error in this API.

Which is okay. I dunno what should be returned from clk_round_rate() if clk is NULL. I would fix CLK framework, though I would like to gather more details.

Btw, I hope you also noticed this one:

http://www.spinics.net/lists/linux-serial/msg25314.html

author
#11 lore raw

RE: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

HI James,

Maybe instead of that, we should do this instead

If ((IS_ERR(d->clk) && PTR_ERR(d->clk)) || !old)

Note that this is what is done in the probe function of the dw driver.

Regards,
Jason

-----Original Message-----
From: James Hogan [mailto:[email protected]]
Sent: March-03-17 3:07 PM
To: Jason Uy <[email protected]>
Cc: Ray Jui <[email protected]>; Andy Shevchenko <[email protected]>; Heiko Stuebner <[email protected]>; Greg Kroah-Hartman <[email protected]>; Jiri Slaby <[email protected]>; Kefeng Wang <[email protected]>; Noam Camus <[email protected]>; Heikki Krogerus <[email protected]>; Wang Hongcheng <[email protected]>; [email protected]; LKML <[email protected]>; [email protected]; Linux MIPS Mailing List <[email protected]>; David Daney <[email protected]>; Russell King <[email protected]>; [email protected]; Viresh Kumar <[email protected]>
Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Hi Jason,

Quoted 6 lines · Jason Uy

James,

Can you verify that changing the code to the following fixes your problem?

if (IS_ERR_OR_NULL(d->clk) || !old)

    goto out;

It does, however I'm not at all convinced it is correct. clk_get either returns a valid opaque clock cookie that can be passed to other clock functions (which includes NULL), or ERR_PTR(-errno), which IS_ERR() should catch for errors.

According to this thread:

https://lists.gt.net/linux/kernel/2102623

we should stick to the clk API and use IS_ERR() rather than IS_ERR_OR_NULL(), but shouldn't be blindly accepting the result of clk_get_rate() (or I suppose clk_round_rate()), but rather checking for the value 0 and handling that case as "we don't have a usable clock from the clk api, fall back to something else".

Cheers
James

Quoted 113 lines

Regards,
Jason

-----Original Message-----
From: Ray Jui [mailto:[email protected]]
Sent: March-03-17 9:34 AM
To: Andy Shevchenko <[email protected]>; James Hogan <[email protected]>; Heiko Stuebner <[email protected]>
Cc: Jason Uy <[email protected]>; Greg Kroah-Hartman <[email protected]>; Jiri Slaby <[email protected]>; Kefeng Wang <[email protected]>; Noam Camus <[email protected]>; Heikki Krogerus <[email protected]>; Wang Hongcheng <[email protected]>; [email protected]; LKML <[email protected]>; [email protected]; Linux MIPS Mailing List <[email protected]>; David Daney <[email protected]>; Russell King <[email protected]>; [email protected]; Viresh Kumar <[email protected]>
Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Hi Andy/Jason,

Quoted 53 lines · Andy Shevchenko

Heiko, you might be interested in this as well.

Quoted 36 lines · James Hogan
Quoted 29 lines · Andy Shevchenko
Quoted 28 lines · James Hogan
Quoted 10 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not set the set_termios callback function. This prevents UPSTAT_AUTOCTS from being set when the UART flag CRTSCTS is set. As a result, the driver will use software flow control as opposed to hardware flow control.

To fix the problem, the set_termios callback function is set to the DW specific function. The logic to set UPSTAT_AUTOCTS is moved so that any clock error will not affect setting the hardware flow control.

Bisection shows that this patch, commit 6a171b29937984a5e0bf29d6577b055998f03edb, has broken boot of the Cavium Octeon III based UTM-8 board (MIPS architecture).

I now get the following warning:

[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8 Then it hangs and

the watchdog restarts the machine.

Quoted 3 lines
Quoted 1 line

Any ideas?

1. Does it use clock on that platform?

I've now dug a little deeper. Essentially what is going on is:

Quoted 13 lines

1) CONFIG_HAVE_CLK=n (Octeon doesn't select it)
2) The CONFIG_HAVE_CLK=n implementation of devm_clk_get() returns NULL
3) The "if (IS_ERR(d->clk) || !old) {" check in dw8250_set_termios() doesn't match, since !IS_ERR(NULL)
4) The CONFIG_HAVE_CLK=n implementation of clk_round_rate() returns 0
5) The CONFIG_HAVE_CLK=n implementation of clk_set_rate(d->clk, 0) returns 0
6) dw8250_set_termios() thinks the frequency for that baud rate has been
set successfully and writes 0 into uartclk
7) it all goes wrong from there...

Quoted 3 lines

So, it means we have need special care of NULL case here, and honestly, I don't like it. But it seems the only feasible (quick) fix right now.

I agree. I think it should have been:

if (IS_ERR_OR_NULL(d->clk) || !old)

    goto out;

I think it makes sense to validate to make sure the 'clk' pointer is valid before proceeding any further down below (regardless of how well or how not well the clock framework handles it).

Thanks,

Ray

Quoted 19 lines
Quoted 10 lines

The CONFIG_HAVE_CLK=n implementation of devm_clk_get() in particular seems highly questionable to me, given that commit 93abe8e4b13a ("clk:
add non CONFIG_HAVE_CLK routines") which added it 5 years ago says:

Quoted 2 lines

These calls will return error for platforms that don't select HAVE_CLK

And NULL isn't an error in this API.

Which is okay. I dunno what should be returned from clk_round_rate() if clk is NULL. I would fix CLK framework, though I would like to gather more details.

Btw, I hope you also noticed this one:

http://www.spinics.net/lists/linux-serial/msg25314.html

#12 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Hi Jason,

Quoted 5 lines · Jason Uy

HI James,

Maybe instead of that, we should do this instead

If ((IS_ERR(d->clk) && PTR_ERR(d->clk)) || !old)

IS_ERR(x) matches a range of non-zero negative values, so it implies PTR_ERR(x) already, so it doesn't change anything.

Cheers
James

Quoted 164 lines

Note that this is what is done in the probe function of the dw driver.

Regards,
Jason

-----Original Message-----
From: James Hogan [mailto:[email protected]]
Sent: March-03-17 3:07 PM
To: Jason Uy <[email protected]>
Cc: Ray Jui <[email protected]>; Andy Shevchenko <[email protected]>; Heiko Stuebner <[email protected]>; Greg Kroah-Hartman <[email protected]>; Jiri Slaby <[email protected]>; Kefeng Wang <[email protected]>; Noam Camus <[email protected]>; Heikki Krogerus <[email protected]>; Wang Hongcheng <[email protected]>; [email protected]; LKML <[email protected]>; [email protected]; Linux MIPS Mailing List <[email protected]>; David Daney <[email protected]>; Russell King <[email protected]>; [email protected]; Viresh Kumar <[email protected]>
Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Hi Jason,

Quoted 6 lines · Jason Uy

James,

Can you verify that changing the code to the following fixes your problem?

if (IS_ERR_OR_NULL(d->clk) || !old)

    goto out;

It does, however I'm not at all convinced it is correct. clk_get either returns a valid opaque clock cookie that can be passed to other clock functions (which includes NULL), or ERR_PTR(-errno), which IS_ERR() should catch for errors.

According to this thread:

https://lists.gt.net/linux/kernel/2102623

we should stick to the clk API and use IS_ERR() rather than IS_ERR_OR_NULL(), but shouldn't be blindly accepting the result of clk_get_rate() (or I suppose clk_round_rate()), but rather checking for the value 0 and handling that case as "we don't have a usable clock from the clk api, fall back to something else".

Cheers
James

Quoted 113 lines

Regards,
Jason

-----Original Message-----
From: Ray Jui [mailto:[email protected]]
Sent: March-03-17 9:34 AM
To: Andy Shevchenko <[email protected]>; James Hogan <[email protected]>; Heiko Stuebner <[email protected]>
Cc: Jason Uy <[email protected]>; Greg Kroah-Hartman <[email protected]>; Jiri Slaby <[email protected]>; Kefeng Wang <[email protected]>; Noam Camus <[email protected]>; Heikki Krogerus <[email protected]>; Wang Hongcheng <[email protected]>; [email protected]; LKML <[email protected]>; [email protected]; Linux MIPS Mailing List <[email protected]>; David Daney <[email protected]>; Russell King <[email protected]>; [email protected]; Viresh Kumar <[email protected]>
Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Hi Andy/Jason,

Quoted 53 lines · Andy Shevchenko

Heiko, you might be interested in this as well.

Quoted 36 lines · James Hogan
Quoted 29 lines · Andy Shevchenko
Quoted 28 lines · James Hogan
Quoted 10 lines · Jason Uy

In the most common use case, the Synopsys DW UART driver does not set the set_termios callback function. This prevents UPSTAT_AUTOCTS from being set when the UART flag CRTSCTS is set. As a result, the driver will use software flow control as opposed to hardware flow control.

To fix the problem, the set_termios callback function is set to the DW specific function. The logic to set UPSTAT_AUTOCTS is moved so that any clock error will not affect setting the hardware flow control.

Bisection shows that this patch, commit 6a171b29937984a5e0bf29d6577b055998f03edb, has broken boot of the Cavium Octeon III based UTM-8 board (MIPS architecture).

I now get the following warning:

[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8 Then it hangs and

the watchdog restarts the machine.

Quoted 3 lines
Quoted 1 line

Any ideas?

1. Does it use clock on that platform?

I've now dug a little deeper. Essentially what is going on is:

Quoted 13 lines

1) CONFIG_HAVE_CLK=n (Octeon doesn't select it)
2) The CONFIG_HAVE_CLK=n implementation of devm_clk_get() returns NULL
3) The "if (IS_ERR(d->clk) || !old) {" check in dw8250_set_termios() doesn't match, since !IS_ERR(NULL)
4) The CONFIG_HAVE_CLK=n implementation of clk_round_rate() returns 0
5) The CONFIG_HAVE_CLK=n implementation of clk_set_rate(d->clk, 0) returns 0
6) dw8250_set_termios() thinks the frequency for that baud rate has been
set successfully and writes 0 into uartclk
7) it all goes wrong from there...

Quoted 3 lines

So, it means we have need special care of NULL case here, and honestly, I don't like it. But it seems the only feasible (quick) fix right now.

I agree. I think it should have been:

if (IS_ERR_OR_NULL(d->clk) || !old)

    goto out;

I think it makes sense to validate to make sure the 'clk' pointer is valid before proceeding any further down below (regardless of how well or how not well the clock framework handles it).

Thanks,

Ray

Quoted 19 lines
Quoted 10 lines

The CONFIG_HAVE_CLK=n implementation of devm_clk_get() in particular seems highly questionable to me, given that commit 93abe8e4b13a ("clk:
add non CONFIG_HAVE_CLK routines") which added it 5 years ago says:

Quoted 2 lines

These calls will return error for platforms that don't select HAVE_CLK

And NULL isn't an error in this API.

Which is okay. I dunno what should be returned from clk_round_rate() if clk is NULL. I would fix CLK framework, though I would like to gather more details.

Btw, I hope you also noticed this one:

http://www.spinics.net/lists/linux-serial/msg25314.html

#13 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · James Hogan

The CONFIG_HAVE_CLK=n implementation of devm_clk_get() in particular seems highly questionable to me, given that commit 93abe8e4b13a ("clk:
add non CONFIG_HAVE_CLK routines") which added it 5 years ago says:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

These calls will return error for platforms that don't select HAVE_CLK

And NULL isn't an error in this API.

Which is okay. I dunno what should be returned from clk_round_rate() if clk is NULL. I would fix CLK framework, though I would like to gather more details.

Hmm, the common clock framwork is just one implementation of the clock API that won't use NULL as a valid clock handle. HAVE_CLK=n is just another implementation that does return NULL as a valid value, and accepts that value in the other clk functions.

Quoted 3 lines

Btw, I hope you also noticed this one:

http://www.spinics.net/lists/linux-serial/msg25314.html

Interesting.

Following Russel's past advise[1], the following patch on top of Heiko's patch also fixes things for me on Octeon:

[1] https://lists.gt.net/linux/kernel/2102623

If thats an acceptable fix I'll post it properly. Thoughts?

Cheers
James

drivers/tty/serial/8250/8250_dw.c +2 -0
index 223ac234ddb2..e65808c482f1 100644
@@ -267,6 +267,8 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
 	rate = clk_round_rate(d->clk, baud * 16);
 	if (rate < 0)
 		ret = rate;
+	else if (rate == 0)
+		ret = -ENOENT;
 	else
 		ret = clk_set_rate(d->clk, rate);
 	clk_prepare_enable(d->clk);
#14 lore raw

Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to be used

Quoted 10 lines · James Hogan
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · James Hogan

The CONFIG_HAVE_CLK=n implementation of devm_clk_get() in particular seems highly questionable to me, given that commit 93abe8e4b13a ("clk:
add non CONFIG_HAVE_CLK routines") which added it 5 years ago says:

Btw, I hope you also noticed this one:

http://www.spinics.net/lists/linux-serial/msg25314.html

Quoted 8 lines

Interesting.

Following Russel's past advise[1], the following patch on top of Heiko's patch also fixes things for me on Octeon:

[1] https://lists.gt.net/linux/kernel/2102623

If thats an acceptable fix I'll post it properly. Thoughts?

Fine by me. Looks definitely better than IS_ERR_OR_NULL().

Please, submit as usual with your SoB tag.

Quoted 13 lines
drivers/tty/serial/8250/8250_dw.c +2 -0
index 223ac234ddb2..e65808c482f1 100644
@@ -267,6 +267,8 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
        rate = clk_round_rate(d->clk, baud * 16);
        if (rate < 0)
                ret = rate;
+       else if (rate == 0)
+               ret = -ENOENT;
        else
                ret = clk_set_rate(d->clk, rate);
        clk_prepare_enable(d->clk);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#15 lore raw

PATCH 1/1 serial: 8250_dw: Fix breakage when HAVE_CLK=n

Commit 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used") recently broke the 8250_dw driver on platforms which don't select HAVE_CLK, as dw8250_set_termios() gets confused by the behaviour of the fallback HAVE_CLK=n clock API in linux/clk.h which pretends everything is fine but returns (valid) NULL clocks and 0 HZ clock rates.

That 0 rate is written into the uartclk resulting in a crash at boot, e.g. on Cavium Octeon III based UTM-8 we get something like this:

1180000000800.serial: ttyS0 at MMIO 0x1180000000800 (irq = 41, base_baud = 25000000) is a OCTEON

------------[ cut here ]------------
WARNING: CPU: 2 PID: 1 at drivers/tty/serial/serial_core.c:441 uart_get_baud_rate+0xfc/0x1f0
...
Call Trace:
...
[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8

...

The clock API is defined such that NULL is a valid clock handle so it wouldn't be right to check explicitly for NULL. Instead treat a clk_round_rate() return value of 0 as an error which prevents uartclk being overwritten.

Fixes 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used")
Cc Greg Kroah-Hartman <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Jason Uy <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc David Daney <[email protected]>
Cc Russell King <[email protected]>
---
 drivers/tty/serial/8250/8250_dw.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/tty/serial/8250/8250_dw.c +2 -0
index 223ac234ddb2..e65808c482f1 100644
@@ -267,6 +267,8 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
 	rate = clk_round_rate(d->clk, baud * 16);
 	if (rate < 0)
 		ret = rate;
+	else if (rate == 0)
+		ret = -ENOENT;
 	else
 		ret = clk_set_rate(d->clk, rate);
 	clk_prepare_enable(d->clk);
Signature · 1 line
2.11.1
Reviewed-by on v1 1/1
#16 lore raw

Re: [PATCH] serial: 8250_dw: Fix breakage when HAVE_CLK=n

Quoted 24 lines · James Hogan

Commit 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used") recently broke the 8250_dw driver on platforms which don't select HAVE_CLK, as dw8250_set_termios() gets confused by the behaviour of the fallback HAVE_CLK=n clock API in linux/clk.h which pretends everything is fine but returns (valid) NULL clocks and 0 HZ clock rates.

That 0 rate is written into the uartclk resulting in a crash at boot, e.g. on Cavium Octeon III based UTM-8 we get something like this:

1180000000800.serial: ttyS0 at MMIO 0x1180000000800 (irq = 41, base_baud = 25000000) is a OCTEON

------------[ cut here ]------------
WARNING: CPU: 2 PID: 1 at drivers/tty/serial/serial_core.c:441 uart_get_baud_rate+0xfc/0x1f0
...
Call Trace:
...
[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8
Quoted 7 lines

...

The clock API is defined such that NULL is a valid clock handle so it wouldn't be right to check explicitly for NULL. Instead treat a clk_round_rate() return value of 0 as an error which prevents uartclk being overwritten.

You forgot to add that it is dependent to Heiko's patch
http://www.spinics.net/lists/linux-serial/msg25314.html

Patch looks good to me and shouldn't bring any regression to Intel hardware (x86 is using clock framework).

Quoted 33 lines
Fixes 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used")
Cc Greg Kroah-Hartman <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Jason Uy <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc David Daney <[email protected]>
Cc Russell King <[email protected]>
---
 drivers/tty/serial/8250/8250_dw.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/tty/serial/8250/8250_dw.c +2 -1
index 223ac234ddb2..e65808c482f1 100644
@@ -267,6 +267,8 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
        rate = clk_round_rate(d->clk, baud * 16);
        if (rate < 0)
                ret = rate;
+       else if (rate == 0)
+               ret = -ENOENT;
        else
                ret = clk_set_rate(d->clk, rate);
        clk_prepare_enable(d->clk);
--

2.11.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#17 lore raw

Re: [PATCH] serial: 8250_dw: Fix breakage when HAVE_CLK=n

Quoted 27 lines · Andy Shevchenko
Quoted 26 lines · James Hogan

Commit 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used") recently broke the 8250_dw driver on platforms which don't select HAVE_CLK, as dw8250_set_termios() gets confused by the behaviour of the fallback HAVE_CLK=n clock API in linux/clk.h which pretends everything is fine but returns (valid) NULL clocks and 0 HZ clock rates.

That 0 rate is written into the uartclk resulting in a crash at boot, e.g. on Cavium Octeon III based UTM-8 we get something like this:

1180000000800.serial: ttyS0 at MMIO 0x1180000000800 (irq = 41, base_baud = 25000000) is a OCTEON

------------[ cut here ]------------
WARNING: CPU: 2 PID: 1 at drivers/tty/serial/serial_core.c:441 uart_get_baud_rate+0xfc/0x1f0
...
Call Trace:
...
[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8

...

Quoted 8 lines
Quoted 5 lines

The clock API is defined such that NULL is a valid clock handle so it wouldn't be right to check explicitly for NULL. Instead treat a clk_round_rate() return value of 0 as an error which prevents uartclk being overwritten.

You forgot to add that it is dependent to Heiko's patch
http://www.spinics.net/lists/linux-serial/msg25314.html

Indeed I did. Sorry about that.

Quoted 5 lines

Patch looks good to me and shouldn't bring any regression to Intel hardware (x86 is using clock framework).

Thanks
James

author Reviewed-by
#18 lore raw

RE: [PATCH] serial: 8250_dw: Fix breakage when HAVE_CLK=n

Looks good

-----Original Message-----
From: James Hogan [mailto:[email protected]]
Sent: March-06-17 2:16 AM
To: Andy Shevchenko <[email protected]>
Cc: [email protected]; Greg Kroah-Hartman <[email protected]>; Andy Shevchenko <[email protected]>; Jason Uy <[email protected]>; Kefeng Wang <[email protected]>; Heiko Stuebner <[email protected]>; David Daney <[email protected]>; Russell King <[email protected]>; [email protected]; [email protected]; [email protected]; bcm-kernel-feedback-list <[email protected]>
Subject: Re: [PATCH] serial: 8250_dw: Fix breakage when HAVE_CLK=n

Quoted 30 lines · Andy Shevchenko
Quoted 28 lines · James Hogan

Commit 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be
used") recently broke the 8250_dw driver on platforms which don't select HAVE_CLK, as dw8250_set_termios() gets confused by the behaviour of the fallback HAVE_CLK=n clock API in linux/clk.h which pretends everything is fine but returns (valid) NULL clocks and 0 HZ clock rates.

That 0 rate is written into the uartclk resulting in a crash at boot, e.g. on Cavium Octeon III based UTM-8 we get something like this:

1180000000800.serial: ttyS0 at MMIO 0x1180000000800 (irq = 41, base_baud = 25000000) is a OCTEON ------------[ cut here ]------------

WARNING: CPU: 2 PID: 1 at drivers/tty/serial/serial_core.c:441
uart_get_baud_rate+0xfc/0x1f0 ...
Call Trace:
...
[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8 ...
Quoted 8 lines
Quoted 5 lines

The clock API is defined such that NULL is a valid clock handle so it wouldn't be right to check explicitly for NULL. Instead treat a clk_round_rate() return value of 0 as an error which prevents uartclk being overwritten.

You forgot to add that it is dependent to Heiko's patch
http://www.spinics.net/lists/linux-serial/msg25314.html

Indeed I did. Sorry about that.

Quoted 5 lines

Patch looks good to me and shouldn't bring any regression to Intel hardware (x86 is using clock framework).

Thanks
James

Reviewed-by on v1 1/1
#19 lore raw

Re: [PATCH] serial: 8250_dw: Fix breakage when HAVE_CLK=n

In reply to James Hogan

Am Samstag, 4. März 2017, 13:09:58 CET schrieb James Hogan:

Quoted 53 lines

Commit 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used") recently broke the 8250_dw driver on platforms which don't select HAVE_CLK, as dw8250_set_termios() gets confused by the behaviour of the fallback HAVE_CLK=n clock API in linux/clk.h which pretends everything is fine but returns (valid) NULL clocks and 0 HZ clock rates.

That 0 rate is written into the uartclk resulting in a crash at boot, e.g. on Cavium Octeon III based UTM-8 we get something like this:

1180000000800.serial: ttyS0 at MMIO 0x1180000000800 (irq = 41, base_baud = 25000000) is a OCTEON ------------[ cut here ]------------

WARNING: CPU: 2 PID: 1 at drivers/tty/serial/serial_core.c:441
uart_get_baud_rate+0xfc/0x1f0 ...
Call Trace:
...
[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8

...

The clock API is defined such that NULL is a valid clock handle so it wouldn't be right to check explicitly for NULL. Instead treat a clk_round_rate() return value of 0 as an error which prevents uartclk being overwritten.

Fixes 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be

used") Signed-off-by: James Hogan <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Jason Uy <[email protected]>
Cc: Kefeng Wang <[email protected]>
Cc: Heiko Stuebner <[email protected]>
Cc: David Daney <[email protected]>
Cc: Russell King <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 drivers/tty/serial/8250/8250_dw.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/tty/serial/8250/8250_dw.c index 223ac234ddb2..e65808c482f1 100644

drivers/tty/serial/8250/8250_dw.c static void dw8250_set_termios(struct uart_port *p, · line 274

Quoted 8 lines
drivers/tty/serial/8250/8250_dw.c +2 -0
@@ -267,6 +267,8 @@ static void dw8250_set_termios(struct uart_port *p,
 struct ktermios *termios, rate = clk_round_rate(d->clk, baud * 16);
 	if (rate < 0)
 		ret = rate;
+	else if (rate == 0)
+		ret = -ENOENT;
 	else
 		ret = clk_set_rate(d->clk, rate);
 	clk_prepare_enable(d->clk);

Looks good

#20 lore raw

Re: [PATCH] serial: 8250_dw: Fix breakage when HAVE_CLK=n

In reply to James Hogan

Hi Greg,

Quoted 31 lines · James Hogan

Commit 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used") recently broke the 8250_dw driver on platforms which don't select HAVE_CLK, as dw8250_set_termios() gets confused by the behaviour of the fallback HAVE_CLK=n clock API in linux/clk.h which pretends everything is fine but returns (valid) NULL clocks and 0 HZ clock rates.

That 0 rate is written into the uartclk resulting in a crash at boot, e.g. on Cavium Octeon III based UTM-8 we get something like this:

1180000000800.serial: ttyS0 at MMIO 0x1180000000800 (irq = 41, base_baud = 25000000) is a OCTEON

------------[ cut here ]------------
WARNING: CPU: 2 PID: 1 at drivers/tty/serial/serial_core.c:441 uart_get_baud_rate+0xfc/0x1f0
...
Call Trace:
...
[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8

...

The clock API is defined such that NULL is a valid clock handle so it wouldn't be right to check explicitly for NULL. Instead treat a clk_round_rate() return value of 0 as an error which prevents uartclk being overwritten.

Quoted 13 lines
Fixes 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used")
Cc Greg Kroah-Hartman <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Jason Uy <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc David Daney <[email protected]>
Cc Russell King <[email protected]>

Any chance we could have this patch in v4.11-rc3?

As Andy pointed out, it depends on Heiko's patch:
https://www.spinics.net/lists/linux-serial/msg25483.html

Thanks
James

#21 lore raw

Re: [PATCH] serial: 8250_dw: Fix breakage when HAVE_CLK=n

Quoted 48 lines · James Hogan

Hi Greg,

Quoted 31 lines · James Hogan

Commit 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used") recently broke the 8250_dw driver on platforms which don't select HAVE_CLK, as dw8250_set_termios() gets confused by the behaviour of the fallback HAVE_CLK=n clock API in linux/clk.h which pretends everything is fine but returns (valid) NULL clocks and 0 HZ clock rates.

That 0 rate is written into the uartclk resulting in a crash at boot, e.g. on Cavium Octeon III based UTM-8 we get something like this:

1180000000800.serial: ttyS0 at MMIO 0x1180000000800 (irq = 41, base_baud = 25000000) is a OCTEON

------------[ cut here ]------------
WARNING: CPU: 2 PID: 1 at drivers/tty/serial/serial_core.c:441 uart_get_baud_rate+0xfc/0x1f0
...
Call Trace:
...
[<ffffffff8149c2e4>] uart_get_baud_rate+0xfc/0x1f0
[<ffffffff814a5098>] serial8250_do_set_termios+0xb0/0x440
[<ffffffff8149c710>] uart_set_options+0xe8/0x190
[<ffffffff814a6cdc>] serial8250_console_setup+0x84/0x158
[<ffffffff814a11ec>] univ8250_console_setup+0x54/0x70
[<ffffffff811901a0>] register_console+0x1c8/0x418
[<ffffffff8149f004>] uart_add_one_port+0x434/0x4b0
[<ffffffff814a1af8>] serial8250_register_8250_port+0x2d8/0x440
[<ffffffff814aa620>] dw8250_probe+0x388/0x5e8

...

The clock API is defined such that NULL is a valid clock handle so it wouldn't be right to check explicitly for NULL. Instead treat a clk_round_rate() return value of 0 as an error which prevents uartclk being overwritten.

Quoted 13 lines
Fixes 6a171b299379 ("serial: 8250_dw: Allow hardware flow control to be used")
Cc Greg Kroah-Hartman <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Jason Uy <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc David Daney <[email protected]>
Cc Russell King <[email protected]>
Quoted 4 lines

Any chance we could have this patch in v4.11-rc3?

As Andy pointed out, it depends on Heiko's patch:
https://www.spinics.net/lists/linux-serial/msg25483.html

Yes, will be queueing both up soon.

thanks,

greg k-h