Skip to contentSkip to conversation

fix for kernel flow control patch mh7

PATCH In review Zsolt Barat 2 participants 4 messages Dec 5, 2006 – Dec 7, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix for kernel flow control patch mh7

hi list,
attached is a trivially fixed version of the flow-control-patch mh7, which could be found on
http://bluetooth-alsa.sf.net/bluez-sco-flowcontrol-mh7.patch
to work with gentoo-suspend2-sources and linux-2.6.18-vanilla. i don't know which kernel-version it supposed to be apply. would be nice to mention it on the website somewhere.
i tested till 2.6.18.3 and there is always a tiny mismatch in hci_event.c in function hci_cc_info_param:
static void hci_cc_info_param(struct hci_dev *hdev, __u16 ocf, struct sk_buff *skb)

{
	struct hci_rp_read_local_features *lf;
	struct hci_rp_read_buffer_size *bs;
	struct hci_rp_read_bd_addr *ba;

	BT_DBG("%s ocf 0x%x", hdev->name, ocf);

	switch (ocf) {
	case OCF_READ_LOCAL_FEATURES:
		lf = (struct hci_rp_read_local_features *) skb->data;

		if (lf->status) {
			BT_DBG("%s READ_LOCAL_FEATURES failed %d", hdev->name, lf->status);
			break;
		}

the original patch wants to rename lf->status to lv->status, which was a bug probably but in vanilla sources it's done other ways and the struct is renamed.
so nothing serious, just that it a applies cleanly.

regards

zsolt

include/net/bluetooth/hci_core.h +26 -7
diff -urN linux-2.6.18-mh7/include/net/bluetooth/hci_core.h linux-2.6.18-mh7-sco/include/net/bluetooth/hci_core.h
@@ -25,6 +25,8 @@
 #ifndef __HCI_CORE_H
 #define __HCI_CORE_H
 
+#include <linux/hrtimer.h>
+
 #include <net/bluetooth/hci.h>
 
 /* HCI upper protocols */
@@ -88,12 +90,18 @@
 	unsigned long	quirks;
 
 	atomic_t	cmd_cnt;
+	/* Number of available controller buffers for ACL packets */
 	unsigned int	acl_cnt;
-	unsigned int	sco_cnt;
+	/* Number of available controller buffers for SCO packets */
+	atomic_t	sco_cnt;
 
+	/* Maximum transmition unit for ACL packets */
 	unsigned int	acl_mtu;
+	/* Maximum transmition unit for SCO packets */
 	unsigned int	sco_mtu;
+	/* Maximum number of ACL packets the controller is able to buffer */
 	unsigned int	acl_pkts;
+	/* Maximum number of SCO packets the controller is able to buffer */
 	unsigned int	sco_pkts;
 
 	unsigned long	cmd_last_tx;
@@ -145,7 +153,6 @@
 	struct list_head list;
 
 	atomic_t	 refcnt;
-	spinlock_t	 lock;
 
 	bdaddr_t	 dst;
 	__u16		 handle;
@@ -162,10 +169,19 @@
 	__u8             power_save;
 	unsigned long	 pend;
 
-	unsigned int	 sent;
-
-	struct sk_buff_head data_q;
-
+	/* sent represents the number of packets this connections
+           has "on the wire" : .... oh f.... there are no wire
+           with bluetooth. By on the wire, i mean packets that have been sent
+	   to the HCI device, and that are still in its buffers */
+	atomic_t	 sent;
+
+	struct sk_buff_head out_q;
+	/* This is only used for SCO for now */
+	void (*pkt_sent_cb)(struct hci_conn *conn);
+
+	/* tx timer : used only for SCO */
+	struct hrtimer tx_timer;
+	/* Disconnect timer */
 	struct timer_list disc_timer;
 	struct timer_list idle_timer;
 
@@ -614,7 +630,10 @@
 
 int hci_send_cmd(struct hci_dev *hdev, __u16 ogf, __u16 ocf, __u32 plen, void *param);
 int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
-int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
+int hci_send_sco(struct hci_conn *conn, 
+			struct sk_buff *skb, 
+			int sndbufsize, 
+			void (*send_complete_cb)(struct hci_conn *conn));
 
 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 ogf, __u16 ocf);
 
include/net/bluetooth/hci_core.h~ +661 -0

661 lines not on this page · raw message

include/net/bluetooth/hci.h +7 -0
diff -urN linux-2.6.18-mh7/include/net/bluetooth/hci.h linux-2.6.18-mh7-sco/include/net/bluetooth/hci.h
@@ -767,6 +767,9 @@
 	__u32 byte_tx;
 };
 
+/* Fields down there are mostly the same as hci_dev,
+   as this structure is meant to communicate info
+   to userspace */
 struct hci_dev_info {
 	__u16 dev_id;
 	char  name[8];
@@ -782,9 +785,13 @@
 	__u32 link_policy;
 	__u32 link_mode;
 
+	/* Maximum transmition unit for ACL packets */
 	__u16 acl_mtu;
+	/* Number of ACL packets the baseband is able to buffer */
 	__u16 acl_pkts;
+	/* Maximum transmition unit for SCO packets */
 	__u16 sco_mtu;
+	/* Number of SCO packets the baseband is able to buffer */
 	__u16 sco_pkts;
 
 	struct hci_dev_stats stat;
include/net/bluetooth/sco.h +3 -5
diff -urN linux-2.6.18-mh7/include/net/bluetooth/sco.h linux-2.6.18-mh7-sco/include/net/bluetooth/sco.h
@@ -26,12 +26,7 @@
 #define __SCO_H
 
 /* SCO defaults */
-#define SCO_DEFAULT_MTU		500
-#define SCO_DEFAULT_FLUSH_TO	0xFFFF
-
 #define SCO_CONN_TIMEOUT	(HZ * 40)
-#define SCO_DISCONN_TIMEOUT	(HZ * 2)
-#define SCO_CONN_IDLE_TIMEOUT	(HZ * 60)
 
 /* SCO socket address */
 struct sockaddr_sco {
@@ -51,6 +46,9 @@
 	__u8  dev_class[3];
 };
 
+#define SCO_TXBUFS	0x03
+#define SCO_RXBUFS	0x04
+
 /* ---- SCO connections ---- */
 struct sco_conn {
 	struct hci_conn	*hcon;
net/bluetooth/hci_conn.c +9 -3
diff -urN linux-2.6.18-mh7/net/bluetooth/hci_conn.c linux-2.6.18-mh7-sco/net/bluetooth/hci_conn.c
@@ -184,7 +184,10 @@
 
 	conn->power_save = 1;
 
-	skb_queue_head_init(&conn->data_q);
+	conn->pkt_sent_cb = NULL;
+	skb_queue_head_init(&conn->out_q);
+
+	hrtimer_init(&conn->tx_timer, CLOCK_MONOTONIC, HRTIMER_NORESTART);
 
 	init_timer(&conn->disc_timer);
 	conn->disc_timer.function = hci_conn_timeout;
@@ -195,6 +198,7 @@
 	conn->idle_timer.data = (unsigned long) conn;
 
 	atomic_set(&conn->refcnt, 0);
+	atomic_set(&conn->sent, 0);
 
 	hci_dev_hold(hdev);
 
@@ -221,6 +225,8 @@
 
 	del_timer(&conn->disc_timer);
 
+	hrtimer_cancel(&conn->tx_timer);
+
 	if (conn->type == SCO_LINK) {
 		struct hci_conn *acl = conn->link;
 		if (acl) {
@@ -233,7 +239,7 @@
 			sco->link = NULL;
 
 		/* Unacked frames */
-		hdev->acl_cnt += conn->sent;
+		hdev->acl_cnt += atomic_read(&conn->sent);
 	}
 
 	tasklet_disable(&hdev->tx_task);
@@ -246,7 +252,7 @@
 
 	tasklet_enable(&hdev->tx_task);
 
-	skb_queue_purge(&conn->data_q);
+	skb_queue_purge(&conn->out_q);
 
 	hci_dev_put(hdev);
 
net/bluetooth/hci_core.c +120 -50

272 lines not on this page · raw message

net/bluetooth/hci_event.c +6 -6
diff -urN linux-2.6.18-mh7/net/bluetooth/hci_event.c linux-2.6.18-mh7-sco/net/bluetooth/hci_event.c
@@ -372,7 +372,7 @@
 		}
 
 		hdev->acl_cnt = hdev->acl_pkts;
-		hdev->sco_cnt = hdev->sco_pkts;
+		atomic_set(&hdev->sco_cnt, hdev->sco_pkts);
 
 		BT_DBG("%s mtu: acl %d, sco %d max_pkt: acl %d, sco %d", hdev->name,
 			hdev->acl_mtu, hdev->sco_mtu, hdev->acl_pkts, hdev->sco_pkts);
@@ -861,15 +861,15 @@
 
 		conn = hci_conn_hash_lookup_handle(hdev, handle);
 		if (conn) {
-			conn->sent -= count;
+			atomic_sub(count, &conn->sent);
 
-			if (conn->type == SCO_LINK) {
-				if ((hdev->sco_cnt += count) > hdev->sco_pkts)
-					hdev->sco_cnt = hdev->sco_pkts;
-			} else {
+			if (conn->type == ACL_LINK) {
 				if ((hdev->acl_cnt += count) > hdev->acl_pkts)
 					hdev->acl_cnt = hdev->acl_pkts;
 			}
+			/* Note : we do not use the "number of completed packets" event
+			to increment hdev->sco_cnt, as this feature is only optionnally support
+			by bluetooth controllers. So there is no if branch for SCO_LINK packets */
 		}
 	}
 	hci_sched_tx(hdev);
net/bluetooth/sco.c +149 -14

264 lines not on this page · raw message

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

#1 lore raw

Zsolt

Quoted 6 lines

attached is a trivially fixed version of the flow-control-patch mh7, which could be found on
http://bluetooth-alsa.sf.net/bluez-sco-flowcontrol-mh7.patch
to work with gentoo-suspend2-sources and linux-2.6.18-vanilla. i don't know which kernel-version it supposed to be apply. would be nice to mention it on the website somewhere.

I've linked to Fabien's latest submission and linked to the bluez patch page. Fabien's patch is against -mh7 but I will try it against -mh8 to se if there are any conflicts.

It would be good to know if suspend2 patches complicate things. I don't use suspend2 myself.

Brad

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

#2 lore raw
Quoted 9 lines · Brad Midgley

Zsolt

Quoted 6 lines

attached is a trivially fixed version of the flow-control-patch mh7, which could be found on
http://bluetooth-alsa.sf.net/bluez-sco-flowcontrol-mh7.patch
to work with gentoo-suspend2-sources and linux-2.6.18-vanilla. i don't know which kernel-version it supposed to be apply. would be nice to mention it on the website somewhere.

Quoted 3 lines

I've linked to Fabien's latest submission and linked to the bluez patch page. Fabien's patch is against -mh7 but I will try it against -mh8 to se if there are any conflicts.

ah, ok now i understand. mh is an extra patch set. i thought mh is already fabians private patch set.
then all is probably wrong.
nevertheless with the small fix above the flow-control patch applies also against 2.6.18 with suspend2-patches and even to 2.6.18-vanilla. if it has any use it's another question.
what i can say for sure is that with the flow-control-patch sco and the alsa-plugin layer works. i had to figure out to do resampling and channel-routing right to get it work. but it was after i applied the patch. btw. the setup with the kernel module is much easier in this regard.

Quoted 3 lines

It would be good to know if suspend2 patches complicate things. I don't use suspend2 myself.

no, no complications so far. i think suspend2 doesn't touch this areas where flow-control is involved. i have the kernel running on my notebook since i posted the patch. suspend+resume works fine.

regards

zsolt

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

#3 lore raw

i tried also 2.6.18-mh8 now. it apllies cleanly and works. the order i applied the patches where:
for gentoo:
4410-suspend2-2.2.8-for-2.6.18.patch 4411-x86_64-nosave.patch

patch-2.6.18-mh8
bluez-sco-flowcontrol-mh7.patch (without fix)

the two gentoo patches forms the suspend2-source. if someone wants to build a non-suspen2/non-gentoo kernel he has to apply the two latest ones naturally.
this would be the safest way to apply the flow-controll patch i think, since it implies the mh-patch-set.

regards

zsolt

Quoted 34 lines · Zsolt Barat
Quoted 11 lines · Brad Midgley

Zsolt

Quoted 6 lines

attached is a trivially fixed version of the flow-control-patch mh7, which could be found on
http://bluetooth-alsa.sf.net/bluez-sco-flowcontrol-mh7.patch
to work with gentoo-suspend2-sources and linux-2.6.18-vanilla. i don't know which kernel-version it supposed to be apply. would be nice to mention it on the website somewhere.

I've linked to Fabien's latest submission and linked to the bluez patch page. Fabien's patch is against -mh7 but I will try it against -mh8 to se if there are any conflicts.

ah, ok now i understand. mh is an extra patch set. i thought mh is already fabians private patch set.
then all is probably wrong.
nevertheless with the small fix above the flow-control patch applies also against 2.6.18 with suspend2-patches and even to 2.6.18-vanilla. if it has any use it's another question.
what i can say for sure is that with the flow-control-patch sco and the alsa-plugin layer works. i had to figure out to do resampling and channel-routing right to get it work. but it was after i applied the patch. btw. the setup with the kernel module is much easier in this regard.

Quoted 2 lines

It would be good to know if suspend2 patches complicate things. I don't use suspend2 myself.

no, no complications so far. i think suspend2 doesn't touch this areas where flow-control is involved. i have the kernel running on my notebook since i posted the patch. suspend+resume works fine.

regards

zsolt

Quoted 9 lines

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users