All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vicente Bergas <vicencb@gmail.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	giulio.benetti@micronovasrl.com,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	heikki.krogerus@linux.intel.com,
	"Heiko Stübner" <heiko@sntech.de>,
	jirislaby@kernel.org, johan@kernel.org,
	linux-api@vger.kernel.org,
	linux-serial <linux-serial@vger.kernel.org>,
	"Lukas Wunner" <lukas@wunner.de>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: Re: [PATCH v3 00/12] Add RS485 support to DW UART
Date: Sun, 24 Apr 2022 01:57:50 +0200	[thread overview]
Message-ID: <CAAMcf8DQcArMRqL-uYUt-aUT-LaETn4a7+wjqeet15cFQuy3uQ@mail.gmail.com> (raw)
In-Reply-To: <184ccf6c-e1db-8a64-24e0-f045a9d88751@linux.intel.com>

Hi Ilpo, thank you for your quick reply with a solution!

On Fri, Apr 22, 2022 at 3:07 PM Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
>
> On Fri, 22 Apr 2022, Ilpo Järvinen wrote:
>
> > On Thu, 21 Apr 2022, Vicente Bergas wrote:
> >
> > > 1.- rs485_stop_tx is never called because there are no interrupts.
> > > I worked around this by disabling DMA:
> >
> > I'll need to look into this.
>
> 8250 DMA tx complete path lacks calls to normal 8250 stop handling and
> I think it probably also assumes too much from dmaengine's completion
> callback. ...It also seems bit early to call serial8250_rpm_put_tx from
> there(?).
>
> This patch allowed em485_start/stop_tx to be called in my tests:
> [PATCH 1/1] serial: 8250: use THRE & __stop_tx also with DMA

I confirm that this patch fixes the issue when DMA is enabled.

I also confirm that your other patch
> +                       stop_delay = p->port.frame_time + DIV_ROUND_UP(p->port.frame_time, 7);
fixes the issue with RTS/DriverEnable deassertion time.
I've tested it again at 19200e1 and now RTS is deasserted
approximately at the same time as the end of the stop bit.
Please, note the "e" for even parity bit, that extra bit after the
data byte might have an impact on this timings.

Regards,
  Vicente.

On Fri, Apr 22, 2022 at 3:07 PM Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
>
> On Fri, 22 Apr 2022, Ilpo Järvinen wrote:
>
> > On Thu, 21 Apr 2022, Vicente Bergas wrote:
> >
> > > i have tested your v3 patch on v3 hardware, that is, using the
> > > emulated em485 because of lack of HW support. It is not working
> > > due to three issues.
> >
> > Thanks for testing!
> >
> > > 1.- rs485_stop_tx is never called because there are no interrupts.
> > > I worked around this by disabling DMA:
> > >
> > > --- a/drivers/tty/serial/8250/8250_dw.c
> > > +++ b/drivers/tty/serial/8250/8250_dw.c
> > > @@ -577,3 +577,3 @@ static int dw8250_probe(struct platform_device *pdev)
> > >             data->data.dma.rxconf.src_maxburst = p->fifosize / 4;
> > >             data->data.dma.txconf.dst_maxburst = p->fifosize / 4;
> > > -           up->dma = &data->data.dma;
> > > +           up->dma = 0; // Proof of concept, not to be merged!
> >
> > I'll need to look into this.
>
> 8250 DMA tx complete path lacks calls to normal 8250 stop handling and
> I think it probably also assumes too much from dmaengine's completion
> callback. ...It also seems bit early to call serial8250_rpm_put_tx from
> there(?).
>
> This patch allowed em485_start/stop_tx to be called in my tests:
>
>
> [PATCH 1/1] serial: 8250: use THRE & __stop_tx also with DMA
>
> Currently, DMA complete handling in 8250 driver does not use THRE
> to detect true completion of the tx and also doesn't call __stop_tx.
> This leads to problems with em485 that needs to handle RTS timing.
>
> Instead of handling tx stop within 8250 dma code, enable THRE when
> tx data runs out and tweak serial8250_handle_irq to call
> __stop_tx when uart is using DMA.
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
>  drivers/tty/serial/8250/8250_dma.c  | 4 ++--
>  drivers/tty/serial/8250/8250_port.c | 9 ++++++---
>  2 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c
> index 890fa7ddaa7f..e84db0abf365 100644
> --- a/drivers/tty/serial/8250/8250_dma.c
> +++ b/drivers/tty/serial/8250/8250_dma.c
> @@ -29,12 +29,13 @@ static void __dma_tx_complete(void *param)
>         xmit->tail += dma->tx_size;
>         xmit->tail &= UART_XMIT_SIZE - 1;
>         p->port.icount.tx += dma->tx_size;
> +       dma->tx_size = 0;
>
>         if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
>                 uart_write_wakeup(&p->port);
>
>         ret = serial8250_tx_dma(p);
> -       if (ret)
> +       if (ret || !dma->tx_size)
>                 serial8250_set_THRI(p);
>
>         spin_unlock_irqrestore(&p->port.lock, flags);
> @@ -71,7 +72,6 @@ int serial8250_tx_dma(struct uart_8250_port *p)
>
>         if (uart_tx_stopped(&p->port) || uart_circ_empty(xmit)) {
>                 /* We have been called from __dma_tx_complete() */
> -               serial8250_rpm_put_tx(p);
>                 return 0;
>         }
>
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index b3289ef117d1..72f144449ee1 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -1960,9 +1960,12 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
>                         status = serial8250_rx_chars(up, status);
>         }
>         serial8250_modem_status(up);
> -       if ((!up->dma || up->dma->tx_err) && (status & UART_LSR_THRE) &&
> -               (up->ier & UART_IER_THRI))
> -               serial8250_tx_chars(up);
> +       if ((status & UART_LSR_THRE) && (up->ier & UART_IER_THRI)) {
> +               if (!up->dma || up->dma->tx_err)
> +                       serial8250_tx_chars(up);
> +               else
> +                       __stop_tx(up);
> +       }
>
>         uart_unlock_and_check_sysrq_irqrestore(port, flags);
>
> --
> 2.35.1

  reply	other threads:[~2022-04-23 23:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11  8:33 [PATCH v3 00/12] Add RS485 support to DW UART Ilpo Järvinen
2022-04-11  8:33 ` [PATCH v3 01/12] serial: Store character timing information to uart_port Ilpo Järvinen
2022-04-11 10:52   ` Andy Shevchenko
2022-04-11 10:56     ` Andy Shevchenko
2022-04-11 11:00       ` Andy Shevchenko
2022-04-11  8:33 ` [PATCH v3 02/12] serial: 8250: Handle UART without interrupt on TEMT Ilpo Järvinen
2022-04-11  8:33 ` [PATCH v3 03/12] serial: 8250_dwlib: RS485 HW half & full duplex support Ilpo Järvinen
2022-04-11  8:33 ` [PATCH v3 04/12] serial: 8250_dwlib: Implement SW half " Ilpo Järvinen
2022-04-11  8:33 ` [PATCH v3 05/12] dt_bindings: rs485: Add receiver enable polarity Ilpo Järvinen
2022-04-11  8:33 ` [PATCH v3 06/12] ACPI / property: Document RS485 _DSD properties Ilpo Järvinen
2022-04-11 11:02   ` Andy Shevchenko
2022-04-11  8:33 ` [PATCH v3 07/12] serial: termbits: ADDRB to indicate 9th bit addressing mode Ilpo Järvinen
2022-04-11  8:33   ` Ilpo Järvinen
2022-04-11  8:33   ` Ilpo Järvinen
2022-04-11  8:33 ` [PATCH v3 08/12] serial: General support for multipoint addresses Ilpo Järvinen
2022-04-11  8:33   ` Ilpo Järvinen
2022-04-11  8:33   ` Ilpo Järvinen
2022-04-11  8:33 ` [PATCH v3 09/12] serial: 8250: make saved LSR larger Ilpo Järvinen
2022-04-11  8:33 ` [PATCH v3 10/12] serial: 8250: create lsr_save_mask Ilpo Järvinen
2022-04-11  8:33 ` [PATCH v3 11/12] serial: 8250_lpss: Use 32-bit reads Ilpo Järvinen
2022-04-11 11:12   ` Andy Shevchenko
2022-04-11  8:33 ` [PATCH v3 12/12] serial: 8250_dwlib: Support for 9th bit multipoint addressing Ilpo Järvinen
2022-04-11 11:19   ` Andy Shevchenko
2022-04-21 15:36 ` [PATCH v3 00/12] Add RS485 support to DW UART Vicente Bergas
2022-04-21 19:38   ` Lukas Wunner
2022-04-21 20:41     ` Vicente Bergas
2022-04-22  9:25   ` Ilpo Järvinen
2022-04-22 13:07     ` Ilpo Järvinen
2022-04-23 23:57       ` Vicente Bergas [this message]
2022-04-25 11:16         ` Ilpo Järvinen

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=CAAMcf8DQcArMRqL-uYUt-aUT-LaETn4a7+wjqeet15cFQuy3uQ@mail.gmail.com \
    --to=vicencb@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=giulio.benetti@micronovasrl.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=heiko@sntech.de \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=johan@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=lukas@wunner.de \
    --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.