From nobody@FreeBSD.org  Thu Mar  6 08:23:09 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 674C5106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  6 Mar 2008 08:23:09 +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 5666D8FC1E
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  6 Mar 2008 08:23:09 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m268K6Lm049096
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 6 Mar 2008 08:20:06 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m268K6we049095;
	Thu, 6 Mar 2008 08:20:06 GMT
	(envelope-from nobody)
Message-Id: <200803060820.m268K6we049095@www.freebsd.org>
Date: Thu, 6 Mar 2008 08:20:06 GMT
From: Tetsuya Uemura <t_uemura@macome.co.jp>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [uart][patch]: Tune 16550A FIFO interrupt level via device.hints
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         121421
>Category:       kern
>Synopsis:       [uart][patch]: Tune 16550A FIFO interrupt level via device.hints
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    marcel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 06 08:30:00 UTC 2008
>Closed-Date:    Sat Nov 22 20:44:09 UTC 2008
>Last-Modified:  Sat Nov 22 20:44:09 UTC 2008
>Originator:     Tetsuya Uemura
>Release:        7.0-PRERELEASE
>Organization:
MACOME, Corp.
>Environment:
FreeBSD s2882g3nr.macome.co.jp 7.0-PRERELEASE FreeBSD 7.0-PRERELEASE #0: Fri Feb  1 08:56:55 JST 2008     root@s2882g3nr.macome.co.jp:/usr/obj/usr/src/sys/S2882G3NR  amd64
>Description:
I have a timing sensitive sensor device connected to the onboard 16550A clone which doesn't work correct because the 16550A FIFO interrupt latency is too large.

The latency can be reduced by lowering the FIFO interrupt level, though there is no way to do so in the stock uart(4) driver, which always set the level fairly high (FCR_RX_MEDH).

With the attached patch, the FIFO interrupt level can be changed to low (FCR_RX_LOW), fairly low (FCR_RX_MEDL) or high (FCR_RX_HIGH) by setting one of 0x100, 0x200 or 0x800 bit to hint.uart.N.flags, while the default is still FCR_RX_MEDH.

Thanks in advance.
>How-To-Repeat:
1. Establish a 9600 bps serial connection. The one is the transmitter and the other is the receiver.
2. Send 1 byte from the transmitter.
3. The receiver receives the data 5 millisecs or more after the transmitter sent it.

Most of the delay is introduced by the FIFO. The delay between the interrupt handler and the application is about or less than a few handreds of microsecs.
>Fix:
Lowering the FIFO interrupt level from the default 8 bytes to 4 or 1.

Patch attached with submission follows:

--- uart.h.orig	2007-04-03 07:00:22.000000000 +0900
+++ uart.h	2008-03-05 15:36:39.000000000 +0900
@@ -73,6 +73,10 @@
  */
 #define	UART_FLAGS_CONSOLE(f)		((f) & 0x10)
 #define	UART_FLAGS_DBGPORT(f)		((f) & 0x80)
+#define	UART_FLAGS_FCR_RX_LOW(f)	((f) & 0x100)
+#define	UART_FLAGS_FCR_RX_MEDL(f)	((f) & 0x200)
+#define	UART_FLAGS_FCR_RX_MEDH(f)	((f) & 0x400)
+#define	UART_FLAGS_FCR_RX_HIGH(f)	((f) & 0x800)
 
 /*
  * Data parity values (magical numbers related to ns8250).
--- uart_dev_ns8250.c.orig	2007-04-03 10:21:10.000000000 +0900
+++ uart_dev_ns8250.c	2008-03-05 15:45:48.000000000 +0900
@@ -382,11 +382,24 @@
 {
 	struct ns8250_softc *ns8250 = (struct ns8250_softc*)sc;
 	struct uart_bas *bas;
+	unsigned int ivar;
 
 	bas = &sc->sc_bas;
 
 	ns8250->mcr = uart_getreg(bas, REG_MCR);
-	ns8250->fcr = FCR_ENABLE | FCR_RX_MEDH;
+	ns8250->fcr = FCR_ENABLE;
+	if (!resource_int_value(
+		"uart", device_get_unit(sc->sc_dev), "flags", &ivar)) {
+		if (UART_FLAGS_FCR_RX_LOW(ivar)) 
+			ns8250->fcr |= FCR_RX_LOW;
+		else if (UART_FLAGS_FCR_RX_MEDL(ivar)) 
+			ns8250->fcr |= FCR_RX_MEDL;
+		else if (UART_FLAGS_FCR_RX_HIGH(ivar)) 
+			ns8250->fcr |= FCR_RX_HIGH;
+		else
+			ns8250->fcr |= FCR_RX_MEDH;
+	} else 
+		ns8250->fcr |= FCR_RX_MEDH;
 	uart_setreg(bas, REG_FCR, ns8250->fcr);
 	uart_barrier(bas);
 	ns8250_bus_flush(sc, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->marcel 
Responsible-Changed-By: vwe 
Responsible-Changed-When: Tue Mar 11 17:47:39 UTC 2008 
Responsible-Changed-Why:  

Over to maintainer. 
Marcel, can you please have a look into this? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121421 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/121421: commit references a PR
Date: Wed, 12 Mar 2008 19:09:26 +0000 (UTC)

 sam         2008-03-12 19:09:20 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/dev/uart         uart.h uart_dev_ns8250.c 
   Log:
   add device hints to control the rx FIFO interrupt level on 16550A parts
   
   PR:             kern/121421
   Submitted by:   UEMURA Tetsuya
   Reviewed by:    marcel
   MFC after:      2 weeks
   
   Revision  Changes    Path
   1.8       +4 -0      src/sys/dev/uart/uart.h
   1.28      +14 -1     src/sys/dev/uart/uart_dev_ns8250.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: gavin 
State-Changed-When: Wed Jun 11 13:04:28 UTC 2008 
State-Changed-Why:  
This has been fixed in HEAD and RELENG_7 but has not yet been MFC'd to 
RELENG_6 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121421 
State-Changed-From-To: patched->closed 
State-Changed-By: marcel 
State-Changed-When: Sat Nov 22 20:41:54 UTC 2008 
State-Changed-Why:  
I do not plan on adding this feature to RELENG_6. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=121421 
>Unformatted:
