linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tty: serial: msm_serial: Fix flow control
@ 2019-10-21 15:46 Jeffrey Hugo
  2019-10-21 16:26 ` Bjorn Andersson
  2019-10-27  5:55 ` Andy Gross
  0 siblings, 2 replies; 6+ messages in thread
From: Jeffrey Hugo @ 2019-10-21 15:46 UTC (permalink / raw)
  To: agross, bjorn.andersson, gregkh, jslaby
  Cc: linux-arm-msm, linux-serial, linux-kernel, Jeffrey Hugo

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.

Fixes: 04896a77a97b ("msm_serial: serial driver for MSM7K onboard serial peripheral.")
Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
---

v2:
-mask out RX_RDY_CTL in msm_reset() to close a small race window for RFR

 drivers/tty/serial/msm_serial.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
index 3657a24913fc..00964b6e4ac1 100644
--- a/drivers/tty/serial/msm_serial.c
+++ b/drivers/tty/serial/msm_serial.c
@@ -980,6 +980,7 @@ static unsigned int msm_get_mctrl(struct uart_port *port)
 static void msm_reset(struct uart_port *port)
 {
 	struct msm_port *msm_port = UART_TO_MSM(port);
+	unsigned int mr;
 
 	/* reset everything */
 	msm_write(port, UART_CR_CMD_RESET_RX, UART_CR);
@@ -987,7 +988,10 @@ 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);
+	mr = msm_read(port, UART_MR1);
+	mr &= ~UART_MR1_RX_RDY_CTL;
+	msm_write(port, mr, UART_MR1);
 
 	/* Disable DM modes */
 	if (msm_port->is_uartdm)
-- 
2.17.1


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

* Re: [PATCH v2] tty: serial: msm_serial: Fix flow control
  2019-10-21 15:46 [PATCH v2] tty: serial: msm_serial: Fix flow control Jeffrey Hugo
@ 2019-10-21 16:26 ` Bjorn Andersson
  2019-10-27  5:55 ` Andy Gross
  1 sibling, 0 replies; 6+ messages in thread
From: Bjorn Andersson @ 2019-10-21 16:26 UTC (permalink / raw)
  To: Jeffrey Hugo
  Cc: agross, gregkh, jslaby, linux-arm-msm, linux-serial, linux-kernel

On Mon 21 Oct 08:46 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.
> 
> Fixes: 04896a77a97b ("msm_serial: serial driver for MSM7K onboard serial peripheral.")
> Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>

Looks good!

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

> ---
> 
> v2:
> -mask out RX_RDY_CTL in msm_reset() to close a small race window for RFR
> 
>  drivers/tty/serial/msm_serial.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
> index 3657a24913fc..00964b6e4ac1 100644
> --- a/drivers/tty/serial/msm_serial.c
> +++ b/drivers/tty/serial/msm_serial.c
> @@ -980,6 +980,7 @@ static unsigned int msm_get_mctrl(struct uart_port *port)
>  static void msm_reset(struct uart_port *port)
>  {
>  	struct msm_port *msm_port = UART_TO_MSM(port);
> +	unsigned int mr;
>  
>  	/* reset everything */
>  	msm_write(port, UART_CR_CMD_RESET_RX, UART_CR);
> @@ -987,7 +988,10 @@ 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);
> +	mr = msm_read(port, UART_MR1);
> +	mr &= ~UART_MR1_RX_RDY_CTL;
> +	msm_write(port, mr, UART_MR1);
>  
>  	/* Disable DM modes */
>  	if (msm_port->is_uartdm)
> -- 
> 2.17.1
> 

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

* Re: [PATCH v2] tty: serial: msm_serial: Fix flow control
  2019-10-21 15:46 [PATCH v2] tty: serial: msm_serial: Fix flow control Jeffrey Hugo
  2019-10-21 16:26 ` Bjorn Andersson
@ 2019-10-27  5:55 ` Andy Gross
  2019-11-03 21:51   ` Jeffrey Hugo
  1 sibling, 1 reply; 6+ messages in thread
From: Andy Gross @ 2019-10-27  5:55 UTC (permalink / raw)
  To: Jeffrey Hugo
  Cc: bjorn.andersson, gregkh, jslaby, linux-arm-msm, linux-serial,
	linux-kernel

On Mon, Oct 21, 2019 at 08:46:16AM -0700, 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.
> 
> Fixes: 04896a77a97b ("msm_serial: serial driver for MSM7K onboard serial peripheral.")
> Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
> ---

Reviewed-by: Andy Gross <agross@kernel.org>

Greg, can you pick this one up?

Thanks,
Andy

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

* Re: [PATCH v2] tty: serial: msm_serial: Fix flow control
  2019-10-27  5:55 ` Andy Gross
@ 2019-11-03 21:51   ` Jeffrey Hugo
  2019-11-04 16:41     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey Hugo @ 2019-11-03 21:51 UTC (permalink / raw)
  To: Andy Gross, Greg Kroah-Hartman
  Cc: Bjorn Andersson, jslaby, MSM, linux-serial, lkml

On Sat, Oct 26, 2019 at 11:55 PM Andy Gross <agross@kernel.org> wrote:
>
> On Mon, Oct 21, 2019 at 08:46:16AM -0700, 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.
> >
> > Fixes: 04896a77a97b ("msm_serial: serial driver for MSM7K onboard serial peripheral.")
> > Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
> > ---
>
> Reviewed-by: Andy Gross <agross@kernel.org>
>
> Greg, can you pick this one up?
>
> Thanks,
> Andy

Greg, will this be queued for 5.5?

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

* Re: [PATCH v2] tty: serial: msm_serial: Fix flow control
  2019-11-03 21:51   ` Jeffrey Hugo
@ 2019-11-04 16:41     ` Greg Kroah-Hartman
  2019-11-04 21:13       ` Jeffrey Hugo
  0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2019-11-04 16:41 UTC (permalink / raw)
  To: Jeffrey Hugo; +Cc: Andy Gross, Bjorn Andersson, jslaby, MSM, linux-serial, lkml

On Sun, Nov 03, 2019 at 02:51:17PM -0700, Jeffrey Hugo wrote:
> On Sat, Oct 26, 2019 at 11:55 PM Andy Gross <agross@kernel.org> wrote:
> >
> > On Mon, Oct 21, 2019 at 08:46:16AM -0700, 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.
> > >
> > > Fixes: 04896a77a97b ("msm_serial: serial driver for MSM7K onboard serial peripheral.")
> > > Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
> > > ---
> >
> > Reviewed-by: Andy Gross <agross@kernel.org>
> >
> > Greg, can you pick this one up?
> >
> > Thanks,
> > Andy
> 
> Greg, will this be queued for 5.5?

Yes, catching up now...

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

* Re: [PATCH v2] tty: serial: msm_serial: Fix flow control
  2019-11-04 16:41     ` Greg Kroah-Hartman
@ 2019-11-04 21:13       ` Jeffrey Hugo
  0 siblings, 0 replies; 6+ messages in thread
From: Jeffrey Hugo @ 2019-11-04 21:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Andy Gross, Bjorn Andersson, jslaby, MSM, linux-serial, lkml

On Mon, Nov 4, 2019 at 9:41 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Sun, Nov 03, 2019 at 02:51:17PM -0700, Jeffrey Hugo wrote:
> > On Sat, Oct 26, 2019 at 11:55 PM Andy Gross <agross@kernel.org> wrote:
> > >
> > > On Mon, Oct 21, 2019 at 08:46:16AM -0700, 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.
> > > >
> > > > Fixes: 04896a77a97b ("msm_serial: serial driver for MSM7K onboard serial peripheral.")
> > > > Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
> > > > ---
> > >
> > > Reviewed-by: Andy Gross <agross@kernel.org>
> > >
> > > Greg, can you pick this one up?
> > >
> > > Thanks,
> > > Andy
> >
> > Greg, will this be queued for 5.5?
>
> Yes, catching up now...

Excellent, thank you very much.

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

end of thread, other threads:[~2019-11-04 21:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 15:46 [PATCH v2] tty: serial: msm_serial: Fix flow control Jeffrey Hugo
2019-10-21 16:26 ` Bjorn Andersson
2019-10-27  5:55 ` Andy Gross
2019-11-03 21:51   ` Jeffrey Hugo
2019-11-04 16:41     ` Greg Kroah-Hartman
2019-11-04 21:13       ` Jeffrey Hugo

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