All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baruch Siach <baruch@tkos.co.il>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-serial@vger.kernel.org
Subject: Re: [PATCH] serial: imx: support RS-485 Rx disable on Tx
Date: Sun, 28 Feb 2016 12:23:23 +0200	[thread overview]
Message-ID: <20160228102323.GI2399@tarshish> (raw)
In-Reply-To: <20160228095601.GB2613@pengutronix.de>

Hi Uwe,

Thanks for your prompt response.

On Sun, Feb 28, 2016 at 10:56:01AM +0100, Uwe Kleine-König wrote:
> On Sun, Feb 28, 2016 at 11:25:51AM +0200, Baruch Siach wrote:
> > Some RS-232 to RS-485 transceivers require Rx to be disabled on Tx to
> > avoid echo of Tx data into the Rx buffer. Specifically, the XR3160E
> > RS-232/RS-485/RS-422 transceiver behaves this way.
> > 
> > This commit disables Rx on active Tx when SER_RS485_ENABLED is active and
> > SER_RS485_RX_DURING_TX is disabled.
> > 
> > Note that this is a change in behavior of the driver. Until now
> 
> But this change is a good one (assuming it does what it advertises :-).
> Userspace got informed before that SER_RS485_RX_DURING_TX is enabled, so
> this is not an incompatible change.

I thought it is a good idea to mention this fact in the commit log anyway. It 
is not hard to imagine broken userspace being affected by this change.

> > SER_RS485_RX_DURING_TX was enabled unconditionally even when disabled in
> > the TIOCSRS485 ioctl serial_rs485 flags field.
> > 
> > Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> > ---
> >  drivers/tty/serial/imx.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> > index 9362f54c816c..333d34ff358c 100644
> > --- a/drivers/tty/serial/imx.c
> > +++ b/drivers/tty/serial/imx.c
> > @@ -361,6 +361,8 @@ static void imx_stop_tx(struct uart_port *port)
> >  			imx_port_rts_inactive(sport, &temp);
> >  		else
> >  			imx_port_rts_active(sport, &temp);
> > +		if (!(port->rs485.flags & SER_RS485_RX_DURING_TX))
> > +			temp |= UCR2_RXEN;
> >  		writel(temp, port->membase + UCR2);
> >  
> >  		temp = readl(port->membase + UCR4);
> > @@ -568,6 +570,8 @@ static void imx_start_tx(struct uart_port *port)
> >  			imx_port_rts_inactive(sport, &temp);
> >  		else
> >  			imx_port_rts_active(sport, &temp);
> > +		if (!(port->rs485.flags & SER_RS485_RX_DURING_TX))
> > +			temp &= ~UCR2_RXEN;
> >  		writel(temp, port->membase + UCR2);
> 
> Can this happen:
> 
>  - SER_RS485_RX_DURING_TX is off
>  - thread A starts sending (and so disables RX)
>  - thread B sets SER_RS485_RX_DURING_TX
>  - thread A finishes sending, and doesn't restore RXEN.
> 
> ?
> 
> Even if this cannot happen it might be more robust to restore RXEN
> unconditionally in imx_stop_tx?!

Sounds like a good idea. But if I take your comment to its logical conclusion, 
thread B might just disable SER_RS485_ENABLED entirely. Would it make sense to 
restore RXEN outside the 'if (port->rs485.flags & SER_RS485_ENABLED)' block?  
Or maybe we should just set RXEN in imx_rs485_config() when 
SER_RS485_RX_DURING_TX is enabled?

baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

WARNING: multiple messages have this Message-ID (diff)
From: baruch@tkos.co.il (Baruch Siach)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] serial: imx: support RS-485 Rx disable on Tx
Date: Sun, 28 Feb 2016 12:23:23 +0200	[thread overview]
Message-ID: <20160228102323.GI2399@tarshish> (raw)
In-Reply-To: <20160228095601.GB2613@pengutronix.de>

Hi Uwe,

Thanks for your prompt response.

On Sun, Feb 28, 2016 at 10:56:01AM +0100, Uwe Kleine-K?nig wrote:
> On Sun, Feb 28, 2016 at 11:25:51AM +0200, Baruch Siach wrote:
> > Some RS-232 to RS-485 transceivers require Rx to be disabled on Tx to
> > avoid echo of Tx data into the Rx buffer. Specifically, the XR3160E
> > RS-232/RS-485/RS-422 transceiver behaves this way.
> > 
> > This commit disables Rx on active Tx when SER_RS485_ENABLED is active and
> > SER_RS485_RX_DURING_TX is disabled.
> > 
> > Note that this is a change in behavior of the driver. Until now
> 
> But this change is a good one (assuming it does what it advertises :-).
> Userspace got informed before that SER_RS485_RX_DURING_TX is enabled, so
> this is not an incompatible change.

I thought it is a good idea to mention this fact in the commit log anyway. It 
is not hard to imagine broken userspace being affected by this change.

> > SER_RS485_RX_DURING_TX was enabled unconditionally even when disabled in
> > the TIOCSRS485 ioctl serial_rs485 flags field.
> > 
> > Cc: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
> > Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> > ---
> >  drivers/tty/serial/imx.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> > index 9362f54c816c..333d34ff358c 100644
> > --- a/drivers/tty/serial/imx.c
> > +++ b/drivers/tty/serial/imx.c
> > @@ -361,6 +361,8 @@ static void imx_stop_tx(struct uart_port *port)
> >  			imx_port_rts_inactive(sport, &temp);
> >  		else
> >  			imx_port_rts_active(sport, &temp);
> > +		if (!(port->rs485.flags & SER_RS485_RX_DURING_TX))
> > +			temp |= UCR2_RXEN;
> >  		writel(temp, port->membase + UCR2);
> >  
> >  		temp = readl(port->membase + UCR4);
> > @@ -568,6 +570,8 @@ static void imx_start_tx(struct uart_port *port)
> >  			imx_port_rts_inactive(sport, &temp);
> >  		else
> >  			imx_port_rts_active(sport, &temp);
> > +		if (!(port->rs485.flags & SER_RS485_RX_DURING_TX))
> > +			temp &= ~UCR2_RXEN;
> >  		writel(temp, port->membase + UCR2);
> 
> Can this happen:
> 
>  - SER_RS485_RX_DURING_TX is off
>  - thread A starts sending (and so disables RX)
>  - thread B sets SER_RS485_RX_DURING_TX
>  - thread A finishes sending, and doesn't restore RXEN.
> 
> ?
> 
> Even if this cannot happen it might be more robust to restore RXEN
> unconditionally in imx_stop_tx?!

Sounds like a good idea. But if I take your comment to its logical conclusion, 
thread B might just disable SER_RS485_ENABLED entirely. Would it make sense to 
restore RXEN outside the 'if (port->rs485.flags & SER_RS485_ENABLED)' block?  
Or maybe we should just set RXEN in imx_rs485_config() when 
SER_RS485_RX_DURING_TX is enabled?

baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

  reply	other threads:[~2016-02-28 10:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-28  9:25 [PATCH] serial: imx: support RS-485 Rx disable on Tx Baruch Siach
2016-02-28  9:25 ` Baruch Siach
2016-02-28  9:56 ` Uwe Kleine-König
2016-02-28  9:56   ` Uwe Kleine-König
2016-02-28 10:23   ` Baruch Siach [this message]
2016-02-28 10:23     ` Baruch Siach
2016-02-29  8:51     ` Uwe Kleine-König
2016-02-29  8:51       ` Uwe Kleine-König

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=20160228102323.GI2399@tarshish \
    --to=baruch@tkos.co.il \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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.