From nobody@FreeBSD.org Sun Aug 15 14:31:21 2010 Return-Path: Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 513E51065673 for ; Sun, 15 Aug 2010 14:31:21 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 409418FC12 for ; Sun, 15 Aug 2010 14:31:21 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o7FEVKxG026530 for ; Sun, 15 Aug 2010 14:31:20 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o7FEVKS0026529; Sun, 15 Aug 2010 14:31:20 GMT (envelope-from nobody) Message-Id: <201008151431.o7FEVKS0026529@www.freebsd.org> Date: Sun, 15 Aug 2010 14:31:20 GMT From: Paul Thornton To: freebsd-gnats-submit@FreeBSD.org Subject: uftdi doesn't react to break properly X-Send-Pr-Version: www-3.1 X-GNATS-Notify: >Number: 149675 >Category: usb >Synopsis: [uftdi] [usb_serial] doesn't react to break properly >Confidential: no >Severity: non-critical >Priority: medium >Responsible: thompsa >State: patched >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Aug 15 14:40:00 UTC 2010 >Closed-Date: >Last-Modified: Tue Mar 01 10:22:58 EST 2011 >Originator: Paul Thornton >Release: 8.1-RELEASE >Organization: >Environment: FreeBSD base01.local 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Sun Aug 15 09:38:55 UTC 2010 root@base01.local:/usr/src/sys/i386/compile/TEST2 i386 The same issue is seen with GENERIC kernel >Description: When setting the BRKINT and ~IGNBRK options on a handle where the underlying hardware has an FTDI chipset driven by uftdi and ucom, the break condition is not correctly acted upon. The underlying hardware is an FTDI FT232BL chip. The expected behaviour is that the buffer be flushed on reception of a break when BRKINT is used, however the driver appears to behave as if BRKINT is clear, as an additional 0x00 byte is seen and the buffer isn't flushed. FreeBSD 7.2 and 8.0 also exhibit the same behaviour. Using the same test program, and same USB hardware, Linux behaves as per documentation and flushes the buffer on reception of the break when BRKINT is set. >How-To-Repeat: Connect two machines using ftdi-driven hardware. Send a break followed by some data A. Send another break, followed by some data B. The correct response should be that on the receiver the buffer is flushed by both breaks, and a read will only return the data B. What is likely to be read, however, is: 0x00 [A A A A A] 0x00 [B B B B B] The code I was using which brought this issue to light can be downloaded from: http://www.prt.org/dmxrx2.c >Fix: >Release-Note: >Audit-Trail: From: Hans Petter Selasky To: freebsd-usb@freebsd.org Cc: Paul Thornton , freebsd-gnats-submit@freebsd.org Subject: Re: usb/149675: uftdi doesn't react to break properly Date: Sun, 15 Aug 2010 17:11:56 +0200 Hi, Compile a kernel with "options USB_DEBUG". Enable FTDI debugging: sysctl hw.usb.uftdi.debug=15 Do you seen any debug prints when sending BREAK? --HPS From: Ed Schouten To: bug-followup@FreeBSD.org, prt@prt.org, hselasky@c2i.net Cc: Subject: Re: usb/149675: uftdi doesn't react to break properly Date: Sun, 15 Aug 2010 18:02:40 +0200 --wr1Q/2bz0MCWWNYv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hans, Paul, I just looked at the usb_serial.c source code and it seems break/parity conditions are never propagated to the TTY layer: if (ttydisc_rint(tp, buf[cnt], 0) =3D=3D -1) { The third argument is supposed to be a bitmask of TRE_FRAMING, TRE_PARITY, TRE_OVERRUN and TRE_BREAK, to indicate the type of transmission error/condition. This is why breaks are probably just received as zero-bytes. --=20 Ed Schouten WWW: http://80386.nl/ --wr1Q/2bz0MCWWNYv Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (FreeBSD) iEYEARECAAYFAkxoD6AACgkQ52SDGA2eCwWfegCeLUhVFlBv4Khtv99m2XHXsqqI GpwAn2wJturYMHd40W+kVGafw8Pkv2iu =Rmbv -----END PGP SIGNATURE----- --wr1Q/2bz0MCWWNYv-- From: Hans Petter Selasky To: freebsd-usb@freebsd.org Cc: Paul Thornton , freebsd-gnats-submit@freebsd.org, ed@freebsd.org Subject: Re: usb/149675: uftdi doesn't react to break properly Date: Sun, 15 Aug 2010 19:47:04 +0200 Hi, I believe the following patch will fix your problem. Please apply and rebuild kernel / ucom module. --HPS --- sys/dev/usb/serial/usb_serial.c +++ sys/dev/usb/serial/usb_serial.c @@ -942,6 +942,7 @@ uint8_t new_msr; uint8_t new_lsr; uint8_t onoff; + uint8_t lsr_delta; tp = sc->sc_tty; @@ -965,6 +966,7 @@ return; } onoff = ((sc->sc_msr ^ new_msr) & SER_DCD); + lsr_delta = (sc->sc_lsr ^ new_lsr); sc->sc_msr = new_msr; sc->sc_lsr = new_lsr; @@ -977,6 +979,27 @@ ttydisc_modem(tp, onoff); } + + if ((lsr_delta & ULSR_BI) && (sc->sc_lsr & ULSR_BI)) { + + DPRINTF("BREAK detected\n"); + + ttydisc_rint(tp, 0, TRE_BREAK); + } + + if ((lsr_delta & ULSR_FE) && (sc->sc_lsr & ULSR_FE)) { + + DPRINTF("Frame error detected\n"); + + ttydisc_rint(tp, 0, TRE_FRAMING); + } + + if ((lsr_delta & ULSR_PE) && (sc->sc_lsr & ULSR_PE)) { + + DPRINTF("Parity error detected\n"); + + ttydisc_rint(tp, 0, TRE_PARITY); + } } void See USB P4 change ID 182430 for more details. http://p4web.freebsd.org/@@182430?ac=10 From: Hans Petter Selasky To: freebsd-usb@freebsd.org Cc: Paul Thornton , freebsd-gnats-submit@freebsd.org, ed@freebsd.org Subject: Re: usb/149675: uftdi doesn't react to break properly Date: Sun, 15 Aug 2010 19:54:17 +0200 And this patch, which I'm not sure is needed. See USB P4 change ID 182431 for more details. http://p4web.freebsd.org/@@182431?ac=10 Ed, can you comment? --HPS From: Hans Petter Selasky To: Paul Thornton Cc: freebsd-usb@freebsd.org, freebsd-gnats-submit@freebsd.org, ed@freebsd.org Subject: Re: usb/149675: uftdi doesn't react to break properly Date: Sun, 15 Aug 2010 21:11:59 +0200 I guess you will have to turn on ucom and uftdi debugging knobs under hw.usb.xxx to figure that out. USB is just forwarding what it gets from the hardware. --HPS From: Paul Thornton To: Hans Petter Selasky Cc: freebsd-usb@freebsd.org, freebsd-gnats-submit@freebsd.org, ed@freebsd.org Subject: Re: usb/149675: uftdi doesn't react to break properly Date: Sun, 15 Aug 2010 19:57:44 +0100 Hi, Hans Petter Selasky wrote: > I believe the following patch will fix your problem. Please apply and rebuild > kernel / ucom module. That has made a dramatic difference - things now look much better. Thank you very much for that. I'm still seeing a slight problem though. In my test setup, I have a PC (Windows but that shouldn't matter!) running an appplication which transmits a break followed by the 513 data bytes - and this repeats continually at near line-rate at 250kbaud. Pre-patching, FreeBSD was unable to keep data byte 1 in location 1 at all - it appeared randomly wherever it happened to be due to the lack of break clearing the input buffer, and as the data dump of the buffer refreshed, the values moved around as the breaks were turning up as datab. After I've applied the patch, it starts off well - data byte 1 is in location 1, but every 5-10 seconds there is a shift by a byte suggesting that an extra byte has been received. Is there any way that a break could still be creeping in to the data stream periodically? Under Linux, the code runs properly and there is no movement of the data bytes, so I'm reasonably confident that it isn't a bug of mine. Paul. From: Ed Schouten To: Hans Petter Selasky Cc: freebsd-usb@freebsd.org, Paul Thornton , freebsd-gnats-submit@freebsd.org Subject: Re: usb/149675: uftdi doesn't react to break properly Date: Mon, 16 Aug 2010 02:09:24 +0200 --PY8tzLeNxmyMVNR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Both patches look good! --=20 Ed Schouten WWW: http://80386.nl/ --PY8tzLeNxmyMVNR3 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (FreeBSD) iEYEARECAAYFAkxogbQACgkQ52SDGA2eCwVsQACfUXGH8krzk6oBZIJw+kcoUXXE iEEAni8hMmlWZ7eOGwVN0G+yGqzqfx+o =WpY0 -----END PGP SIGNATURE----- --PY8tzLeNxmyMVNR3-- From: dfilter@FreeBSD.ORG (dfilter service) To: bug-followup@FreeBSD.org Cc: Subject: Re: usb/149675: commit references a PR Date: Thu, 14 Oct 2010 21:45:48 +0000 (UTC) Author: hselasky Date: Thu Oct 14 21:45:41 2010 New Revision: 213872 URL: http://svn.freebsd.org/changeset/base/213872 Log: Fix forwarding of Line Register Status changes to TTY layer. PR: usb/149675 Approved by: thompsa (mentor) Modified: head/sys/dev/usb/serial/usb_serial.c Modified: head/sys/dev/usb/serial/usb_serial.c ============================================================================== --- head/sys/dev/usb/serial/usb_serial.c Thu Oct 14 21:41:08 2010 (r213871) +++ head/sys/dev/usb/serial/usb_serial.c Thu Oct 14 21:45:41 2010 (r213872) @@ -942,6 +942,7 @@ ucom_cfg_status_change(struct usb_proc_m uint8_t new_msr; uint8_t new_lsr; uint8_t onoff; + uint8_t lsr_delta; tp = sc->sc_tty; @@ -965,6 +966,7 @@ ucom_cfg_status_change(struct usb_proc_m return; } onoff = ((sc->sc_msr ^ new_msr) & SER_DCD); + lsr_delta = (sc->sc_lsr ^ new_lsr); sc->sc_msr = new_msr; sc->sc_lsr = new_lsr; @@ -977,6 +979,30 @@ ucom_cfg_status_change(struct usb_proc_m ttydisc_modem(tp, onoff); } + + if ((lsr_delta & ULSR_BI) && (sc->sc_lsr & ULSR_BI)) { + + DPRINTF("BREAK detected\n"); + + ttydisc_rint(tp, 0, TRE_BREAK); + ttydisc_rint_done(tp); + } + + if ((lsr_delta & ULSR_FE) && (sc->sc_lsr & ULSR_FE)) { + + DPRINTF("Frame error detected\n"); + + ttydisc_rint(tp, 0, TRE_FRAMING); + ttydisc_rint_done(tp); + } + + if ((lsr_delta & ULSR_PE) && (sc->sc_lsr & ULSR_PE)) { + + DPRINTF("Parity error detected\n"); + + ttydisc_rint(tp, 0, TRE_PARITY); + ttydisc_rint_done(tp); + } } void _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org" From: dfilter@FreeBSD.ORG (dfilter service) To: bug-followup@FreeBSD.org Cc: Subject: Re: usb/149675: commit references a PR Date: Sun, 28 Nov 2010 07:28:18 +0000 (UTC) Author: thompsa Date: Sun Nov 28 07:28:10 2010 New Revision: 215986 URL: http://svn.freebsd.org/changeset/base/215986 Log: MFC r213872 Fix forwarding of Line Register Status changes to TTY layer. PR: usb/149675 Modified: stable/8/sys/dev/usb/serial/usb_serial.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) Modified: stable/8/sys/dev/usb/serial/usb_serial.c ============================================================================== --- stable/8/sys/dev/usb/serial/usb_serial.c Sun Nov 28 07:23:05 2010 (r215985) +++ stable/8/sys/dev/usb/serial/usb_serial.c Sun Nov 28 07:28:10 2010 (r215986) @@ -942,6 +942,7 @@ ucom_cfg_status_change(struct usb_proc_m uint8_t new_msr; uint8_t new_lsr; uint8_t onoff; + uint8_t lsr_delta; tp = sc->sc_tty; @@ -965,6 +966,7 @@ ucom_cfg_status_change(struct usb_proc_m return; } onoff = ((sc->sc_msr ^ new_msr) & SER_DCD); + lsr_delta = (sc->sc_lsr ^ new_lsr); sc->sc_msr = new_msr; sc->sc_lsr = new_lsr; @@ -977,6 +979,30 @@ ucom_cfg_status_change(struct usb_proc_m ttydisc_modem(tp, onoff); } + + if ((lsr_delta & ULSR_BI) && (sc->sc_lsr & ULSR_BI)) { + + DPRINTF("BREAK detected\n"); + + ttydisc_rint(tp, 0, TRE_BREAK); + ttydisc_rint_done(tp); + } + + if ((lsr_delta & ULSR_FE) && (sc->sc_lsr & ULSR_FE)) { + + DPRINTF("Frame error detected\n"); + + ttydisc_rint(tp, 0, TRE_FRAMING); + ttydisc_rint_done(tp); + } + + if ((lsr_delta & ULSR_PE) && (sc->sc_lsr & ULSR_PE)) { + + DPRINTF("Parity error detected\n"); + + ttydisc_rint(tp, 0, TRE_PARITY); + ttydisc_rint_done(tp); + } } void _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org" State-Changed-From-To: open->patched State-Changed-By: eadler State-Changed-When: Tue Mar 1 10:15:22 EST 2011 State-Changed-Why: committed in head and MFCed to 8 but not 7 http://www.freebsd.org/cgi/query-pr.cgi?pr=149675 Responsible-Changed-From-To: freebsd-usb->thompsa Responsible-Changed-By: eadler Responsible-Changed-When: Tue Mar 1 10:22:57 EST 2011 Responsible-Changed-Why: same as above http://www.freebsd.org/cgi/query-pr.cgi?pr=149675 >Unformatted: