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

2017-03-03 Thread Andy Shevchenko
On Sat, Mar 4, 2017 at 1:23 AM, James Hogan  wrote:
> On Fri, Mar 03, 2017 at 03:31:06PM +0200, Andy Shevchenko wrote:
>> On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
>> > 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
>
> 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.

> diff --git a/drivers/tty/serial/8250/8250_dw.c 
> b/drivers/tty/serial/8250/8250_dw.c
> index 223ac234ddb2..e65808c482f1 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -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);

-- 
With Best Regards,
Andy Shevchenko


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

2017-03-03 Thread Andy Shevchenko
On Sat, Mar 4, 2017 at 1:23 AM, James Hogan  wrote:
> On Fri, Mar 03, 2017 at 03:31:06PM +0200, Andy Shevchenko wrote:
>> On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
>> > 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
>
> 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.

> diff --git a/drivers/tty/serial/8250/8250_dw.c 
> b/drivers/tty/serial/8250/8250_dw.c
> index 223ac234ddb2..e65808c482f1 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -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);

-- 
With Best Regards,
Andy Shevchenko


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

2017-03-03 Thread James Hogan
Hi Jason,

On Fri, Mar 03, 2017 at 04:02:56PM -0800, Jason Uy wrote:
> 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

> 
> Note that this is what is done in the probe function of the dw driver.
> 
> Regards,
> Jason
> 
> -Original Message-
> From: James Hogan [mailto:james.ho...@imgtec.com]
> Sent: March-03-17 3:07 PM
> To: Jason Uy <jason...@broadcom.com>
> Cc: Ray Jui <ray@broadcom.com>; Andy Shevchenko
> <andriy.shevche...@linux.intel.com>; Heiko Stuebner <he...@sntech.de>; Greg
> Kroah-Hartman <gre...@linuxfoundation.org>; Jiri Slaby <jsl...@suse.com>;
> Kefeng Wang <wangkefeng.w...@huawei.com>; Noam Camus <no...@ezchip.com>;
> Heikki Krogerus <heikki.kroge...@linux.intel.com>; Wang Hongcheng
> <annie.w...@amd.com>; linux-ser...@vger.kernel.org; LKML
> <linux-kernel@vger.kernel.org>; bcm-kernel-feedback-l...@broadcom.com; Linux
> MIPS Mailing List <linux-m...@linux-mips.org>; David Daney
> <david.da...@cavium.com>; Russell King <li...@armlinux.org.uk>;
> linux-...@vger.kernel.org; Viresh Kumar <viresh.ku...@st.com>
> Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to
> be used
> 
> Hi Jason,
> 
> On Fri, Mar 03, 2017 at 09:43:55AM -0800, Jason Uy wrote:
> > 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
> 
> >
> > Regards,
> > Jason
> >
> > -Original Message-
> > From: Ray Jui [mailto:ray@broadcom.com]
> > Sent: March-03-17 9:34 AM
> > To: Andy Shevchenko <andriy.shevche...@linux.intel.com>; James Hogan
> > <james.ho...@imgtec.com>; Heiko Stuebner <he...@sntech.de>
> > Cc: Jason Uy <jason...@broadcom.com>; Greg Kroah-Hartman
> > <gre...@linuxfoundation.org>; Jiri Slaby <jsl...@suse.com>; Kefeng
> > Wang <wangkefeng.w...@huawei.com>; Noam Camus <no...@ezchip.com>;
> > Heikki Krogerus <heikki.kroge...@linux.intel.com>; Wang Hongcheng
> > <annie.w...@amd.com>; linux-ser...@vger.kernel.org; LKML
> > <linux-kernel@vger.kernel.org>; bcm-kernel-feedback-l...@broadcom.com;
> > Linux MIPS Mailing List <linux-m...@linux-mips.org>; David Daney
> > <david.da...@cavium.com>; Russell King <li...@armlinux.org.uk>;
> > linux-...@vger.kernel.org; Viresh Kumar <viresh.ku...@st.com>
> > Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow
> > control to be used
> >
> > Hi Andy/Jason,
> >
> > On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> > > Heiko, you might be interested in this as well.
> > >
> > > On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> > >> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> > >>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> > >>>> On 11 January 2017 at 19:48, Jason Uy <jason...@broadcom.com>
> > >>>> wrote:
> > >>>>> 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

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

2017-03-03 Thread James Hogan
Hi Jason,

On Fri, Mar 03, 2017 at 04:02:56PM -0800, Jason Uy wrote:
> 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

> 
> Note that this is what is done in the probe function of the dw driver.
> 
> Regards,
> Jason
> 
> -Original Message-
> From: James Hogan [mailto:james.ho...@imgtec.com]
> Sent: March-03-17 3:07 PM
> To: Jason Uy 
> Cc: Ray Jui ; Andy Shevchenko
> ; Heiko Stuebner ; Greg
> Kroah-Hartman ; Jiri Slaby ;
> Kefeng Wang ; Noam Camus ;
> Heikki Krogerus ; Wang Hongcheng
> ; linux-ser...@vger.kernel.org; LKML
> ; bcm-kernel-feedback-l...@broadcom.com; Linux
> MIPS Mailing List ; David Daney
> ; Russell King ;
> linux-...@vger.kernel.org; Viresh Kumar 
> Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to
> be used
> 
> Hi Jason,
> 
> On Fri, Mar 03, 2017 at 09:43:55AM -0800, Jason Uy wrote:
> > 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
> 
> >
> > Regards,
> > Jason
> >
> > -Original Message-
> > From: Ray Jui [mailto:ray@broadcom.com]
> > Sent: March-03-17 9:34 AM
> > To: Andy Shevchenko ; James Hogan
> > ; Heiko Stuebner 
> > Cc: Jason Uy ; Greg Kroah-Hartman
> > ; Jiri Slaby ; Kefeng
> > Wang ; Noam Camus ;
> > Heikki Krogerus ; Wang Hongcheng
> > ; linux-ser...@vger.kernel.org; LKML
> > ; bcm-kernel-feedback-l...@broadcom.com;
> > Linux MIPS Mailing List ; David Daney
> > ; Russell King ;
> > linux-...@vger.kernel.org; Viresh Kumar 
> > Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow
> > control to be used
> >
> > Hi Andy/Jason,
> >
> > On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> > > Heiko, you might be interested in this as well.
> > >
> > > On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> > >> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> > >>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> > >>>> On 11 January 2017 at 19:48, Jason Uy 
> > >>>> wrote:
> > >>>>> 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:
> > >>>> [] uart_get_baud_rate+0xfc/0x1f0
> > >>>> [] serial8250_do_set_termios+0xb0/0x440
> > >>>> [] uart_set_options+0xe8/0x190
> > >>>> [] serial8250_console_setup+0x84/0x158
> > >>>> [] univ8250_console_setup+0x54/0x70
> > >>>> [] register_console+0x1c8/0x418
> > >>>> [] uart_add_one_port+0x434/0x4b0
> > >>>> [] serial8250_register_8250_port+0x2d8/0x440
> > >>>> [] dw8

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

2017-03-03 Thread Jason Uy
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:james.ho...@imgtec.com]
Sent: March-03-17 3:07 PM
To: Jason Uy <jason...@broadcom.com>
Cc: Ray Jui <ray@broadcom.com>; Andy Shevchenko
<andriy.shevche...@linux.intel.com>; Heiko Stuebner <he...@sntech.de>; Greg
Kroah-Hartman <gre...@linuxfoundation.org>; Jiri Slaby <jsl...@suse.com>;
Kefeng Wang <wangkefeng.w...@huawei.com>; Noam Camus <no...@ezchip.com>;
Heikki Krogerus <heikki.kroge...@linux.intel.com>; Wang Hongcheng
<annie.w...@amd.com>; linux-ser...@vger.kernel.org; LKML
<linux-kernel@vger.kernel.org>; bcm-kernel-feedback-l...@broadcom.com; Linux
MIPS Mailing List <linux-m...@linux-mips.org>; David Daney
<david.da...@cavium.com>; Russell King <li...@armlinux.org.uk>;
linux-...@vger.kernel.org; Viresh Kumar <viresh.ku...@st.com>
Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to
be used

Hi Jason,

On Fri, Mar 03, 2017 at 09:43:55AM -0800, Jason Uy wrote:
> 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

>
> Regards,
> Jason
>
> -Original Message-
> From: Ray Jui [mailto:ray@broadcom.com]
> Sent: March-03-17 9:34 AM
> To: Andy Shevchenko <andriy.shevche...@linux.intel.com>; James Hogan
> <james.ho...@imgtec.com>; Heiko Stuebner <he...@sntech.de>
> Cc: Jason Uy <jason...@broadcom.com>; Greg Kroah-Hartman
> <gre...@linuxfoundation.org>; Jiri Slaby <jsl...@suse.com>; Kefeng
> Wang <wangkefeng.w...@huawei.com>; Noam Camus <no...@ezchip.com>;
> Heikki Krogerus <heikki.kroge...@linux.intel.com>; Wang Hongcheng
> <annie.w...@amd.com>; linux-ser...@vger.kernel.org; LKML
> <linux-kernel@vger.kernel.org>; bcm-kernel-feedback-l...@broadcom.com;
> Linux MIPS Mailing List <linux-m...@linux-mips.org>; David Daney
> <david.da...@cavium.com>; Russell King <li...@armlinux.org.uk>;
> linux-...@vger.kernel.org; Viresh Kumar <viresh.ku...@st.com>
> Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow
> control to be used
>
> Hi Andy/Jason,
>
> On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> > Heiko, you might be interested in this as well.
> >
> > On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> >> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> >>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> >>>> On 11 January 2017 at 19:48, Jason Uy <jason...@broadcom.com>
> >>>> wrote:
> >>>>> 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:
> >>>> [] uart_get_baud_rate+0xfc/0x1f0
> >>>> [] serial8250_do_set_termios+0xb0/0x440
> >>>> [] uart_set_options+0xe8/0x190
> >>>> [] serial8250_console_setup+0x84/0x158
> >>>> [] univ8250_console_setup+0x54/0x70
> >>&

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

2017-03-03 Thread Jason Uy
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:james.ho...@imgtec.com]
Sent: March-03-17 3:07 PM
To: Jason Uy 
Cc: Ray Jui ; Andy Shevchenko
; Heiko Stuebner ; Greg
Kroah-Hartman ; Jiri Slaby ;
Kefeng Wang ; Noam Camus ;
Heikki Krogerus ; Wang Hongcheng
; linux-ser...@vger.kernel.org; LKML
; bcm-kernel-feedback-l...@broadcom.com; Linux
MIPS Mailing List ; David Daney
; Russell King ;
linux-...@vger.kernel.org; Viresh Kumar 
Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to
be used

Hi Jason,

On Fri, Mar 03, 2017 at 09:43:55AM -0800, Jason Uy wrote:
> 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

>
> Regards,
> Jason
>
> -Original Message-
> From: Ray Jui [mailto:ray@broadcom.com]
> Sent: March-03-17 9:34 AM
> To: Andy Shevchenko ; James Hogan
> ; Heiko Stuebner 
> Cc: Jason Uy ; Greg Kroah-Hartman
> ; Jiri Slaby ; Kefeng
> Wang ; Noam Camus ;
> Heikki Krogerus ; Wang Hongcheng
> ; linux-ser...@vger.kernel.org; LKML
> ; bcm-kernel-feedback-l...@broadcom.com;
> Linux MIPS Mailing List ; David Daney
> ; Russell King ;
> linux-...@vger.kernel.org; Viresh Kumar 
> Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow
> control to be used
>
> Hi Andy/Jason,
>
> On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> > Heiko, you might be interested in this as well.
> >
> > On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> >> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> >>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> >>>> On 11 January 2017 at 19:48, Jason Uy 
> >>>> wrote:
> >>>>> 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:
> >>>> [] uart_get_baud_rate+0xfc/0x1f0
> >>>> [] serial8250_do_set_termios+0xb0/0x440
> >>>> [] uart_set_options+0xe8/0x190
> >>>> [] serial8250_console_setup+0x84/0x158
> >>>> [] univ8250_console_setup+0x54/0x70
> >>>> [] register_console+0x1c8/0x418
> >>>> [] uart_add_one_port+0x434/0x4b0
> >>>> [] serial8250_register_8250_port+0x2d8/0x440
> >>>> [] dw8250_probe+0x388/0x5e8 Then it hangs and
> >>>> the watchdog restarts the machine.
> >>>>
> >>>> Any ideas?
> >>>
> >>> 1. Does it use clock on that platform?
> >
> >> 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 CONF

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

2017-03-03 Thread James Hogan
On Fri, Mar 03, 2017 at 03:31:06PM +0200, Andy Shevchenko wrote:
> On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> > 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:
> > 
> > > 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.

> 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

diff --git a/drivers/tty/serial/8250/8250_dw.c 
b/drivers/tty/serial/8250/8250_dw.c
index 223ac234ddb2..e65808c482f1 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -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.asc
Description: Digital signature


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

2017-03-03 Thread James Hogan
On Fri, Mar 03, 2017 at 03:31:06PM +0200, Andy Shevchenko wrote:
> On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> > 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:
> > 
> > > 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.

> 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

diff --git a/drivers/tty/serial/8250/8250_dw.c 
b/drivers/tty/serial/8250/8250_dw.c
index 223ac234ddb2..e65808c482f1 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -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.asc
Description: Digital signature


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

2017-03-03 Thread James Hogan
Hi Jason,

On Fri, Mar 03, 2017 at 09:43:55AM -0800, Jason Uy wrote:
> 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

> 
> Regards,
> Jason
> 
> -Original Message-
> From: Ray Jui [mailto:ray@broadcom.com]
> Sent: March-03-17 9:34 AM
> To: Andy Shevchenko <andriy.shevche...@linux.intel.com>; James Hogan
> <james.ho...@imgtec.com>; Heiko Stuebner <he...@sntech.de>
> Cc: Jason Uy <jason...@broadcom.com>; Greg Kroah-Hartman
> <gre...@linuxfoundation.org>; Jiri Slaby <jsl...@suse.com>; Kefeng Wang
> <wangkefeng.w...@huawei.com>; Noam Camus <no...@ezchip.com>; Heikki Krogerus
> <heikki.kroge...@linux.intel.com>; Wang Hongcheng <annie.w...@amd.com>;
> linux-ser...@vger.kernel.org; LKML <linux-kernel@vger.kernel.org>;
> bcm-kernel-feedback-l...@broadcom.com; Linux MIPS Mailing List
> <linux-m...@linux-mips.org>; David Daney <david.da...@cavium.com>; Russell
> King <li...@armlinux.org.uk>; linux-...@vger.kernel.org; Viresh Kumar
> <viresh.ku...@st.com>
> Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to
> be used
> 
> Hi Andy/Jason,
> 
> On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> > Heiko, you might be interested in this as well.
> >
> > On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> >> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> >>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> >>>> On 11 January 2017 at 19:48, Jason Uy <jason...@broadcom.com>
> >>>> wrote:
> >>>>> 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:
> >>>> [] uart_get_baud_rate+0xfc/0x1f0
> >>>> [] serial8250_do_set_termios+0xb0/0x440
> >>>> [] uart_set_options+0xe8/0x190
> >>>> [] serial8250_console_setup+0x84/0x158
> >>>> [] univ8250_console_setup+0x54/0x70
> >>>> [] register_console+0x1c8/0x418
> >>>> [] uart_add_one_port+0x434/0x4b0
> >>>> [] serial8250_register_8250_port+0x2d8/0x440
> >>>> [] dw8250_probe+0x388/0x5e8 Then it hangs and the
> >>>> watchdog restarts the machine.
> >>>>
> >>>> Any ideas?
> >>>
> >>> 1. Does it use clock on that platform?
> >
> >> 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
>

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

2017-03-03 Thread James Hogan
Hi Jason,

On Fri, Mar 03, 2017 at 09:43:55AM -0800, Jason Uy wrote:
> 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

> 
> Regards,
> Jason
> 
> -Original Message-
> From: Ray Jui [mailto:ray@broadcom.com]
> Sent: March-03-17 9:34 AM
> To: Andy Shevchenko ; James Hogan
> ; Heiko Stuebner 
> Cc: Jason Uy ; Greg Kroah-Hartman
> ; Jiri Slaby ; Kefeng Wang
> ; Noam Camus ; Heikki Krogerus
> ; Wang Hongcheng ;
> linux-ser...@vger.kernel.org; LKML ;
> bcm-kernel-feedback-l...@broadcom.com; Linux MIPS Mailing List
> ; David Daney ; Russell
> King ; linux-...@vger.kernel.org; Viresh Kumar
> 
> Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to
> be used
> 
> Hi Andy/Jason,
> 
> On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> > Heiko, you might be interested in this as well.
> >
> > On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> >> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> >>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> >>>> On 11 January 2017 at 19:48, Jason Uy 
> >>>> wrote:
> >>>>> 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:
> >>>> [] uart_get_baud_rate+0xfc/0x1f0
> >>>> [] serial8250_do_set_termios+0xb0/0x440
> >>>> [] uart_set_options+0xe8/0x190
> >>>> [] serial8250_console_setup+0x84/0x158
> >>>> [] univ8250_console_setup+0x54/0x70
> >>>> [] register_console+0x1c8/0x418
> >>>> [] uart_add_one_port+0x434/0x4b0
> >>>> [] serial8250_register_8250_port+0x2d8/0x440
> >>>> [] dw8250_probe+0x388/0x5e8 Then it hangs and the
> >>>> watchdog restarts the machine.
> >>>>
> >>>> Any ideas?
> >>>
> >>> 1. Does it use clock on that platform?
> >
> >> 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...
> >
> > 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
> 
> >
> >> 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:
> >>
> >>> 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.asc
Description: Digital signature


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

2017-03-03 Thread 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;

Regards,
Jason

-Original Message-
From: Ray Jui [mailto:ray@broadcom.com]
Sent: March-03-17 9:34 AM
To: Andy Shevchenko <andriy.shevche...@linux.intel.com>; James Hogan
<james.ho...@imgtec.com>; Heiko Stuebner <he...@sntech.de>
Cc: Jason Uy <jason...@broadcom.com>; Greg Kroah-Hartman
<gre...@linuxfoundation.org>; Jiri Slaby <jsl...@suse.com>; Kefeng Wang
<wangkefeng.w...@huawei.com>; Noam Camus <no...@ezchip.com>; Heikki Krogerus
<heikki.kroge...@linux.intel.com>; Wang Hongcheng <annie.w...@amd.com>;
linux-ser...@vger.kernel.org; LKML <linux-kernel@vger.kernel.org>;
bcm-kernel-feedback-l...@broadcom.com; Linux MIPS Mailing List
<linux-m...@linux-mips.org>; David Daney <david.da...@cavium.com>; Russell
King <li...@armlinux.org.uk>; linux-...@vger.kernel.org; Viresh Kumar
<viresh.ku...@st.com>
Subject: Re: [PATCH v2 1/1] serial: 8250_dw: Allow hardware flow control to
be used

Hi Andy/Jason,

On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> Heiko, you might be interested in this as well.
>
> On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
>> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
>>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
>>>> On 11 January 2017 at 19:48, Jason Uy <jason...@broadcom.com>
>>>> wrote:
>>>>> 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:
>>>> [] uart_get_baud_rate+0xfc/0x1f0
>>>> [] serial8250_do_set_termios+0xb0/0x440
>>>> [] uart_set_options+0xe8/0x190
>>>> [] serial8250_console_setup+0x84/0x158
>>>> [] univ8250_console_setup+0x54/0x70
>>>> [] register_console+0x1c8/0x418
>>>> [] uart_add_one_port+0x434/0x4b0
>>>> [] serial8250_register_8250_port+0x2d8/0x440
>>>> [] dw8250_probe+0x388/0x5e8 Then it hangs and the
>>>> watchdog restarts the machine.
>>>>
>>>> Any ideas?
>>>
>>> 1. Does it use clock on that platform?
>
>> 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...
>
> 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

>
>> 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:
>>
>>> 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
>


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

2017-03-03 Thread 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;

Regards,
Jason

-Original Message-
From: Ray Jui [mailto:ray@broadcom.com]
Sent: March-03-17 9:34 AM
To: Andy Shevchenko ; James Hogan
; Heiko Stuebner 
Cc: Jason Uy ; Greg Kroah-Hartman
; Jiri Slaby ; Kefeng Wang
; Noam Camus ; Heikki Krogerus
; Wang Hongcheng ;
linux-ser...@vger.kernel.org; LKML ;
bcm-kernel-feedback-l...@broadcom.com; Linux MIPS Mailing List
; David Daney ; Russell
King ; linux-...@vger.kernel.org; Viresh Kumar

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

Hi Andy/Jason,

On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> Heiko, you might be interested in this as well.
>
> On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
>> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
>>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
>>>> On 11 January 2017 at 19:48, Jason Uy 
>>>> wrote:
>>>>> 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:
>>>> [] uart_get_baud_rate+0xfc/0x1f0
>>>> [] serial8250_do_set_termios+0xb0/0x440
>>>> [] uart_set_options+0xe8/0x190
>>>> [] serial8250_console_setup+0x84/0x158
>>>> [] univ8250_console_setup+0x54/0x70
>>>> [] register_console+0x1c8/0x418
>>>> [] uart_add_one_port+0x434/0x4b0
>>>> [] serial8250_register_8250_port+0x2d8/0x440
>>>> [] dw8250_probe+0x388/0x5e8 Then it hangs and the
>>>> watchdog restarts the machine.
>>>>
>>>> Any ideas?
>>>
>>> 1. Does it use clock on that platform?
>
>> 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...
>
> 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

>
>> 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:
>>
>>> 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
>


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

2017-03-03 Thread Ray Jui
Hi Andy/Jason,

On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> Heiko, you might be interested in this as well.
> 
> On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
>> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
>>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
 On 11 January 2017 at 19:48, Jason Uy 
 wrote:
> 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:
 [] uart_get_baud_rate+0xfc/0x1f0
 [] serial8250_do_set_termios+0xb0/0x440
 [] uart_set_options+0xe8/0x190
 [] serial8250_console_setup+0x84/0x158
 [] univ8250_console_setup+0x54/0x70
 [] register_console+0x1c8/0x418
 [] uart_add_one_port+0x434/0x4b0
 [] serial8250_register_8250_port+0x2d8/0x440
 [] dw8250_probe+0x388/0x5e8
 Then it hangs and the watchdog restarts the machine.

 Any ideas?
>>>
>>> 1. Does it use clock on that platform?
> 
>> 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...
> 
> 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

> 
>> 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:
>>
>>> 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
> 


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

2017-03-03 Thread Ray Jui
Hi Andy/Jason,

On 3/3/2017 5:31 AM, Andy Shevchenko wrote:
> Heiko, you might be interested in this as well.
> 
> On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
>> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
>>> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
 On 11 January 2017 at 19:48, Jason Uy 
 wrote:
> 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:
 [] uart_get_baud_rate+0xfc/0x1f0
 [] serial8250_do_set_termios+0xb0/0x440
 [] uart_set_options+0xe8/0x190
 [] serial8250_console_setup+0x84/0x158
 [] univ8250_console_setup+0x54/0x70
 [] register_console+0x1c8/0x418
 [] uart_add_one_port+0x434/0x4b0
 [] serial8250_register_8250_port+0x2d8/0x440
 [] dw8250_probe+0x388/0x5e8
 Then it hangs and the watchdog restarts the machine.

 Any ideas?
>>>
>>> 1. Does it use clock on that platform?
> 
>> 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...
> 
> 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

> 
>> 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:
>>
>>> 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
> 


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

2017-03-03 Thread Andy Shevchenko
Heiko, you might be interested in this as well.

On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> > On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> > > On 11 January 2017 at 19:48, Jason Uy 
> > > wrote:
> > > > 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:
> > > [] uart_get_baud_rate+0xfc/0x1f0
> > > [] serial8250_do_set_termios+0xb0/0x440
> > > [] uart_set_options+0xe8/0x190
> > > [] serial8250_console_setup+0x84/0x158
> > > [] univ8250_console_setup+0x54/0x70
> > > [] register_console+0x1c8/0x418
> > > [] uart_add_one_port+0x434/0x4b0
> > > [] serial8250_register_8250_port+0x2d8/0x440
> > > [] dw8250_probe+0x388/0x5e8
> > > Then it hangs and the watchdog restarts the machine.
> > > 
> > > Any ideas?
> > 
> > 1. Does it use clock on that platform?

> 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...

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.

> 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:
> 
> > 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

-- 
Andy Shevchenko 
Intel Finland Oy


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

2017-03-03 Thread Andy Shevchenko
Heiko, you might be interested in this as well.

On Fri, 2017-03-03 at 00:21 +, James Hogan wrote:
> On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> > On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> > > On 11 January 2017 at 19:48, Jason Uy 
> > > wrote:
> > > > 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:
> > > [] uart_get_baud_rate+0xfc/0x1f0
> > > [] serial8250_do_set_termios+0xb0/0x440
> > > [] uart_set_options+0xe8/0x190
> > > [] serial8250_console_setup+0x84/0x158
> > > [] univ8250_console_setup+0x54/0x70
> > > [] register_console+0x1c8/0x418
> > > [] uart_add_one_port+0x434/0x4b0
> > > [] serial8250_register_8250_port+0x2d8/0x440
> > > [] dw8250_probe+0x388/0x5e8
> > > Then it hangs and the watchdog restarts the machine.
> > > 
> > > Any ideas?
> > 
> > 1. Does it use clock on that platform?

> 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...

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.

> 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:
> 
> > 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

-- 
Andy Shevchenko 
Intel Finland Oy


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

2017-03-02 Thread James Hogan
On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> > On 11 January 2017 at 19:48, Jason Uy  wrote:
> > > 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:
> 
> > [] uart_get_baud_rate+0xfc/0x1f0
> > [] serial8250_do_set_termios+0xb0/0x440
> > [] uart_set_options+0xe8/0x190
> > [] serial8250_console_setup+0x84/0x158
> > [] univ8250_console_setup+0x54/0x70
> > [] register_console+0x1c8/0x418
> > [] uart_add_one_port+0x434/0x4b0
> > [] serial8250_register_8250_port+0x2d8/0x440
> > [] dw8250_probe+0x388/0x5e8
> 
> > 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:

> 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


signature.asc
Description: Digital signature


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

2017-03-02 Thread James Hogan
On Wed, Mar 01, 2017 at 08:50:20PM +0200, Andy Shevchenko wrote:
> On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> > On 11 January 2017 at 19:48, Jason Uy  wrote:
> > > 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:
> 
> > [] uart_get_baud_rate+0xfc/0x1f0
> > [] serial8250_do_set_termios+0xb0/0x440
> > [] uart_set_options+0xe8/0x190
> > [] serial8250_console_setup+0x84/0x158
> > [] univ8250_console_setup+0x54/0x70
> > [] register_console+0x1c8/0x418
> > [] uart_add_one_port+0x434/0x4b0
> > [] serial8250_register_8250_port+0x2d8/0x440
> > [] dw8250_probe+0x388/0x5e8
> 
> > 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:

> 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


signature.asc
Description: Digital signature


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

2017-03-01 Thread Andy Shevchenko
On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> On 11 January 2017 at 19:48, Jason Uy  wrote:
> > 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:

> [] uart_get_baud_rate+0xfc/0x1f0
> [] serial8250_do_set_termios+0xb0/0x440
> [] uart_set_options+0xe8/0x190
> [] serial8250_console_setup+0x84/0x158
> [] univ8250_console_setup+0x54/0x70
> [] register_console+0x1c8/0x418
> [] uart_add_one_port+0x434/0x4b0
> [] serial8250_register_8250_port+0x2d8/0x440
> [] dw8250_probe+0x388/0x5e8

> 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.

-- 
Andy Shevchenko 
Intel Finland Oy


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

2017-03-01 Thread Andy Shevchenko
On Wed, 2017-03-01 at 18:02 +, James Hogan wrote:
> On 11 January 2017 at 19:48, Jason Uy  wrote:
> > 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:

> [] uart_get_baud_rate+0xfc/0x1f0
> [] serial8250_do_set_termios+0xb0/0x440
> [] uart_set_options+0xe8/0x190
> [] serial8250_console_setup+0x84/0x158
> [] univ8250_console_setup+0x54/0x70
> [] register_console+0x1c8/0x418
> [] uart_add_one_port+0x434/0x4b0
> [] serial8250_register_8250_port+0x2d8/0x440
> [] dw8250_probe+0x388/0x5e8

> 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.

-- 
Andy Shevchenko 
Intel Finland Oy


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

2017-01-12 Thread Kefeng Wang


On 2017/1/12 3:48, Jason Uy wrote:
> 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.
> 
> Reviewed-by: Scott Branden 
> Reviewed-by: Ray Jui 
> Signed-off-by: Jason Uy 

Reviewed-by: Kefeng Wang 

> ---
>  drivers/tty/serial/8250/8250_dw.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_dw.c 
> b/drivers/tty/serial/8250/8250_dw.c
> index c89fafc..c89ae45 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -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)
> 



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

2017-01-12 Thread Kefeng Wang


On 2017/1/12 3:48, Jason Uy wrote:
> 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.
> 
> Reviewed-by: Scott Branden 
> Reviewed-by: Ray Jui 
> Signed-off-by: Jason Uy 

Reviewed-by: Kefeng Wang 

> ---
>  drivers/tty/serial/8250/8250_dw.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_dw.c 
> b/drivers/tty/serial/8250/8250_dw.c
> index c89fafc..c89ae45 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -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)
> 



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

2017-01-11 Thread Andy Shevchenko
On Wed, 2017-01-11 at 11:48 -0800, Jason Uy wrote:
> 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.
> 
> Reviewed-by: Scott Branden 
> Reviewed-by: Ray Jui 

FWIW:
Reviewed-by: Andy Shevchenko 

> Signed-off-by: Jason Uy 
> ---
>  drivers/tty/serial/8250/8250_dw.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_dw.c
> b/drivers/tty/serial/8250/8250_dw.c
> index c89fafc..c89ae45 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -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)

-- 
Andy Shevchenko 
Intel Finland Oy


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

2017-01-11 Thread Andy Shevchenko
On Wed, 2017-01-11 at 11:48 -0800, Jason Uy wrote:
> 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.
> 
> Reviewed-by: Scott Branden 
> Reviewed-by: Ray Jui 

FWIW:
Reviewed-by: Andy Shevchenko 

> Signed-off-by: Jason Uy 
> ---
>  drivers/tty/serial/8250/8250_dw.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_dw.c
> b/drivers/tty/serial/8250/8250_dw.c
> index c89fafc..c89ae45 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -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)

-- 
Andy Shevchenko 
Intel Finland Oy