All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: "Alex Villacís Lasso" <a_villacis@palosanto.com>
Cc: linux-usb@vger.kernel.org, David Frey <dpfrey@gmail.com>,
	Pho Tran <pho.tran@silabs.com>, Tung Pham <tung.pham@silabs.com>,
	Hung.Nguyen@silabs.com
Subject: Re: cp210x module broken in 5.12.5 and 5.12.6, works in 5.11.21 (with bisection)
Date: Sat, 5 Jun 2021 12:24:34 +0200	[thread overview]
Message-ID: <YLtQ4pV0JBSOfLRw@hovoldconsulting.com> (raw)
In-Reply-To: <a3a37639-0cba-fb3e-96bf-b4c2dae544a7@palosanto.com>

On Fri, Jun 04, 2021 at 01:25:19PM -0500, Alex Villacís Lasso wrote:
> El 4/6/21 a las 10:42, Johan Hovold escribió:

> > I just ran a quick test here and and leaving the ixoff_limit at zero
> > essentially breaks software flow control since XOFF will be sent when
> > there are only 7 characters in the receive buffer.
> >
> > Since software flow control support was only recently added, we may have
> > to accept that for CP2102N to fix the regression, but I'd really like to
> > understand why your devices behave the way they do first and see if
> > there's some other way to work around this.
> >
> > Hopefully Silabs can provide some insight.
> >
> > Also, could you try setting those limits to some other values and see if
> > the SET_MHS (request 0x7) errors go away?
> >
> > Setting both to 513 is supposed to give us 192/64 according to the
> > datasheet which would be good enough, for example. Seems to work as
> > documented here (at least for XOFF).

> I am starting to suspect that the root cause is that the 0x07 command 
> (CP210X_SET_MHS macro in the code) is invalid to send, if the device has 
> been previously programmed with nonzero ulXonLimit/ulXoffLimit. When the 
> patch programs both limits back to 0, the command succeeds.

Right, that's what the bisection and logs seem to suggest.

> I am attaching the patch I used, which is the combination of both debug 
> patches, plus this change:
> 
> @@ -1195,11 +1201,14 @@
>          else
>                  flow_repl &= ~CP210X_SERIAL_AUTO_TRANSMIT;
> 
> -       flow_ctl.ulXonLimit = cpu_to_le32(128);
> -       flow_ctl.ulXoffLimit = cpu_to_le32(128);
> +       flow_ctl.ulXonLimit = (I_IXON(tty)) ? cpu_to_le32(128) : 
> cpu_to_le32(0);
> +       flow_ctl.ulXoffLimit = (I_IXOFF(tty)) ? cpu_to_le32(128) : 
> cpu_to_le32(0);

These are both only needed when IXOFF (input flow control) is used (IXON
is for output flow control and does not use these limits).

And the fact that they cause a mostly unrelated error when set still
indicates a firmware bug. That doesn't mean it may be possible to work
around it somehow of course.

> With this patch, the miniterm.py program sort of keeps running and shows 
> output. Not a perfect patch by any means, since some failures still happen:

> $ miniterm.py /dev/ttyUSB0 115200
> <program waits for input>
> 
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_change_speed - setting baud rate to 9600
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_set_flow_control - BEFORE: ctrl = 0x00, flow = 0x00
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_set_flow_control - BEFORE: xon_limit = 0, xoff_limit = 0
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_set_flow_control - AFTER: ctrl = 0x00, flow = 0x01
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_set_flow_control - AFTER: xon_limit = 128, xoff_limit = 0

Another data point: just setting the XON limit is enough to trigger the
bug.

> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_tiocmset_port - control = 0x0303
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: failed set request 
> 0x7 status: -32

As here SET_MHS fails.

> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_change_speed - setting baud rate to 115384
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_set_flow_control - BEFORE: ctrl = 0x00, flow = 0x01
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_set_flow_control - BEFORE: xon_limit = 128, xoff_limit = 0
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_set_flow_control - AFTER: ctrl = 0x01, flow = 0x40
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_set_flow_control - AFTER: xon_limit = 0, xoff_limit = 0
> jun 04 13:05:12 karlalex-asus kernel: cp210x ttyUSB0: 
> cp210x_tiocmset_port - control = 0x0101

And when XON is reset, settings RTS again works.

For completeness you could try setting only the XOFF limit and see if
that alone is sufficient to trigger the issue.

But please also try hardcoding both limits to 513 as I mentioned
above and see if that makes any difference.

Johan

  reply	other threads:[~2021-06-05 10:24 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31 17:38 cp210x module broken in 5.12.5 and 5.12.6, works in 5.11.21 (with bisection) Alex Villacís Lasso
2021-06-01  7:50 ` Johan Hovold
2021-06-01 14:51   ` Alex Villacís Lasso
2021-06-01 15:40     ` Johan Hovold
2021-06-01 17:18       ` Alex Villacís Lasso
2021-06-02 14:50         ` Johan Hovold
2021-06-02 15:54           ` Alex Villacís Lasso
2021-06-04 15:42             ` Johan Hovold
2021-06-04 18:25               ` Alex Villacís Lasso
2021-06-05 10:24                 ` Johan Hovold [this message]
2021-06-05 10:54                   ` Johan Hovold
2021-06-04 23:16               ` David Frey
2021-06-05 10:13                 ` Johan Hovold
2021-06-07 15:16                   ` Alex Villacís Lasso
2021-06-07 16:45                     ` Johan Hovold
2021-06-07 16:44                   ` David Frey
2021-06-07 16:52                     ` Johan Hovold
2021-06-07 18:02                       ` David Frey
2021-06-07 20:44                         ` David Frey
2021-06-07 23:50                           ` Alex Villacís Lasso
2021-06-08  9:10                             ` Tung Pham
2021-06-08  9:52                               ` Johan Hovold
2021-06-08  9:41                           ` Johan Hovold
2021-06-09 16:15                             ` [PATCH] USB: serial: cp210x: fix CP2102N-A01 modem control Johan Hovold
2021-06-09 17:00                               ` Alex Villacís Lasso
2021-06-10  7:23                                 ` Johan Hovold
2021-06-10 14:55                                   ` Alex Villacís Lasso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YLtQ4pV0JBSOfLRw@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=Hung.Nguyen@silabs.com \
    --cc=a_villacis@palosanto.com \
    --cc=dpfrey@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=pho.tran@silabs.com \
    --cc=tung.pham@silabs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.