Date: Tue, 09 Dec 2008 11:52:31 -0500 From: Mike Tancsa <mike@sentex.net> To: freebsd-usb@freebsd.org Subject: uftdi buffer size and latency Message-ID: <200812091652.mB9GqWSk048070@lava.sentex.ca>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812091652.mB9GqWSk048070>