From owner-freebsd-usb@FreeBSD.ORG Tue Dec 9 16:52:37 2008 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10E541065670 for ; Tue, 9 Dec 2008 16:52:37 +0000 (UTC) (envelope-from mike@sentex.net) Received: from smarthost1.sentex.ca (smarthost1.sentex.ca [64.7.153.18]) by mx1.freebsd.org (Postfix) with ESMTP id B7A128FC12 for ; Tue, 9 Dec 2008 16:52:36 +0000 (UTC) (envelope-from mike@sentex.net) Received: from lava.sentex.ca (pyroxene.sentex.ca [199.212.134.18]) by smarthost1.sentex.ca (8.14.3/8.14.3) with ESMTP id mB9GqXFE050386 for ; Tue, 9 Dec 2008 11:52:34 -0500 (EST) (envelope-from mike@sentex.net) Received: from mdt-xp.sentex.net (simeon.sentex.ca [192.168.43.27]) by lava.sentex.ca (8.13.8/8.13.3) with ESMTP id mB9GqWSk048070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 9 Dec 2008 11:52:32 -0500 (EST) (envelope-from mike@sentex.net) Message-Id: <200812091652.mB9GqWSk048070@lava.sentex.ca> X-Mailer: QUALCOMM Windows Eudora Version 7.1.0.9 Date: Tue, 09 Dec 2008 11:52:31 -0500 To: freebsd-usb@freebsd.org From: Mike Tancsa Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Scanned-By: MIMEDefang 2.64 on 64.7.153.18 Subject: uftdi buffer size and latency X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Dec 2008 16:52:37 -0000 Hi, Based on what we found in http://lists.freebsd.org/pipermail/freebsd-current/2008-December/001052.html I hacked up the following patch to uftdi which allows the recv/xmit buffer size to be tuned at bootup time. This allows our app which is low speed (1200bps), but very timing sensitive to work using a usb serial adaptor based on the uftdi chipset. For us, adding hint.uftdi.0.buffersize="9" to /boot/device.hints does the trick. Is there a better way to do this ? Are there any other side effects anyone can think of ? --- sys/dev/usb/uftdi.c.orig 2008-12-09 11:47:02.000000000 -0500 +++ sys/dev/usb/uftdi.c 2008-12-09 11:47:05.000000000 -0500 @@ -198,6 +198,7 @@ usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; int i; + unsigned int ivar; usbd_status err; struct ucom_softc *ucom = &sc->sc_ucom; DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc)); @@ -353,11 +354,27 @@ ucom->sc_portno = FTDI_PIT_SIOA; else ucom->sc_portno = FTDI_PIT_SIOA + id->bInterfaceNumber; - /* bulkin, bulkout set above */ - ucom->sc_ibufsize = UFTDIIBUFSIZE; - ucom->sc_obufsize = UFTDIOBUFSIZE - sc->sc_hdrlen; - ucom->sc_ibufsizepad = UFTDIIBUFSIZE; + /* For certain low speed / timing sensitive applications having the buffers too large causes + data to be stuck in the queue too long. By adding a tuneable, users can lower the buffer + size to what works for their application + */ + + if (!resource_int_value( + "uftdi", device_get_unit(ucom->sc_dev), "buffersize", &ivar) && (ivar > sc->sc_hdrlen && ivar <= UFTDIIBUFSIZE) ) { + ucom->sc_ibufsize = ivar; + ucom->sc_obufsize = ivar - sc->sc_hdrlen; + ucom->sc_ibufsizepad = ivar;; + device_printf(ucom->sc_dev, "Setting buffers to %d\n",ivar); + } + else + { + ucom->sc_ibufsize = UFTDIIBUFSIZE; + ucom->sc_obufsize = UFTDIOBUFSIZE - sc->sc_hdrlen; + ucom->sc_ibufsizepad = UFTDIIBUFSIZE; + device_printf(ucom->sc_dev, "Setting buffers to default of %d\n",UFTDIIBUFSIZE); + + } ucom->sc_opkthdrlen = sc->sc_hdrlen; ---Mike -------------------------------------------------------------------- Mike Tancsa, tel +1 519 651 3400 Sentex Communications, mike@sentex.net Providing Internet since 1994 www.sentex.net Cambridge, Ontario Canada www.sentex.net/mike