linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 2/2] USB: serial: cp210x: Proper RTS control when buffers fill
@ 2020-06-26  4:24 Phu Luu
  2020-06-26  7:42 ` Johan Hovold
  0 siblings, 1 reply; 5+ messages in thread
From: Phu Luu @ 2020-06-26  4:24 UTC (permalink / raw)
  To: johan, gregkh, linux-usb, linux-kernel
  Cc: Brant Merryman, Richard Hendricks, Phú Lưu An, hungnd3

From: Brant Merryman <brant.merryman@silabs.com>

CP210x hardware disables auto-RTS but leaves auto-CTS when
in hardware flow control mode and UART on cp210x hardware
is disabled. This allows data to flow out, but new data
will not come into the port. When re-opening the port, if
auto-CTS is enabled on the cp210x, then auto-RTS must be
re-enabled in the driver.

Signed-off-by: Phu Luu <phu.luu@silabs.com>
Signed-off-by: Brant Merryman <brant.merryman@silabs.com>
---
06/09/2020: Patch v3 2/2 Modified based on feedback from Johan Hovold <johan@kernel.org>
12/18/2019: Patch v2 Broken into two patches and modified based on feedback from Johan Hovold <johan@kernel.org>
12/09/2019: Initial submission of patch "Proper RTS control when buffers fill"

 drivers/usb/serial/cp210x.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index bcceb4ad8be0..091441b1c5b9 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -917,6 +917,7 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
 	u32 baud;
 	u16 bits;
 	u32 ctl_hs;
+	u32 flow_repl;
 
 	cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
 
@@ -1017,6 +1018,23 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
 	ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
 	if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) {
 		dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
+		/*
+		 * When the port is closed, the CP210x hardware disables
+		 * auto-RTS and RTS is deasserted but it leaves auto-CTS when
+		 * in hardware flow control mode. This prevents new data from
+		 * being received by the port. When re-opening the port, if
+		 * auto-CTS is enabled on the cp210x, then auto-RTS must be
+		 * re-enabled in the driver.
+		 */
+		flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
+		flow_repl &= ~CP210X_SERIAL_RTS_MASK;
+		flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL);
+		flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl);
+		cp210x_write_reg_block(port,
+				CP210X_SET_FLOW,
+				&flow_ctl,
+				sizeof(flow_ctl));
+
 		cflag |= CRTSCTS;
 	} else {
 		dev_dbg(dev, "%s - flow control = NONE\n", __func__);
-- 
2.17.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] USB: serial: cp210x: Proper RTS control when buffers fill
  2020-06-26  4:24 [PATCH v3 2/2] USB: serial: cp210x: Proper RTS control when buffers fill Phu Luu
@ 2020-06-26  7:42 ` Johan Hovold
  2020-07-06 10:18   ` Johan Hovold
  0 siblings, 1 reply; 5+ messages in thread
From: Johan Hovold @ 2020-06-26  7:42 UTC (permalink / raw)
  To: Phu Luu
  Cc: johan, gregkh, linux-usb, linux-kernel, Brant Merryman,
	Richard Hendricks, Phú Lưu An, hungnd3

On Fri, Jun 26, 2020 at 04:24:20AM +0000, Phu Luu wrote:
> From: Brant Merryman <brant.merryman@silabs.com>
> 
> CP210x hardware disables auto-RTS but leaves auto-CTS when
> in hardware flow control mode and UART on cp210x hardware
> is disabled. This allows data to flow out, but new data
> will not come into the port. When re-opening the port, if
> auto-CTS is enabled on the cp210x, then auto-RTS must be
> re-enabled in the driver.
> 
> Signed-off-by: Phu Luu <phu.luu@silabs.com>
> Signed-off-by: Brant Merryman <brant.merryman@silabs.com>

Please revisit these tags as well.

> ---
> 06/09/2020: Patch v3 2/2 Modified based on feedback from Johan Hovold <johan@kernel.org>
> 12/18/2019: Patch v2 Broken into two patches and modified based on feedback from Johan Hovold <johan@kernel.org>
> 12/09/2019: Initial submission of patch "Proper RTS control when buffers fill"
> 
>  drivers/usb/serial/cp210x.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> index bcceb4ad8be0..091441b1c5b9 100644
> --- a/drivers/usb/serial/cp210x.c
> +++ b/drivers/usb/serial/cp210x.c
> @@ -917,6 +917,7 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
>  	u32 baud;
>  	u16 bits;
>  	u32 ctl_hs;
> +	u32 flow_repl;
>  
>  	cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
>  
> @@ -1017,6 +1018,23 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
>  	ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
>  	if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) {
>  		dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
> +		/*
> +		 * When the port is closed, the CP210x hardware disables
> +		 * auto-RTS and RTS is deasserted but it leaves auto-CTS when
> +		 * in hardware flow control mode. This prevents new data from
> +		 * being received by the port. When re-opening the port, if
> +		 * auto-CTS is enabled on the cp210x, then auto-RTS must be
> +		 * re-enabled in the driver.
> +		 */

I already asked this of Brant, but could you please be more specific
about which state the RTS-line end up in when disabling the UART (e.g.
0x00: statically inactive)?

The reason I ask is that after open() returns, the tty layer would raise
RTS, which should again allow data to flow in in contrast to what the
comment and changelog text claims.

We still want to enable auto-RTS of course so the patch is otherwise
correct.

> +		flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
> +		flow_repl &= ~CP210X_SERIAL_RTS_MASK;
> +		flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL);
> +		flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl);
> +		cp210x_write_reg_block(port,
> +				CP210X_SET_FLOW,
> +				&flow_ctl,
> +				sizeof(flow_ctl));
> +
>  		cflag |= CRTSCTS;
>  	} else {
>  		dev_dbg(dev, "%s - flow control = NONE\n", __func__);

Johan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] USB: serial: cp210x: Proper RTS control when buffers fill
  2020-06-26  7:42 ` Johan Hovold
@ 2020-07-06 10:18   ` Johan Hovold
       [not found]     ` <CAP847ynZDozdA0kDEo6Zjuk0LOeaiTyW_fnU89hnFUD8ntL8uw@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Johan Hovold @ 2020-07-06 10:18 UTC (permalink / raw)
  To: Phu Luu
  Cc: johan, gregkh, linux-usb, linux-kernel, Brant Merryman,
	Richard Hendricks, Phú Lưu An, hungnd3

On Fri, Jun 26, 2020 at 09:42:06AM +0200, Johan Hovold wrote:
> On Fri, Jun 26, 2020 at 04:24:20AM +0000, Phu Luu wrote:
> > From: Brant Merryman <brant.merryman@silabs.com>
> > 
> > CP210x hardware disables auto-RTS but leaves auto-CTS when
> > in hardware flow control mode and UART on cp210x hardware
> > is disabled. This allows data to flow out, but new data
> > will not come into the port. When re-opening the port, if
> > auto-CTS is enabled on the cp210x, then auto-RTS must be
> > re-enabled in the driver.
> > 
> > Signed-off-by: Phu Luu <phu.luu@silabs.com>
> > Signed-off-by: Brant Merryman <brant.merryman@silabs.com>
> 
> Please revisit these tags as well.
> 
> > ---
> > 06/09/2020: Patch v3 2/2 Modified based on feedback from Johan Hovold <johan@kernel.org>
> > 12/18/2019: Patch v2 Broken into two patches and modified based on feedback from Johan Hovold <johan@kernel.org>
> > 12/09/2019: Initial submission of patch "Proper RTS control when buffers fill"
> > 
> >  drivers/usb/serial/cp210x.c | 18 ++++++++++++++++++
> >  1 file changed, 18 insertions(+)
> > 
> > diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> > index bcceb4ad8be0..091441b1c5b9 100644
> > --- a/drivers/usb/serial/cp210x.c
> > +++ b/drivers/usb/serial/cp210x.c
> > @@ -917,6 +917,7 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
> >  	u32 baud;
> >  	u16 bits;
> >  	u32 ctl_hs;
> > +	u32 flow_repl;
> >  
> >  	cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
> >  
> > @@ -1017,6 +1018,23 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
> >  	ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
> >  	if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) {
> >  		dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
> > +		/*
> > +		 * When the port is closed, the CP210x hardware disables
> > +		 * auto-RTS and RTS is deasserted but it leaves auto-CTS when
> > +		 * in hardware flow control mode. This prevents new data from
> > +		 * being received by the port. When re-opening the port, if
> > +		 * auto-CTS is enabled on the cp210x, then auto-RTS must be
> > +		 * re-enabled in the driver.
> > +		 */
> 
> I already asked this of Brant, but could you please be more specific
> about which state the RTS-line end up in when disabling the UART (e.g.
> 0x00: statically inactive)?
> 
> The reason I ask is that after open() returns, the tty layer would raise
> RTS, which should again allow data to flow in in contrast to what the
> comment and changelog text claims.

I had another reason to look at this driver so I could determine that
the patch description and comment were indeed incorrect; the tty layer
asserts RTS when reopening the port just fine and data flows in.

> We still want to enable auto-RTS of course so the patch is otherwise
> correct.

I've fixed up the commit message and comment, reordered the SOB tags
and added your Co-developed-by tag before applying both of these now:

	https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git/log/?h=usb-next

Johan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] USB: serial: cp210x: Proper RTS control when buffers fill
       [not found]     ` <CAP847ynZDozdA0kDEo6Zjuk0LOeaiTyW_fnU89hnFUD8ntL8uw@mail.gmail.com>
@ 2020-08-17  9:55       ` Johan Hovold
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2020-08-17  9:55 UTC (permalink / raw)
  To: Phú Lưu An
  Cc: Johan Hovold, Phu Luu, gregkh, linux-usb, linux-kernel,
	Brant Merryman, Richard Hendricks, hungnd3

On Mon, Aug 17, 2020 at 09:24:05AM +0700, Phú Lưu An wrote:
> Hi Johan,
> 
> My customer asked me when this patch is applied to the community. So, could
> you please tell me when it appears in a various distributions?

You'll have to ask the distributions about that.

The patch in question is in Linus's tree since about two weeks and
should be picked up and backported to the stable trees soon:

	c7614ff9b73a ("USB: serial: cp210x: re-enable auto-RTS on open")

Johan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] USB: serial: cp210x: Proper RTS control when buffers fill
       [not found] <DM6PR11MB2857CC4B06D64F290FC42E739C950@DM6PR11MB2857.namprd11.prod.outlook.com>
@ 2020-06-24  7:09 ` gregkh
  0 siblings, 0 replies; 5+ messages in thread
From: gregkh @ 2020-06-24  7:09 UTC (permalink / raw)
  To: Phu Luu; +Cc: johan, linux-usb, linux-kernel, Brant Merryman, Richard Hendricks

On Wed, Jun 24, 2020 at 07:03:04AM +0000, Phu Luu wrote:
> CP210x hardware disables auto-RTS but leaves auto-CTS when
> in hardware flow control mode and UART on cp210x hardware
> is disabled. This allows data to flow out, but new data
> will not come into the port. When re-opening the port, if
> auto-CTS is enabled on the cp210x, then auto-RTS must be
> re-enabled in the driver.
> 
> Signed-off-by: Phu Luu <phu.luu@silabs.com>
> Signed-off-by: Brant Merryman <brant.merryman@silabs.com>
> ---
> 06/09/2020: Patch v3 2/2 Modified based on feedback from Johan Hovold <johan@kernel.org>
> 12/18/2019: Patch v2 Broken into two patches and modified based on feedback from Johan Hovold <johan@kernel.org>
> 12/09/2019: Initial submission of patch "Proper RTS control when buffers fill"
> 
> drivers/usb/serial/cp210x.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> index bcceb4ad8be0..091441b1c5b9 100644
> --- a/drivers/usb/serial/cp210x.c
> +++ b/drivers/usb/serial/cp210x.c
> @@ -917,6 +917,7 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
>                u32 baud;
>                u16 bits;
>                u32 ctl_hs;
> +             u32 flow_repl;
>                 cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
> @@ -1017,6 +1018,23 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
>                ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
>                if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) {
>                                dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
> +                             /*
> +                             * When the port is closed, the CP210x hardware disables
> +                             * auto-RTS and RTS is deasserted but it leaves auto-CTS when
> +                             * in hardware flow control mode. This prevents new data from
> +                             * being received by the port. When re-opening the port, if
> +                             * auto-CTS is enabled on the cp210x, then auto-RTS must be
> +                             * re-enabled in the driver.
> +                             */
> +                             flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
> +                             flow_repl &= ~CP210X_SERIAL_RTS_MASK;
> +                             flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL);
> +                             flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl);
> +                             cp210x_write_reg_block(port,
> +                                                             CP210X_SET_FLOW,
> +                                                             &flow_ctl,
> +                                                             sizeof(flow_ctl));
> +
>                                cflag |= CRTSCTS;
>                } else {
>                                dev_dbg(dev, "%s - flow control = NONE\n", __func__);
> --
> 2.17.0
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- Your patch is malformed (tabs converted to spaces, linewrapped, etc.)
  and can not be applied.  Please read the file,
  Documentation/email-clients.txt in order to fix this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-17  9:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-26  4:24 [PATCH v3 2/2] USB: serial: cp210x: Proper RTS control when buffers fill Phu Luu
2020-06-26  7:42 ` Johan Hovold
2020-07-06 10:18   ` Johan Hovold
     [not found]     ` <CAP847ynZDozdA0kDEo6Zjuk0LOeaiTyW_fnU89hnFUD8ntL8uw@mail.gmail.com>
2020-08-17  9:55       ` Johan Hovold
     [not found] <DM6PR11MB2857CC4B06D64F290FC42E739C950@DM6PR11MB2857.namprd11.prod.outlook.com>
2020-06-24  7:09 ` gregkh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).