linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: "Ivan Šištík - 3K Solutions, s. r. o." <sistik@3ksolutions.sk>
Cc: Russell King <linux@armlinux.org.uk>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Ray Jui <rjui@broadcom.com>,
	Scott Branden <sbranden@broadcom.com>,
	bcm-kernel-feedback-list@broadcom.com,
	Eric Anholt <eric@anholt.net>,
	Stefan Wahren <stefan.wahren@i2se.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-rpi-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Subject: Re: [PATCH] tty: serial: amba-pl011: added RS485 support
Date: Tue, 21 Jan 2020 09:49:48 +0100	[thread overview]
Message-ID: <20200121084948.7d6om2fgaa7ikmof@wunner.de> (raw)
In-Reply-To: <4e082c29-9a47-accc-425b-8d1854fb6ac6@3ksolutions.sk>

On Fri, Jan 17, 2020 at 01:58:57AM +0100, Ivan Šištík - 3K Solutions, s. r. o. wrote:
> On 16. 1. 2020 at 14:29 Lukas Wunner wrote:
> > So I've implemented rs485 support for amba-pl011.c two years ago
> > but the patches need a little more polishing before they can be
> > upstreamed and I haven't gotten around to that yet.  I apologize
> > that it meant you had to reinvent the wheel.
> > You can find my implementation on this branch:
> > https://github.com/RevolutionPi/linux/commits/revpi-4.19
> > 
> > Specifically this commit:
> > https://github.com/RevolutionPi/linux/commit/0099313962a5
> 
> The wheel with octagonal shape is still not perfect. I made it more
> smoother. Your implementation in recommended commit use an active
> waiting (pl011_rs485_tx_start, pl011_rs485_tx_stop) and that could
> cause lots of problems in upper layers of tty driver or application.
> I think you forgot to implement possibility to start TX during
> "delay after send", too.

Are these delays ever set to a value > 0 in practice?  struct serial_rs485
supports millisecond delays, but all RS485 transceivers I know of only
require delays in the microsecond or nanosecond range.  It was likely
a mistake that the delays were originally declared as millisecond values.
However we can't easily change that now because it's ABI and thus set in
stone.

E.g. the MAXM22510 has a "Driver Enable to Output" delay of 2.540 usec.
In practice no delay is necessary at all because the MMIO operations
performed by the driver take longer:

https://datasheets.maximintegrated.com/en/ds/MAXM22510-MAXM22511.pdf


> > I took a completely different approach:  I converted amba-pl011.c
> > to threaded interrupt handling using two kthreads, one for sending,
> > one for receiving.  This allows simultaneous writing to and reading
> > from the FIFO.  The driver keeps track of the FIFO fill level,
> > which allows writing to the FIFO blindly.  The hardirq handler
> > updates the fill level counter and wakes either of the IRQ threads.
> 
> I do not see any used thread in link:
> https://github.com/RevolutionPi/linux/commit/0099313962a5
> I am not kernel thread expert but I think that thread is not as
> lightweight as hrtimer. According to my knowledge the hrtimer use some
> kind of interrupt. Compare to this the kthread is created as thread
> with all its scheduling structures. Did you implemented proper thread
> shutdown? Has the thread right priority? There are many questions
> like this...

You're not seeing the conversion to threaded IRQ handling because it's
in separate commits on the above-linked branch, e.g.

serial: pl011: Use threaded interrupt for RX
https://github.com/RevolutionPi/linux/commit/4f3a6e9ea335

serial: pl011: Use threaded interrupt for TX
https://github.com/RevolutionPi/linux/commit/fae65b5a2c5b

I implemented threaded IRQ handling to maximize TX throughput
and minimize RX FIFO overruns at high baudrates.  Additionally,
threaded IRQ handling integrates more nicely with the realtime
patch set.  So the ability to simply use msleep() for rs485 delays
is merely a by-product.

The IRQ threads run at RT priority -50 with SCHED_FIFO policy just
as any other IRQ thread and user space may adjust that with chrt(1)
if desired.

Thanks,

Lukas

  reply	other threads:[~2020-01-21  9:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-06 23:52 [PATCH] tty: serial: amba-pl011: added RS485 support Ivan Sistik
2020-01-07  7:27 ` Greg Kroah-Hartman
2020-01-17  0:31   ` Ivan Sistik - 3K Solutions, s. r. o.
2020-01-07  7:28 ` Greg Kroah-Hartman
2020-01-16 13:29 ` Lukas Wunner
2020-01-17  0:58   ` Ivan Šištík - 3K Solutions, s. r. o.
2020-01-21  8:49     ` Lukas Wunner [this message]
2020-12-21 23:18 Ivan Sistik
2020-12-28 15:13 ` Greg Kroah-Hartman

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=20200121084948.7d6om2fgaa7ikmof@wunner.de \
    --to=lukas@wunner.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=eric@anholt.net \
    --cc=f.fainelli@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=nsaenzjulienne@suse.de \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.com \
    --cc=sistik@3ksolutions.sk \
    --cc=stefan.wahren@i2se.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 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).