[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bluetooth-dev] Re: Suggestion and question for USB bluetooth driver



On Thu, Nov 23, 2000 at 10:38:40AM +0900, mgkim@xxxxxxx.kr wrote:
> > > I have another problem that 
> > > the FTP file transfer from Digianswer PC card to USB Ericcson module to 
> > >(many calls for bluetooth_read_bulk_callback() and small calls for 
> > >bluetooth_int_callback()  are needed in this case.)    
> > >always fails ... 
> > Again, kernel debug log output would help out a lot here.  But it sounds 
> > like the Bluetooth device is getting out of sequence.  Could this be due 
> > to the data coming in on the different endpoints?
> I found that the reason is the tty buffer overflow 
> when receiving ACL packets whose size is greater than 512 bytes.
> 
>  /usr/include/linux/tty_flip.h
> _INLINE_ void tty_insert_flip_char(struct tty_struct *tty,
>                                    unsigned char ch, char flag)
> {
>         if (tty->flip.count < TTY_FLIPBUF_SIZE) {
>                 tty->flip.count++;
>                 *tty->flip.flag_buf_ptr++ = flag;
>                 *tty->flip.char_buf_ptr++ = ch;
>         } 
> }
> In the current tty implementation,   TTY_FLIPBUF_SIZE is 512.
> How about using "netlink device" instead of tty?
> The netlink device also looks like more reasonable because it can provide
> "datagram transfer" instead of "stream transfer".

Ah, I just fixed this same problem in the USB Visor driver too.  Can you
test out the attached patch and let me know if it solves this problem
for you?

As for being a netlink device, I was trying to make the driver look just
like a serial port, so that no stack changes would be necessary.  The
stack just thinks it is writing to a serial port, be it a USB device, or
a serial device.  This has enabled the driver to be used and debugged a
lot easier.  It also has allowed other companies to use the driver with
their Bluetooth stack (besides the Axis one.)

I'll take a look at your kernel logs later on this weekend.

thanks,

greg k-h

-- 
greg@xxxxxxx.com
diff -Naur -X /home/greg/linux/dontdiff linux-2.4.0-test11/drivers/usb/bluetooth.c linux-2.4.0-test11-greg/drivers/usb/bluetooth.c
--- linux-2.4.0-test11/drivers/usb/bluetooth.c	Mon Nov 20 11:10:01 2000
+++ linux-2.4.0-test11-greg/drivers/usb/bluetooth.c	Wed Nov 22 17:52:37 2000
@@ -1,11 +1,14 @@
 /*
- * bluetooth.c   Version 0.6
+ * bluetooth.c   Version 0.7
  *
  * Copyright (c) 2000 Greg Kroah-Hartman	<greg@xxxxxxx.com>
  * Copyright (c) 2000 Mark Douglas Corner	<mcorner@xxxxxxx.edu>
  *
  * USB Bluetooth driver, based on the Bluetooth Spec version 1.0B
  *
+ * (11/22/2000) Version 0.7 gkh
+ *	Fixed problem with overrunning the tty flip buffer.
+ *
  * (10/05/2000) Version 0.6 gkh
  *	Fixed bug with urb->dev not being set properly, now that the usb
  *	core needs it.
@@ -327,6 +330,11 @@
 	tty->driver_data = bluetooth;
 	bluetooth->tty = tty;
 
+	/* force low_latency on so that our tty_push actually forces the data through, 
+	 * otherwise it is scheduled, and with high data rates (like with OHCI) data
+	 * can get lost. */
+	bluetooth->tty->low_latency = 1;
+	
 	bluetooth->active = 1;
 
 	/* Reset the packet position counters */
@@ -786,9 +794,14 @@
 		return;
 	}
 
-	if (packet_size + EVENT_HDR_SIZE == bluetooth->int_packet_pos){
-		for (i = 0; i < bluetooth->int_packet_pos; ++i)
+	if (packet_size + EVENT_HDR_SIZE == bluetooth->int_packet_pos) {
+		for (i = 0; i < bluetooth->int_packet_pos; ++i) {
+			/* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them */
+			if (bluetooth->tty->flip.count >= TTY_FLIPBUF_SIZE) {
+				tty_flip_buffer_push(bluetooth->tty);
+			}
 			tty_insert_flip_char(bluetooth->tty, bluetooth->int_buffer[i], 0);
+		}
 		tty_flip_buffer_push(bluetooth->tty);
 
 		bluetooth->int_packet_pos = 0;
@@ -900,8 +913,13 @@
 	}
 
 	if (packet_size + ACL_HDR_SIZE == bluetooth->bulk_packet_pos) {
-		for (i = 0; i < bluetooth->bulk_packet_pos; ++i)
+		for (i = 0; i < bluetooth->bulk_packet_pos; ++i) {
+			/* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
+			if (bluetooth->tty->flip.count >= TTY_FLIPBUF_SIZE) {
+				tty_flip_buffer_push(bluetooth->tty);
+			}
 			tty_insert_flip_char(bluetooth->tty, bluetooth->bulk_buffer[i], 0);
+		}
 		tty_flip_buffer_push(bluetooth->tty);
 		bluetooth->bulk_packet_pos = 0;
 	}	

PGP signature