linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Grant Edwards <grant.b.edwards@gmail.com>
To: linux-serial@vger.kernel.org
Subject: Re: API to flush rx fifo?
Date: Fri, 14 Jun 2013 15:17:09 +0000 (UTC)	[thread overview]
Message-ID: <kpfc5k$5u4$1@ger.gmane.org> (raw)
In-Reply-To: 51BB2C2A.9050601@hurleysoftware.com

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]
   
   6) Now that there's room for more rx data in the tty layer, the
      uart driver resumes transferring (old) data from the rx fifo to
      the tty layer.

   7) read() is called and returns data that was received an arbitrary
      amount of time before tcflush(TCIFLUSH) was called.

My "old" drivers that interfaced directly with the tty layer handled
this scenario, but those drivers were becoming unmaintainable because
of instability of the tty API over the range of kernel versions I
support. So, I converted them over to be "uart drivers" for the common
serial layer which has a much more stable API (and generally requires
much less code). Now I've got a customer complaining about not being
able to flush data, so I'm looking closer at how the tcflush() calls
are handled.

[1] Because of a bug in the serial-driver layer's handling of the
    setting of Xon/Xoff characters by the settermios() call, it's not
    possible to correctly use Xon/Xoff support in a UART for the case
    where the user wants to use non-default Xon/Xoff characters.

-- 
Grant Edwards               grant.b.edwards        Yow! I feel ... JUGULAR ...
                                  at               
                              gmail.com            


  reply	other threads:[~2013-06-14 15:17 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 [this message]
2013-06-14 15:46     ` Peter Hurley
2013-06-14 16:29       ` Grant Edwards
2013-06-14 17:09         ` Peter Hurley
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='kpfc5k$5u4$1@ger.gmane.org' \
    --to=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 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).