All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Hurley <peter@hurleysoftware.com>
To: Grant Edwards <grant.b.edwards@gmail.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: API to flush rx fifo?
Date: Fri, 14 Jun 2013 13:09:56 -0400	[thread overview]
Message-ID: <51BB4E64.2000705@hurleysoftware.com> (raw)
In-Reply-To: <kpfgdu$nfb$1@ger.gmane.org>

On 06/14/2013 12:29 PM, Grant Edwards wrote:
> On 2013-06-14, Peter Hurley <peter@hurleysoftware.com> wrote:
>> On 06/14/2013 11:17 AM, Grant Edwards wrote:
>>> On 2013-06-14, Peter Hurley <peter@hurleysoftware.com> wrote:
>>>> On 06/12/2013 04:03 PM, Grant Edwards wrote:
>>>>> I see the uart_ops.flush_buffer method which is used to flush the
>>>>> UART's tx fifo (presumably when the user calls tcflush(TCOFLUSH)).
>>>>>
>>>>> How does the rx fifo get flushed when the user calls tcflush(TCIFLUSH)?
>>>>
>>>> It doesn't.
>>>
>>> Thanks.  I couldn't see any mechanism to do that, and I thought I must
>>> be missing something.
>>>
>>>> If you're seeing stale i/o, it's more likely due to the flip buffers
>>>> not being flushed
>>>
>>> Probably.  There is a scenario where you can get old data because the
>>> rx fifo isn't flushed, but I suspect it's not what my customer is
>>> complaining about.  FWIW, here's the scenario I'm worrying about:
>>>
>>>      1) Enable either RTS/CTS or Xon/Xoff flow control for a UART driver
>>>         that handles that flow control in hardware[1].
>>>
>>>      2) Stop making read() calls on the tty device.
>>>
>>>      3) The buffers in the tty layer fill up, so the uart driver stops
>>>         transferring data from the rx fifo to the tty layer.
>>>
>>>      4) The rx fifo fills up, and the flow control stops the other end
>>>         from sending data.
>>>
>>>      [all working OK up to this point, now you wait for an arbitrary
>>>      amount of time]
>>>
>>>      5) tcflush(TCIFLUSH) is called.
>>>
>>>      [data in the tty layer gets flushed, but old data in the rx
>>>       fifo remains]
>>
>> Yep. Your driver continues to push new data as it should, but that's
>> getting buffered up in the flip buffers. So that is what the app is
>> reading now that it has restarted read()s.
>>
>> Your hardware rx fifo shouldn't have stale data in it because that
>> should generate an overrun; ie., if the flip buffers cannot accept
>> data because they're full then the next char pushed when space
>> becomes available should be a NUL flagged with TTY_OVERRUN.
>
> If flow control is enabled, there should be no rx overruns -- that's
> what flow control is for.  In the scenario above, flow control is
> enabled (and working).  In order to allow the UART to handle flow
> control, the UART driver must stop reading data from the rx fifo when
> the tty layer is "full".  The documentation for the serial core API
> specifically states that UARTs are allowed to implement flow control
> in hardware, and the only way that can be done is to alow the rx fifo
> to fill up when the application stops makeing read() calls and the tty
> layer fills up.
>
> I think in newer kernels instead of explicitly checking for room in
> the tty layer before unloading the rx fifo, the UART is supposed to
> rely on the throttle/unthrottle callbacks, but the end result is the
> same: when the tty layer gets "full", the UART driver stops reading
> data from the rx fifo, and the rx fifo fills up.

AFAIK, only USB serial stops reading the rx fifo on throttle;
the serial core and other tty drivers continue to empty the rx fifo --
throttle only shuts off the transmitter on the other end.

Without handling throttle/unthrottle, how are you determining that the
tty layer is "full"?  Return code from tty_insert_flip_xxxx()?

Regards,
Peter Hurley

  reply	other threads:[~2013-06-14 17:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-12 20:03 API to flush rx fifo? Grant Edwards
2013-06-14 14:43 ` Peter Hurley
2013-06-14 15:17   ` Grant Edwards
2013-06-14 15:46     ` Peter Hurley
2013-06-14 16:29       ` Grant Edwards
2013-06-14 17:09         ` Peter Hurley [this message]
2013-06-14 17:39           ` Grant Edwards
2013-06-14 18:04             ` Peter Hurley
2013-06-14 19:12               ` Grant Edwards
2013-06-14 20:53                 ` Peter Hurley
2013-06-14 18:41             ` Grant Edwards
2013-06-14 20:19               ` Peter Hurley
2014-02-26 17:14       ` Peter Hurley
2014-02-26 17:51         ` Grant Edwards

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=51BB4E64.2000705@hurleysoftware.com \
    --to=peter@hurleysoftware.com \
    --cc=grant.b.edwards@gmail.com \
    --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 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.