Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
Cc: Andy Gross <agross@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	jslaby@suse.com, MSM <linux-arm-msm@vger.kernel.org>,
	linux-serial@vger.kernel.org, lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] tty: serial: msm_serial: Fix flow control
Date: Mon, 21 Oct 2019 09:24:52 -0700	[thread overview]
Message-ID: <20191021162452.GB1204@tuxbook-pro> (raw)
In-Reply-To: <CAOCk7NpvXb3zBAM1DQng3sQWgWXc5AP2vo=i+gX0mQtA2W7QWg@mail.gmail.com>

On Mon 21 Oct 08:19 PDT 2019, Jeffrey Hugo wrote:

> On Sun, Oct 20, 2019 at 12:28 AM Bjorn Andersson
> <bjorn.andersson@linaro.org> wrote:
> >
> > On Sat 19 Oct 14:06 PDT 2019, Jeffrey Hugo wrote:
> >
> > > hci_qca interfaces to the wcn3990 via a uart_dm on the msm8998 mtp and
> > > Lenovo Miix 630 laptop.  As part of initializing the wcn3990, hci_qca
> > > disables flow, configures the uart baudrate, and then reenables flow - at
> > > which point an event is expected to be received over the uart from the
> > > wcn3990.  It is observed that this event comes after the baudrate change
> > > but before hci_qca re-enables flow. This is unexpected, and is a result of
> > > msm_reset() being broken.
> > >
> > > According to the uart_dm hardware documentation, it is recommended that
> > > automatic hardware flow control be enabled by setting RX_RDY_CTL.  Auto
> > > hw flow control will manage RFR based on the configured watermark.  When
> > > there is space to receive data, the hw will assert RFR.  When the watermark
> > > is hit, the hw will de-assert RFR.
> > >
> > > The hardware documentation indicates that RFR can me manually managed via
> > > CR when RX_RDY_CTL is not set.  SET_RFR asserts RFR, and RESET_RFR
> > > de-asserts RFR.
> > >
> > > msm_reset() is broken because after resetting the hardware, it
> > > unconditionally asserts RFR via SET_RFR.  This enables flow regardless of
> > > the current configuration, and would undo a previous flow disable
> > > operation.  It should instead de-assert RFR via RESET_RFR to block flow
> > > until the hardware is reconfigured.  msm_serial should rely on the client
> > > to specify that flow should be enabled, either via mctrl() or the termios
> > > structure, and only assert RFR in response to those triggers.
> > >
> >
> > I traced msm_reset() and msm_set_mctrl() and I get the following:
> >        swapper/0-1     [000] d..1     3.091726: msm_set_mctrl: msm_set_mctrl() reset rfr
> >        swapper/0-1     [000] d..1     3.117046: msm_set_mctrl: msm_set_mctrl() reset rfr
> >        swapper/0-1     [000] d..1     3.125484: msm_set_termios: msm_reset() set rfr
> >        swapper/0-1     [003] d..1     4.491430: msm_set_termios: msm_reset() set rfr
> >        swapper/0-1     [003] d..1     4.491733: msm_set_mctrl: msm_set_mctrl() auto rfr
> >            login-313   [001] d..1    78.010785: msm_set_mctrl: msm_set_mctrl() reset rfr
> >            login-313   [001] d..1    78.011007: msm_set_termios: msm_reset() set rfr
> >            login-313   [001] d..1    78.011021: msm_set_mctrl: msm_set_mctrl() auto rfr
> >            login-313   [001] d..1    78.063330: msm_set_termios: msm_reset() set rfr
> >            login-313   [001] d..1    78.063641: msm_set_termios: msm_reset() set rfr
> >
> > So while your change does make sense for BT, wouldn't this mean that
> > with your patch and a 4-pin UART for the console I would end this dance
> > with receive flow blocked?
> 
> No.  I don't think it occurred to you to consider how RX_RDY_CTL
> factors into this.  RX_RDY_CTL allows the hardware to enable flow when
> the hardware determines it is able to receive data.  RX_RDY_CTL gets
> set in mctrl, and set_termios - essentially when the uart client has
> indicated flow can be enabled.
> 

I see, so per above trace when login does it's rfr toggling RX_RDY_CTL
is already set (and will be maintained), so we'll allow flow at each
part of the process.

> Even though the console is a 2 wire console on msm8998, the driver
> will go through the same flow.  I verified that RX_RDY_CTL is set on
> the console uart after boot, so we won't end up with flow blocked.
> 
> However, this does bring up another issue.  RX_RDY_CTL doesn't get
> unset in msm_reset.  RESET_RX will disable the rx path in the
> hardware, and prevent RX_RDY_CTL from being active, but the rx path is
> enabled in set_baud_rate() before RX_RDY_CTL can be masked out in
> set_termios, so there may be a small window where flow can
> inadvertently enabled.  I'll spin a v2 that also unsets RX_RDY_CTL in
> msm_reset().
> 

Yes, that sounds reasonable. And for the console case the difference
will be that we deassert RFR while the serial is being reset and
reconfigured; which sounds like the right thing to do.

Regards,
Bjorn

> >
> > Regards,
> > Bjorn
> >
> > > Fixes: 04896a77a97b ("msm_serial: serial driver for MSM7K onboard serial peripheral.")
> > > Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
> > > ---
> > >  drivers/tty/serial/msm_serial.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
> > > index 3657a24913fc..aedabf7646f1 100644
> > > --- a/drivers/tty/serial/msm_serial.c
> > > +++ b/drivers/tty/serial/msm_serial.c
> > > @@ -987,7 +987,7 @@ static void msm_reset(struct uart_port *port)
> > >       msm_write(port, UART_CR_CMD_RESET_ERR, UART_CR);
> > >       msm_write(port, UART_CR_CMD_RESET_BREAK_INT, UART_CR);
> > >       msm_write(port, UART_CR_CMD_RESET_CTS, UART_CR);
> > > -     msm_write(port, UART_CR_CMD_SET_RFR, UART_CR);
> > > +     msm_write(port, UART_CR_CMD_RESET_RFR, UART_CR);
> > >
> > >       /* Disable DM modes */
> > >       if (msm_port->is_uartdm)
> > > --
> > > 2.17.1
> > >

      reply	other threads:[~2019-10-21 16:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-19 21:06 [PATCH] tty: serial: msm_serial: Fix flow control Jeffrey Hugo
2019-10-20  6:28 ` Bjorn Andersson
2019-10-21 15:19   ` Jeffrey Hugo
2019-10-21 16:24     ` Bjorn Andersson [this message]

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=20191021162452.GB1204@tuxbook-pro \
    --to=bjorn.andersson@linaro.org \
    --cc=agross@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeffrey.l.hugo@gmail.com \
    --cc=jslaby@suse.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox