From phk@critter.freebsd.dk  Mon Mar 21 15:31:43 2011
Return-Path: <phk@critter.freebsd.dk>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 67A6F106566C
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 Mar 2011 15:31:43 +0000 (UTC)
	(envelope-from phk@critter.freebsd.dk)
Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222])
	by mx1.freebsd.org (Postfix) with ESMTP id 2E2F08FC1F
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 Mar 2011 15:31:42 +0000 (UTC)
Received: from critter.freebsd.dk (critter.freebsd.dk [192.168.61.3])
	by phk.freebsd.dk (Postfix) with ESMTP id DF3AA5DF8
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 Mar 2011 15:15:08 +0000 (UTC)
Received: from critter.freebsd.dk (localhost [127.0.0.1])
	by critter.freebsd.dk (8.14.4/8.14.4) with ESMTP id p2LFF874027068
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 Mar 2011 15:15:08 GMT
	(envelope-from phk@critter.freebsd.dk)
Received: (from phk@localhost)
	by critter.freebsd.dk (8.14.4/8.14.4/Submit) id p2LFF8Ca027067;
	Mon, 21 Mar 2011 15:15:08 GMT
	(envelope-from phk)
Message-Id: <201103211515.p2LFF8Ca027067@critter.freebsd.dk>
Date: Mon, 21 Mar 2011 15:15:08 GMT
From: Poul-Henning Kamp <phk@critter.freebsd.dk>
Reply-To: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: tcdrain(3) does not work with uart(4) driver
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         155752
>Category:       kern
>Synopsis:       [uart] tcdrain(3) does not work with uart(4) driver
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 21 15:40:01 UTC 2011
>Closed-Date:    
>Last-Modified:  Tue Mar 22 00:26:30 UTC 2011
>Originator:     Poul-Henning Kamp
>Release:        FreeBSD 9.0-CURRENT amd64
>Organization:
>Environment:
System: FreeBSD critter.freebsd.dk 9.0-CURRENT FreeBSD 9.0-CURRENT #0 r218760M: Thu Feb 17 06:36:02 UTC 2011 root@critter.freebsd.dk:/usr/obj/freebsd/head/sys/CRITTER amd64

	Also affected: FreeBSD 8.1-RELEASE

>Description:

	With the change from sio(4) to uart(4), tcdrain(3) broke.

	Now tcdrain(3) only tests if the characters have been
	delivered to the uart(4) subdriver, it does not wait for
	them to have actually been sent on the wire.

	This prevents half-duplex communications with CTS/RTS from
	working.

	This contradicts both our own manpage and The Open Group
	Standards.

>How-To-Repeat:

	#define AZ(x) assert ((x) == 0)
	int j, fd;

	fd = open(),
 	makeraw() etc.
	set speed 300BPS

	j = TIOCM_RTS;
        AZ(ioctl(fd, TIOCMBIS, &j));
        assert(3 == write(fd, "FOO", 3))
        AZ(tcdrain(fd));
        AZ(ioctl(fd, TIOCMBIC, &j));

	Observe that RTS flips high + low, long before the three
	characters make it out through the TXD pin.

>Fix:

	There don't seem to be a newbus uart(4) method to ask or
	wait until all transmitted characters have been sent.

	One is obviously necessary.
>Release-Note:
>Audit-Trail:
>Unformatted:
